import type {
    ApplePayElement,
    BankElement,
    IframeElementEventMap,
    CardElement,
    FramePay as FramepayApi,
    GooglePayElement,
    IbanElement,
    PayPalElement,
    SamsungPayElement,
} from '@rebilly/framepay';

/**
 * framepay-react react element types
 */
interface FramepayProps extends FramepayApi {
    readonly error: FramePayErrorCode | null;
    readonly ready: boolean;
}

interface PaymentComponentProps extends FramepayProps {
    readonly Framepay: FramepayProps;
    readonly id?: string;
    readonly onReady?: () => void;
    readonly onChange?: (data: IframeElementEventMap['change'][0]) => void;
    readonly onFocus?: () => void;
    readonly onBlur?: () => void;
}

interface PaymentComponentState {
    readonly element:
        | null
        | BankElement
        | CardElement
        | ApplePayElement
        | GooglePayElement
        | IbanElement
        | PayPalElement
        | SamsungPayElement;
    readonly mounted: boolean;
    readonly ready: boolean;
}

interface BankProps extends PaymentComponentProps {
    readonly Framepay: FramepayProps;
    readonly elementType:
        | 'bankAccountType'
        | 'bankAccountNumber'
        | 'bankRoutingNumber';
}

interface IBANProps extends PaymentComponentProps {
    readonly Framepay: FramepayProps;
    readonly elementType: 'iban';
}

interface CardProps extends PaymentComponentProps {
    readonly Framepay: FramepayProps;
    readonly elementType?: 'cardNumber' | 'cardCvv' | 'cardExpiration';
}

interface ApplePayProps extends FramepayProps {
    readonly Framepay: FramepayProps;
    readonly id?: string;
}

interface SamsungPayProps extends FramepayProps {
    readonly Framepay: FramepayProps;
    readonly id?: string;
}

interface GooglePayProps extends FramepayProps {
    readonly Framepay: FramepayProps;
    readonly id?: string;
}

interface PaypalProps extends FramepayProps {
    readonly Framepay: FramepayProps;
    readonly id?: string;
}

interface BankState extends PaymentComponentState {
    readonly element: BankElement | null;
}

interface CardState extends PaymentComponentState {
    readonly element: CardElement | null;
}

interface IBANState extends PaymentComponentState {
    readonly element: IbanElement | null;
}

interface ApplePayState extends PaymentComponentState {
    readonly element: ApplePayElement | null;
}

interface SamsungPayState extends PaymentComponentState {
    readonly element: SamsungPayElement | null;
}

interface GooglePayState extends PaymentComponentState {
    readonly element: GooglePayElement | null;
}

interface PaypalState extends PaymentComponentState {
    readonly element: PayPalElement | null;
}
