/* eslint-disable import/no-extraneous-dependencies */
import type {
  TCheckoutSessionExpanded,
  TCustomer,
  TPaymentIntent,
  TPaymentLink,
  TPaymentMethodExpanded,
} from '@blocklet/payment-types';
import type { SxProps, ThemeOptions } from '@mui/material';
import type { LiteralUnion } from 'type-fest';

export type CheckoutContext = {
  checkoutSession: TCheckoutSessionExpanded;
  paymentMethods: TPaymentMethodExpanded[];
  paymentLink?: TPaymentLink;
  paymentIntent?: TPaymentIntent;
  customer?: TCustomer;
  mode: LiteralUnion<'standalone' | 'inline' | 'popup', string>;
  action?: string;
  showCheckoutSummary?: boolean;
  currencyId?: string;
};

export type CheckoutFormData = {
  customer_name: string;
  customer_email?: string;
  customer_phone?: string;
  payment_method: string;
  payment_currency: string;
  billing_address?: {
    country: string;
    state?: string;
    city?: string;
    line1?: string;
    line2?: string;
    postal_code: string;
  };
};

export type PaymentThemeOptions = ThemeOptions & {
  sx?: SxProps;
};

export type CheckoutProps = Partial<CheckoutCallbacks> & {
  id: string;
  extraParams?: Record<string, any>;
  action?: string;
  mode?: LiteralUnion<'standalone' | 'inline' | 'popup' | 'inline-minimal' | 'popup-minimal', string>;
  theme?: 'default' | 'inherit' | PaymentThemeOptions;
  formType?: 'donation' | 'payment';
  formRender?: Record<string, any>;
};

export type CheckoutCallbacks = {
  onPaid: (res: CheckoutContext) => void;
  onError: (err: Error) => void;
  onChange?: (data: CheckoutFormData) => void;
  goBack?: () => void;
};

export type PricingRenderProps = {
  totalPrice: string;
  unitPrice?: string;
  quantity: string;
  totalAmount: string;
};

export type ActionProps = {
  [key: string]: {
    color?: string;
    variant?: string;
    sx?: {
      [key: string]: any;
    };
    text?: string;
  };
};
