import { Schema } from "effect";
import { getProperty } from "dot-prop";
import { Locale } from "../../../../../share/locale.js";
import { CelRowAccess, derivedRowField, editableColumnFields, editableHeader } from "../../../utils/shared.js";
export const type = "com.shwfed.table.column.text-input";
export const compatibilityDate = "2026-05-20";
export const metadata = {
  name: "\u6587\u672C\u8F93\u5165",
  icon: "fluent:text-field-20-regular"
};
export function schema(configure) {
  const CelBool = CelRowAccess(configure, { resultType: "bool" });
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    ...editableColumnFields(),
    placeholder: Schema.optional(Locale.annotations({
      title: "\u5360\u4F4D\u7B26",
      description: "\u5355\u5143\u683C\u4E3A\u7A7A\u65F6\u663E\u793A\u7684\u63D0\u793A\u6587\u672C"
    })),
    hidden: Schema.optional(CelBool.annotations({
      title: "\u9690\u85CF\u6761\u4EF6",
      description: "\u8FD4\u56DE `true` \u65F6\u8BE5\u884C\u7684\u8F93\u5165\u6846\u4E0D\u6E32\u67D3\uFF08\u5176\u4F59\u884C\u4E0D\u53D7\u5F71\u54CD\uFF09"
    })),
    disabled: Schema.optional(CelBool.annotations({
      title: "\u7981\u7528\u6761\u4EF6",
      description: "\u8FD4\u56DE `true` \u65F6\u8F93\u5165\u6846\u4ECD\u7136\u6E32\u67D3\u4F46\u4E0D\u53EF\u7F16\u8F91"
    })),
    readonly: Schema.optional(CelBool.annotations({
      title: "\u53EA\u8BFB\u6761\u4EF6",
      description: "\u8FD4\u56DE `true` \u65F6\u4EC5\u4EE5\u7EAF\u6587\u672C\u5C55\u793A\u5F53\u524D\u503C"
    })),
    derived: derivedRowField(configure, "string")
  }).annotations({ title: "TextInputRenderer", description: "\u6587\u672C\u8F93\u5165\u6E32\u67D3\u5668\uFF08\u53EF\u7F16\u8F91\uFF09" });
}
export function defaults() {
  return {
    title: [{ locale: "zh", message: "" }],
    binding: "",
    size: 120
  };
}
export function toColumnDef(value, { getLocaleText }) {
  return {
    header: editableHeader(getLocaleText(value.title)),
    // `binding` is a dot-prop path (validated non-empty); the cell renderer
    // reads through the same path it writes to. No CEL — accessor is literal.
    accessorFn: (row) => {
      if (!row || typeof row !== "object") return void 0;
      return getProperty(row, value.binding);
    },
    enableSorting: value.enableSorting ?? false,
    sortingFn: "alphanumeric",
    size: value.size,
    meta: {
      grow: value.grow ?? false,
      tooltip: getLocaleText(value.tooltip)
    }
  };
}
