'use client'; import { useState } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { ArrowLeft, Zap, Shield, TrendingUp, Check, Info, Calendar, DollarSign, CreditCard, FileText, ChevronRight, AlertCircle, ArrowDown, Wallet, Clock, Activity } from 'lucide-react'; import toast from 'react-hot-toast'; const PLAN_TEMPLATES = [ { id: '1bike', name: '1 Bike Plan', description: 'Investment plan for 1 bike - perfect for small investors', evBasePrice: 200000, minQty: 1, minInvestment: 200000, maxInvestment: 1000000, duration: 12, lockIn: 3, exitPenalty: 10, ficoShare: { single: 45, own: 55, ev: 60 }, icon: Zap, color: 'bg-blue-600', lightColor: 'bg-blue-50 text-blue-700' }, { id: '5bike', name: '5 Bike Plan', description: 'Perfect for established investors looking for better returns', evBasePrice: 180000, minQty: 5, minInvestment: 900000, maxInvestment: 5000000, duration: 24, lockIn: 6, exitPenalty: 15, ficoShare: { single: 40, own: 50, ev: 55 }, icon: TrendingUp, color: 'bg-purple-600', lightColor: 'bg-purple-50 text-purple-700' } ]; export default function NewInvestmentPage() { const router = useRouter(); const [step, setStep] = useState<'select' | 'form'>('select'); const [selectedTemplate, setSelectedTemplate] = useState(null); const [formData, setFormData] = useState({ planName: '', planType: 'Gold', investmentAmount: 0, initialPayment: 0, startDate: new Date().toISOString().split('T')[0], endDate: '', paymentMethod: 'Bank Transfer', transactionRef: '', description: '' }); const handleSelectTemplate = (template: typeof PLAN_TEMPLATES[0]) => { setSelectedTemplate(template); setFormData({ ...formData, planName: template.name, investmentAmount: template.minInvestment, initialPayment: Math.floor(template.minInvestment * 0.5) // Default 50% initial }); setStep('form'); }; const handleCreateInvestment = (e: React.FormEvent) => { e.preventDefault(); if (formData.investmentAmount < (selectedTemplate?.minInvestment || 0)) { toast.error(`Minimum investment for this plan is ৳${selectedTemplate?.minInvestment.toLocaleString()}`); return; } toast.success('Investment request created successfully! Admin will review and assign bikes.'); router.push('/investor/plans'); }; return (

{step === 'select' ? 'Select Investment Plan' : 'Configure New Investment'}

{step === 'select' ? 'Choose a template to start' : `Set up investment under ${selectedTemplate?.name}`}

{step === 'select' && (
{PLAN_TEMPLATES.map((plan) => { const Icon = plan.icon; return (
handleSelectTemplate(plan)} >

{plan.name}

{plan.description}

Min Investment ৳{plan.minInvestment.toLocaleString()}
EV Base Price ৳{plan.evBasePrice.toLocaleString()}
Duration {plan.duration} Months
); })}
)} {step === 'form' && selectedTemplate && (
{/* Core Configuration */}

Plan Configuration

setFormData({...formData, planName: e.target.value})} className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-investor/20 focus:border-investor outline-none transition-all font-medium" placeholder="e.g. My First Bike" required />

EV Base Price

৳{selectedTemplate.evBasePrice.toLocaleString()}

Min Qty

{selectedTemplate.minQty} Bike(s)

Min Invest

৳{selectedTemplate.minInvestment.toLocaleString()}

Max Invest

৳{selectedTemplate.maxInvestment.toLocaleString()}

setFormData({...formData, investmentAmount: Number(e.target.value)})} className="w-full px-4 py-3 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-investor/20 focus:border-investor outline-none transition-all font-extrabold" required />
setFormData({...formData, initialPayment: Number(e.target.value)})} className="w-full px-4 py-3 border border-investor rounded-xl text-sm focus:ring-2 focus:ring-investor/20 outline-none transition-all font-extrabold text-investor" placeholder="Amount to pay now" required />

Pay part of your investment now to confirm

{/* Profit Sharing Policy */}

FICO Share - Jaiben's Profit per Ride

Profit sharing when bikes are rented to end customers

Single Rent

{selectedTemplate.ficoShare.single}%

Rent to Own

{selectedTemplate.ficoShare.own}%

Share an EV

{selectedTemplate.ficoShare.ev}%

{/* Auto-Journal Entry Visualization */}

Auto-Journal Entry (Draft)

Account Details Amount (৳)

Debit (Dr)

Bank - City Bank

CODE: 1200

৳{formData.investmentAmount.toLocaleString()}

Credit (Cr)

Investor Liabilities

CODE: 2200

৳{formData.investmentAmount.toLocaleString()}

Reference: INV/{new Date().getFullYear()}/AUTO-{Math.random().toString(36).substring(7).toUpperCase()}

Status: Draft - On Creation

{/* Time & Period */}

Schedule

setFormData({...formData, startDate: e.target.value})} className="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-investor/20 outline-none font-bold" required />
setFormData({...formData, endDate: e.target.value})} className="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-investor/20 outline-none font-bold" />

Duration is fixed at {selectedTemplate.duration} months with a {selectedTemplate.lockIn} month lock-in period as per template.

{/* Payment Details */}

Payment

setFormData({...formData, transactionRef: e.target.value})} className="w-full px-4 py-2.5 bg-slate-50 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-investor/20 outline-none font-bold" placeholder="Auto-generated if empty" />
Pay Now ৳{formData.initialPayment.toLocaleString()}
Balance Due ৳{(formData.investmentAmount - formData.initialPayment).toLocaleString()}
{/* Actions */}
)}
); }