import {
  agedx
} from "./chunk-32AI7I4C.js";
import {
  NumericHandler
} from "./chunk-ZXTHADSC.js";
import "./chunk-WHI6466S.js";
import {
  termjson
} from "./chunk-DHPLHIVP.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/NumDiscreteEditor.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: term.bins.default
  };
  let handler = {};
  const vocabApi = {
    state: {
      termfilter: { filter: { type: "tvslst", in: "", lst: [] } }
    },
    getViolinBox() {
      return agedx;
    }
  };
  const tw = await TwRouter.initRaw(rawTw, { vocabApi });
  handler = new NumericHandler({
    termsetting: {
      tw,
      term: rawTw.term,
      q: rawTw.q,
      opts: {
        numericEditMenuVersion: ["discrete"],
        usecase: opts.usecase
      },
      api: {
        runCallback() {
        }
      },
      dom: {
        tip: {
          hide() {
          }
        }
      },
      vocabApi
    }
  });
  handler.density_data = { min: agedx.min, max: agedx.max };
  const holder = select_default("body").append("div").style("position", "relative").style("width", "fit-content").style("margin", "20px").style("padding", "5px").style("border", "1px solid #000");
  handler.dom.editDiv = holder;
  await handler.setEditHandler(handler.tabs[0]);
  return {
    rawTw,
    tw,
    handler,
    editHandler: handler.editHandler,
    holder,
    destroy: () => {
      if ("destroy" in handler.editHandler) handler.editHandler.destroy();
      if (typeof handler.destroy == "function") handler.destroy();
      holder.remove();
    }
  };
}
(0, import_tape.default)("\n", (test) => {
  test.comment("-***- NumDiscreteEditor.unit.spec -***-");
  test.end();
});
(0, import_tape.default)("handler methods", async (test) => {
  const { editHandler, destroy } = await getNumericHandler();
  editHandler.setDefaultBoundaryInclusion();
  test.equal(editHandler.boundaryInclusion, "stopinclusive", "should set the expected default boundaryInclusion");
  editHandler.termsetting.tw.q = {
    mode: "discrete",
    type: "custom-bin",
    lst: [
      { start: 0, stop: 5, startinclusive: true },
      { start: 5, stop: 10, startinclusive: true }
    ]
  };
  editHandler.setDefaultBoundaryInclusion();
  test.equal(
    editHandler.boundaryInclusion,
    "startinclusive",
    "should set the expected default boundaryInclusion for custom-bin"
  );
  editHandler.termsetting.tw.q = { mode: "continuous" };
  editHandler.setDefaultBoundaryInclusion();
  test.equal(
    editHandler.boundaryInclusion,
    "stopinclusive",
    `should set the expected default boundaryInclusion when q.mode != 'discrete'`
  );
  if (test._ok) destroy();
  test.end();
});
(0, import_tape.default)("initial rendered UI", async (test) => {
  const { editHandler, holder, destroy } = await getNumericHandler();
  await editHandler.showEditMenu(holder);
  test.equal(editHandler.dom?.density_div.selectAll("svg").size(), 1, `should render a density plot svg`);
  test.equal(
    editHandler.dom.boundaryInclusionDiv.selectAll("option").size(),
    2,
    `should render a boundary inclusion dropdown with 2 options`
  );
  test.equal(
    editHandler.dom.boundaryInclusionDiv.select("select").property("value"),
    "stopinclusive",
    `should default to startinclusive boundary inclusion input value`
  );
  test.deepEqual(
    [...editHandler.dom.binsDiv.node().querySelectorAll(`button[data-testid='sja_toggle_button']`)].map(
      (b) => b.firstChild.innerText
    ),
    ["Same bin size", "Varying bin sizes"],
    `should render 2 toggle buttons, one each for regular-bin and custom-bin menu`
  );
  const boundaryInclusionDiv = editHandler.dom.boundaryInclusionDiv.node();
  await editHandler.showEditMenu(holder);
  test.equal(
    boundaryInclusionDiv,
    editHandler.dom.boundaryInclusionDiv.node(),
    `should not re-render the menu when the holder has not changed`
  );
  editHandler.dom.boundaryInput.property("value", "startinclusive");
  editHandler.dom.boundaryInput.node().dispatchEvent(new Event("change", { bubbles: true }));
  test.deepEqual(
    editHandler.getEditedQ(false),
    {
      mode: "discrete",
      type: "regular-bin",
      startinclusive: true,
      stopinclusive: false,
      bin_size: 500,
      first_bin: { startunbounded: true, stop: 2 },
      rounding: ".0f"
    },
    `should give the expected edited tw.q object`
  );
  await editHandler.undoEdits();
  test.deepEqual(
    editHandler.getEditedQ(false),
    {
      mode: "discrete",
      type: "regular-bin",
      startinclusive: false,
      stopinclusive: true,
      bin_size: 500,
      first_bin: { startunbounded: true, stop: 2 },
      rounding: ".0f"
    },
    `should give the expected edited tw.q object`
  );
  if (test._ok) destroy();
  test.end();
});
//# sourceMappingURL=NumDiscreteEditor.unit.spec-5BIAWAVN.js.map
