import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; import { useAuthStore } from '../../store/authStore'; import { Button, Input, Card, CardHeader, CardTitle, CardContent } from '../ui'; import { User, CreditCard, Crown, Zap, Star, Check } from 'lucide-react'; import toast from 'react-hot-toast'; import { Link } from 'react-router-dom'; const profileSchema = z.object({ firstName: z.string().min(1, 'First name is required'), lastName: z.string().min(1, 'Last name is required'), email: z.string().email('Please enter a valid email address'), }); type ProfileFormData = z.infer; export function UserProfile() { const { user, updateUser } = useAuthStore(); const [isEditing, setIsEditing] = useState(false); const [isLoading, setIsLoading] = useState(false); const { register, handleSubmit, formState: { errors }, reset, } = useForm({ resolver: zodResolver(profileSchema), defaultValues: { firstName: user?.name?.split(' ')[0] || '', lastName: user?.name?.split(' ').slice(1).join(' ') || '', email: user?.email || '', }, }); const onSubmit = async (data: ProfileFormData) => { try { setIsLoading(true); // Combine first and last name const fullName = `${data.firstName} ${data.lastName}`.trim(); // Update user profile updateUser({ name: fullName, email: data.email, }); toast.success('Profile updated successfully!'); setIsEditing(false); } catch (error: any) { toast.error(error.message || 'Failed to update profile'); } finally { setIsLoading(false); } }; const handleCancel = () => { setIsEditing(false); reset({ firstName: user?.name?.split(' ')[0] || '', lastName: user?.name?.split(' ').slice(1).join(' ') || '', email: user?.email || '', }); }; const getPlanIcon = (plan: string) => { switch (plan) { case 'pro': return ; case 'enterprise': return ; default: return ; } }; const getPlanColor = (plan: string) => { switch (plan) { case 'pro': return 'bg-blue-50 border-blue-200 text-blue-800 dark:bg-blue-900/20 dark:border-blue-800 dark:text-blue-200'; case 'enterprise': return 'bg-purple-50 border-purple-200 text-purple-800 dark:bg-purple-900/20 dark:border-purple-800 dark:text-purple-200'; default: return 'bg-gray-50 border-gray-200 text-gray-800 dark:bg-gray-800/20 dark:border-gray-700 dark:text-gray-200'; } }; const currentPlan = user?.subscription?.plan || 'free'; const planStatus = user?.subscription?.status || 'active'; return (
{/* Profile Information */}
Profile Information {!isEditing && ( )}
{isEditing ? (
) : (

{user?.name?.split(' ')[0] || 'Not provided'}

{user?.name?.split(' ').slice(1).join(' ') || 'Not provided'}

{user?.email}

{user?.createdAt ? new Date(user.createdAt).toLocaleDateString() : 'N/A'}

)}
{/* Subscription Information */} Subscription Plan
{/* Current Plan */}
{getPlanIcon(currentPlan)}

{currentPlan} Plan

{currentPlan === 'free' && 'Basic features with limited usage'} {currentPlan === 'pro' && 'Full features with unlimited usage'} {currentPlan === 'enterprise' && 'Advanced features for teams'}

{currentPlan === 'free' && '$0/month'} {currentPlan === 'pro' && '$19/month'} {currentPlan === 'enterprise' && '$99/month'}
{planStatus}
{/* Plan Features */}
{currentPlan === 'free' && ( <>
10 conversations/month
Basic AI models
Standard support
Web access
)} {currentPlan === 'pro' && ( <>
Unlimited conversations
Advanced AI models
Priority support
API access
Custom themes
Export conversations
)} {currentPlan === 'enterprise' && ( <>
Everything in Pro
Team collaboration
Admin dashboard
SSO integration
Custom branding
Dedicated support
)}
{/* Upgrade Options */} {currentPlan !== 'enterprise' && (

Upgrade Your Plan

{currentPlan === 'free' && ( <>
Pro Plan

Unlimited conversations and advanced features

$19/month
Enterprise Plan

Advanced features for teams and organizations

$99/month
)} {currentPlan === 'pro' && (
Enterprise Plan

Advanced features for teams and organizations

$99/month
)}
)} {/* Usage Statistics */}

Usage This Month

0
Conversations
0
Messages
0
API Calls
); }