import { TableComp as I } from "./9639b54b.js";
import { i as y } from "./bdf03194.js";
import { gR as l, c1 as C, dU as g, dS as E } from "./684d2f28.js";
import "./ff81ee95.js";
import "react";
import "react-dom";
import "./6b18b908.js";
import "./b1144c16.js";
import "./6cb1f6af.js";
import "./36711569.js";
import "./0667825e.js";
import "./49a8125c.js";
import "./7281819e.js";
import "./9869e60a.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 "./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 "./392e04da.js";
import "./619fbfe2.js";
import "./e3ea3031.js";
import "./913682de.js";
const s = (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 d = e[o], n = i[o];
      if (n !== void 0 && !C.isEqual(d, n))
        throw new Error(`ColumnKey:${o}, expect: "${n}", but found: "${d}"`);
    });
  });
  const c = a.children.dynamicColumnConfig.getView();
  if ((c == null ? void 0 : c.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(), c, a.columnAggrData, i);
    expect(t.length).toBeGreaterThanOrEqual(e.length), e.forEach((o) => {
      const d = o.dataIndex, n = t.find((f) => f.dataIndex === d);
      if (!n)
        throw new Error(`Error, column should not be undefined, column: ${JSON.stringify(o)}`);
      const m = n.isCustom ? n.title : n.dataIndex;
      if (!c.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), s(t, a), t = l(t.reduce(t.changeChildAction("data", JSON.stringify([{
    a: 1,
    c: 2,
    d: 3
  }])))), await x();
  const c = [...a, {
    dataIndex: "c",
    hide: !1,
    title: "c"
  }, {
    dataIndex: "d",
    title: "d"
  }];
  s(t, c), t = l(t.reduce(t.changeChildAction("data", JSON.stringify([{
    c: 2,
    d: 3
  }])))), await x(), s(t, c.filter((i) => i.dataIndex !== "a"));
}, 1e3);
async function u(a, r, p) {
  const {
    initColumns: t,
    tableData: c,
    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: {
      ...c,
      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();
  }, d = [{
    dataIndex: "q1",
    title: "q1"
  }, {
    dataIndex: "custom1",
    title: "custom",
    isCustom: !0
  }];
  await o(), !a && r ? s(e, t) : s(e, d);
  const n = [{
    q1: 1,
    a: 2
  }];
  i.query1 = g({
    data: n
  }), await o();
  const m = [...d, {
    dataIndex: "a",
    title: "a"
  }];
  expect(e.children.data.getView()).toEqual(n), !a && r ? s(e, t) : s(e, m);
  const f = [{
    a: 2
  }];
  i.query1 = g({
    data: f
  }), await o(), expect(e.children.data.getView()).toEqual(f), a ? s(e, m.filter((h) => h.dataIndex !== "q1")) : r ? s(e, t) : s(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);
