import { Effect, Schema } from "effect";
import { Align, columnFields } from "../../../utils/shared.js";
export const type = "com.shwfed.table.column.number";
export const compatibilityDate = "2026-04-14";
export const metadata = {
  name: "\u6570\u503C",
  icon: "fluent:number-symbol-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: () => "right" }),
    displayMode: Schema.optionalWith(
      Schema.Literal("plain", "uppercaseChinese", "monoThousand").annotations({
        title: "\u6A21\u5F0F",
        description: "\u6570\u503C\u7684\u5C55\u793A\u6A21\u5F0F\uFF1A\u6570\u503C\uFF08\u539F\u6837\uFF09\u3001\u4E2D\u6587\u5927\u5199\uFF08\u5982 4200 \u2192 `\u8086\u4EDF\u8D30\u4F70\u96F6\u62FE`\uFF09\u3001\u7B49\u5BBD\u5B57\u4F53\u52A0\u5343\u5206\u4F4D\uFF08\u5982 `4,200`\uFF09"
      }),
      { default: () => "plain" }
    ),
    preserveMode: Schema.optional(Schema.Literal("round", "floor", "ceil").annotations({
      title: "\u4FDD\u7559\u6A21\u5F0F",
      description: "\u5C0F\u6570\u4FDD\u7559\u6A21\u5F0F"
    })),
    preserveDigits: Schema.optional(Schema.Number.pipe(Schema.int(), Schema.nonNegative()).annotations({
      title: "\u4FDD\u7559\u5C0F\u6570\u4F4D\u6570",
      description: "\u5F3A\u5236\u4FDD\u7559\u8BE5\u6570\u91CF\u7684\u5C0F\u6570\u4F4D\u6570\uFF1A\u5F53\u4E0D\u6EE1\u65F6\u81EA\u52A8\u586B\u5145\uFF1B\u5F53\u8D85\u8FC7\u65F6\u820D\u5F03"
    }))
  }).annotations({ title: "NumberRenderer", description: "\u6570\u503C\u6E32\u67D3\u5668" });
}
export function defaults() {
  return {
    title: [{ locale: "zh", message: "" }],
    accessor: "",
    size: 120,
    align: "right"
  };
}
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)
    }
  };
}
