var O = Object.defineProperty;
var K = (e, s, t) => s in e ? O(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
var x = (e, s, t) => (K(e, typeof s != "symbol" ? s + "" : s, t), t);
import { t as U, g as _, s as H, f as M, a as F, O as y, b as j, E as V, d as q, e as B, h as G, i as W, T as Y } from "./158dca8d.js";
import { getPageSize as I } from "./048c5fdf.js";
import { e2 as k, _ as c, e3 as v, b$ as J, c0 as Q, e4 as L, dq as R, dm as E, e5 as X, dT as f, dV as C, dW as m, dY as D, e6 as Z, aa as $, e7 as w, Y as u, dZ as N, cc as ee, ac as te, d as ae, e as ne, e8 as oe, e9 as se, at as ie, cd as re, F as b, ea as le, af as de } from "./603b75d9.js";
import { getSelectedRowKeys as z } from "./2d0ef255.js";
import { compTablePropertyView as ce } from "./44e33607.js";
import { TableInitComp as he, RowColorComp as ue, RowHeightComp as pe } from "./6cc9aba1.js";
import { useState as ge, useContext as me } from "react";
import "./18a95abc.js";
import "./c2be1293.js";
import "./4963ac97.js";
import "./ffcffc16.js";
import "./62f393ec.js";
import "./26dac75c.js";
import "./11b05d65.js";
import "./56edae87.js";
import "./0cc240d3.js";
import "./00d44232.js";
import "./f9847c56.js";
import "./a4d0e31e.js";
import "./41aba172.js";
import "react-dom";
import "./e735e391.js";
import "./140b48ce.js";
import "./f5fb28b1.js";
import "./930af84f.js";
import "./9c5ea6de.js";
import "./7f1b43fa.js";
import "./cee178c0.js";
import "./43b58a96.js";
import "./19a46fb5.js";
import "./98f17e53.js";
import "./794d827a.js";
import "./0cdeb449.js";
import "./d50792b8.js";
import "./f64a8554.js";
import "./cf72e8e5.js";
import "./84cede66.js";
import "./3dfed0b7.js";
import "./57f24d28.js";
import "./be662667.js";
import "./8064caf1.js";
import "./d8fd0c14.js";
import "./2effcf20.js";
import "./c873d014.js";
class De extends he {
  constructor() {
    super(...arguments);
    x(this, "prevUnevaledValue");
    x(this, "filterData", []);
    x(this, "columnAggrData", {});
  }
  autoHeight() {
    return this.children.autoHeight.getView();
  }
  getTableAutoHeight() {
    return this.children.autoHeight.getView();
  }
  getSlotContainer() {
    return this.children.expansion.children.slot.getSelectedComp().getComp().children.container;
  }
  findContainer(t) {
    return this.getSlotContainer().findContainer(t);
  }
  getCompTree() {
    return this.getSlotContainer().getCompTree();
  }
  getPasteValue(t) {
    return {
      ...this.toJsonValue(),
      expansion: this.children.expansion.getPasteValue(t)
    };
  }
  realSimpleContainer(t) {
    return this.getSlotContainer().realSimpleContainer(t);
  }
  downloadData(t) {
    k({
      data: this.exposingValues.displayData,
      filename: t,
      fileType: "csv",
      delimiter: this.children.toolbar.children.columnSeparator.getView()
    });
  }
  refreshData(t, a) {
    const o = this.children.data.exposingNode().dependNames().map((i) => i.split(".")[0]);
    if (c.isEmpty(o)) {
      a(!0), setTimeout(() => a(!1), 200);
      return;
    }
    const r = new Set(t);
    o.forEach((i) => {
      r.has(i) && this.dispatch(v(J(i, Q({}))));
    });
  }
  // only for test?
  getProps() {
    return L(c.omit(this.children, "style"));
  }
  shouldGenerateColumn(t, a) {
    const n = t.children.columns.getView().map((l) => {
      const h = l.getView();
      return h.isCustom ? "" : h.dataIndex;
    }).filter((l) => !!l), o = t.children.data.unevaledValue, r = this.prevUnevaledValue;
    if (!a)
      return this.prevUnevaledValue = o, !1;
    let i = !1;
    const d = Object.keys(a), p = t.children.dynamicColumn.getView();
    if ((!r && n.length === 0 || r && o !== r || p || n.length < d.length && n.every((l) => d.includes(l))) && (i = !0), !i) {
      const l = t.children.dataRowExample.getView(), h = n.length !== d.length || !c.isEqual(c.sortBy(n), c.sortBy(d));
      h && !c.isEqual(l, a) ? setTimeout(() => {
        t.children.dataRowExample.dispatchChangeValueAction(a);
      }) : !h && l && setTimeout(() => {
        t.children.dataRowExample.dispatchChangeValueAction(null);
      });
    }
    return this.prevUnevaledValue = o, i;
  }
  reduce(t) {
    let a = super.reduce(t), n = !1;
    if (t.type === R.UPDATE_NODES_V2) {
      const l = U(a.children.data.getView());
      if (n = a.children.data !== this.children.data && !c.isEqual(this.children.data.getView(), a.children.data.getView()), n && (a = a.setChild("rowColor", a.children.rowColor.reduce(ue.changeContextDataAction({
        currentRow: l,
        currentIndex: 0,
        currentOriginalIndex: 0,
        columnTitle: l ? Object.keys(l)[0] : void 0
      }))), a = a.setChild("rowHeight", a.children.rowHeight.reduce(pe.changeContextDataAction({
        currentRow: l,
        currentIndex: 0,
        currentOriginalIndex: 0,
        columnTitle: l ? Object.keys(l)[0] : void 0
      })))), n) {
        const h = a.shouldGenerateColumn(a, l), g = [];
        g.push(E("columns", a.children.columns.dataChangedAction({
          rowExample: l || {},
          doGeneColumn: h,
          dynamicColumn: a.children.dynamicColumn.getView(),
          data: a.children.data.getView()
        }))), h && g.push(a.changeChildAction("dataRowExample", null)), setTimeout(() => {
          g.forEach((P) => a.dispatch(v(P)));
        }, 0);
      }
    }
    let o = !1;
    const r = z(this.children.selection)[0] ?? "0", i = z(a.children.selection)[0] ?? "0", d = this.children.selection !== a.children.selection && r !== i;
    (t.type === R.CUSTOM && a.children.columns.getView().length !== this.children.columns.getView().length || d) && (a = a.setChild("columns", a.children.columns.reduce(a.children.columns.setSelectionAction(i))), o = !0);
    let p = a.children.expansion.children.slot.getCachedParams(i);
    return (d || c.isNil(p) || n) && (p = c.isNil(p) || n ? _(a.filterData, i) : void 0, a = a.setChild("expansion", a.children.expansion.reduce(a.children.expansion.setSelectionAction(i, p))), o = !0), t.type === R.UPDATE_NODES_V2 && o && setTimeout(() => a.dispatch(X())), a;
  }
  extraNode() {
    return {
      node: {
        sortedData: this.sortDataNode(),
        filterData: this.filterNode(),
        oriDisplayData: this.oriDisplayDataNode(),
        columnAggrData: this.columnAggrNode()
      },
      updateNodeFields: (a) => ({
        filterData: a.filterData,
        columnAggrData: a.columnAggrData
      })
    };
  }
  // handle sort: data -> sortedData
  sortDataNode() {
    const t = {
      data: this.children.data.exposingNode(),
      sort: this.children.sort.node(),
      dataIndexes: this.children.columns.getColumnsNode("dataIndex"),
      sortables: this.children.columns.getColumnsNode("sortable")
    }, a = f(C(t), (n) => {
      const {
        data: o,
        sort: r,
        dataIndexes: i,
        sortables: d
      } = n, p = c(i).mapValues((h, g) => ({
        sortable: !!d[g]
      })).mapKeys((h, g) => i[g]).value();
      return H(o, p, r);
    });
    return m(this, "sortedDataNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
  // handle hide/search/filter: sortedData->filteredData
  filterNode() {
    const t = {
      data: this.sortDataNode(),
      searchValue: this.children.searchText.node(),
      filter: this.children.toolbar.children.filter.node(),
      showFilter: this.children.toolbar.children.showFilter.node()
    };
    let a = this;
    const n = f(C(t), (o) => {
      const {
        data: r,
        searchValue: i,
        filter: d,
        showFilter: p
      } = o, l = M(r, i.value, d, p.value);
      if (i.value && r.length !== l.length) {
        const h = a.children.onEvent.getView();
        setTimeout(() => {
          h("dataSearch");
        });
      }
      return l.map((h) => F(h, h[y]));
    });
    return m(this, "filteredDataNode", [n, t], (o, r) => D(o[1], r[1]))[0];
  }
  oriDisplayDataNode() {
    const t = {
      data: this.filterNode(),
      // --> pageSize
      showSizeChanger: this.children.pagination.children.showSizeChanger.node(),
      pageSize: this.children.pagination.children.pageSize.node(),
      pageSizeOptions: this.children.pagination.children.pageSizeOptions.node(),
      changablePageSize: this.children.pagination.children.changeablePageSize.node(),
      // <-- pageSize
      withParams: this.children.columns.withParamsNode(),
      dataIndexes: this.children.columns.getColumnsNode("dataIndex")
    }, a = f(C(t), (n) => {
      const o = c(n.dataIndexes).mapValues((i, d) => ({
        dataIndex: i,
        render: n.withParams[d]
      })).value(), r = I(n.showSizeChanger.value, n.pageSize.value, n.pageSizeOptions.value, n.changablePageSize);
      return j(n.data, r, Object.values(o));
    });
    return m(this, "oriDisplayDataNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
  displayDataIndexesNode() {
    const t = {
      oriDisplayData: this.oriDisplayDataNode()
    }, a = f(C(t), (n) => c(n.oriDisplayData).map((o, r) => [o[y], r]).fromPairs().value());
    return m(this, "displayDataIndexesNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
  getUpsertSetResNode(t, a) {
    return f(C(t), (n) => {
      const o = c(n.dataIndexes).mapValues((i, d) => n.renders[d]).mapKeys((i, d) => n.dataIndexes[d]).value(), r = {};
      return c.forEach(o, (i, d) => {
        c.forEach(i[Z], (p, l) => {
          const h = p.comp.comp.changeValue, g = a && l.startsWith(V) || !a && !l.startsWith(V);
          !c.isNil(h) && g && (r[l] || (r[l] = {}), r[l][d] = h);
        });
      }), r;
    });
  }
  changeSetNode() {
    const t = {
      dataIndexes: this.children.columns.getColumnsNode("dataIndex"),
      renders: this.children.columns.getColumnsNode("render")
    }, a = this.getUpsertSetResNode(t);
    return m(this, "changeSetNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
  insertSetNode() {
    const t = {
      dataIndexes: this.children.columns.getColumnsNode("dataIndex"),
      renders: this.children.columns.getColumnsNode("render")
    }, a = this.getUpsertSetResNode(t, !0);
    return m(this, "insertSetNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
  getToUpsertRowsResNodes(t) {
    return f(C(t), (a) => c(a.changeSet).map((o, r) => {
      const i = a.indexes[r];
      return {
        ...c.omit(a.oriDisplayData[i], y),
        ...o
      };
    }).value());
  }
  toUpdateRowsNode() {
    const t = {
      oriDisplayData: this.oriDisplayDataNode(),
      indexes: this.displayDataIndexesNode(),
      changeSet: this.changeSetNode()
    }, a = this.getToUpsertRowsResNodes(t);
    return m(this, "toUpdateRowsNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
  toInsertRowsNode() {
    const t = {
      oriDisplayData: this.oriDisplayDataNode(),
      indexes: this.displayDataIndexesNode(),
      changeSet: this.insertSetNode()
    }, a = this.getToUpsertRowsResNodes(t);
    return m(this, "toInsertRowsNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
  columnAggrNode() {
    const t = {
      oriDisplayData: this.oriDisplayDataNode(),
      withParams: this.children.columns.withParamsNode(),
      dataIndexes: this.children.columns.getColumnsNode("dataIndex")
    }, a = f(C(t), (n) => {
      const o = c(n.dataIndexes).mapValues((i, d) => n.withParams[d]).mapKeys((i, d) => n.dataIndexes[d]).value();
      return q(n.oriDisplayData, o);
    });
    return m(this, "columnAggrNode", [a, t], (n, o) => D(n[1], o[1]))[0];
  }
}
let S = ae(De, (e) => (ge([]), /* @__PURE__ */ b(le, {
  hidden: e.children.hidden.getView(),
  children: /* @__PURE__ */ b(Y, {
    comp: e,
    onRefresh: (s, t) => e.refreshData(s, t),
    onDownload: (s) => e.downloadData(s)
  })
})));
const we = (e) => (s) => {
  const t = me(de).editorModeStatus;
  return /* @__PURE__ */ b(e, {
    ...s,
    editorModeStatus: t
  });
};
S = ne(S, (e) => we(ce)(e));
S = oe(S, (e) => (s) => {
  if (e) {
    if (se(s)) {
      const t = s.value.context;
      if (t && !c.isNil(t.currentOriginalIndex)) {
        const a = t.currentOriginalIndex + "";
        e(E("selection", ie("selectedRowKey", a, !1)));
      }
    }
    return e(s);
  }
});
function A(e, s) {
  const t = (s + "").split("-");
  let a = e, n;
  for (let o of t) {
    const r = Number(o);
    r >= 0 && Array.isArray(a) && r < a.length && (n = a[r], a = n[W]);
  }
  return n;
}
function T(e, s) {
  const t = s.split("-"), a = t[0];
  if (!a)
    return "";
  let n;
  return e.forEach((o, r) => {
    o[y] === a && (n = r);
  }), n && t.length > 1 ? [n, ...t.slice(1)].join("-") : n;
}
S = re(S, [{
  method: {
    name: "setFilter",
    description: "",
    params: [{
      name: "filter",
      type: "JSON"
    }]
  },
  execute: (e, s) => {
    if (s[0]) {
      const t = s[0], a = e.children.toolbar.children.filter.getView();
      e.children.toolbar.children.filter.dispatchChangeValueAction({
        ...a,
        ...t
      });
    }
  }
}, {
  method: {
    name: "setPage",
    description: "",
    params: [{
      name: "page",
      type: "number"
    }]
  },
  execute: (e, s) => {
    const t = s[0];
    t && t > 0 && e.children.pagination.children.pageNo.dispatchChangeValueAction(t);
  }
}, {
  method: {
    name: "setSort",
    description: "",
    params: [{
      name: "sortColumn",
      type: "string"
    }, {
      name: "sortDesc",
      type: "boolean"
    }]
  },
  execute: (e, s) => {
    s[0] && e.children.sort.dispatchChangeValueAction([{
      column: s[0],
      desc: s[1]
    }]);
  }
}, {
  method: {
    name: "resetSelections",
    description: "",
    params: []
  },
  execute: (e) => {
    e.children.selection.children.selectedRowKey.dispatchChangeValueAction("0"), e.children.selection.children.selectedRowKeys.dispatchChangeValueAction([]);
  }
}, {
  method: {
    name: "cancelChanges",
    description: "",
    params: []
  },
  execute: (e, s) => {
    e.children.columns.dispatchClearChangeSet();
  }
}, {
  method: {
    name: "cancelInsertChanges",
    description: "",
    params: []
  },
  execute: (e, s) => {
    e.children.columns.dispatchClearInsertSet();
  }
}]);
const dt = $(S, [new w("selectedRow", (e) => ({
  selectedRowKey: e.selection.children.selectedRowKey.node(),
  data: e.data.exposingNode()
}), (e) => {
  if (e.data)
    return A(e.data, e.selectedRowKey);
}, u("table.selectedRowDesc")), new w("selectedRows", (e) => ({
  selectedRowKeys: e.selection.children.selectedRowKeys.node(),
  data: e.data.exposingNode()
}), (e) => {
  if (e.data)
    return e.selectedRowKeys.flatMap((s) => {
      const t = A(e.data, s);
      return t === void 0 ? [] : [t];
    });
}, u("table.selectedRowsDesc")), new N("selectedIndex", (e) => ({
  oriDisplayData: e.oriDisplayDataNode(),
  selectedRowKey: e.children.selection.children.selectedRowKey.node()
}), (e) => T(e.oriDisplayData, e.selectedRowKey), u("table.selectedIndexDesc")), new N("selectedIndexes", (e) => ({
  oriDisplayData: e.oriDisplayDataNode(),
  selectedRowKeys: e.children.selection.children.selectedRowKeys.node()
}), (e) => e.selectedRowKeys.flatMap((s) => {
  const t = T(e.oriDisplayData, s);
  return t === void 0 ? [] : [t];
}), u("table.selectedIndexDesc")), new N("changeSet", (e) => ({
  changeSet: e.changeSetNode()
}), (e) => e.changeSet, u("table.changeSetDesc")), new N("insertSet", (e) => ({
  insertSet: e.insertSetNode()
}), (e) => e.insertSet, u("table.changeSetDesc")), new N("toUpdateRows", (e) => ({
  toUpdateRows: e.toUpdateRowsNode()
}), (e) => e.toUpdateRows, u("table.toUpdateRowsDesc")), new N("toInsertRows", (e) => ({
  toInsertRows: e.toInsertRowsNode()
}), (e) => e.toInsertRows, u("table.toUpdateRowsDesc")), new w("pageNo", (e) => ({
  pageNo: e.pagination.children.pageNo.exposingNode()
}), (e) => e.pageNo, u("table.pageNoDesc")), new w("pageSize", (e) => ({
  showSizeChanger: e.pagination.children.showSizeChanger.node(),
  changeablePageSize: e.pagination.children.changeablePageSize.node(),
  pageSize: e.pagination.children.pageSize.node(),
  pageSizeOptions: e.pagination.children.pageSizeOptions.node()
}), (e) => I(e.showSizeChanger.value, e.pageSize.value, e.pageSizeOptions.value, e.changeablePageSize), u("table.pageSizeDesc")), new w("sortColumn", (e) => ({
  sort: e.sort.node(),
  columns: e.columns.node()
}), (e) => {
  var a;
  const s = (a = e.sort[0]) == null ? void 0 : a.column, t = Object.values(e.columns).find((n) => n.dataIndex === s);
  return t != null && t.isCustom && (t != null && t.title.value) ? t.title.value : s;
}, u("table.sortColumnDesc")), ee({
  name: "sortDesc",
  desc: u("table.sortDesc"),
  depKeys: ["sort"],
  func: (e) => {
    var s;
    return ((s = e.sort[0]) == null ? void 0 : s.desc) || !1;
  }
}), new w("pageOffset", (e) => ({
  showSizeChanger: e.pagination.children.showSizeChanger.node(),
  changeablePageSize: e.pagination.children.changeablePageSize.node(),
  pageSize: e.pagination.children.pageSize.node(),
  pageSizeOptions: e.pagination.children.pageSizeOptions.node(),
  pageNo: e.pagination.children.pageNo.node()
}), (e) => I(e.showSizeChanger.value, e.pageSize.value, e.pageSizeOptions.value, e.changeablePageSize) * (e.pageNo - 1), u("table.pageOffsetDesc")), new N("displayData", (e) => ({
  oriDisplayData: e.oriDisplayDataNode(),
  dataIndexes: e.children.columns.getColumnsNode("dataIndex"),
  titles: e.children.columns.getColumnsNode("title"),
  // --> hide
  hides: e.children.columns.getColumnsNode("hide"),
  tempHides: e.children.columns.getColumnsNode("tempHide"),
  columnSetting: e.children.toolbar.children.columnSetting.node()
  // <-- hide
}), (e) => {
  const s = c(e.dataIndexes).pickBy((t, a) => !B({
    hide: e.hides[a].value,
    tempHide: e.tempHides[a],
    enableColumnSetting: e.columnSetting.value
  })).mapValues((t, a) => {
    var n;
    return (n = e.titles[a]) == null ? void 0 : n.value;
  }).mapKeys((t, a) => e.dataIndexes[a]).value();
  return G(e.oriDisplayData, s);
}, u("table.displayDataDesc")), new w("filter", (e) => ({
  filter: e.toolbar.children.filter.node()
}), (e) => e.filter, u("table.filterDesc")), new w("selectedCell", (e) => ({
  selectedCell: e.selectedCell.node()
}), (e) => e.selectedCell, u("table.selectedCellDesc")), new te("data", u("table.dataDesc"))]);
export {
  dt as TableComp,
  De as TableImplComp
};
