import { newPrimaryColumn as D, ColumnComp as O } from "./0667825e.js";
import { _ as j } from "./9869e60a.js";
import { tableFilterOperatorMap as F } from "./6cb1f6af.js";
import { c1 as c, gs as w, ea as q, P as z, V as H, iD as k, dF as B, dG as U, dY as x, iE as b, dX as _, fE as X, iF as G } from "./684d2f28.js";
import "react";
const f = "children", d = "__ob_origin_index", K = "__ob_origin_record", C = 55, S = 500;
function Y(a, t, e, i) {
  let o = a;
  return t && (o = o.filter((r) => {
    let s = t == null ? void 0 : t.toLowerCase();
    return s ? Object.values(r).find((l) => l == null ? void 0 : l.toString().toLowerCase().includes(s)) : !0;
  })), i && e.filters.length > 0 && (o = o.filter((r) => {
    for (let s of e.filters) {
      const l = r[s.columnKey], u = F[s.operator].filter(s.filterValue, l);
      if (e.stackType === "or" && u)
        return !0;
      if (e.stackType === "and" && !u)
        return !1;
    }
    return e.filters.length === 0 || e.stackType === "and" ? !0 : e.stackType !== "or";
  })), o;
}
function $(a, t, e) {
  let i = a.map((o, r) => ({
    ...o,
    [d]: r + ""
  }));
  if (e.length > 0) {
    const [o, r] = c(e).filter((s) => {
      var l;
      return !!s.column && ((l = t[s.column]) == null ? void 0 : l.sortable);
    }).map((s) => [s.column, s.desc ? "desc" : "asc"]).unzip().value();
    i = c.orderBy(i, o.map((s) => (l) => {
      const u = l[s];
      return typeof u == "string" ? u.toLowerCase() : u;
    }), r);
  }
  return i;
}
function v({
  hide: a,
  tempHide: t,
  enableColumnSetting: e
}) {
  return e && t || a;
}
function A(a, t) {
  return a + "-" + t;
}
function I(a, t) {
  const e = t + "";
  return Array.isArray(a[f]) ? {
    ...a,
    [d]: e,
    children: a[f].map((i, o) => I(i, A(e, o + "")))
  } : {
    ...a,
    [d]: e
  };
}
function E(a, t, e) {
  return a.map((i, o) => {
    const r = {
      [d]: i[d]
    };
    return e.forEach((s) => {
      const l = s.render.wrap({
        currentCell: i[s.dataIndex],
        currentRow: c.omit(i, d),
        currentIndex: o % t,
        currentOriginalIndex: i[d]
      });
      Array.isArray(i[f]) && (r[f] = E(i[f], t, e));
      const u = l.comp[j](l.comp);
      u !== null && (r[s.dataIndex] = u);
    }), r;
  });
}
function T(a, t) {
  return a.map((e) => {
    const i = c(e).omit(d).mapKeys((o, r) => t[r] || r).value();
    return Array.isArray(e[f]) ? {
      ...i,
      [f]: T(e[f], t)
    } : i;
  });
}
function J(a, t) {
  return c.mapValues(t, (e, i) => {
    const o = e.wrap().compType, r = {
      compType: o
    };
    return o === "tag" ? r.uniqueTags = c(a).map((s) => s[i]).filter((s) => !!s).uniq().value() : o === "badgeStatus" && (r.uniqueStatus = c(a).map((s) => {
      const l = s[i];
      return l.split(" ")[1] ? {
        status: l.slice(0, l.indexOf(" ")),
        text: l.slice(l.indexOf(" ") + 1)
      } : {
        status: l,
        text: ""
      };
    }).uniqBy("text").value()), r;
  });
}
function Q(a) {
  const {
    title: t,
    editable: e
  } = a;
  return /* @__PURE__ */ z("div", {
    children: [t, e && /* @__PURE__ */ H(k, {
      style: {
        verticalAlign: "baseline",
        marginLeft: "4px"
      }
    })]
  });
}
function Z(a, t) {
  let e = [];
  return Object.keys(a).forEach((i) => {
    t.includes(i) || e.push({
      label: i,
      value: `{{currentRow.${i}}}`
    });
  }), e.push({
    label: "Select with handlebars",
    value: "{{currentCell}}"
  }), e;
}
function tt(a, t, e, i, o, r, s, l) {
  const u = a.filter((n) => n.isCustom).map((n) => n.dataIndex), h = Z(s, u), p = new Map(t.map((n) => [n.column, n.desc ? "descend" : "ascend"]));
  return c.sortBy(a, (n) => {
    if (n.fixed === "left")
      return -1;
    if (n.fixed === "right")
      return Number.MAX_SAFE_INTEGER;
    if (r.length > 0) {
      const g = r.indexOf(n.isCustom ? n.title : n.dataIndex);
      if (g >= 0)
        return g;
    }
    return 0;
  }).flatMap((n) => {
    if (v({
      hide: n.hide,
      tempHide: n.tempHide,
      enableColumnSetting: e
    }))
      return [];
    if (o && r.length > 0 && !r.includes(n.isCustom ? n.title : n.dataIndex))
      return [];
    const g = (s[n.dataIndex] ?? {}).uniqueTags ?? [], V = (s[n.dataIndex] ?? {}).uniqueStatus ?? [], W = Q({
      title: n.title,
      editable: n.editable
    });
    return {
      title: n.showTitle ? W : "",
      titleText: n.title,
      dataIndex: n.dataIndex,
      align: n.align,
      width: n.autoWidth === "auto" ? 0 : n.width,
      fixed: n.fixed === "close" ? !1 : n.fixed,
      style: {
        background: n.background,
        margin: n.margin,
        text: n.text,
        border: n.border,
        radius: n.radius,
        textSize: n.textSize,
        textWeight: n.textWeight,
        fontStyle: n.fontStyle,
        fontFamily: n.fontFamily,
        borderWidth: n.borderWidth
      },
      linkStyle: {
        text: n.linkColor,
        hoverText: n.linkHoverColor,
        activeText: n.linkActiveColor
      },
      cellColorFn: n.cellColor,
      onWidthResize: n.onWidthResize,
      render: (N, m, P) => n.render({
        currentCell: N,
        currentRow: c.omit(m, d),
        currentIndex: P,
        currentOriginalIndex: w(m[d]),
        initialColumns: h
      }, String(m[d])).getView().view({
        editable: n.editable,
        size: i,
        candidateTags: g,
        candidateStatus: V,
        textOverflow: n.textOverflow,
        onTableEvent: l
      }),
      ...n.sortable ? {
        sorter: !0,
        sortOrder: p.get(n.dataIndex)
      } : {}
    };
  });
}
function y(a) {
  var t;
  return (t = a.column) != null && t.dataIndex ? {
    column: a.column.dataIndex.toString(),
    desc: a.order === "descend"
  } : null;
}
function et(a, t, e, i, o, r) {
  if (i.action === "sort") {
    let s = [];
    if (Array.isArray(e))
      e.forEach((l) => {
        const u = y(l);
        u && s.push(u);
      });
    else {
      const l = y(e);
      l && s.push(l);
    }
    o(q("sort", s, !0)), r("sortChange");
  }
}
function R(a, t) {
  const e = (r) => {
    const s = new Blob([r]).size;
    return r.length === s ? r.length * 10 : r.length * 20;
  }, i = c.max(t.map((r) => {
    const s = r[a];
    return s ? e(s.toString()) : C;
  })) || 0, o = e(a);
  return Math.max(Math.min(S, Math.max(o, i) + 10), C);
}
function rt(a, t) {
  const e = a.findIndex((o) => o[d] === t);
  if (e < 0)
    return;
  const i = a[e];
  return {
    currentRow: c.omit(i, d),
    currentIndex: e,
    currentOriginalIndex: w(i[d])
  };
}
function L(a) {
  const t = M(a);
  return t && Array.isArray(t[f]);
}
const ct = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  COLUMN_CHILDREN_KEY: f,
  COL_MAX_WIDTH: S,
  COL_MIN_WIDTH: C,
  OB_ROW_ORI_INDEX: d,
  OB_ROW_RECORD: K,
  buildOriginIndex: A,
  calcColumnWidth: R,
  columnHide: v,
  columnsToAntdFormat: tt,
  filterData: Y,
  genSelectionParams: rt,
  getColumnsAggr: J,
  getOriDisplayData: E,
  onTableChange: et,
  sortData: $,
  supportChildrenTree: L,
  tranToTableRecord: I,
  transformDispalyData: T
}, Symbol.toStringTag, { value: "Module" })), nt = X(O);
function M(a) {
  if (a.length <= 0 || typeof a[0] == "string")
    return;
  const t = {};
  return a.slice(0, 50).forEach((e) => {
    Object.keys(e).forEach((i) => {
      t.hasOwnProperty(i) || (t[i] = e[i]);
    });
  }), t;
}
class it extends nt {
  reduce(t) {
    if (B(t, "dataChanged")) {
      const e = t.value.rowExample, {
        readOnly: i
      } = G();
      let o = this;
      if (t.value.doGeneColumn && (t.value.dynamicColumn || !i)) {
        const r = this.geneColumnsAction(e, t.value.data);
        o = this.reduce(this.multiAction(r));
      }
      return o;
    }
    return super.reduce(t);
  }
  getChangeSet() {
    const t = {};
    return this.getView().forEach((i) => {
      const o = i.getChangeSet();
      Object.keys(o).forEach((r) => {
        Object.keys(o[r]).forEach((s) => {
          c.isNil(o[r][s]) || (t[s] || (t[s] = {}), t[s][r] = o[r][s]);
        });
      });
    }), t;
  }
  dispatchClearChangeSet() {
    this.getView().forEach((e) => e.dispatchClearChangeSet());
  }
  /**
   * If the table data changes, call this method to trigger the action
   */
  dataChangedAction(t) {
    return U({
      type: "dataChanged",
      ...t
    }, !1);
  }
  /**
   * According to the data, adjust the column
   */
  geneColumnsAction(t, e) {
    if (t == null)
      return [];
    const i = Object.keys(t);
    if (i.length === 0)
      return [];
    const o = this.getView(), r = [];
    let s = 0;
    return o.forEach((l, u) => {
      if (l.getView().isCustom)
        return;
      const h = l.getView().dataIndex;
      (h === f || !i.find((p) => h === p)) && (r.push(this.deleteAction(u - s)), s += 1);
    }), i.forEach((l) => {
      l === f && L(e) || o.find((u) => u.getView().dataIndex === l) || r.push(this.pushAction(D(l, R(l, e))));
    }), r.length === 0 ? [] : r;
  }
  withParamsNode() {
    const t = this.getView(), e = c(t).map((o) => o.children.render.getOriginalComp().node()).toPairs().fromPairs().value();
    return x(this, "withParamsNode", [_(e), e], (o, r) => b(o[1], r[1]))[0];
  }
  getColumnsNode(t) {
    const e = this.getView(), i = c(e).map((r) => r.children[t].node()).toPairs().fromPairs().value();
    return x(this, "col_nodes_" + t, [_(i), i], (r, s) => b(r[1], s[1]))[0];
  }
  setSelectionAction(t) {
    return this.forEachAction(O.setSelectionAction(t));
  }
}
const ft = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  ColumnListComp: it,
  tableDataRowExample: M
}, Symbol.toStringTag, { value: "Module" }));
export {
  f as C,
  d as O,
  I as a,
  E as b,
  R as c,
  J as d,
  v as e,
  Y as f,
  rt as g,
  T as h,
  tt as i,
  L as j,
  C as k,
  it as l,
  ct as m,
  ft as n,
  et as o,
  $ as s,
  M as t
};
