/* eslint-disable @typescript-eslint/indent */
/* 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;
  quotes?: Record<
    string,
    {
      quote_id: string;
      expires_at: number;
      quoted_amount: string;
      exchange_rate?: string;
      rate_provider_name?: string;
      rate_provider_id?: string;
    }
  >;
  rateUnavailable?: boolean;
  rateError?: 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;
  onRefreshQuote?: () => Promise<boolean>;
};

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;
  };
};
