import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { useAuthStore } from '@/store/authStore' import { authApi } from '@/api/auth' import { toast } from '@/lib/toast' import { PasswordInput } from '@/components/common/PasswordInput' import { BrandLogo } from '@/components/common/BrandLogo' import { cn } from '@/lib/utils' export function ChangePasswordPage() { const navigate = useNavigate() const { user, logout } = useAuthStore() const isForced = user?.must_change_password ?? false const [currentPassword, setCurrentPassword] = useState('') const [newPassword, setNewPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const [isLoading, setIsLoading] = useState(false) const [error, setError] = useState('') const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') if (!currentPassword || !newPassword || !confirmPassword) { setError('Please fill in all fields') return } if (newPassword !== confirmPassword) { setError('New passwords do not match') return } if (newPassword.length < 10) { setError('Password must be at least 10 characters') return } setIsLoading(true) try { await authApi.changePassword(currentPassword, newPassword) toast.success('Password changed successfully. Please sign in again.') await logout() navigate('/login', { replace: true }) } catch (err: unknown) { if (err && typeof err === 'object' && 'response' in err) { const axiosErr = err as { response?: { data?: { detail?: string } } } setError(axiosErr.response?.data?.detail || 'Failed to change password') } else { setError('Failed to change password') } } finally { setIsLoading(false) } } return (