'use client'; import React, { useState, useMemo } from 'react'; import { User, Building, Mail, Lock, Save, Bell, Camera, RotateCcw, Check, X, Eye, EyeOff, Shield, AlertCircle } from 'lucide-react'; type TabType = 'profile' | 'password' | 'notifications'; interface NotificationSettings { emailNotifications: boolean; dealUpdates: boolean; weeklyDigest: boolean; marketingEmails: boolean; smsAlerts: boolean; } export default function SettingsPage() { const [activeTab, setActiveTab] = useState('profile'); const [showCurrentPassword, setShowCurrentPassword] = useState(false); const [showNewPassword, setShowNewPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [profileSaveStatus, setProfileSaveStatus] = useState<'idle' | 'saving' | 'success' | 'error'>('idle'); const [passwordSaveStatus, setPasswordSaveStatus] = useState<'idle' | 'saving' | 'success' | 'error'>('idle'); const [notificationSaveStatus, setNotificationSaveStatus] = useState<'idle' | 'saving' | 'success' | 'error'>('idle'); // Simulated current user data const initialProfileData = { firstName: 'John', lastName: 'Doe', email: 'john.doe@example.com', brokerage: 'Premier Real Estate', phone: '(555) 123-4567', }; const [formData, setFormData] = useState({ ...initialProfileData, currentPassword: '', newPassword: '', confirmPassword: '', }); const [notifications, setNotifications] = useState({ emailNotifications: true, dealUpdates: true, weeklyDigest: false, marketingEmails: false, smsAlerts: true, }); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value })); }; const handleNotificationChange = (key: keyof NotificationSettings) => { setNotifications((prev) => ({ ...prev, [key]: !prev[key] })); }; const resetProfileForm = () => { setFormData((prev) => ({ ...prev, ...initialProfileData, })); setProfileSaveStatus('idle'); }; const resetPasswordForm = () => { setFormData((prev) => ({ ...prev, currentPassword: '', newPassword: '', confirmPassword: '', })); setPasswordSaveStatus('idle'); }; const handleProfileSubmit = (e: React.FormEvent) => { e.preventDefault(); setProfileSaveStatus('saving'); // Simulate API call setTimeout(() => { setProfileSaveStatus('success'); setTimeout(() => setProfileSaveStatus('idle'), 3000); }, 1000); }; const handlePasswordSubmit = (e: React.FormEvent) => { e.preventDefault(); if (formData.newPassword !== formData.confirmPassword) { setPasswordSaveStatus('error'); return; } setPasswordSaveStatus('saving'); // Simulate API call setTimeout(() => { setPasswordSaveStatus('success'); resetPasswordForm(); setTimeout(() => setPasswordSaveStatus('idle'), 3000); }, 1000); }; const handleNotificationSubmit = (e: React.FormEvent) => { e.preventDefault(); setNotificationSaveStatus('saving'); // Simulate API call setTimeout(() => { setNotificationSaveStatus('success'); setTimeout(() => setNotificationSaveStatus('idle'), 3000); }, 1000); }; // Password strength calculation const passwordStrength = useMemo(() => { const password = formData.newPassword; if (!password) return { score: 0, label: '', color: '' }; let score = 0; if (password.length >= 8) score++; if (password.length >= 12) score++; if (/[a-z]/.test(password) && /[A-Z]/.test(password)) score++; if (/\d/.test(password)) score++; if (/[^a-zA-Z0-9]/.test(password)) score++; if (score <= 1) return { score: 1, label: 'Weak', color: 'bg-red-500' }; if (score <= 2) return { score: 2, label: 'Fair', color: 'bg-orange-500' }; if (score <= 3) return { score: 3, label: 'Good', color: 'bg-yellow-500' }; if (score <= 4) return { score: 4, label: 'Strong', color: 'bg-green-500' }; return { score: 5, label: 'Very Strong', color: 'bg-emerald-500' }; }, [formData.newPassword]); const tabs: { id: TabType; label: string; icon: React.ReactNode }[] = [ { id: 'profile', label: 'Profile', icon: }, { id: 'password', label: 'Password', icon: }, { id: 'notifications', label: 'Notifications', icon: }, ]; const SaveStatusBadge = ({ status }: { status: 'idle' | 'saving' | 'success' | 'error' }) => { if (status === 'idle') return null; return (
{status === 'saving' && ( <>
Saving changes... )} {status === 'success' && ( <> Changes saved successfully! )} {status === 'error' && ( <> Failed to save. Please try again. )}
); }; return (

Settings

Manage your account and preferences

{/* Tab Navigation */}
{tabs.map((tab) => ( ))}
{/* Profile Tab */} {activeTab === 'profile' && (

Profile Information

Update your personal details and photo

{/* Profile Photo Upload */}
{formData.firstName.charAt(0)}{formData.lastName.charAt(0)}

Profile Photo

JPG, PNG or GIF. Max size 2MB.

)} {/* Password Tab */} {activeTab === 'password' && (

Change Password

Update your security credentials

{/* Security Tips */}

Password Security Tips

  • Use at least 12 characters with uppercase, lowercase, numbers, and symbols
  • Avoid using personal information or common words
  • Do not reuse passwords from other accounts
{/* Password Strength Indicator */} {formData.newPassword && (
Password Strength {passwordStrength.label}
{[1, 2, 3, 4, 5].map((level) => (
))}
)}
{formData.confirmPassword && formData.newPassword !== formData.confirmPassword && (

Passwords do not match

)} {formData.confirmPassword && formData.newPassword === formData.confirmPassword && formData.newPassword && (

Passwords match

)}
)} {/* Notifications Tab */} {activeTab === 'notifications' && (

Notification Preferences

Choose how you want to be notified

{[ { key: 'emailNotifications', label: 'Email Notifications', description: 'Receive important updates via email' }, { key: 'dealUpdates', label: 'Deal Updates', description: 'Get notified when deals change status' }, { key: 'weeklyDigest', label: 'Weekly Digest', description: 'Receive a summary of your activity each week' }, { key: 'marketingEmails', label: 'Marketing Communications', description: 'Stay updated on new features and tips' }, { key: 'smsAlerts', label: 'SMS Alerts', description: 'Receive text messages for urgent notifications' }, ].map((item) => (

{item.label}

{item.description}

))}
)}
); }