'use client'; import { useState } from 'react'; import { Plus, Save, Trash2, X, Gift } from 'lucide-react'; import { CompanySettings } from '../page'; interface PlanSelectionProps { settings: CompanySettings; setSettings: React.Dispatch>; activePlanTab: 'singleRent' | 'rentToOwn' | 'shareEv'; setActivePlanTab: (tab: 'singleRent' | 'rentToOwn' | 'shareEv') => void; handleSave: () => void; addNewPlan: (type: 'singleRent' | 'rentToOwn' | 'shareEv') => void; isDirty?: boolean; } // Reusable Free Service Conditions editor function FreeServiceConditions({ conditions, accentColor, onChange, }: { conditions: { months: number; freeServices: number }[]; accentColor: string; onChange: (updated: { months: number; freeServices: number }[]) => void; }) { const addCondition = () => { onChange([...conditions, { months: 3, freeServices: 1 }]); }; const removeCondition = (i: number) => { onChange(conditions.filter((_, idx) => idx !== i)); }; const updateCondition = (i: number, field: 'months' | 'freeServices', value: number) => { const updated = conditions.map((c, idx) => idx === i ? { ...c, [field]: value } : c); onChange(updated); }; return (
e.g. "3 months → 2 free services"
{conditions.length === 0 && (

No free service conditions set. Click "Add Condition" to add one.

)}
{conditions.map((cond, i) => (
{/* Month input */}
updateCondition(i, 'months', parseInt(e.target.value) || 1)} className="w-16 px-2 py-1 border border-slate-200 rounded-md text-xs text-slate-800 text-center font-semibold focus:outline-none focus:ring-1 focus:ring-amber-400" />
{/* Free services input */}
updateCondition(i, 'freeServices', parseInt(e.target.value) || 1)} className="w-16 px-2 py-1 border border-slate-200 rounded-md text-xs text-slate-800 text-center font-semibold focus:outline-none focus:ring-1 focus:ring-amber-400" />
{/* Preview badge */} {cond.months} {cond.months === 1 ? 'month' : 'months'} → {cond.freeServices} free service{cond.freeServices !== 1 ? 's' : ''} free {/* Remove */}
))}
); } export default function PlanSelection({ settings, setSettings, activePlanTab, setActivePlanTab, handleSave, addNewPlan, }: PlanSelectionProps) { const [deleteModal, setDeleteModal] = useState<{ type: 'singleRent' | 'rentToOwn' | 'shareEv' | null; idx: number | null }>({ type: null, idx: null }); const handleDeletePlan = () => { if (deleteModal.type !== null && deleteModal.idx !== null) { const updated = settings.plans[deleteModal.type].filter((_, i) => i !== deleteModal.idx); setSettings({ ...settings, plans: { ...settings.plans, [deleteModal.type]: updated } }); setDeleteModal({ type: null, idx: null }); } }; return ( <>

Plan Selection

{activePlanTab === 'singleRent' && (
{settings.plans.singleRent.map((plan, idx) => (

{plan.name} - ৳{plan.dailyRent}/day