'use client'; import { useState } from 'react'; import clsx from 'clsx'; import { BanknotesIcon, BoltIcon, BuildingLibraryIcon, GiftIcon, ChevronDownIcon, } from '@heroicons/react/24/outline'; import type { DoorPaymentMethod } from '@/lib/api'; import { formatCurrency } from '@/lib/utils'; // The four tenders staff can take at the door. One tap settles and checks in; // long-press (or the chevron) opens multiples for someone paying for their group. const TENDERS: { method: DoorPaymentMethod; label: string; icon: typeof BanknotesIcon; className: string; }[] = [ { method: 'cash', label: 'Cash', icon: BanknotesIcon, className: 'bg-emerald-600 active:bg-emerald-700' }, { method: 'bitcoin', label: 'Bitcoin', icon: BoltIcon, className: 'bg-orange-500 active:bg-orange-600' }, { method: 'transfer', label: 'Transfer', icon: BuildingLibraryIcon, className: 'bg-blue-600 active:bg-blue-700' }, { method: 'guest', label: 'Guest', icon: GiftIcon, className: 'bg-gray-600 active:bg-gray-700' }, ]; const LONG_PRESS_MS = 450; export function PaymentButtons({ price, currency, onPay, disabled, }: { price: number; currency: string; onPay: (method: DoorPaymentMethod, amount: number) => void; disabled?: boolean; }) { // Which tender has its quick-amounts open. Guest is always free, so it never opens one. const [amountsFor, setAmountsFor] = useState(null); const [customOpen, setCustomOpen] = useState(false); const [customValue, setCustomValue] = useState(''); const [pressTimer, setPressTimer] = useState | null>(null); const [longPressed, setLongPressed] = useState(false); const openAmounts = (method: DoorPaymentMethod) => { if (method === 'guest') return; setAmountsFor(method); setCustomOpen(false); setCustomValue(''); }; const startPress = (method: DoorPaymentMethod) => { setLongPressed(false); const timer = setTimeout(() => { setLongPressed(true); openAmounts(method); }, LONG_PRESS_MS); setPressTimer(timer); }; const endPress = (method: DoorPaymentMethod) => { if (pressTimer) clearTimeout(pressTimer); setPressTimer(null); // A long press already opened the multiples; don't also charge 1x on release. if (longPressed) { setLongPressed(false); return; } if (disabled) return; onPay(method, method === 'guest' ? 0 : price); }; const cancelPress = () => { if (pressTimer) clearTimeout(pressTimer); setPressTimer(null); setLongPressed(false); }; if (amountsFor) { const tender = TENDERS.find((t) => t.method === amountsFor)!; return (

{tender.label} — how many?

{[1, 2, 3].map((qty) => ( ))}
{customOpen && (
setCustomValue(e.target.value)} placeholder={`Amount in ${currency}`} className="flex-1 min-h-[48px] px-4 bg-gray-800 border border-gray-700 rounded-xl text-white placeholder:text-gray-500 focus:outline-none focus:ring-2 focus:ring-primary-yellow" />
)}
); } return (
{TENDERS.map((tender) => ( ))}
); }