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