import { TableComp as I } from "./9a3e93cb.js";
import { l as y } from "./158dca8d.js";
import { J as l, _ as C, dS as g, dQ as E } from "./603b75d9.js";
import "./048c5fdf.js";
import "react";
import "react-dom";
import "./2d0ef255.js";
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 "./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 "./44e33607.js";
import "./2effcf20.js";
import "./6cc9aba1.js";
import "./c873d014.js";
const c = (a, r) => {
  const t = a.children.columns.getView().map((i) => i.getView());
  expect(r.length).toEqual(t.length), r.forEach((i) => {
    const e = t.find((o) => o.dataIndex === i.dataIndex);
    if (!e)
      throw new Error(`expect column: ${JSON.stringify(i)}, but not found.`);
    Object.keys(i).forEach((o) => {
      const s = e[o], n = i[o];
      if (n !== void 0 && !C.isEqual(s, n))
        throw new Error(`ColumnKey:${o}, expect: "${n}", but found: "${s}"`);
    });
  });
  const d = a.children.dynamicColumnConfig.getView();
  if ((d == null ? void 0 : d.length) > 0) {
    const i = (o) => {
    }, e = y(t, a.children.sort.getView(), a.children.toolbar.getView().columnSetting, a.children.size.getView(), a.children.dynamicColumn.getView(), d, a.columnAggrData, a.children.editModeClicks.getView(), i);
    expect(t.length).toBeGreaterThanOrEqual(e.length), e.forEach((o) => {
      const s = o.dataIndex, n = t.find((f) => f.dataIndex === s);
      if (!n)
        throw new Error(`Error, column should not be undefined, column: ${JSON.stringify(o)}`);
      const m = n.isCustom ? n.title : n.dataIndex;
      if (!d.includes(m))
        throw new Error(`dynamic config test fail: unexpect column: ${m}`);
    });
  }
};
function q() {
  const a = {
    query1: g({
      data: [{
        q1: 1
      }]
    }),
    query2: g({
      data: [{
        q2: 2
      }]
    })
  };
  return {
    tableData: {
      data: JSON.stringify([{
        a: 1
      }]),
      columns: [{
        dataIndex: "a",
        title: "a",
        hide: !0
      }, {
        title: "custom",
        dataIndex: "custom1",
        isCustom: !0
      }]
    },
    exposingInfo: a,
    initColumns: [{
      dataIndex: "a",
      hide: !0,
      title: "a"
    }, {
      dataIndex: "custom1",
      hide: !1,
      title: "custom",
      isCustom: !0
    }]
  };
}
async function x() {
  await new Promise((a) => setTimeout(a, 20));
}
test("test table dynamic columns: Change unEvalValue", async () => {
  const {
    initColumns: a,
    tableData: r,
    exposingInfo: p
  } = q();
  let t = new I({
    dispatch: (i) => {
      t = l(t.reduce(i), p);
    },
    value: r
  });
  t = l(t), c(t, a), t = l(t.reduce(t.changeChildAction("data", JSON.stringify([{
    a: 1,
    c: 2,
    d: 3
  }])))), await x();
  const d = [...a, {
    dataIndex: "c",
    hide: !1,
    title: "c"
  }, {
    dataIndex: "d",
    title: "d"
  }];
  c(t, d), t = l(t.reduce(t.changeChildAction("data", JSON.stringify([{
    c: 2,
    d: 3
  }])))), await x(), c(t, d.filter((i) => i.dataIndex !== "a"));
}, 1e3);
async function u(a, r, p) {
  const {
    initColumns: t,
    tableData: d,
    exposingInfo: i
  } = q();
  let e = new I({
    dispatch: (h) => {
      let w;
      r ? w = E({
        readOnly: r
      }, () => e.reduce(h)) : w = e.reduce(h), e = l(w, i);
    },
    value: {
      ...d,
      dynamicColumn: a,
      ...a && p && {
        dynamicColumnConfig: JSON.stringify(p)
      }
    }
  });
  e = l(e);
  const o = async () => {
    e = l(e.reduce(e.changeChildAction("data", "{{query1.data}}")), i), await x();
  }, s = [{
    dataIndex: "q1",
    title: "q1"
  }, {
    dataIndex: "custom1",
    title: "custom",
    isCustom: !0
  }];
  await o(), !a && r ? c(e, t) : c(e, s);
  const n = [{
    q1: 1,
    a: 2
  }];
  i.query1 = g({
    data: n
  }), await o();
  const m = [...s, {
    dataIndex: "a",
    title: "a"
  }];
  expect(e.children.data.getView()).toEqual(n), !a && r ? c(e, t) : c(e, m);
  const f = [{
    a: 2
  }];
  i.query1 = g({
    data: f
  }), await o(), expect(e.children.data.getView()).toEqual(f), a ? c(e, m.filter((h) => h.dataIndex !== "q1")) : r ? c(e, t) : c(e, m);
}
test("test table dynamic columns", async () => {
  await u(!1, !1), await u(!1, !0), await u(!0, !1), await u(!0, !0), await u(!0, !1, ["custom", "q1"]), await u(!0, !0, ["custom", "q1"]);
}, 2e3);
