import {
  PlotBase,
  controlsInit
} 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/imagePlot.ts
var ImagePlot = class _ImagePlot extends PlotBase {
  static {
    this.type = "imagePlot";
  }
  constructor(opts, api) {
    super(opts, api);
    this.opts = opts;
    this.api = api;
    this.type = _ImagePlot.type;
    if (this.opts?.header) {
      if (this.opts?.headerText)
        this.opts.header.append("span").style("padding-right", "5px").text(this.opts.headerText);
      this.opts.header.append("span").text("IMAGE PLOT").style("font-size", "0.7em").style("opacity", 0.6);
    }
  }
  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,
      termfilter: appState.termfilter,
      vocab: appState.vocab
    };
  }
  async init(appState) {
    const config = this.getState(appState).config;
    const holder = this.opts.holder.append("div").attr("data-testid", "sjpp-imagePlot-holder");
    this.dom = {
      holder,
      controlsHolder: holder.append("div").attr("data-testid", "sjpp-imagePlot-controlsDiv").style("display", "inline-block"),
      imageHolder: holder.append("div").attr("data-testid", "sjpp-imagePlot-imagesDiv").style("display", "inline-block")
    };
    const sampleId = config.sample?.sampleId || config.sample?.sID;
    let images;
    if (config?.imgDir) {
      const img = await dofetch3(
        `img?file=${config.imgDir.folder}${config.imgDir.folder.endsWith("/") ? "" : "/"}${sampleId}/${config.imgDir.fileName}`
      );
      if (!img || img?.error) throw new Error(img?.error || "Error fetching image");
      images = [img];
    } else {
      const result = await this.app.vocabApi.getSampleImages(sampleId);
      if (result.error) throw new Error(result.error);
      images = result.images;
    }
    for (const img of images) {
      this.dom.imageHolder.append("img").style("padding", "10px").attr("src", img.src).attr("width", config.settings.imagePlot.width).attr("height", config.settings.imagePlot.height);
    }
  }
  async setControls() {
    this.components = {
      controls: await controlsInit({
        app: this.app,
        id: this.id,
        holder: this.dom.controlsHolder,
        inputs: [
          {
            label: "Image width",
            type: "number",
            chartType: this.type,
            settingsKey: "width"
          },
          {
            label: "Image height",
            type: "number",
            chartType: this.type,
            settingsKey: "height"
          }
        ]
      })
    };
  }
  async main() {
  }
};
async function getPlotConfig(opts) {
  const settings = getDefaultImagePlotSettings();
  if (opts.settings) copyMerge(settings, opts.settings);
  const config = {
    settings: {
      controls: {
        isOpen: false
      },
      imagePlot: settings
    }
  };
  return copyMerge(config, opts);
}
function getDefaultImagePlotSettings() {
  return {
    width: 500,
    height: 500
  };
}
var imagePlotInit = getCompInit(ImagePlot);
var componentInit = imagePlotInit;
async function renderImagePlot(state, holder, sample) {
  const opts = {
    holder,
    state: {
      vocab: state.vocab,
      plots: [
        {
          chartType: "imagePlot",
          sample
        }
      ]
    }
  };
  const plot = await import("./plot.app-NRUARQCN.js");
  await plot.appInit(opts);
}
export {
  componentInit,
  getDefaultImagePlotSettings,
  getPlotConfig,
  imagePlotInit,
  renderImagePlot
};
//# sourceMappingURL=imagePlot-M5JSHEY4.js.map
