import {
  addGeneSearchbox,
  getSCGEunit
} from "./chunk-SA7APTJR.js";
import {
  Menu
} from "./chunk-HYOEWQ5P.js";
import {
  SINGLECELL_GENE_EXPRESSION
} from "./chunk-NOEAT6CX.js";

// termdb/handlers/singleCellGeneExpression.ts
var SearchHandler = class {
  init(opts) {
    this.validateOpts(opts);
    this.callback = opts.callback;
    this.app = opts.app;
    const holder = opts.holder.append("div").style("padding", "10px 0px");
    const geneSearch = addGeneSearchbox({
      tip: new Menu({ padding: "0px" }),
      genome: opts.genomeObj,
      row: holder,
      searchOnly: "gene",
      callback: () => this.selectGene(geneSearch.geneSymbol, opts.usecase?.specialCase?.config?.sample)
    });
  }
  /**TODO: scge tw handler will validate that a sample is included. Need to resolve issue
   * with sample info not included.*/
  async selectGene(gene, sample) {
    if (!gene) throw new Error("No gene selected");
    const unit = getSCGEunit(this.app.vocabApi);
    const name = `${gene} ${unit}`;
    this.callback({ gene, name, type: SINGLECELL_GENE_EXPRESSION, sample });
  }
  validateOpts(opts) {
    if (opts.callback == null) throw new Error("callback is required");
    if (opts.app == null) throw new Error("app is required");
    if (opts.holder == null) throw new Error("holder is required");
    if (opts.genomeObj == null) throw new Error("genomeObj is required");
    if (opts.usecase == null) throw new Error("usecase is required");
    if (!opts.usecase?.specialCase?.config?.sample) {
      throw new Error("usecase.specialCase.config.sample is required for singleCellGeneExpression handler");
    }
  }
};

export {
  SearchHandler
};
//# sourceMappingURL=chunk-EVN6KWPN.js.map
