import React from 'react'; import { Ticket, Edit, Percent, Calendar, Tag, DollarSign, RefreshCw } from 'lucide-react'; export interface CouponFormData { code: string; category: string; discountType: 'percentage' | 'flat'; discountValue: string; discountValueUsd: string; discountValueEur: string; maxDiscountCap: string; maxDiscountCapUsd: string; maxDiscountCapEur: string; description: string; startDate: string; endDate: string; scope: 'storewide' | 'specific'; applicablePlanIds: string[]; applicableModuleIds: string[]; minSpend: string; minSpendUsd: string; minSpendEur: string; usageLimit: string; firstOnly: boolean; } interface CouponModalProps { mode: 'create' | 'edit' | null; data: CouponFormData; plans: any[]; modules: any[]; saving: boolean; onChange: (field: keyof CouponFormData, val: any) => void; onSave: (e: React.FormEvent) => void; onClose: () => void; } export const CouponModal: React.FC = ({ mode, data, plans, modules, saving, onChange, onSave, onClose, }) => { if (!mode) return null; const isEdit = mode === 'edit'; const isDateRangeInvalid = Boolean(data.startDate && data.endDate && data.endDate <= data.startDate); return (
{/* Header */}

{isEdit ? : } {isEdit ? `Edit Coupon: ${data.code}` : 'Create Promotional Coupon'}

Configure discount rules, date schedule, scope, and cart thresholds.

{/* BLOCK 1: Code & Discount Value */}
Block 1: Promo Code & Discount Value
onChange('code', e.target.value.toUpperCase())} className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono font-bold text-slate-800 uppercase focus:outline-none focus:border-indigo-500 disabled:bg-slate-100" />
{data.discountType === 'percentage' ? (
onChange('discountValue', e.target.value)} placeholder="e.g. 20" className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500" /> %
onChange('maxDiscountCap', e.target.value)} placeholder="0 = None" className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
onChange('maxDiscountCapUsd', e.target.value)} placeholder="0 = None" className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
onChange('maxDiscountCapEur', e.target.value)} placeholder="0 = None" className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
) : (
₹ onChange('discountValue', e.target.value)} placeholder="INR (₹)" className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500" />
$ onChange('discountValueUsd', e.target.value)} placeholder="USD ($)" className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500" />
€ onChange('discountValueEur', e.target.value)} placeholder="EUR (€)" className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500" />
)}
onChange('description', e.target.value)} className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
{/* BLOCK 2: Schedule & Validity */}
Block 2: Schedule & Date Window
onChange('startDate', e.target.value)} className={`w-full bg-white border rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none cursor-pointer ${ isDateRangeInvalid ? 'border-rose-400 focus:border-rose-500' : 'border-slate-200 focus:border-indigo-500' }`} />
onChange('endDate', e.target.value)} className={`w-full bg-white border rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none cursor-pointer ${ isDateRangeInvalid ? 'border-rose-400 focus:border-rose-500' : 'border-slate-200 focus:border-indigo-500' }`} />
{isDateRangeInvalid && (
⚠️ Invalid date range: Expiration date must be later than start date.
)}
{/* BLOCK 3: Scope & Item Restrictions */}
Block 3: Scope & Applicability
{data.scope === 'specific' && (
{plans.map((p) => { const pids: string[] = [p.inr_plan_id, p.usd_plan_id, p.eur_plan_id, p.id].filter(Boolean); const checked = pids.some((id) => data.applicablePlanIds.includes(id)); return ( ); })}
{modules.map((m) => { const checked = data.applicableModuleIds.includes(m.id); return ( ); })}
)}
{/* BLOCK 4: Conditions & Thresholds */}
Block 4: Conditions & Usage Limits
₹ onChange('minSpend', e.target.value)} placeholder="Min ₹ (INR)" className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
$ onChange('minSpendUsd', e.target.value)} placeholder="Min $ (USD)" className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
€ onChange('minSpendEur', e.target.value)} placeholder="Min € (EUR)" className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
onChange('usageLimit', e.target.value)} placeholder="0" className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500" />
{/* Actions */}
); };