'use client' import { useState, useEffect } from 'react' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Textarea } from '@/components/ui/textarea' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { toast } from 'sonner' import { Loader2, CheckCircle, Crown, Award, Star } from 'lucide-react' import { signIn } from 'next-auth/react' interface PartnershipApplicationFormProps { isOpen: boolean onClose: () => void selectedTier?: string } export default function PartnershipApplicationForm({ isOpen, onClose, selectedTier = 'Silver' }: PartnershipApplicationFormProps) { const [formData, setFormData] = useState({ firstName: '', lastName: '', email: '', phone: '', businessName: '', businessType: '', experience: '', partnershipTier: selectedTier, expectedCustomers: '', address: '', city: '', state: '', zipCode: '', motivation: '', marketingPlan: '' }) const [isSubmitting, setIsSubmitting] = useState(false) const [isSuccess, setIsSuccess] = useState(false) // Update form data when selectedTier prop changes useEffect(() => { setFormData(prev => ({ ...prev, partnershipTier: selectedTier })) }, [selectedTier]) // Reset form when modal opens useEffect(() => { if (isOpen) { setFormData({ firstName: '', lastName: '', email: '', phone: '', businessName: '', businessType: '', experience: '', partnershipTier: selectedTier, expectedCustomers: '', address: '', city: '', state: '', zipCode: '', motivation: '', marketingPlan: '' }) setIsSuccess(false) setIsSubmitting(false) } }, [isOpen, selectedTier]) const handleInputChange = (field: string, value: string) => { setFormData(prev => ({ ...prev, [field]: value })) } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsSubmitting(true) try { const response = await fetch('/api/partnership/apply', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ ...formData, expectedCustomers: parseInt(formData.expectedCustomers) || 0 }), }) const result = await response.json() if (result.success) { setIsSuccess(true) toast.success('Application submitted successfully! Check your email for login details.') // Auto-login the user after successful registration setTimeout(async () => { try { await signIn('credentials', { email: formData.email, redirect: false }) window.location.href = '/dashboard' } catch (error) { console.error('Auto-login failed:', error) } }, 2000) } else { toast.error(result.message || 'Application failed. Please try again.') } } catch (error) { console.error('Application error:', error) toast.error('Something went wrong. Please try again.') } finally { setIsSubmitting(false) } } const getTierIcon = (tier: string) => { switch (tier) { case 'Diamond': return Crown case 'Gold': return Award case 'Silver': return Star default: return Star } } const getTierColor = (tier: string) => { switch (tier) { case 'Diamond': return '#3B82F6' case 'Gold': return '#F59E0B' case 'Silver': return '#8B5CF6' default: return '#8B5CF6' } } const getTierMaxCustomers = (tier: string) => { switch (tier) { case 'Diamond': return 3000 case 'Gold': return 1500 case 'Silver': return 500 default: return 500 } } if (isSuccess) { return (

Application Submitted!

Welcome to Padmaaja Rasooi! Check your email for login details.

You'll be automatically logged in and redirected to your dashboard.

) } return ( Partnership Application {/* Selected Tier Display */}
{(() => { const TierIcon = getTierIcon(formData.partnershipTier) return (
) })()}

{formData.partnershipTier} Partner

Max {getTierMaxCustomers(formData.partnershipTier).toLocaleString()} customers

{/* Personal Information */} Personal Information
handleInputChange('firstName', e.target.value)} required />
handleInputChange('lastName', e.target.value)} required />
handleInputChange('email', e.target.value)} required />
handleInputChange('phone', e.target.value)} required />
{/* Business Information */} Business Information
handleInputChange('businessName', e.target.value)} />
{/* Partnership Details */} Partnership Details
handleInputChange('expectedCustomers', e.target.value)} max={getTierMaxCustomers(formData.partnershipTier)} />
{/* Address Information */} Address Information
handleInputChange('address', e.target.value)} required />
handleInputChange('city', e.target.value)} required />
handleInputChange('state', e.target.value)} required />
handleInputChange('zipCode', e.target.value)} required />
{/* Additional Information */} Additional Information