import {
  agedx
} from "./chunk-32AI7I4C.js";
import {
  NumericHandler
} from "./chunk-ZXTHADSC.js";
import "./chunk-WHI6466S.js";
import {
  termjson
} from "./chunk-DHPLHIVP.js";
import {
  sleep
} from "./chunk-DJQTUDJM.js";
import {
  require_tape
} from "./chunk-QWOE5YTB.js";
import {
  TwRouter
} from "./chunk-SA7APTJR.js";
import "./chunk-HJ6L54YS.js";
import "./chunk-LSEFWW72.js";
import "./chunk-SKREEF3H.js";
import "./chunk-HYOEWQ5P.js";
import "./chunk-HBW42TDT.js";
import "./chunk-G6O3URDN.js";
import "./chunk-FN5XPUPH.js";
import "./chunk-IIT367QZ.js";
import "./chunk-RZGEKL77.js";
import "./chunk-UI7OCM2A.js";
import "./chunk-YZK37YCC.js";
import "./chunk-7EMWHCVW.js";
import "./chunk-7IYJZZQI.js";
import "./chunk-M3J4MINX.js";
import "./chunk-PF4DSFDR.js";
import "./chunk-QH6W3NVF.js";
import "./chunk-NOEAT6CX.js";
import "./chunk-4UWS5Y3N.js";
import "./chunk-DD4R5P6W.js";
import "./chunk-JNITUVXP.js";
import "./chunk-KSGA62R2.js";
import "./chunk-LOZEKOES.js";
import "./chunk-TOU7EVFQ.js";
import "./chunk-OAWQ6LOO.js";
import "./chunk-TLT4YIG3.js";
import "./chunk-KYBIQBXE.js";
import {
  select_default
} from "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import {
  __toESM
} from "./chunk-HFNDKYVF.js";

// termsetting/handlers/test/NumericHandler.unit.spec.ts
var import_tape = __toESM(require_tape(), 1);
async function getNumericHandler(_opts = {}) {
  const term = JSON.parse(JSON.stringify(termjson.agedx));
  if (term.bins.default.type == "regular-bin") term.bins.default.bin_size = 500;
  const rawTw = {
    term,
    q: {
      mode: "discrete",
      //type: 'regular-bin',
      ...term.bins.default
    }
  };
  const tw = await TwRouter.initRaw(rawTw);
  const handler = new NumericHandler({
    termsetting: {
      tw,
      term: rawTw.term,
      q: rawTw.q,
      opts: {
        numericEditMenuVersion: ["continuous", "discrete", "binary", "spline"],
        // _opts will any matching override previous opts key-values
        ..._opts
      },
      api: {
        async runCallback() {
          const self = handler.termsetting;
          const q = handler.editHandler.q;
          self.tw = await TwRouter.initRaw({ term: self.term, q }, self.opts);
        }
      },
      dom: {
        tip: {
          hide() {
          }
        }
      },
      vocabApi: {
        getViolinBox() {
          return agedx;
        },
        getPercentile() {
          return {
            values: [0.03537315665, 3.13072460515, 8.164619357749999, 17.8726813385]
          };
        }
      }
    }
  });
  const holder = select_default("body").append("div").style("width", "fit-content").style("margin", "20px").style("padding", "5px").style("border", "1px solid #000");
  return {
    rawTw,
    tw,
    handler,
    holder,
    destroy: () => {
      if (handler.editHandler && "destroy" in handler.editHandler) handler.editHandler.destroy();
      if (typeof handler.destroy == "function") handler.destroy();
      holder.remove();
    }
  };
}
(0, import_tape.default)("\n", (test) => {
  test.comment("-***- NumericHandler.unit.spec -***-");
  test.end();
});
(0, import_tape.default)("tabs data and pill status", async (test) => {
  const { handler, destroy } = await getNumericHandler();
  test.deepEqual(
    handler.tabs.map((t) => t.label),
    ["Continuous", "Discrete", "Cubic spline", "Binary"],
    "sets the expected tab data"
  );
  test.deepEqual(handler.getPillStatus(), { text: "bin size=500" }, `should give the expected pill status`);
  if (test._ok) destroy();
  test.end();
});
(0, import_tape.default)("editHandler", async (test) => {
  const { handler, destroy } = await getNumericHandler();
  handler.density_data = { min: 0, max: 100 };
  await handler.setEditHandler(handler.tabs[0]);
  test.equal(
    handler.editHandler.constructor.name,
    "NumContEditor",
    `sets the expected editHandler for mode='continuous'`
  );
  await handler.setEditHandler(handler.tabs[1]);
  test.equal(
    handler.editHandler.constructor.name,
    "NumDiscreteEditor",
    `sets the expected editHandler for mode='discrete'`
  );
  await handler.setEditHandler(handler.tabs[2]);
  test.equal(handler.editHandler.constructor.name, "NumSplineEditor", `sets the expected editHandler for mode='binary'`);
  await handler.setEditHandler(handler.tabs[3]);
  test.equal(handler.editHandler.constructor.name, "NumBinaryEditor", `sets the expected editHandler for mode='spline'`);
  if (test._ok) destroy();
  test.end();
});
(0, import_tape.default)("showEditMenu, multiple modes", async (test) => {
  const { handler, holder, destroy } = await getNumericHandler();
  await handler.showEditMenu(holder);
  await sleep(0);
  test.equal(handler.editHandler.dom.density_div.selectAll("svg").size(), 1, `should render a density plot svg`);
  test.equal(
    handler.dom.topBar?.selectAll(".sj-toggle-button").size(),
    4,
    `should render 4 tabs, one toggle button for each mode`
  );
  test.equal(handler.dom.btnDiv?.selectAll("button").size(), 2, `should render an apply and reset button`);
  test.deepEqual(handler.getPillStatus(), { text: "bin size=500" }, "should have the expected initial pill status");
  const tabBtns = handler.dom.topBar.node().querySelectorAll("button");
  tabBtns[2].click();
  await sleep(10);
  handler.dom.btnDiv.select("button").node().click();
  await sleep(10);
  test.deepEqual(
    handler.getPillStatus(),
    { text: "cubic spline" },
    "should have a different pill status after switching q.modes"
  );
  if (test._ok) destroy();
  test.end();
});
(0, import_tape.default)("showEditMenu, single mode", async (test) => {
  const { handler, holder, destroy } = await getNumericHandler({ numericEditMenuVersion: ["binary"] });
  await handler.showEditMenu(holder);
  await sleep(0);
  test.equal(handler.editHandler.dom.density_div.selectAll("svg").size(), 1, `should render a density plot svg`);
  test.equal(
    handler.dom.topBar?.selectAll(".sj-toggle-button").size(),
    void 0,
    `should not render mode toggle buttons`
  );
  test.equal(handler.dom.btnDiv?.selectAll("button").size(), 2, `should render an apply and reset button`);
  if (test._ok) destroy();
  test.end();
});
(0, import_tape.default)("apply and reset", async (test) => {
  test.timeoutAfter(50);
  test.plan(2);
  const { handler, holder, destroy } = await getNumericHandler();
  handler.editHandler = {
    getEditedQ() {
      test.pass("should trigger editHandler.getEditedQ() from applyEdits()");
      return { mode: "discrete", type: "regular-bin" };
    },
    undoEdits() {
      test.pass("should trigger editHandler.undoEdits() from undoEdits()");
    }
  };
  try {
    await handler.renderButtons(holder);
    const btns = holder.node()?.querySelectorAll("button");
    if (btns?.length) {
      btns[0].click();
      btns[1].click();
    }
    if (test._ok) destroy();
    test.end();
  } catch (e) {
    test.fail("should trigger editHandler.getEditedQ and .undoEdits(): " + e);
  }
});
//# sourceMappingURL=NumericHandler.unit.spec-NKLYDVTG.js.map
