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/NumSplineEditor.unit.spec.ts
var import_tape = __toESM(require_tape(), 1);
async function getNumericHandler(opts = {}) {
  const term = JSON.parse(JSON.stringify(termjson.agedx));
  const rawTw = {
    term,
    q: {
      mode: "spline",
      //[{value: 0.04}, {value: 3.13}, {value: 8.16}, {value: 17.87}]
      knots: [{ value: 10 }, { value: 100 }, { value: 500 }, { value: 1e3 }]
    }
  };
  let handler = {};
  const vocabApi = {
    state: {
      termfilter: { filter: { type: "tvslst", in: "", lst: [] } }
    },
    getViolinBox() {
      return agedx;
    },
    getPercentile() {
      return {
        values: [0.03537315665, 3.13072460515, 8.164619357749999, 17.8726813385]
      };
    }
  };
  const tw = await TwRouter.initRaw(rawTw, { vocabApi });
  handler = new NumericHandler({
    termsetting: {
      tw,
      term: rawTw.term,
      q: rawTw.q,
      opts: {
        numericEditMenuVersion: ["spline"],
        usecase: opts.usecase
      },
      api: {
        runCallback() {
        }
      },
      dom: {
        tip: {
          hide() {
          }
        }
      },
      vocabApi
    }
  });
  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("-***- NumBinaryEditor.unit.spec -***-");
  test.end();
});
(0, import_tape.default)("handler methods", async (test) => {
  const { editHandler, destroy } = await getNumericHandler();
  test.deepEqual(editHandler.getPillStatus(), { text: "cubic spline" }, "should give the expected status");
  editHandler.termsetting.tw.q = { mode: "discrete" };
  test.deepEqual(
    await editHandler.getDefaultQ(),
    { mode: "spline", knots: [{ value: "0.04" }, { value: "3.13" }, { value: "8.16" }, { value: "17.87" }] },
    "should give the expected defaultQ"
  );
  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`);
  const lines = [...editHandler.handler.density.dom.binsize_g.node().querySelectorAll("line")];
  test.equal(lines.length, 4, `should render 4 draggable lines in the density plot`);
  test.deepEqual(
    lines.map((l) => l.getAttribute("x1")),
    ["11", "21", "63", "116"],
    `should render the draggable lines in the expected x-positions`
  );
  test.equal(
    editHandler.dom.customKnotsInput.property("value"),
    "10\n100\n500\n1000",
    "should display line-separated values in the knots inputs"
  );
  test.equal(editHandler.dom.knot_select_div.selectAll("select").size(), 1, `should render an auto-compute dropdown`);
  test.equal(
    editHandler.dom.knot_select_div.select("select").property("value"),
    "4",
    `should default to 4 knots for auto-compute`
  );
  const density_div = editHandler.dom.density_div.node();
  await editHandler.showEditMenu(holder);
  test.equal(
    density_div,
    editHandler.dom.density_div.node(),
    `should not re-render the menu when the holder has not changed`
  );
  if (test._ok) destroy();
  test.end();
});
(0, import_tape.default)("knots interactivity", async (test) => {
  const { editHandler, holder, destroy } = await getNumericHandler();
  await editHandler.showEditMenu(holder);
  const newKnots = [10, 200, 600, 3e3];
  editHandler.dom.customKnotsInput.property("value", newKnots.join("\n"));
  editHandler.dom.customKnotsInput.node().dispatchEvent(new Event("change", { bubbles: true }));
  const lines = [...editHandler.handler.density.dom.binsize_g.node().querySelectorAll("line")];
  test.deepEqual(
    lines.map((l) => l.getAttribute("x1")),
    ["11", "31", "74", "328"],
    `should re-render the draggable lines in the updated x-positions`
  );
  test.deepEqual(
    editHandler.getEditedQ(false),
    { mode: "spline", knots: newKnots.map((value) => ({ value })) },
    `should give the expected edited q object`
  );
  editHandler.undoEdits();
  await sleep(0);
  {
    const lines2 = [...editHandler.handler.density.dom.binsize_g.node().querySelectorAll("line")];
    test.equal(lines2.length, 4, `should render 4 draggable lines in the density plot`);
    test.deepEqual(
      lines2.map((l) => l.getAttribute("x1")),
      ["11", "21", "63", "116"],
      `should render the draggable lines in the expected x-positions`
    );
  }
  if (test._ok) destroy();
  test.end();
});
//# sourceMappingURL=NumSplineEditor.unit.spec-N34QBZN3.js.map
