"use client"; import { useState } from "react"; import { Label } from "@/app/components/ui/label"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, DialogFooter, } from "@/app/components/ui/dialog"; import { Input } from "@/app/components/ui/input"; import { Button } from "@/app/components/ui/button"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/app/components/ui/select"; import { LOCATION_TYPE_LABELS } from "@/app/components/locations/tabs/GeneralTab"; import { useT } from "@/app/lib/i18n/MessagesProvider"; // The backend's save does not validate parent/child types (HierarchyType.next() exists but is unused), so every type except the single Global root // is offered. ponytail: hard-code a parent->child map here if the hierarchy ever gets one. const CHILD_TYPES = Object.entries(LOCATION_TYPE_LABELS).filter(([code]) => code !== "G"); export function AddLocationDialog({ parentName, onConfirm, }: { parentName: string; onConfirm: (fields: { code: string; name: string; type: string }) => Promise; }) { const t = useT(); const [open, setOpen] = useState(false); const [code, setCode] = useState(""); const [name, setName] = useState(""); const [type, setType] = useState(""); const [error, setError] = useState(null); const [pending, setPending] = useState(false); async function handleConfirm() { if (!code.trim() || !name.trim() || !type.trim()) { setError("CatCodeNameTypeRequired"); return; } setError(null); setPending(true); try { await onConfirm({ code, name, type }); setOpen(false); setCode(""); setName(""); setType(""); } catch (err) { setError(err instanceof Error ? err.message : "LocAddFailed"); } finally { setPending(false); } } return ( {t("LocAddTitle", { parentName })}

{t("LocAddDescription", { parentName })}

setCode(e.target.value)} />
setName(e.target.value)} />
{error && (

{t(error)}

)}
); }