import { Effect, Schema } from "effect";
import { Align, CelRowAccess, columnFields } from "../../../utils/shared.js";
export const type = "com.shwfed.table.column.icon";
export const compatibilityDate = "2026-04-14";
export const metadata = {
  name: "\u56FE\u6807",
  icon: "fluent:shapes-20-regular"
};
export function schema(configure) {
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    ...columnFields(configure),
    accessor: CelRowAccess(configure).annotations({
      title: "\u56FE\u6807",
      description: "\u56FE\u6807\u540D\u79F0 CEL \u8868\u8FBE\u5F0F\uFF08Iconify \u6807\u8BC6\u7B26\uFF09\uFF0C\u4F8B\u5982 `row.iconName`"
    }),
    color: Schema.optional(
      CelRowAccess(configure, { resultType: "string" }).annotations({
        title: "\u989C\u8272",
        description: '\u56FE\u6807\u989C\u8272 CEL \u8868\u8FBE\u5F0F\uFF0C\u8FD4\u56DE CSS \u989C\u8272\u5B57\u7B26\u4E32\uFF08\u5982 `"#ef4444"` \u6216 `"red"`\uFF09'
      })
    ),
    align: Schema.optionalWith(Align.annotations({ title: "\u5BF9\u9F50" }), { default: () => "center" })
  }).annotations({ title: "IconRenderer", description: "\u56FE\u6807\u6E32\u67D3\u5668" });
}
export function defaults() {
  return {
    title: [{ locale: "zh", message: "" }],
    accessor: "",
    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)
    }
  };
}
