/** @format */

import { StripeConfigTypes } from "@/types/payment";
import { StripeProvider } from "@stripe/stripe-react-native";
import React from "react";
import { ActivityIndicator } from "react-native";
import StripeCheckoutForm from "./StripeCheckoutForm";

type StripeProps = {
  config: StripeConfigTypes | null;
  setShowCheckoutModal: React.Dispatch<React.SetStateAction<boolean>>;
};

const Stripe: React.FC<StripeProps> = ({ config, setShowCheckoutModal }) => {
  if (!config || !config.public_key || !config.client_secret) {
    return <ActivityIndicator size="large" color="#000000" />;
  }

  return (
    <StripeProvider publishableKey={config.public_key}>
      <StripeCheckoutForm
        clientSecret={config.client_secret}
        setShowCheckoutModal={setShowCheckoutModal}
      />
    </StripeProvider>
  );
};

export default Stripe;
