import type { Dispatch, FormEvent, SetStateAction } from 'react'; import Card from '@/components/ui/Card'; import Button from '@/components/ui/Button'; import clsx from 'clsx'; import { BanknotesIcon, CheckCircleIcon, EnvelopeIcon, LinkIcon, StarIcon, XMarkIcon, } from '@heroicons/react/24/outline'; import type { AddTicketType, AddTicketFormState } from '../_types'; interface AddTicketModalProps { open: boolean; onClose: () => void; form: AddTicketFormState; setForm: Dispatch>; onSubmit: (e: FormEvent) => void; submitting: boolean; eventPriceLabel: string; } const TYPE_OPTIONS: { value: AddTicketType; label: string }[] = [ { value: 'paid', label: 'Paid' }, { value: 'door', label: 'At Door' }, { value: 'unpaid', label: 'Unpaid' }, { value: 'guest', label: 'Guest' }, ]; const SUBMIT_LABELS: Record = { paid: 'Create & send ticket', door: 'Record door payment', unpaid: 'Create & send pay link', guest: 'Invite guest', }; const SUBMIT_ICONS: Record = { paid: EnvelopeIcon, door: BanknotesIcon, unpaid: LinkIcon, guest: StarIcon, }; // Live "what happens" preview lines for the selected type / email / check-in combo function previewLines(form: AddTicketFormState, eventPriceLabel: string): string[] { const hasEmail = !!form.email.trim(); const lines: string[] = []; if (form.type === 'paid') { lines.push(`Payment of ${eventPriceLabel} recorded as paid — counts toward revenue`); lines.push('Confirmation email with QR ticket sent'); } else if (form.type === 'door') { lines.push(`Cash payment of ${eventPriceLabel} recorded as paid at the door — counts toward revenue`); lines.push('QR code issued'); if (!form.firstName.trim()) { lines.push('No name — the ticket is logged as a "Walk-in"'); } lines.push(hasEmail ? 'Confirmation email with QR ticket sent' : 'No email — nothing is sent, walk-in kept on the list only'); } else if (form.type === 'unpaid') { lines.push(`Ticket marked unpaid — balance of ${eventPriceLabel} to collect at the door`); lines.push('QR code issued, flagged "unpaid" for door staff'); lines.push(hasEmail ? 'Bancard (TPago) payment link emailed to the attendee' : 'No email — no pay link sent, payment collected at the door'); } else { lines.push('Free guest ticket (comp) — not counted in revenue'); lines.push('Auto-confirmed with QR code'); lines.push(hasEmail ? 'Confirmation email sent' : 'No email — nothing is sent'); } if (form.checkinNow) { lines.push('Checked in immediately'); } return lines; } const PREVIEW_STYLES: Record = { paid: { box: 'bg-blue-50 border-blue-200', icon: 'text-blue-500', text: 'text-blue-800' }, door: { box: 'bg-emerald-50 border-emerald-200', icon: 'text-emerald-500', text: 'text-emerald-800' }, unpaid: { box: 'bg-orange-50 border-orange-200', icon: 'text-orange-500', text: 'text-orange-800' }, guest: { box: 'bg-amber-50 border-amber-200', icon: 'text-amber-500', text: 'text-amber-800' }, }; const PREVIEW_ICONS: Record = { paid: CheckCircleIcon, door: BanknotesIcon, unpaid: BanknotesIcon, guest: StarIcon, }; export function AddTicketModal({ open, onClose, form, setForm, onSubmit, submitting, eventPriceLabel, }: AddTicketModalProps) { if (!open) return null; const emailRequired = form.type === 'paid'; // Door walk-ins can be logged with nothing filled in const nameRequired = form.type !== 'door'; const style = PREVIEW_STYLES[form.type]; const PreviewIcon = PREVIEW_ICONS[form.type]; const SubmitIcon = SUBMIT_ICONS[form.type]; return (
e.stopPropagation()} >

Add Ticket

{/* Segmented ticket-type control */}
{TYPE_OPTIONS.map((option) => ( ))}
setForm((f) => ({ ...f, firstName: e.target.value }))} className="w-full px-3 py-2.5 text-sm rounded-btn border border-secondary-light-gray focus:outline-none focus:ring-2 focus:ring-primary-yellow" placeholder={nameRequired ? 'First name' : 'First name (optional)'} />
setForm((f) => ({ ...f, lastName: e.target.value }))} className="w-full px-3 py-2.5 text-sm rounded-btn border border-secondary-light-gray focus:outline-none focus:ring-2 focus:ring-primary-yellow" placeholder="Last name" />
setForm((f) => ({ ...f, email: e.target.value }))} className="w-full px-3 py-2.5 text-sm rounded-btn border border-secondary-light-gray focus:outline-none focus:ring-2 focus:ring-primary-yellow" placeholder={emailRequired ? 'email@example.com' : 'email@example.com (optional)'} />

{form.type === 'paid' && 'Ticket will be sent to this email'} {form.type === 'door' && 'Optional — if provided, the ticket confirmation is sent here'} {form.type === 'unpaid' && 'If provided, the payment link is sent here'} {form.type === 'guest' && 'If provided, a confirmation email will be sent'}

setForm((f) => ({ ...f, phone: e.target.value }))} className="w-full px-3 py-2.5 text-sm rounded-btn border border-secondary-light-gray focus:outline-none focus:ring-2 focus:ring-primary-yellow" placeholder="+595 981 123456" />