import { createVNode as y, Fragment as w } from "vue";
import { isArray as b, isUndefined as E, isString as o, isBoolean as F, isNumber as O, pick as v } from "lodash-unified";
import "../../ap-table/components/paragraph-ellipsis/index.vue.mjs";
import { noRenderAsFormItemValueList as S } from "../../ap-table/constants.mjs";
import { valueEnumToArray as $, objectToString as V, getTableTitle as x, getTableRenderType as B, getTableRenderProps as M, getTableCellRenderNode as _ } from "../../ap-table/utils.mjs";
import "../../utils/index.mjs";
import j from "../../ap-table/components/paragraph-ellipsis/index.vue2.mjs";
import { isDef as q } from "../../utils/is.mjs";
function h(e, t) {
  if (t)
    return b(t) ? t.reduce((r, n) => r?.[n], e) : e?.[t];
}
function R(e) {
  if (!E(e))
    return b(e) ? e.reduce((t, r) => o(r) ? `${t}${t ? "." : ""}${r}` : `${t}[${r}]`, "") : String(e);
}
function A(e) {
  if (e)
    return e === !0 ? "left" : e;
}
function D(e) {
  return F(e) ? {
    sortable: e
  } : e ? {
    sortable: !0,
    sortType: e?.type,
    sortBy: e?.by
  } : {
    sortable: !1
  };
}
function I(e) {
  let t;
  return F(e.filters) && e.valueEnum ? t = $(e.valueEnum) : t = e.filters, t?.map((r) => ({
    label: o(r.text) ? r.text : "",
    value: r.value
  }));
}
function W(e) {
  if (e)
    return (t) => e(t.value, t.row);
}
function k(e, t) {
  return e ? O(e) ? {
    tooltip: t,
    rows: e
  } : e === !0 || e === "tooltip" ? {
    tooltip: t,
    rows: 1
  } : {
    tooltip: null,
    rows: 1,
    htmlTitle: e === "title" ? t : ""
  } : !1;
}
function m(e, t, r) {
  if (S.includes(e.valueType))
    return r;
  if (e.copyable || e.ellipsis) {
    const n = k(e.ellipsis, t), i = V(t);
    return y(j, {
      rawValue: i,
      copyable: e.copyable,
      ellipsis: n,
      content: r
    }, null);
  }
  return r;
}
function T(e, t, r) {
  const n = v(e, ["width", "minWidth", "align"]);
  return n.field = R(e.dataIndex), n.fixed = A(e.fixed), n.slots = {
    header: () => x(e, r, void 0, t)
  }, n.headerAlign = e.align, n.showOverflow = !1, n.showFooterOverflow = !1, n;
}
function z(e, t, r) {
  if (r)
    return o(r) ? e[r] : r(e, t);
}
const G = ({
  value: e,
  ...t
}, r, n, i = !0) => {
  const s = B(r), a = M({
    ...r,
    valueType: s
  }, {
    value: e,
    ...t
  }), l = _(s, a, t.record, n), d = r.renderText?.({
    value: e,
    ...t
  }) || e, u = r.renderText ? d : l;
  let f = i ? m(r, d, u) : u;
  if (r.customRender) {
    const N = r._path || [], p = z(t.record, t.rowIndex, t.params?.rowKey);
    f = r.customRender({
      value: e,
      ...t,
      column: r,
      originalNode: f,
      originalText: d,
      path: q(p) && [...N, String(p)]
    });
  }
  return y(w, null, [f]);
};
function c(e, t, r, n) {
  const i = v(e, ["width", "minWidth", "align", "resizable", "className", "headerClassName", "footerClassName", "treeNode"]);
  i.field = R(e.dataIndex), i.fixed = A(e.fixed), i.headerAlign = e.align, i.footerAlign = e.align, i.showOverflow = !1, i.showFooterOverflow = !1, Object.assign(i, D(e.sorter)), i.filters = I(e), i.filterMultiple = e.filterMultiple, i.filterMethod = W(e.onFilter);
  const s = ({
    row: a,
    rowIndex: l
  }) => G({
    value: h(a, e.dataIndex),
    text: h(a, e.dataIndex),
    record: a,
    index: l,
    renderIndex: l,
    column: e
  }, e, n);
  return i.slots = {
    header: () => x(e, r, void 0, t),
    default: s,
    footer: s
  }, e.html && (delete i.slots.default, delete i.slots.footer, i.type = "html"), e.seq && (i.type = "seq", i.slots = {}), i;
}
function Z(e, t, r, n) {
  if (!e.children?.length)
    return c(e, t, r, n);
  function i(a) {
    return a.map((l) => {
      if (l.children?.length) {
        const d = T(l, t, r);
        return d.children = i(l.children), d;
      }
      return c(l, t, r, n);
    });
  }
  const s = T(e, t, r);
  return s.children = i(e.children), s;
}
export {
  G as contentCustom,
  R as dataIndexToField,
  h as getValueByDataIndex,
  Z as transformCol,
  A as transformFixed,
  T as transformToColGroup,
  c as transformToColumn
};
