import { Schema } from "effect";
import { Locale } from "../../../../../share/locale.js";
import { TableConfig, defaultTableConfig } from "../../../../table/schema.js";
import { commonFieldFields } from "../../../utils/common.js";
export const type = "com.shwfed.form.field.table";
export const compatibilityDate = "2026-05-18";
export const metadata = {
  name: "\u8868\u683C",
  icon: "fluent:table-20-regular",
  w: { initial: 12, min: 6, max: Infinity },
  h: { initial: 10, min: 5, max: Infinity, grow: true },
  // Nested table/column editor — too complex for the fullscreen inline-config
  // pane; keep the (fullscreen-exiting) drill-down.
  inlineConfig: false
};
export function schema(configure) {
  const Table = Schema.suspend(
    () => TableConfig(configure)
  );
  return Schema.Struct({
    type: Schema.Literal(type),
    compatibilityDate: Schema.Literal(compatibilityDate),
    ...commonFieldFields(configure),
    label: Schema.optional(Locale.annotations({
      title: "\u6807\u7B7E",
      description: "\u8868\u683C\u4E0A\u65B9\u5C55\u793A\u7684\u6587\u672C\uFF1B\u7559\u7A7A\u5219\u4E0D\u6E32\u67D3\u6807\u7B7E"
    })),
    tooltip: Schema.optional(Locale.annotations({
      title: "\u63D0\u793A",
      description: "\u9F20\u6807\u60AC\u505C\u5728\u6807\u7B7E\u4E0A\u65F6\u5C55\u793A\u7684\u8BF4\u660E\uFF0C\u652F\u6301 Markdown"
    })),
    binding: Schema.optional(Schema.String.pipe(Schema.minLength(1)).annotations({
      title: "\u7ED1\u5B9A\u8DEF\u5F84",
      description: "\u8868\u683C\u6570\u636E\u5728\u8868\u5355\u72B6\u6001\u4E2D\u7684 `dot-prop` \u8DEF\u5F84\uFF0C\u4F8B\u5982 `rows`\uFF1B\u8868\u683C\u4ECE `form.<binding>` \u8BFB\u53D6\u884C\u6570\u636E\uFF0C\u672C\u5730\u589E\u5220\u6539\u5B9E\u65F6\u5199\u56DE\u540C\u4E00\u8DEF\u5F84\uFF1B\u7559\u7A7A\u65F6\u8868\u683C\u65E0\u6570\u636E\uFF0C\u884C\u7F16\u8F91\u4E0D\u6301\u4E45\u5316"
    })),
    table: Table.annotations({
      identifier: "FormFieldTableConfig",
      title: "\u8868\u683C\u914D\u7F6E",
      description: "\u5185\u5D4C\u8868\u683C\u7684\u5B8C\u6574\u914D\u7F6E\uFF1B\u6570\u636E\u6E90\u81EA\u52A8\u7ED1\u5B9A\u5230 `form.<binding>`\uFF0C\u65E0\u9700\u5355\u72EC\u914D\u7F6E"
    })
  }).annotations({
    title: "TableField",
    description: "\u628A\u4E00\u4E2A\u53EF\u672C\u5730\u7F16\u8F91\u7684\u8868\u683C\u5D4C\u5165\u8868\u5355\uFF0C\u5176\u5B9E\u65F6\u6570\u636E\u5199\u5165\u7ED1\u5B9A\u8DEF\u5F84"
  });
}
export function defaults() {
  const { dataSource: _omit, ...rest } = defaultTableConfig();
  return { table: rest };
}
