import React, { useState } from 'react'; import { Plus, Tag, Users, Edit, Sparkles } from 'lucide-react'; import { Pagination } from '../common/Pagination'; interface PlansTabProps { plans: any[]; searchQuery: string; typeFilter: string; currentPage: number; perPage: number; onSearchChange: (q: string) => void; onTypeFilterChange: (f: string) => void; onPageChange: (p: number) => void; onPerPageChange: (pp: number) => void; onOpenCreatePlan: () => void; onTogglePlanStatus: (plan: any) => void; onOpenEditPrice: (plan: any) => void; } export const PlansTab: React.FC = ({ plans, searchQuery, typeFilter, currentPage, perPage, onSearchChange, onTypeFilterChange, onPageChange, onPerPageChange, onOpenCreatePlan, onTogglePlanStatus, onOpenEditPrice, }) => { const [expandedModules, setExpandedModules] = useState>({}); const toggleExpandModules = (planKey: string) => { setExpandedModules((prev) => ({ ...prev, [planKey]: !prev[planKey] })); }; const filteredPlans = plans.filter((plan) => { const q = searchQuery.toLowerCase().trim(); const matchesSearch = !q || plan.base_code?.toLowerCase().includes(q) || plan.name?.toLowerCase().includes(q) || plan.description?.toLowerCase().includes(q) || (plan.modules && plan.modules.some( (m: any) => m.name?.toLowerCase().includes(q) || m.slug?.toLowerCase().includes(q) )); if (!matchesSearch) return false; if (typeFilter === 'bundle') return plan.plan_type === 'bundle'; if (typeFilter === 'one_time') return plan.plan_type !== 'bundle'; if (typeFilter === 'active') return plan.is_active === true; if (typeFilter === 'inactive') return plan.is_active === false; return true; }); const totalFiltered = filteredPlans.length; const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage)); const safePage = Math.min(currentPage, totalPages); const startIndex = (safePage - 1) * perPage; const paginatedPlans = filteredPlans.slice(startIndex, startIndex + perPage); return (
{/* Header & Filter Bar */}
{ onSearchChange(e.target.value); onPageChange(1); }} className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-4 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm" /> 🔍
{/* Filter Pills */}
Filter: {[ { key: 'all', label: `All Plans (${plans.length})` }, { key: 'bundle', label: `Bundles (${plans.filter((p) => p.plan_type === 'bundle').length})` }, { key: 'one_time', label: `Single Modules (${plans.filter((p) => p.plan_type !== 'bundle').length})` }, { key: 'active', label: `Active (${plans.filter((p) => p.is_active).length})` }, { key: 'inactive', label: `Inactive (${plans.filter((p) => !p.is_active).length})` }, ].map((f) => ( ))}
{/* Plans Ledger Table */} {filteredPlans.length === 0 ? (

No subscription plans found

Try adjusting your search query or filter settings.

) : (
{paginatedPlans.map((plan) => ( {/* Plan Details */} {/* Type & Duration */} {/* Included Modules */} {/* Pricing */} {/* Subscribers */} {/* Live Status Toggle */} {/* Actions */} ))}
Plan Details Type & Duration Included Modules Live Pricing (INR / USD / EUR) Subscribers Status Actions
{plan.name}
{plan.base_code || plan.code}
{plan.description && (

{plan.description}

)}
{plan.plan_type === 'bundle' ? 'Package Bundle' : 'Single Module'}

{plan.billing_period === 'lifetime' ? 'Lifetime Access' : `${plan.billing_period || 'yearly'} Billing`}

{plan.modules && plan.modules.length > 0 ? (
{plan.code === 'LIFETIME_ALL' || plan.base_code === 'LIFETIME_ALL' ? (
All Modules ({plan.modules.length})
{expandedModules[plan.base_code || plan.code || plan.id] && (
{plan.modules.map((m: any, i: number) => ( {m.name || m.slug} ))}
)}
) : (
{(expandedModules[plan.base_code || plan.code || plan.id] ? plan.modules : plan.modules.slice(0, 3) ).map((m: any, i: number) => ( {m.name || m.slug} ))} {plan.modules.length > 3 && ( )}
)}
) : ( No modules attached )}

₹{plan.price_inr ?? '—'}

${plan.price_usd ?? '—'} • €{plan.price_eur ?? plan.price_usd ?? '—'}
0 ? 'bg-indigo-50 text-indigo-700 border border-indigo-200' : 'bg-slate-50 text-slate-400 border border-slate-200' }`} > {plan.subscribers_count || 0} {plan.is_active ? 'Active' : 'Inactive'}
)}
); };