import React, { useState } from 'react'; import { User, Mail, Phone, Lock, Globe, Clock, Camera, Save, X } from 'lucide-react'; import { Button, Card, Avatar, Input, Select } from '../../../../components/ui'; import { PageHeader } from '../../../../components/layout'; import { useAuthUser } from '../../../../stores/auth.store'; import { useToast } from '../../../../hooks/ui/useToast'; interface ProfileFormData { first_name: string; last_name: string; email: string; phone: string; language: string; timezone: string; } interface PasswordData { currentPassword: string; newPassword: string; confirmPassword: string; } const ProfilePage: React.FC = () => { const user = useAuthUser(); const { showToast } = useToast(); const [isEditing, setIsEditing] = useState(false); const [isLoading, setIsLoading] = useState(false); const [showPasswordForm, setShowPasswordForm] = useState(false); const [profileData, setProfileData] = useState({ first_name: 'María', last_name: 'González Pérez', email: 'admin@bakery.com', phone: '+34 612 345 678', language: 'es', timezone: 'Europe/Madrid' }); const [passwordData, setPasswordData] = useState({ currentPassword: '', newPassword: '', confirmPassword: '' }); const [errors, setErrors] = useState>({}); const languageOptions = [ { value: 'es', label: 'Español' }, { value: 'ca', label: 'Català' }, { value: 'en', label: 'English' } ]; const timezoneOptions = [ { value: 'Europe/Madrid', label: 'Madrid (CET/CEST)' }, { value: 'Atlantic/Canary', label: 'Canarias (WET/WEST)' }, { value: 'Europe/London', label: 'Londres (GMT/BST)' } ]; const validateProfile = (): boolean => { const newErrors: Record = {}; if (!profileData.first_name.trim()) { newErrors.first_name = 'El nombre es requerido'; } if (!profileData.last_name.trim()) { newErrors.last_name = 'Los apellidos son requeridos'; } if (!profileData.email.trim()) { newErrors.email = 'El email es requerido'; } else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(profileData.email)) { newErrors.email = 'Email inválido'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const validatePassword = (): boolean => { const newErrors: Record = {}; if (!passwordData.currentPassword) { newErrors.currentPassword = 'Contraseña actual requerida'; } if (!passwordData.newPassword) { newErrors.newPassword = 'Nueva contraseña requerida'; } else if (passwordData.newPassword.length < 8) { newErrors.newPassword = 'Mínimo 8 caracteres'; } if (passwordData.newPassword !== passwordData.confirmPassword) { newErrors.confirmPassword = 'Las contraseñas no coinciden'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleSaveProfile = async () => { if (!validateProfile()) return; setIsLoading(true); try { // Simulate API call await new Promise(resolve => setTimeout(resolve, 1000)); setIsEditing(false); showToast({ type: 'success', title: 'Perfil actualizado', message: 'Tu información ha sido guardada correctamente' }); } catch (error) { showToast({ type: 'error', title: 'Error', message: 'No se pudo actualizar tu perfil' }); } finally { setIsLoading(false); } }; const handleChangePassword = async () => { if (!validatePassword()) return; setIsLoading(true); try { // Simulate API call await new Promise(resolve => setTimeout(resolve, 1000)); setShowPasswordForm(false); setPasswordData({ currentPassword: '', newPassword: '', confirmPassword: '' }); showToast({ type: 'success', title: 'Contraseña actualizada', message: 'Tu contraseña ha sido cambiada correctamente' }); } catch (error) { showToast({ type: 'error', title: 'Error', message: 'No se pudo cambiar tu contraseña' }); } finally { setIsLoading(false); } }; const handleInputChange = (field: keyof ProfileFormData) => (e: React.ChangeEvent) => { setProfileData(prev => ({ ...prev, [field]: e.target.value })); if (errors[field]) { setErrors(prev => ({ ...prev, [field]: '' })); } }; const handleSelectChange = (field: keyof ProfileFormData) => (value: string) => { setProfileData(prev => ({ ...prev, [field]: value })); }; const handlePasswordChange = (field: keyof PasswordData) => (e: React.ChangeEvent) => { setPasswordData(prev => ({ ...prev, [field]: e.target.value })); if (errors[field]) { setErrors(prev => ({ ...prev, [field]: '' })); } }; return (
{/* Profile Header */}

{profileData.first_name} {profileData.last_name}

{profileData.email}

En línea
{!isEditing && ( )}
{/* Profile Form */}

Información Personal

} /> } /> } /> } />
{isEditing && (
)}
{/* Password Change Form */} {showPasswordForm && (

Cambiar Contraseña

} /> } /> } />
)}
); }; export default ProfilePage;