import { Button } from "@repo/shadcn-ui/components/button"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@repo/shadcn-ui/components/collapsible"; import { Input } from "@repo/shadcn-ui/components/input"; import { Label } from "@repo/shadcn-ui/components/label"; import { Textarea } from "@repo/shadcn-ui/components/textarea"; import { ArrowDownIcon, ArrowUpIcon, ChevronRightIcon, Trash2Icon } from "lucide-react"; import type { ReactNode } from "react"; import { useId, useState } from "react"; import { flushSync } from "react-dom"; import type { FieldSection } from "./field-sections"; import type { SectionEditorLabels } from "./template-sections-editor"; /** Conserva la edición y el estado de apertura de una sección al reordenarla. */ export function TemplateSectionEditor({ section, index, sectionCount, labels, disabled, dragHandle, onChange, onMove, onRemove, children, }: { section: FieldSection; index: number; sectionCount: number; labels: SectionEditorLabels; disabled: boolean; dragHandle: ReactNode; onChange: (section: FieldSection) => void; onMove: (offset: -1 | 1) => void; onRemove: () => void; children: ReactNode; }) { const prefix = useId(); const [open, setOpen] = useState(true); return (
} > {dragHandle}

{section.name || labels.name}

onChange({ ...section, name: event.target.value })} placeholder={labels.name} required value={section.name} />
{ // Abrir antes de que el navegador enfoque un control inválido oculto. flushSync(() => setOpen(true)); }} >