"use client"; import { useState } from "react"; const TYPE_OPTIONS = [ { value: "", label: "-- Typ wählen --" }, { value: "INF", label: "Verletzungsklage (INF)" }, { value: "REV", label: "Widerruf (REV)" }, { value: "CCR", label: "Einstweilige Verfügung (CCR)" }, { value: "APP", label: "Berufung (APP)" }, { value: "PI", label: "Vorläufiger Rechtsschutz (PI)" }, { value: "ZPO_CIVIL", label: "ZPO Zivilverfahren" }, ]; export interface CaseFormData { case_number: string; title: string; case_type?: string; court?: string; court_ref?: string; status: string; } interface CaseFormProps { initialData?: Partial; onSubmit: (data: CaseFormData) => void; isSubmitting?: boolean; submitLabel?: string; } export function CaseForm({ initialData, onSubmit, isSubmitting, submitLabel = "Akte anlegen", }: CaseFormProps) { const [form, setForm] = useState({ case_number: initialData?.case_number ?? "", title: initialData?.title ?? "", case_type: initialData?.case_type ?? "", court: initialData?.court ?? "", court_ref: initialData?.court_ref ?? "", status: initialData?.status ?? "active", }); const [errors, setErrors] = useState>>({}); function validate(): boolean { const newErrors: Partial> = {}; if (!form.case_number.trim()) { newErrors.case_number = "Aktenzeichen ist erforderlich"; } if (!form.title.trim()) { newErrors.title = "Titel ist erforderlich"; } setErrors(newErrors); return Object.keys(newErrors).length === 0; } function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!validate()) return; const data: CaseFormData = { ...form, case_type: form.case_type || undefined, court: form.court || undefined, court_ref: form.court_ref || undefined, }; onSubmit(data); } function update(field: keyof CaseFormData, value: string) { setForm((prev) => ({ ...prev, [field]: value })); if (errors[field]) { setErrors((prev) => ({ ...prev, [field]: undefined })); } } const inputClass = "w-full rounded-md border border-neutral-200 bg-white px-3 py-1.5 text-sm outline-none transition-colors focus:border-neutral-400 focus:ring-1 focus:ring-neutral-400"; return (
update("case_number", e.target.value)} placeholder="z.B. 2026/001" className={`${inputClass} ${errors.case_number ? "border-red-300 focus:border-red-400 focus:ring-red-400" : ""}`} /> {errors.case_number && (

{errors.case_number}

)}
update("title", e.target.value)} placeholder="Bezeichnung der Akte" className={`${inputClass} ${errors.title ? "border-red-300 focus:border-red-400 focus:ring-red-400" : ""}`} /> {errors.title && (

{errors.title}

)}
update("court", e.target.value)} placeholder="z.B. UPC München Zentralkammer" className={inputClass} />
update("court_ref", e.target.value)} placeholder="z.B. UPC_CFI_123/2026" className={inputClass} />
); }