import { useToken as R } from "@aplus-frontend/antdv/es/theme/internal";
import { clsx as C } from "clsx";
import { isFunction as N, isArray as u, omit as y } from "lodash-unified";
import { useSlots as k, computed as v, unref as m } from "vue";
import { useDevWarning as w } from "../../utils/warning.mjs";
import { updateFormProps as A, getFieldProps as E, getTableRenderProps as q } from "../../ap-table/utils.mjs";
import "../../config-provider/index.mjs";
import { getFinalNode as D, getEditableTableTitle as G } from "../utils.mjs";
import { useNamespace as S } from "../../config-provider/hooks/use-namespace.mjs";
const O = (o, f) => {
  const {
    em: b,
    be: x
  } = S("editable-table"), g = w("EditableTable"), F = k(), [, T] = R();
  return v(() => {
    const d = o.columns;
    if (!d)
      return [];
    function c(h) {
      return h.map((e) => ({
        ...y(e, ["ellipsis"]),
        children: c(e.children || []),
        title: G(e, x("table-header", "title"), b("header-cell", "required"), F.headerCell, m(T).colorTextTertiary),
        customRender({
          value: r,
          ...n
        }) {
          const a = N(e.editable) ? e.editable(n.text, n.record, n.index) : !!e.editable;
          if (!e.valueType && !e.customRender && !e.customRenderFormItem)
            return g(!1, "usage", "'can not render table cell because no `valueType` / `customRender` / `customRenderFormItem`'"), null;
          let l;
          if (a) {
            const t = A(e, E(e.fieldProps, {
              value: r,
              ...n
            })), s = {};
            o.onFieldChange && (s[`onUpdate:${t.valuePropName || "value"}`] = (I) => o.onFieldChange?.(n.index, e.dataIndex, I));
            const p = u(e.dataIndex) ? e.dataIndex : [e.dataIndex];
            l = {
              name: [...u(o.name) ? o.name : [o.name], n.index, ...p],
              ...t || {},
              field: {
                style: "width: 100%",
                ...t?.field || {},
                ...s,
                class: C("is-editable", t.class)
              }
            };
          } else
            l = {
              field: q(e, {
                value: r,
                ...n
              })
            };
          const i = D(e, a, l, r, n.record, m(f));
          return e.customRender ? e.customRender({
            value: r,
            ...n,
            editable: a,
            originalNode: i
          }) : i;
        }
      }));
    }
    return c(d);
  });
};
export {
  O as default
};
