import React from 'react'
import {
  Card,
  CardContent,
  CardHeader,
  CardTitle,
} from '@/components/shadcn/ui/card'
import Currency from '@/components/Currency'
import { Alert, AlertDescription } from '@/components/shadcn/ui/alert'
import { Info } from 'lucide-react'
import { useCurrency } from '@/lib/hooks/useCurrency'
import {
  PaymentChannel,
  PaymentMethod,
  PaymentStatus,
} from '@/lib/types/payment'
import BankTransferPaymentDetail from './BankTransferPaymentDetail'
import { BankTransferPaymentProof } from '@/lib/types/order'
import DokuPaymentDetail from './DokuPaymentDetail'
import PaymentInfo from '@/components/payments/PaymentInfo'
import { Separator } from '@/components/shadcn/ui/separator'

interface PaymentDetailProps {
  invoiceNumber: string
  totalAmount: number
  paymentStatus: PaymentStatus
  paymentMethod: PaymentMethod
  paymentChannel?: PaymentChannel | null
  bankTransferPaymentProof?: BankTransferPaymentProof | null
  paymentUrl: string
  checkingStatus: boolean
  checkPaymentStatus: () => Promise<void>
}

const PaymentDetail: React.FC<PaymentDetailProps> = ({
  invoiceNumber,
  totalAmount,
  paymentStatus,
  paymentMethod,
  paymentChannel,
  bankTransferPaymentProof,
  checkingStatus,
  paymentUrl,
  checkPaymentStatus,
}) => {
  const { format } = useCurrency()

  return (
    <Card className="w-full shadow-none mt-8">
      <CardHeader className="pb-3">
        <CardTitle className="text-xl font-bold">Payment Details</CardTitle>
        <p className="text-sm text-gray-500">Invoice Number: {invoiceNumber}</p>
      </CardHeader>

      <CardContent className="space-y-6">
        <div className="space-y-2">
          <div className="text-sm text-gray-500">Total Payment</div>
          <h2 className="text-3xl font-bold">
            <Currency price={totalAmount} />
          </h2>

          {paymentStatus === 'PENDING' && (
            <Alert className="bg-blue-100 border border-blue-300 text-blue-500 rounded mt-3">
              <Info />
              <AlertDescription className="text-blue-500">
                Your payment will be processed in{' '}
                <b>{format(totalAmount, 'IDR')}</b>
              </AlertDescription>
            </Alert>
          )}
        </div>

        <Separator className="my-4" />

        <div className="space-y-4">
          {paymentMethod.code === 'BANK_TRANSFER' ? (
            <BankTransferPaymentDetail
              paymentMethod={paymentMethod}
              bankTransferPaymentProof={bankTransferPaymentProof}
              invoiceNumber={invoiceNumber}
              paymentStatus={paymentStatus}
              totalAmount={totalAmount}
              checkingStatus={checkingStatus}
              checkPaymentStatus={checkPaymentStatus}
            />
          ) : paymentMethod.code === 'SECURE_PAYMENT' ? (
            <DokuPaymentDetail
              paymentMethod={paymentMethod}
              paymentChannel={paymentChannel}
              paymentStatus={paymentStatus}
              paymentUrl={paymentUrl}
              checkingStatus={checkingStatus}
              checkPaymentStatus={checkPaymentStatus}
            />
          ) : (
            <PaymentInfo
              paymentMethod={paymentMethod}
              paymentStatus={paymentStatus}
            />
          )}
        </div>
      </CardContent>
    </Card>
  )
}

export default PaymentDetail
