import Ionicons from "@expo/vector-icons/Ionicons";
import React from "react";
import { Text, View } from "react-native";
import { IoniconsType } from "../../lib/types";

type AsyncContentProps = {
  isLoading: boolean;
  isVisible?: boolean;
  loadingIcon: IoniconsType;
  loadingText?: string;
  children?: React.ReactNode;
};
export function AsyncContent({
  isLoading,
  isVisible = true,
  loadingIcon = "scan-outline",
  loadingText = "Yükleniyor",
  children,
}: AsyncContentProps) {
  if (!isVisible) {
    return null;
  }
  if (isLoading) {
    return (
      <View className="flex-1 items-center justify-center">
        <View className="animate-bounce items-center justify-center">
          <Ionicons
            name={loadingIcon}
            size={50}
            color="black"
            className=""
          />
          <Text className="text-center text-2xl font-bold">
            {loadingText}
          </Text>
        </View>
      </View>
    );
  }

  return children;
}
