import { Schema } from "effect";
import { Expression, LocaleMarkdown } from "../../../../../share/expression.js";
import { Locale } from "../../../../../share/locale.js";
import { commonFieldFields, derivedField } from "../../../utils/common.js";
export const type = "com.shwfed.form.field.checkbox.group";
export const compatibilityDate = "2026-05-17";
export const metadata = {
  name: "\u590D\u9009\u6846\u7EC4",
  icon: "fluent:checkbox-checked-20-regular",
  w: { initial: 8, min: 2, max: Infinity },
  h: { initial: 2, min: 2, max: 2 }
};
export function itemSchema(configure) {
  const LocaleMd = LocaleMarkdown({ configure });
  const TextValue = Schema.Struct({
    kind: Schema.Literal("text"),
    value: Schema.String
  });
  const NumberValue = Schema.Struct({
    kind: Schema.Literal("number"),
    value: Schema.Number
  });
  const ItemValue = Schema.Union(TextValue, NumberValue).annotations({
    title: "\u503C",
    description: "\u9009\u9879\u7ED1\u5B9A\u7684\u503C\uFF0C\u53EF\u4EE5\u662F\u6587\u672C\u6216\u6570\u5B57"
  });
  return Schema.Struct({
    id: Schema.UUID.annotations({ description: "\u9009\u9879\u552F\u4E00\u6807\u8BC6\uFF0C\u7528\u4E8E\u7A33\u5B9A\u7684 v-for key" }),
    label: LocaleMd.annotations({
      title: "\u6807\u7B7E",
      description: "\u9009\u9879\u5C55\u793A\u7684\u672C\u5730\u5316\u6587\u672C\uFF0C\u652F\u6301 Markdown \u4E0E `{{ form.foo }}` \u63D2\u503C"
    }),
    value: ItemValue,
    tooltip: Schema.optional(LocaleMd.annotations({
      title: "\u63D0\u793A",
      description: "\u5C55\u793A\u5728\u9009\u9879\u6807\u7B7E\u4E0B\u65B9\u7684\u672C\u5730\u5316\u63D0\u793A\uFF0C\u652F\u6301 Markdown"
    }))
  }).annotations({
    title: "CheckboxGroupItem"
  });
}
export function schema(configure) {
  const CelBool = Expression({ configure, resultType: "bool" });
  const Item = itemSchema(configure);
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    ...commonFieldFields(configure),
    label: Schema.optional(Locale.annotations({
      title: "\u6807\u7B7E",
      description: "\u5B57\u6BB5\u524D\u5C55\u793A\u7684\u6587\u672C\uFF1B\u7559\u7A7A\u5219\u4E0D\u6E32\u67D3\u6807\u7B7E"
    })),
    tooltip: Schema.optional(Locale.annotations({
      title: "\u63D0\u793A",
      description: "\u9F20\u6807\u60AC\u505C\u5728\u6807\u7B7E\u4E0A\u65F6\u5C55\u793A\u7684\u8BF4\u660E"
    })),
    binding: Schema.optional(Schema.String.pipe(Schema.minLength(1)).annotations({
      title: "\u7ED1\u5B9A\u8DEF\u5F84",
      description: "\u5199\u5165\u8868\u5355\u72B6\u6001\u7684 `dot-prop` \u8DEF\u5F84\uFF0C\u4F8B\u5982 `user.tags`\uFF1B\u5199\u5165\u503C\u4E3A\u5DF2\u52FE\u9009\u9009\u9879\u503C\u7684\u6570\u7EC4\uFF1B\u7559\u7A7A\u5219\u4E3A\u975E\u53D7\u63A7\u5B57\u6BB5"
    })),
    disabled: Schema.optional(CelBool.annotations({
      title: "\u7981\u7528\u6761\u4EF6",
      description: "\u8FD4\u56DE `true` \u65F6\u590D\u9009\u6846\u4ECD\u7136\u6E32\u67D3\u4F46\u4E0D\u53EF\u52FE\u9009"
    })),
    readonly: Schema.optional(CelBool.annotations({
      title: "\u53EA\u8BFB\u6761\u4EF6",
      description: "\u8FD4\u56DE `true` \u65F6\u4EC5\u4EE5\u7EAF\u6587\u672C\u5C55\u793A\u5F53\u524D\u5DF2\u52FE\u9009\u9009\u9879\u7684\u6807\u7B7E"
    })),
    derived: derivedField(configure, "dyn"),
    items: Schema.optionalWith(Schema.Array(Item).annotations({
      title: "\u9009\u9879",
      description: "\u590D\u9009\u6846\u7EC4\u53EF\u9009\u9879\u5217\u8868"
    }), { default: () => [] })
  }).annotations({
    title: "CheckboxGroupField",
    description: "\u590D\u9009\u6846\u7EC4\u591A\u9009\u8F93\u5165"
  });
}
