import { useId, useState } from "react"; import { useTranslation } from "react-i18next"; import type { components } from "../api/schema"; import { LabelEditor } from "./label-editor"; import { DeleteConfirmDialog } from "./delete-confirm-dialog"; import { MutationError } from "./mutation-error"; import { ExternalUriLink } from "./external-uri-link"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { labelText } from "../lib/labels"; type LabelView = components["schemas"]["LabelView"]; type LabelInput = components["schemas"]["LabelInput"]; export type RecordLike = { id: string; labels: LabelView[]; external_uri: string | null }; /** One labelled record (term/authority): a display row with edit + delete, or an * inline editor. All variance (mutation hooks, arg shapes, delete-confirm key) is * supplied by the caller via callbacks/state — see term-row.tsx / authority-row.tsx. */ export function LabelledRecordRow({ record, lang, deleteConfirmKey, savePending, saveError, onEditOpen, onSave, onDelete, }: { record: RecordLike; lang: string; deleteConfirmKey: string; savePending: boolean; saveError: unknown; onEditOpen: () => void; onSave: (labels: LabelInput[], uri: string | null, done: () => void) => void; onDelete: () => Promise; }) { const { t } = useTranslation(); const uriId = useId(); const [editing, setEditing] = useState(false); const [labels, setLabels] = useState(record.labels as LabelInput[]); const [uri, setUri] = useState(record.external_uri ?? ""); if (editing) { return (
  • setUri(e.target.value)} />
  • ); } return (
  • {labelText(record.labels, lang)}
    {record.external_uri && }
  • ); }