import { Schema } from "effect";
import { Expression } from "../../../../../share/expression.js";
import { Triggers } from "../../../../../share/event-bus.js";
import { md } from "../../../../../share/markdown.js";
export const type = "com.shwfed.actions.button.state.write";
export const compatibilityDate = "2026-05-24";
export const metadata = {
  name: "\u5199\u5165\u8868\u5355\u72B6\u6001",
  icon: "fluent:document-edit-20-regular"
};
export function schema(configure) {
  const CelRecord = Expression({
    configure,
    resultType: (t) => t === "dyn" || t.startsWith("map")
  });
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    expression: CelRecord.annotations({
      title: "\u5199\u5165\u503C",
      description: md`
        点击后求值，返回一个 \`map\`。其每个顶层键都会被写入到最近祖先的表单状态中：
        对象值与当前值深合并（数组整体替换），其他类型直接替换。
        返回 \`{}\` 表示不进行任何写入。
      `
    }),
    onSuccess: Schema.optional(Triggers.annotations({
      title: "\u5199\u5165\u540E",
      description: "\u5199\u5165\u5B8C\u6210\u540E\u6267\u884C\u7684\u64CD\u4F5C"
    }))
  }).annotations({
    title: "StateWriteAction",
    description: "\u70B9\u51FB\u540E\u5C06 CEL \u8868\u8FBE\u5F0F\u7684\u7ED3\u679C\u5199\u56DE\u6700\u8FD1\u7956\u5148\u7684\u8868\u5355\u72B6\u6001"
  });
}
