var O = Object.defineProperty;
var T = (e, o, t) => o in e ? O(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
var N = (e, o, t) => (T(e, typeof o != "symbol" ? o + "" : o, t), t);
import { t as K, g as U, s as _, f as H, a as M, O as S, b as F, d as j, e as k, h as B, C as q } from "./bdf03194.js";
import { getPageSize as V } from "./ff81ee95.js";
import { TableCompView as G } from "./6b18b908.js";
import { e2 as Y, c1 as c, O as I, bI as J, bJ as X, e3 as L, L as b, d8 as P, e4 as Q, dV as m, dX as D, dY as w, d_ as f, e5 as W, bn as $, e6 as y, a0 as u, d$ as x, bX as Z, bo as ee, d as te, V as v, e7 as ae, e as ne, e8 as oe, e9 as ie, ea as se, bY as re, bg as le } from "./684d2f28.js";
import { getSelectedRowKeys as R } from "./392e04da.js";
import { compTablePropertyView as de } from "./619fbfe2.js";
import { TableInitComp as ce, RowColorComp as he, RowHeightComp as ue } from "./e3ea3031.js";
import { useContext as ge } from "react";
import "./0667825e.js";
import "./49a8125c.js";
import "./7281819e.js";
import "./9869e60a.js";
import "./b1144c16.js";
import "./d404aae1.js";
import "./926d8ea1.js";
import "./d6402597.js";
import "./7a630f06.js";
import "./d883a28b.js";
import "./6be5dc74.js";
import "./1312a48b.js";
import "./00dac55d.js";
import "./622ce240.js";
import "./0c4ef413.js";
import "react-dom";
import "./b8f8370b.js";
import "./ca17ca0f.js";
import "./d9d1e856.js";
import "./6538ec2e.js";
import "./226f78bd.js";
import "./8e06f4ed.js";
import "./a014bc57.js";
import "./6cf5f7c0.js";
import "./7f2964c3.js";
import "./602ac28f.js";
import "./f9c25fbe.js";
import "./2d5fc5ff.js";
import "./0f3d7a1a.js";
import "./698a4355.js";
import "./cf2c1864.js";
import "./fcd1d96f.js";
import "./6cb1f6af.js";
import "./36711569.js";
import "./913682de.js";
class pe extends ce {
  constructor() {
    super(...arguments);
    N(this, "prevUnevaledValue");
    N(this, "filterData", []);
    N(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) {
    Y({
      data: this.exposingValues.displayData,
      filename: t,
      fileType: "csv"
    });
  }
  refreshData(t, a) {
    const i = this.children.data.exposingNode().dependNames().map((s) => s.split(".")[0]);
    if (c.isEmpty(i)) {
      a(!0), setTimeout(() => a(!1), 200);
      return;
    }
    const r = new Set(t);
    i.forEach((s) => {
      r.has(s) && this.dispatch(I(J(s, X({}))));
    });
  }
  // only for test?
  getProps() {
    return L(c.omit(this.children, "style"));
  }
  shouldGenerateColumn(t, a) {
    const n = t.children.columns.getView().map((d) => {
      const h = d.getView();
      return h.isCustom ? "" : h.dataIndex;
    }).filter((d) => !!d), i = t.children.data.unevaledValue, r = this.prevUnevaledValue;
    if (!a)
      return this.prevUnevaledValue = i, !1;
    let s = !1;
    const l = Object.keys(a), g = t.children.dynamicColumn.getView();
    if ((!r && n.length === 0 || r && i !== r || g || n.length < l.length && n.every((d) => l.includes(d))) && (s = !0), !s) {
      const d = t.children.dataRowExample.getView(), h = n.length !== l.length || !c.isEqual(c.sortBy(n), c.sortBy(l));
      h && !c.isEqual(d, a) ? setTimeout(() => {
        t.children.dataRowExample.dispatchChangeValueAction(a);
      }) : !h && d && setTimeout(() => {
        t.children.dataRowExample.dispatchChangeValueAction(null);
      });
    }
    return this.prevUnevaledValue = i, s;
  }
  reduce(t) {
    let a = super.reduce(t), n = !1;
    if (t.type === b.UPDATE_NODES_V2) {
      const d = K(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(he.changeContextDataAction({
        currentRow: d,
        currentIndex: 0,
        currentOriginalIndex: 0,
        columnTitle: d ? Object.keys(d)[0] : void 0
      }))), a = a.setChild("rowHeight", a.children.rowHeight.reduce(ue.changeContextDataAction({
        currentRow: d,
        currentIndex: 0,
        currentOriginalIndex: 0,
        columnTitle: d ? Object.keys(d)[0] : void 0
      })))), n) {
        const h = a.shouldGenerateColumn(a, d), p = [];
        p.push(P("columns", a.children.columns.dataChangedAction({
          rowExample: d || {},
          doGeneColumn: h,
          dynamicColumn: a.children.dynamicColumn.getView(),
          data: a.children.data.getView()
        }))), h && p.push(a.changeChildAction("dataRowExample", null)), setTimeout(() => {
          p.forEach((E) => a.dispatch(I(E)));
        }, 0);
      }
    }
    let i = !1;
    const r = R(this.children.selection)[0] ?? "0", s = R(a.children.selection)[0] ?? "0", l = this.children.selection !== a.children.selection && r !== s;
    (t.type === b.CUSTOM && a.children.columns.getView().length !== this.children.columns.getView().length || l) && (a = a.setChild("columns", a.children.columns.reduce(a.children.columns.setSelectionAction(s))), i = !0);
    let g = a.children.expansion.children.slot.getCachedParams(s);
    return (l || c.isNil(g) || n) && (g = c.isNil(g) || n ? U(a.filterData, s) : void 0, a = a.setChild("expansion", a.children.expansion.reduce(a.children.expansion.setSelectionAction(s, g))), i = !0), t.type === b.UPDATE_NODES_V2 && i && setTimeout(() => a.dispatch(Q())), 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 = m(D(t), (n) => {
      const {
        data: i,
        sort: r,
        dataIndexes: s,
        sortables: l
      } = n, g = c(s).mapValues((h, p) => ({
        sortable: !!l[p]
      })).mapKeys((h, p) => s[p]).value();
      return _(i, g, r);
    });
    return w(this, "sortedDataNode", [a, t], (n, i) => f(n[1], i[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 = m(D(t), (i) => {
      const {
        data: r,
        searchValue: s,
        filter: l,
        showFilter: g
      } = i, d = H(r, s.value, l, g.value);
      if (s.value && r.length !== d.length) {
        const h = a.children.onEvent.getView();
        setTimeout(() => {
          h("dataSearch");
        });
      }
      return d.map((h) => M(h, h[S]));
    });
    return w(this, "filteredDataNode", [n, t], (i, r) => f(i[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 = m(D(t), (n) => {
      const i = c(n.dataIndexes).mapValues((s, l) => ({
        dataIndex: s,
        render: n.withParams[l]
      })).value(), r = V(n.showSizeChanger.value, n.pageSize.value, n.pageSizeOptions.value, n.changablePageSize);
      return F(n.data, r, Object.values(i));
    });
    return w(this, "oriDisplayDataNode", [a, t], (n, i) => f(n[1], i[1]))[0];
  }
  displayDataIndexesNode() {
    const t = {
      oriDisplayData: this.oriDisplayDataNode()
    }, a = m(D(t), (n) => c(n.oriDisplayData).map((i, r) => [i[S], r]).fromPairs().value());
    return w(this, "displayDataIndexesNode", [a, t], (n, i) => f(n[1], i[1]))[0];
  }
  changeSetNode() {
    const t = {
      dataIndexes: this.children.columns.getColumnsNode("dataIndex"),
      renders: this.children.columns.getColumnsNode("render")
    }, a = m(D(t), (n) => {
      const i = c(n.dataIndexes).mapValues((s, l) => n.renders[l]).mapKeys((s, l) => n.dataIndexes[l]).value(), r = {};
      return c.forEach(i, (s, l) => {
        c.forEach(s[W], (g, d) => {
          const h = g.comp.comp.changeValue;
          c.isNil(h) || (r[d] || (r[d] = {}), r[d][l] = h);
        });
      }), r;
    });
    return w(this, "changeSetNode", [a, t], (n, i) => f(n[1], i[1]))[0];
  }
  toUpdateRowsNode() {
    const t = {
      oriDisplayData: this.oriDisplayDataNode(),
      indexes: this.displayDataIndexesNode(),
      changeSet: this.changeSetNode()
    }, a = m(D(t), (n) => c(n.changeSet).map((r, s) => {
      const l = n.indexes[s];
      return {
        ...c.omit(n.oriDisplayData[l], S),
        ...r
      };
    }).value());
    return w(this, "toUpdateRowsNode", [a, t], (n, i) => f(n[1], i[1]))[0];
  }
  columnAggrNode() {
    const t = {
      oriDisplayData: this.oriDisplayDataNode(),
      withParams: this.children.columns.withParamsNode(),
      dataIndexes: this.children.columns.getColumnsNode("dataIndex")
    }, a = m(D(t), (n) => {
      const i = c(n.dataIndexes).mapValues((s, l) => n.withParams[l]).mapKeys((s, l) => n.dataIndexes[l]).value();
      return j(n.oriDisplayData, i);
    });
    return w(this, "columnAggrNode", [a, t], (n, i) => f(n[1], i[1]))[0];
  }
}
let C = te(pe, (e) => /* @__PURE__ */ v(ae, {
  hidden: e.children.hidden.getView(),
  children: /* @__PURE__ */ v(G, {
    comp: e,
    onRefresh: (o, t) => e.refreshData(o, t),
    onDownload: (o) => e.downloadData(o)
  })
}));
const me = (e) => (o) => {
  const t = ge(le).editorModeStatus;
  return /* @__PURE__ */ v(e, {
    ...o,
    editorModeStatus: t
  });
};
C = ne(C, (e) => me(de)(e));
C = oe(C, (e) => (o) => {
  if (e) {
    if (ie(o)) {
      const t = o.value.context;
      if (t && !c.isNil(t.currentOriginalIndex)) {
        const a = t.currentOriginalIndex + "";
        e(P("selection", se("selectedRowKey", a, !1)));
      }
    }
    return e(o);
  }
});
function z(e, o) {
  const t = (o + "").split("-");
  let a = e, n;
  for (let i of t) {
    const r = Number(i);
    r >= 0 && Array.isArray(a) && r < a.length && (n = a[r], a = n[q]);
  }
  return n;
}
function A(e, o) {
  const t = o.split("-"), a = t[0];
  if (!a)
    return "";
  let n;
  return e.forEach((i, r) => {
    i[S] === a && (n = r);
  }), n && t.length > 1 ? [n, ...t.slice(1)].join("-") : n;
}
C = re(C, [{
  method: {
    name: "setFilter",
    description: "",
    params: [{
      name: "filter",
      type: "JSON"
    }]
  },
  execute: (e, o) => {
    if (o[0]) {
      const t = o[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, o) => {
    const t = o[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, o) => {
    o[0] && e.children.sort.dispatchChangeValueAction([{
      column: o[0],
      desc: o[1]
    }]);
  }
}, {
  method: {
    name: "resetSelections",
    description: "",
    params: []
  },
  execute: (e) => {
    e.children.selection.children.selectedRowKey.dispatchChangeValueAction("0"), e.children.selection.children.selectedRowKeys.dispatchChangeValueAction([]);
  }
}]);
const st = $(C, [new y("selectedRow", (e) => ({
  selectedRowKey: e.selection.children.selectedRowKey.node(),
  data: e.data.exposingNode()
}), (e) => {
  if (e.data)
    return z(e.data, e.selectedRowKey);
}, u("table.selectedRowDesc")), new y("selectedRows", (e) => ({
  selectedRowKeys: e.selection.children.selectedRowKeys.node(),
  data: e.data.exposingNode()
}), (e) => {
  if (e.data)
    return e.selectedRowKeys.flatMap((o) => {
      const t = z(e.data, o);
      return t === void 0 ? [] : [t];
    });
}, u("table.selectedRowsDesc")), new x("selectedIndex", (e) => ({
  oriDisplayData: e.oriDisplayDataNode(),
  selectedRowKey: e.children.selection.children.selectedRowKey.node()
}), (e) => A(e.oriDisplayData, e.selectedRowKey), u("table.selectedIndexDesc")), new x("selectedIndexes", (e) => ({
  oriDisplayData: e.oriDisplayDataNode(),
  selectedRowKeys: e.children.selection.children.selectedRowKeys.node()
}), (e) => e.selectedRowKeys.flatMap((o) => {
  const t = A(e.oriDisplayData, o);
  return t === void 0 ? [] : [t];
}), u("table.selectedIndexDesc")), new x("changeSet", (e) => ({
  changeSet: e.changeSetNode()
}), (e) => e.changeSet, u("table.changeSetDesc")), new x("toUpdateRows", (e) => ({
  toUpdateRows: e.toUpdateRowsNode()
}), (e) => e.toUpdateRows, u("table.toUpdateRowsDesc")), new y("pageNo", (e) => ({
  pageNo: e.pagination.children.pageNo.exposingNode()
}), (e) => e.pageNo, u("table.pageNoDesc")), new y("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) => V(e.showSizeChanger.value, e.pageSize.value, e.pageSizeOptions.value, e.changeablePageSize), u("table.pageSizeDesc")), new y("sortColumn", (e) => ({
  sort: e.sort.node(),
  columns: e.columns.node()
}), (e) => {
  var a;
  const o = (a = e.sort[0]) == null ? void 0 : a.column, t = Object.values(e.columns).find((n) => n.dataIndex === o);
  return t != null && t.isCustom && (t != null && t.title.value) ? t.title.value : o;
}, u("table.sortColumnDesc")), Z({
  name: "sortDesc",
  desc: u("table.sortDesc"),
  depKeys: ["sort"],
  func: (e) => {
    var o;
    return ((o = e.sort[0]) == null ? void 0 : o.desc) || !1;
  }
}), new y("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) => V(e.showSizeChanger.value, e.pageSize.value, e.pageSizeOptions.value, e.changeablePageSize) * (e.pageNo - 1), u("table.pageOffsetDesc")), new x("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 o = c(e.dataIndexes).pickBy((t, a) => !k({
    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 B(e.oriDisplayData, o);
}, u("table.displayDataDesc")), new y("filter", (e) => ({
  filter: e.toolbar.children.filter.node()
}), (e) => e.filter, u("table.filterDesc")), new ee("data", u("table.dataDesc"))]);
export {
  st as TableComp,
  pe as TableImplComp
};
