import { Schema } from "effect";
import { Expression, Slot, defaultSlot } from "../../share/layout.js";
import { Locale } from "../../share/locale.js";
import * as alertOperation from "../operations/2026-06-09/com.shwfed.operation.alert/schema.js";
import * as httpRequestOperation from "../operations/2026-06-11/com.shwfed.operation.http.request.json/schema.js";
import { blockRef } from "./utils/resolve.js";
export { getStructFieldDescription, getStructFieldTitle } from "../table/utils/schema-meta.js";
const KIND = "shwfed.component.page";
export { PAGE_TARGET_ID } from "../../share/page-target.js";
export const metadata = {
  name: "\u9875\u9762",
  icon: "fluent:document-20-regular",
  operations: [
    { id: "close", name: "\u5173\u95ED\u6807\u7B7E\u9875", icon: "fluent:dismiss-20-regular" },
    // Parameterized op: `compatibilityDate` marks it as carrying params, so the
    // trigger editor seeds `defaults()` and renders the alert's `config.vue`.
    // `id` doubles as the operation-block `type`.
    {
      id: alertOperation.type,
      compatibilityDate: alertOperation.compatibilityDate,
      name: alertOperation.metadata.name,
      icon: alertOperation.metadata.icon
    },
    // Ambient HTTP request — one step of a trigger chain, so a button can
    // sequence several requests (each failure halts the rest). The page hosts
    // it because the request acts on nothing instance-specific.
    {
      id: httpRequestOperation.type,
      compatibilityDate: httpRequestOperation.compatibilityDate,
      name: httpRequestOperation.metadata.name,
      icon: httpRequestOperation.metadata.icon
    }
  ]
};
export function PageConfig(configure) {
  const Block = blockRef(configure).annotations({
    identifier: "PageBlock",
    description: "\u9875\u9762\u5757\uFF0C\u7531 `type` \u5B57\u6BB5\u533A\u5206\u7C7B\u578B"
  });
  const PageSlot = Slot(Block, configure);
  const CelStyle = Expression({
    configure,
    resultType: (t) => t === "string" || t === "dyn" || t.startsWith("map") || t.startsWith("optional")
  });
  return Schema.Struct({
    kind: Schema.tag(KIND),
    title: Schema.optional(Locale).annotations({
      title: "\u6807\u9898",
      description: "\u9875\u9762\u6807\u9898\uFF08\u5185\u8054\u672C\u5730\u5316\u6587\u672C\uFF0C\u65E0 Markdown\uFF09\uFF1B\u8BBE\u7F6E\u540E\u7528\u4E8E\u6D4F\u89C8\u5668\u6807\u7B7E\u9875\u6807\u9898\uFF0C\u6309\u5F53\u524D\u8BED\u8A00\u53D6\u5BF9\u5E94\u6587\u6848\uFF0C\u7559\u7A7A\u5219\u4E0D\u8BBE\u7F6E"
    }),
    style: Schema.optional(CelStyle).annotations({
      title: "\u6837\u5F0F",
      description: "\u8FD4\u56DE\u5E94\u7528\u5728\u9875\u9762\u6839\u5143\u7D20\u4E0A\u7684\u6837\u5F0F\u7684 CEL \u8868\u8FBE\u5F0F\uFF0C\u53EF\u8FD4\u56DE CSS \u5B57\u7B26\u4E32\uFF08\u5982 `'padding: 2rem'`\uFF09\u6216\u6837\u5F0F\u5BF9\u8C61\uFF08\u5982 `{'padding': '2rem'}`\uFF09\uFF1B\u7559\u7A7A\u5219\u4E0D\u8BBE\u989D\u5916\u6837\u5F0F"
    }),
    slot: PageSlot
  }).annotations({
    title: "PageConfig",
    description: "\u9875\u9762\u7EC4\u4EF6\u5B8C\u6574\u914D\u7F6E"
  });
}
export function defaults() {
  return { slot: defaultSlot() };
}
export function createPageConfig(body) {
  return { kind: KIND, ...defaults(), ...body };
}
