"use client" import type React from "react" import { useState } from "react" import { useRouter } from "next/navigation" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Alert, AlertDescription } from "@/components/ui/alert" export default function LoginPage() { const [nationalId, setNationalId] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const [loading, setLoading] = useState(false) const router = useRouter() const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError("") try { const response = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ nationalId, password }), }) const data = await response.json() if (response.ok) { localStorage.setItem("user", JSON.stringify(data.user)) // Check if user must change password if (data.user.must_change_password) { router.push("/change-password") } else { router.push("/dashboard") } } else { setError(data.error || "שגיאה בהתחברות") } } catch (err) { setError("שגיאה בחיבור לשרת") } finally { setLoading(false) } } return (