import {
  dofetch3
} from "./chunk-7EMWHCVW.js";
import "./chunk-7IYJZZQI.js";
import "./chunk-M3J4MINX.js";
import "./chunk-PF4DSFDR.js";
import "./chunk-QH6W3NVF.js";
import "./chunk-NOEAT6CX.js";
import {
  dt2label
} from "./chunk-4UWS5Y3N.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 "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-HFNDKYVF.js";

// plots/plot.disco.js
async function plot_disco_default(termdbConfig, dslabel, sample, holder, genomeObj, _overrides = {}, showError = true) {
  const loadingDiv = holder.append("div").style("margin", "20px").text("Loading...");
  try {
    if (typeof termdbConfig?.queries?.singleSampleMutation != "object")
      throw "termdbConfig.queries.singleSampleMutation{} not object";
    if (typeof sample != "object") throw "sample{} not object";
    if (typeof genomeObj != "object") throw "genomeObj{} not object";
    const body = {
      genome: genomeObj.name,
      dslabel,
      sample: sample[termdbConfig.queries.singleSampleMutation.sample_id_key]
    };
    const data = await dofetch3("termdb/singleSampleMutation", { body });
    if (data.error) throw data.error;
    if (!Array.isArray(data.mlst)) throw "data.mlst is not array";
    if (data.dt2total?.length) {
      for (const o of data.dt2total) {
        holder.append("div").attr("data-testid", "sjpp-disco-maxReached-" + dt2label[o.dt]).style("margin", "20px 20px 0px 40px").text(`(Displaying ${data.mlst.filter((i) => i.dt == o.dt).length} out of total ${o.total} ${dt2label[o.dt]})`);
      }
    }
    const mlst = data.mlst;
    for (const i of mlst) i.position = i.pos;
    const disco_arg = {
      sampleName: sample[termdbConfig.queries.singleSampleMutation.sample_id_key],
      data: mlst,
      genome: genomeObj
    };
    if (data.alternativeDataByDt) {
      disco_arg.alternativeDataByDt = data.alternativeDataByDt;
    }
    if (termdbConfig.queries.singleSampleMutation.discoPlot?.skipChrM) {
      disco_arg.chromosomes = {};
      for (const k in genomeObj.majorchr) {
        if (k.toLowerCase() == "chrm") continue;
        disco_arg.chromosomes[k] = genomeObj.majorchr[k];
      }
    }
    const opts = {
      holder,
      state: {
        genome: genomeObj.name,
        dslabel,
        args: disco_arg,
        plots: [
          {
            chartType: "Disco",
            subfolder: "disco",
            extension: "ts",
            overrides: computeOverrides(_overrides, termdbConfig, genomeObj, sample)
          }
        ]
      }
    };
    const plot = await import("./plot.app-NRUARQCN.js");
    const plotAppApi = await plot.appInit(opts);
    loadingDiv.remove();
    return true;
  } catch (e) {
    if (showError) loadingDiv.text("Error: " + (e.message || e));
    else loadingDiv.remove();
    return false;
  }
}
function computeOverrides(o, termdbConfig, genomeObj, sample) {
  const overrides = structuredClone(o);
  if (!overrides.Disco) overrides.Disco = {};
  if (genomeObj.geneset) {
    overrides.Disco.showPrioritizeGeneLabelsByGeneSets = true;
    overrides.Disco.prioritizeGeneLabelsByGeneSets = termdbConfig.queries.singleSampleMutation.discoPlot?.prioritizeGeneLabelsByGeneSets;
  }
  if (!overrides.downloadImgName) {
    overrides.downloadImgName = sample[termdbConfig.queries.singleSampleMutation.sample_id_key] + " Disco";
  }
  return overrides;
}
export {
  plot_disco_default as default
};
//# sourceMappingURL=plot.disco-OUE4RFHL.js.map
