import { Effect, Schema } from "effect";
import { Align, columnFields } from "../../../utils/shared.js";
import { md } from "../../../../../share/markdown.js";
export const type = "com.shwfed.table.column.date";
export const compatibilityDate = "2026-04-14";
export const metadata = {
  name: "\u65E5\u671F",
  icon: "fluent:calendar-ltr-20-regular"
};
export function schema(configure) {
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    ...columnFields(configure),
    align: Schema.optionalWith(Align.annotations({ title: "\u5BF9\u9F50" }), { default: () => "left" }),
    format: Schema.String.annotations({
      title: "\u65E5\u671F\u683C\u5F0F",
      description: md`
        参考 <a href="https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table" target="_blank">Unicode 日期格式</a>
      `
    })
  }).annotations({ title: "DateRenderer", description: "\u65E5\u671F\u6E32\u67D3\u5668" });
}
export function defaults() {
  return {
    title: [{ locale: "zh", message: "" }],
    accessor: "",
    format: "yyyy-MM-dd",
    size: 120
  };
}
export function toColumnDef(value, { getLocaleText, $cel, inheritedContext }) {
  return {
    header: getLocaleText(value.title),
    accessorFn: (row, index) => {
      try {
        return Effect.runSync($cel(value.accessor, { ...inheritedContext, row, index }));
      } catch (e) {
        console.error("[shwfed-table] accessor failed", e);
        return void 0;
      }
    },
    enableSorting: value.enableSorting ?? false,
    size: value.size,
    meta: {
      grow: value.grow ?? false,
      tooltip: getLocaleText(value.tooltip)
    }
  };
}
