import React from 'react';
import PaystackContext from './paystack-context';
import usePaystackPayment from './use-paystack';
import {PaystackProps, PaystackCallbacks} from './types';

interface PaystackProviderProps extends PaystackProps, PaystackCallbacks {
  children: JSX.Element;
}

const PaystackProvider = ({
  children,
  onSuccess,
  onCancel,
  onClose,
  onError,
  onLoad,
  ...config
}: PaystackProviderProps): JSX.Element => {
  const initializePayment = usePaystackPayment(config);

  return (
    <PaystackContext.Provider value={{config, initializePayment, onSuccess, onCancel, onClose, onLoad, onError}}>
      {children}
    </PaystackContext.Provider>
  );
};

export default PaystackProvider;
