"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Lock, Search, CheckCircle2 } from "lucide-react" interface Props { amount: number eventName: string onComplete: (identity: { donorName: string donorEmail: string donorPhone: string giftAid: boolean }) => void } interface Bank { code: string name: string shortName: string online: boolean } const FPX_BANKS: Bank[] = [ { code: "MBB", name: "Maybank2u", shortName: "Maybank", online: true }, { code: "CIMB", name: "CIMB Clicks", shortName: "CIMB", online: true }, { code: "PBB", name: "PBe Bank", shortName: "Public Bank", online: true }, { code: "RHB", name: "RHB Now", shortName: "RHB", online: true }, { code: "HLB", name: "Hong Leong Connect", shortName: "Hong Leong", online: true }, { code: "AMBB", name: "AmOnline", shortName: "AmBank", online: true }, { code: "BIMB", name: "Bank Islam GO", shortName: "Bank Islam", online: true }, { code: "BKRM", name: "i-Rakyat", shortName: "Bank Rakyat", online: true }, { code: "BSN", name: "myBSN", shortName: "BSN", online: true }, { code: "OCBC", name: "OCBC Online", shortName: "OCBC", online: true }, { code: "UOB", name: "UOB Personal", shortName: "UOB", online: true }, { code: "ABB", name: "Affin Online", shortName: "Affin Bank", online: true }, { code: "ABMB", name: "Alliance Online", shortName: "Alliance Bank", online: true }, { code: "BMMB", name: "Bank Muamalat", shortName: "Muamalat", online: true }, { code: "SCB", name: "SC Online", shortName: "Standard Chartered", online: true }, { code: "HSBC", name: "HSBC Online", shortName: "HSBC", online: true }, { code: "AGR", name: "AGRONet", shortName: "Agrobank", online: true }, { code: "KFH", name: "KFH Online", shortName: "KFH", online: true }, ] const BANK_COLORS: Record = { MBB: "bg-yellow-500", CIMB: "bg-red-600", PBB: "bg-pink-700", RHB: "bg-blue-800", HLB: "bg-blue-600", AMBB: "bg-green-700", BIMB: "bg-emerald-700", BKRM: "bg-blue-900", BSN: "bg-orange-600", OCBC: "bg-red-700", UOB: "bg-blue-700", ABB: "bg-amber-700", ABMB: "bg-teal-700", BMMB: "bg-green-800", SCB: "bg-green-600", HSBC: "bg-red-500", AGR: "bg-green-900", KFH: "bg-yellow-700", } type Phase = "select" | "identity" | "redirecting" | "processing" export function FpxPaymentStep({ amount, eventName, onComplete }: Props) { const [phase, setPhase] = useState("select") const [selectedBank, setSelectedBank] = useState(null) const [search, setSearch] = useState("") const [name, setName] = useState("") const [email, setEmail] = useState("") const [phone, setPhone] = useState("") const [errors, setErrors] = useState>({}) const ringgit = (amount / 100).toFixed(2) const filteredBanks = search ? FPX_BANKS.filter( (b) => b.name.toLowerCase().includes(search.toLowerCase()) || b.shortName.toLowerCase().includes(search.toLowerCase()) || b.code.toLowerCase().includes(search.toLowerCase()) ) : FPX_BANKS const handleBankSelect = (bank: Bank) => { setSelectedBank(bank) } const handleContinueToIdentity = () => { if (!selectedBank) return setPhase("identity") } const handleSubmit = async () => { const errs: Record = {} if (!email.includes("@")) errs.email = "Valid email required" setErrors(errs) if (Object.keys(errs).length > 0) return setPhase("redirecting") // Simulate FPX redirect flow await new Promise((r) => setTimeout(r, 2000)) setPhase("processing") await new Promise((r) => setTimeout(r, 1500)) onComplete({ donorName: name, donorEmail: email, donorPhone: phone, giftAid: false, // Gift Aid not applicable for MYR }) } // Redirecting phase if (phase === "redirecting") { return (

Redirecting to {selectedBank?.name}

You'll be taken to your bank's secure login page to authorize the payment of RM{ringgit}

{selectedBank?.code}
{selectedBank?.name}

Do not close this window. You will be redirected back automatically.

) } // Processing phase if (phase === "processing") { return (

Processing Payment

Verifying your payment with {selectedBank?.shortName}...

) } // Identity phase if (phase === "identity") { return (

Your Details

Before we redirect you to {selectedBank?.name}

{/* Selected bank indicator */}
{selectedBank?.code}

{selectedBank?.name}

FPX Online Banking

RM{ringgit}

{eventName}

setName(e.target.value)} autoComplete="name" />
setEmail(e.target.value)} autoComplete="email" inputMode="email" className={errors.email ? "border-red-500" : ""} /> {errors.email &&

{errors.email}

}

We'll send your receipt here

setPhone(e.target.value)} autoComplete="tel" inputMode="tel" />
Secured by FPX — Bank Negara Malaysia
) } // Bank selection phase (default) return (

FPX Online Banking

Pay RM{ringgit}{" "} for {eventName}

{/* Search */}
setSearch(e.target.value)} className="pl-10" />
{/* Bank list */}
{filteredBanks.map((bank) => ( ))}
{filteredBanks.length === 0 && (

No banks found matching "{search}"

)} {/* Continue */}
Powered by FPX — regulated by Bank Negara Malaysia
) }