import React from 'react'; import { Shield, RefreshCw, Download, CheckCircle } from 'lucide-react'; interface CustomerDrawerProps { customerId: string | null; customerData: any | null; loading: boolean; statusToggling: boolean; activeTab: 'overview' | 'subscriptions' | 'invoices'; onTabChange: (tab: 'overview' | 'subscriptions' | 'invoices') => void; onToggleStatus: () => void; onClose: () => void; onDownloadInvoice?: (paymentId: string) => void; } export const CustomerDrawer: React.FC = ({ customerId, customerData, loading, statusToggling, activeTab, onTabChange, onToggleStatus, onClose, onDownloadInvoice, }) => { if (!customerId) return null; const formatCurrency = (amount: number, currency: string = 'INR') => { const sym = currency === 'USD' ? '$' : currency === 'EUR' ? '€' : '₹'; return `${sym}${Number(amount || 0).toFixed(2)}`; }; return (
{/* Drawer Top Bar */}
{customerData?.display_name ? customerData.display_name[0].toUpperCase() : 'U'}

{customerData?.display_name || 'Customer Account'}

{customerData && ( {customerData.is_active ? 'Active' : 'Suspended'} )}

{customerData?.email || 'Loading...'}

{/* Drawer Body */}
{loading ? (

Loading customer profile & entitlements...

) : customerData ? ( <> {/* Account Status Control */}
Account Access Control

{customerData.is_active ? 'Account is active. Customer has login access to Web and Mobile.' : 'Account is suspended. Customer is blocked from logging in.'}

{/* Drawer Sub-Tabs */}
{[ { id: 'overview' as const, label: 'Overview' }, { id: 'subscriptions' as const, label: `Plans & Modules (${customerData.subscriptions?.length || 0})`, }, { id: 'invoices' as const, label: `Invoices (${customerData.transactions?.length || 0})`, }, ].map((tab) => ( ))}
{/* TAB 1: OVERVIEW */} {activeTab === 'overview' && (
Total Spent

{customerData.total_spent_formatted || formatCurrency( customerData.total_spent ?? customerData.total_spent_inr ?? 0, customerData.currency || 'INR' )}

Total Orders

{customerData.total_orders || 0}

Contact & Account Information

Email Address {customerData.email}
Phone Number {customerData.phone_number || 'Not provided'}
Country {customerData.country || 'India'}
Assigned Roles {customerData.roles?.join(', ') || 'user'}
Member Since {customerData.created_at ? customerData.created_at.split('T')[0] : 'N/A'}
{customerData.external_ref && (
Gateway Ref {customerData.external_ref}
)}
)} {/* TAB 2: SUBSCRIPTIONS */} {activeTab === 'subscriptions' && (
{(!customerData.subscriptions || customerData.subscriptions.length === 0) ? (

No active or past plan subscriptions found.

) : ( customerData.subscriptions.map((sub: any, idx: number) => { const planName = sub.plan?.name || sub.plan_name || sub.plan?.code || sub.plan_code || 'Subscribed Plan'; const planCode = sub.plan?.code || sub.plan_code; const modules = sub.plan?.modules || []; return (
{planName}
{planCode && ( {planCode} )}
{sub.status}
{modules.length > 0 && (
{modules.map((m: any, mIdx: number) => ( {m.name || m.code} ))}
)}
Valid: {sub.started_at ? sub.started_at.split('T')[0] : 'N/A'} →{' '} {sub.expires_at ? sub.expires_at.split('T')[0] : 'Lifetime'} {sub.remaining_days !== null && sub.remaining_days !== undefined && ( {sub.is_expired ? 'Expired' : `${sub.remaining_days} days left`} )}
); }) )}
)} {/* TAB 3: INVOICES */} {activeTab === 'invoices' && (
{(!customerData.transactions || customerData.transactions.length === 0) ? (

No payment transactions found.

) : ( customerData.transactions.map((tx: any, idx: number) => { const invNumber = tx.invoice?.invoice_number || (tx.gateway_transaction_id ? `Tx: ${tx.gateway_transaction_id}` : tx.id); const paymentId = tx.gateway_transaction_id || tx.id; const amount = tx.invoice?.total_amount !== undefined ? tx.invoice.total_amount : tx.amount; const curr = tx.currency || tx.invoice?.currency || 'INR'; return (
{invNumber} {tx.invoice?.invoice_number && ( Invoice )}

{tx.created_at?.split('T')[0] || '—'} {tx.gateway_transaction_id && ` • ${tx.gateway_transaction_id}`}

{formatCurrency(amount, curr)}

{tx.status}
{onDownloadInvoice && paymentId && ( )}
); }) )}
)} ) : null}
); };