/** The page's sections: count, the add menu, and one card per section with move and remove. */
import type { Page, Section } from "@cloudhal/core-contracts";
import {
Badge,
Button,
DropdownMenu,
Empty,
InlineCopyText,
SectionCard,
Text,
Tooltip,
} from "@cloudhal/ui";
import { ArrowDown, ArrowUp, CaretDown, Plus, Rows, Trash } from "@phosphor-icons/react";
import type { ReactNode } from "react";
import { useT } from "../../i18n/index.tsx";
import { blockIcon, newBlockSection } from "../BlockSection.tsx";
import { BodyProposals } from "../BodyProposals.tsx";
import { SectionForm } from "./SectionForm.tsx";
import { KIND_ICON, KINDS, newSection, sectionId, sectionQueryIssues } from "./sections.ts";
import type { PageEditorState } from "./usePageEditor.ts";
export function SectionList({
ed,
draft,
siteId,
readOnly,
}: {
ed: PageEditorState;
draft: Page;
siteId: string;
readOnly: boolean;
}) {
const t = useT();
const { setDraft, blockTypes, blockTitle } = ed;
const updateSection = (i: number, s: Section) =>
setDraft({ ...draft, sections: draft.sections.map((x, j) => (j === i ? s : x)) });
const move = (i: number, dir: -1 | 1) => {
const sections = [...draft.sections];
const j = i + dir;
if (j < 0 || j >= sections.length) return;
[sections[i], sections[j]] = [sections[j] as Section, sections[i] as Section];
setDraft({ ...draft, sections });
};
const kindLabel = (k: Section["kind"]) => t(`editor.sectionKinds.${k}`);
const sectionTitle = (s: Section) =>
s.kind === "component" ? blockTitle(s.type) : kindLabel(s.kind);
const sectionIcon = (s: Section) =>
s.kind === "component"
? blockIcon(blockTypes.find((b) => b.name === s.type))
: KIND_ICON[s.kind];
const addMenu =