"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Card, CardHeader, CardContent } from "@/components/ui/Card"; import Button from "@/components/ui/Button"; import { Input } from "@/components/ui/Input"; import { formatDateForInput } from "@/lib/utils"; import { useTranslation } from "@/lib/i18n"; export default function ContractForm() { const { t } = useTranslation(); const [form, setForm] = useState({ contract_number: "", contract_name: "", customer_contract_number: "", customer: "", investor: "", date_signed: "", finish_date: "", }); const [loading, setLoading] = useState(false); const router = useRouter(); function handleChange(e) { setForm({ ...form, [e.target.name]: e.target.value }); } async function handleSubmit(e) { e.preventDefault(); setLoading(true); try { console.log("Submitting form:", form); const res = await fetch("/api/contracts", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(form), }); if (res.ok) { const contract = await res.json(); router.push(`/contracts/${contract.contract_id}`); } else { alert(t('contracts.failedToCreateContract')); } } catch (error) { console.error("Error creating contract:", error); alert(t('contracts.failedToCreateContract')); } finally { setLoading(false); } } return (

{t('contracts.contractDetails')}

{/* Basic Information Section */}
{" "}
{" "}
{/* Form Actions */}
); }