import { describe, expect, it } from "vitest";
import type { PageOptionsState } from "@/types/page-options";
import {
  PAGE_OPTION_PANEL_GROUPS,
  PAGE_OPTION_SEMANTICS,
  pickLeptosTiptapRuntimePageOptions,
} from "@/lib/documents/page-option-semantics";

const options: PageOptionsState = {
  wideLayout: true,
  smallText: true,
  showHeadingNumbers: false,
  showToc: true,
  showStructure: true,
  protectEditing: true,
  showWordCount: true,
  collapseBacklinks: true,
  pageFont: "song",
  layoutDensity: "compact",
  hideChildPages: true,
  showBlockRefCount: true,
  embedDefaultBlockId: "block-anchor-1",
};

describe("page-option-semantics", () => {
  it("应固定页面设置在 inspector 中的分组，而不是让分组散落在 UI 文件里", () => {
    expect(PAGE_OPTION_PANEL_GROUPS.page).toEqual([
      "wideLayout",
      "smallText",
      "showHeadingNumbers",
      "showToc",
      "protectEditing",
      "showWordCount",
    ]);
    expect(PAGE_OPTION_PANEL_GROUPS.custom).toEqual([
      "collapseBacklinks",
      "hideChildPages",
      "showBlockRefCount",
    ]);
  });

  it("应明确 page options 的运行时语义归属", () => {
    expect(PAGE_OPTION_SEMANTICS.wideLayout.surfaces).toEqual([
      "page_shell_layout",
      "editor_runtime",
    ]);
    expect(PAGE_OPTION_SEMANTICS.showToc.surfaces).toEqual(["read_view"]);
    expect(PAGE_OPTION_SEMANTICS.protectEditing.runtimeSupport).toBe("planned");
    expect(PAGE_OPTION_SEMANTICS.showBlockRefCount.runtimeSupport).toBe("planned");
    expect(PAGE_OPTION_SEMANTICS.embedDefaultBlockId.runtimeSupport).toBe("wired");
  });

  it("应只把已经正式接通的 runtime 选项送入 leptos-tiptap island payload", () => {
    expect(pickLeptosTiptapRuntimePageOptions(options)).toEqual({
      wideLayout: true,
      smallText: true,
      layoutDensity: "compact",
      showHeadingNumbers: false,
      embedDefaultBlockId: "block-anchor-1",
    });
  });
});
