import { Schema } from "effect";
import { Locale } from "../../../../../share/locale.js";
import { Align, CelRowAccess, columnIdentityFields, LocaleMarkdownWithRow } from "../../../utils/shared.js";
export const type = "com.shwfed.table.column.markdown";
export const compatibilityDate = "2026-04-14";
export const metadata = {
  name: "MD",
  icon: "fluent:markdown-20-regular"
};
const isCopyExpressionType = (t) => t === "string" || t === "dyn" || t.startsWith("optional");
export function schema(configure) {
  const cel = CelRowAccess(configure, { resultType: isCopyExpressionType });
  const localeMarkdown = LocaleMarkdownWithRow(configure);
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    ...columnIdentityFields(),
    title: Locale.annotations({ title: "\u6807\u9898", description: "\u5217\u6807\u9898" }),
    align: Schema.optionalWith(Align.annotations({ title: "\u5BF9\u9F50" }), { default: () => "left" }),
    size: Schema.optional(Schema.Number.pipe(Schema.finite(), Schema.positive()).annotations({
      title: "\u5217\u5BBD",
      description: "\u5217\u56FA\u5B9A\u5BBD\u5EA6\uFF08\u50CF\u7D20\uFF09"
    })),
    grow: Schema.optional(Schema.Boolean.annotations({
      title: "\u5360\u636E\u5269\u4F59\u5BBD\u5EA6",
      description: "\u5217\u662F\u5426\u5360\u636E\u5269\u4F59\u7A7A\u4F59\u5BBD\u5EA6"
    })),
    tooltip: Schema.optional(Locale.annotations({
      title: "\u5217\u63D0\u793A",
      description: "\u5217\u6807\u9898\u60AC\u6D6E\u63D0\u793A\uFF0C\u652F\u6301 Markdown"
    })),
    markdown: localeMarkdown.annotations({
      title: "MD",
      description: "\u652F\u6301 {{ CEL }} \u63D2\u503C\u7684\u672C\u5730\u5316 Markdown \u5185\u5BB9"
    }),
    copyExpression: Schema.optional(cel.annotations({
      title: "\u590D\u5236\u8868\u8FBE\u5F0F",
      description: "\u590D\u5236\u503C\u7684 CEL \u8868\u8FBE\u5F0F\uFF1B\u53EF\u8FD4\u56DE optional\uFF08\u5982 `row.?field`\uFF09\uFF0C\u4E3A\u7A7A\u65F6\u4E0D\u663E\u793A\u590D\u5236\u6309\u94AE"
    }))
  }).annotations({ title: "MarkdownRenderer", description: "MD" });
}
export function defaults() {
  return {
    title: [{ locale: "zh", message: "" }],
    markdown: [{ locale: "zh", message: "" }],
    size: 120
  };
}
export function toColumnDef(value, { getLocaleText }) {
  return {
    header: getLocaleText(value.title),
    enableSorting: false,
    size: value.size,
    meta: {
      grow: value.grow ?? false,
      tooltip: getLocaleText(value.tooltip)
    }
  };
}
