import {
  addGeneSearchbox
} from "./chunk-SA7APTJR.js";
import {
  Menu
} from "./chunk-HYOEWQ5P.js";

// termdb/handlers/snp.ts
var SearchHandler = class {
  init(opts) {
    this.callback = opts.callback;
    const geneSearch = addGeneSearchbox({
      tip: new Menu({ padding: "0px" }),
      genome: opts.genomeObj,
      row: opts.holder,
      searchOnly: "snp",
      allowVariant: true,
      callback: () => this.selectSnp(geneSearch)
    });
  }
  async selectSnp(geneSearch) {
    const { chr, ref, alt, fromWhat } = geneSearch;
    if (!chr || !ref || !alt || !fromWhat) throw "missing chr, ref, alt, or fromWhat of snp";
    let start, stop;
    if (!geneSearch.start && !geneSearch.stop) {
      if (geneSearch.pos) {
        start = geneSearch.pos - 1;
        stop = geneSearch.pos;
      } else {
        throw "missing coordinate of snp";
      }
    } else {
      start = geneSearch.start;
      stop = geneSearch.stop;
    }
    const term = {
      id: fromWhat,
      chr,
      start,
      stop,
      name: fromWhat,
      ref,
      alt: typeof alt == "string" ? [alt] : alt,
      // is string if input to geneSearch was in variant or hgvs format // TODO: update genesearch.ts to parse alternative alleles from any input format into arrays
      type: "snp"
    };
    this.callback(term);
  }
};

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