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