import {
  launchPlot
} from "./chunk-ULPMYS5B.js";
import {
  addGeneSearchbox,
  fillTermWrapper,
  make_one_checkbox,
  table2col
} from "./chunk-SA7APTJR.js";
import "./chunk-HJ6L54YS.js";
import "./chunk-LSEFWW72.js";
import "./chunk-SKREEF3H.js";
import {
  Menu
} from "./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 {
  dtcnv
} from "./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 "./chunk-HFNDKYVF.js";

// plots/summarizeCnvGeneexp.ts
var tip = new Menu({ padding: "0px" });
async function makeChartBtnMenu(holder, chartsInstance) {
  let expTw, cnvTw, cnvGeneSameAsExp = true, expSearchPrompt, cnvTableRow;
  make_one_checkbox({
    holder: holder.append("div").style("margin", "20px 10px 5px 15px"),
    labeltext: "Use Same Gene For CNV",
    checked: true,
    testid: "sjpp-summarizeCnvGeneexp-useSameGeneCheckbox",
    callback: async (checked) => {
      cnvGeneSameAsExp = checked;
      await updateUi();
    }
  });
  const table = table2col({
    holder: holder.append("div"),
    margin: "10px",
    cellPadding: "10px"
  });
  {
    const [td1, td2] = table.addRow();
    td1.text("Search Gene For Expression");
    const searchDiv = td2.append("div");
    expSearchPrompt = td2.append("div").style("font-size", ".7em");
    const result = addGeneSearchbox({
      row: searchDiv,
      tip,
      searchOnly: "gene",
      testid: "sjpp-summarizeCnvGeneexp-genesearch-exp",
      genome: chartsInstance.app.opts.genome,
      callback: async () => {
        expSearchPrompt.text("LOADING ...");
        try {
          expTw = { term: { gene: result.geneSymbol, type: "geneExpression" }, q: {} };
          await updateUi();
          if (cnvGeneSameAsExp) launch();
          expSearchPrompt.text("");
        } catch (e) {
          expSearchPrompt.text("Error: " + (e.message || e));
          console.log(e.stack);
        }
      }
    });
  }
  {
    const [td1, td2] = table.addRow();
    cnvTableRow = select_default(td1.node().parentNode);
    td1.text("Search Gene for CNV");
    const searchDiv = td2.append("div");
    const cnvSearchPrompt = td2.append("div").style("font-size", ".7em");
    const result = addGeneSearchbox({
      row: searchDiv,
      tip,
      searchOnly: "gene",
      testid: "sjpp-summarizeCnvGeneexp-genesearch-cnv",
      genome: chartsInstance.app.opts.genome,
      callback: async () => {
        cnvSearchPrompt.text("LOADING ...");
        try {
          cnvTw = await fillGvTw(result.geneSymbol, dtcnv);
          await updateUi();
          cnvSearchPrompt.text("");
        } catch (e) {
          cnvSearchPrompt.text("Error: " + (e.message || e));
          if (e.stack) console.log(e.stack);
        }
      }
    });
  }
  const submitBtn = holder.append("button").attr("data-testid", "sjpp-summarizeCnvGeneexp-submitBtn").text("Launch Plot").style("margin", "0px 15px 15px 15px").property("disabled", true).on("click", launch);
  async function updateUi() {
    if (cnvGeneSameAsExp) {
      if (expTw) {
        cnvTw = await fillGvTw(expTw.term.gene, dtcnv);
      }
    }
    cnvTableRow.style("display", cnvGeneSameAsExp ? "none" : "");
    expSearchPrompt.text(cnvGeneSameAsExp ? "Hit ENTER to launch plot." : "");
    submitBtn.style("display", cnvGeneSameAsExp ? "none" : "").property("disabled", !expTw || !cnvTw);
  }
  updateUi();
  async function fillGvTw(geneSymbol, dt) {
    const name = geneSymbol;
    const tw = {
      term: {
        id: name,
        name,
        genes: [
          {
            kind: "gene",
            id: name,
            gene: name,
            name,
            type: "geneVariant"
          }
        ],
        type: "geneVariant"
      },
      q: { type: "predefined-groupset", dtLst: [dt] }
    };
    await fillTermWrapper(tw, chartsInstance.app.vocabApi);
    return tw;
  }
  function launch() {
    if (!expTw || !cnvTw) throw "either tw is missing";
    launchPlot({
      tw1: expTw,
      tw2: cnvTw,
      chartsInstance,
      holder
    });
  }
}
export {
  makeChartBtnMenu
};
//# sourceMappingURL=summarizeCnvGeneexp-RRP6JUV6.js.map
