"use client"; import { type FormEvent, useState } from "react"; import { FormModal } from "../components/form-modal"; import { estimateDefaultGroups, type EstimateGroupSnapshot, } from "../../shared/estimate-balance/estimate-balance"; import { estimateTextLimits } from "./estimate-balance-document"; export interface EstimateGroupFormValues { costGroup: string; title: string; editor: string | null; } interface EstimateGroupModalProps { group: EstimateGroupSnapshot | null; onClose: () => void; onSave: (values: EstimateGroupFormValues) => void; } /** Creates or edits the KG number, title and "bearbeitet von" of one group. */ export function EstimateGroupModal({ group, onClose, onSave }: EstimateGroupModalProps) { const [costGroup, setCostGroup] = useState(group?.costGroup ?? ""); const [title, setTitle] = useState(group?.title ?? ""); const [editor, setEditor] = useState(group?.editor ?? ""); function applyTemplate(index: string) { const template = estimateDefaultGroups[Number(index)]; if (template) { setCostGroup(template.costGroup); setTitle(template.title); } } function handleSubmit(event: FormEvent) { event.preventDefault(); if (!title.trim()) { return; } onSave({ costGroup: costGroup.trim(), title: title.trim(), editor: editor.trim() || null, }); } return (
{!group ? (
) : null}
setCostGroup(event.target.value)} placeholder="z. B. 440" value={costGroup} />
setTitle(event.target.value)} placeholder="z. B. Starkstromanlagen" required value={title} />
setEditor(event.target.value)} placeholder="Gewerk oder Name (optional)" value={editor} />

Ohne KG-Nummer (z. B. „Allgemein“) wird die Gruppe im Vergleich mit der detaillierten Bilanz keiner Kostengruppe zugeordnet.

); }