import {
  renderTable
} 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 {
  dofetch3
} from "./chunk-7EMWHCVW.js";
import "./chunk-7IYJZZQI.js";
import {
  copyMerge,
  getCompInit
} from "./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 "./chunk-I6Y4O3RR.js";
import "./chunk-OMR2DT66.js";
import "./chunk-DQC5FFGV.js";
import "./chunk-HFNDKYVF.js";

// plots/wsisamples/defaults.ts
function wsiSamplesDefaults(overrides = {}) {
  const defaults = {
    selectedSampleIndex: -1
  };
  return copyMerge(defaults, overrides);
}

// plots/wsisamples/WsiSamplesPlot.ts
var WSISamplesPlot = class _WSISamplesPlot {
  static {
    this.type = "WSISamplesPlot";
  }
  constructor(opts) {
    this.type = _WSISamplesPlot.type;
    this.opts = opts;
  }
  getState(appState) {
    const config = appState.plots.find((p) => p.id === this.id);
    if (!config) {
      throw `No plot with id='${this.id}' found. Did you set this.id before this.api = getComponentApi(this)?`;
    }
    return {
      config,
      dslabel: appState.vocab.dslabel,
      genome: appState.vocab.genome
    };
  }
  async init() {
    const state = this.app.getState();
    const plotConfig = state.plots.find((p) => p.id === this.id);
    const settings = plotConfig.settings;
    const selectedRows = [];
    const selectedSampleIndex = settings.selectedSampleIndex;
    if (selectedSampleIndex != -1) selectedRows.push(selectedSampleIndex);
    const holder = this.opts.holder;
    const contentDiv = holder.append("div").attr("class", "wsi-samples-content");
    const columns = [
      {
        label: "Sample"
      }
    ];
    const rows = [];
    const wsiImages = plotConfig.wsimages;
    wsiImages.forEach((wsiImage) => {
      const row = [];
      const tableCell = {
        value: wsiImage.sampleId
      };
      row.push(tableCell);
      rows.push(row);
    });
    renderTable({
      rows,
      columns,
      resize: true,
      singleMode: true,
      div: contentDiv,
      maxHeight: "50vh",
      selectedRows,
      noButtonCallback: (index) => {
        this.app.dispatch({
          type: "plot_edit",
          id: this.id,
          config: {
            settings: {
              selectedSampleIndex: index
            }
          }
        });
      },
      striped: true,
      header: { style: { "text-transform": "capitalize" } }
    });
  }
  async main() {
    const state = this.app.getState();
    const plotConfig = state.plots.find((p) => p.id === this.id);
    const settings = plotConfig.settings;
    const selectedSampleIndex = settings.selectedSampleIndex;
    const contentDiv = this.opts.holder.select(".wsi-samples-content");
    const wsiImages = plotConfig.wsimages;
    if (selectedSampleIndex != -1) {
      const existingViewer = contentDiv.select(".wsi-viewer");
      if (!existingViewer.empty()) {
        existingViewer.remove();
      }
      const viewerDiv = contentDiv.append("div").attr("class", "wsi-viewer").style("width", "100%");
      const wsiViewer = await import("./plot.wsi-2MU5BDG3.js");
      wsiViewer.default(
        this.app.opts.state.vocab.dslabel,
        viewerDiv,
        this.app.opts.genome,
        wsiImages[selectedSampleIndex].sampleId
      );
    }
  }
};
var wsiSamplesPlot = getCompInit(WSISamplesPlot);
var componentInit = wsiSamplesPlot;
async function getPlotConfig(opts, app) {
  return {
    chartType: "WSISamplesPlot",
    subfolder: "wsisamples",
    extension: "ts",
    wsimages: await getWSISamples(app),
    settings: wsiSamplesDefaults(opts.overrides),
    hidePlotFilter: true
  };
}
async function getWSISamples(app) {
  const data = await dofetch3("wsisamples", {
    body: {
      genome: app.opts.state.vocab.genome,
      dslabel: app.opts.state.vocab.dslabel
    }
  });
  return data.samples;
}
export {
  componentInit,
  WSISamplesPlot as default,
  getPlotConfig,
  wsiSamplesPlot
};
//# sourceMappingURL=WsiSamplesPlot-QPPB7OOD.js.map
