import{aW as O,aX as D,aY as j,g as L,m as M,o as T,r as c,u as F,R as e,b as P,E as z,F as k,aM as B,N as H,G as W,H as J,I as N,J as $,K,a as x,af as V,O as X,ae as Y,c as Q}from"./rpcWorker-CVTx5FIM.js";var p={},G;function U(){if(G)return p;G=1,Object.defineProperty(p,"__esModule",{value:!0}),p.formatFastaLines=r,p.formatSeqFasta=o;function r(a){return a.replaceAll(/(.{1,80})/g,`$1
`).trimEnd()}function o(a){return a.map(n=>`>${n.header}
${r(n.seq)}`).join(`
`)}return p}var Z=U(),d={},_;function ee(){if(_)return d;_=1;var r=O();Object.defineProperty(d,"__esModule",{value:!0}),d.default=void 0;var o=r(D()),a=j();return d.default=(0,o.default)((0,a.jsx)("path",{d:"M19 9h-4V3H9v6H5l7 7zM5 18v2h14v-2z"}),"GetApp"),d}var te=ee(),re=L(te);const ae=M()({dialogContent:{width:"80em"},textAreaFont:{fontFamily:"Courier New"},ml:{marginLeft:10}});async function ne(r,o){const a=F.getSession(r),{leftOffset:n,rightOffset:i}=r;if(!n||!i)throw new Error("no offsets on model to use for range");if(n.assemblyName!==i.assemblyName)throw new Error("not able to fetch sequences from multiple assemblies");const{rpcManager:u,assemblyManager:h}=a,l=n.assemblyName||i.assemblyName||"",g=h.get(l);if(!g)throw new Error(`assembly ${l} not found`);const E=Q.getConf(g,["sequence","adapter"]),m="getSequence";return u.call(m,"CoreGetFeatures",{adapterConfig:E,regions:o,sessionId:m})}const oe=T(function({model:r,handleClose:o}){const{classes:a}=ae(),[n,i]=c.useState(),[u,h]=c.useState(),[l,g]=c.useState(!1),[E,m]=c.useState(!1),[b,I]=c.useState(!1),{leftOffset:w,rightOffset:R}=r,v=u===void 0;c.useEffect(()=>{const s=new AbortController;return(async()=>{try{const t=r.getSelectedRegions(w,R);if(t.length===0)throw new Error("Selected region is out of bounds");const S=await ne(r,t);h(S)}catch(t){console.error(t),i(t)}})(),()=>{s.abort()}},[r,w,R]);const f=u?Z.formatSeqFasta(u.map(s=>{let t=s.get("seq");const S=s.get("refName"),C=s.get("start")+1,y=s.get("end"),A=`${S}:${C}-${y}`;if((t==null?void 0:t.length)!==y-C+1)throw new Error(`${A} returned ${t.length.toLocaleString()} bases, but should have returned ${(y-C).toLocaleString()}`);return l&&(t=F.reverse(t)),b&&(t=F.complement(t)),{header:A+(l?"-rev":"")+(b?"-comp":""),seq:t}})):"",q=f?f.length>1e6:!1;return e.createElement(P.Dialog,{maxWidth:"xl",open:!0,onClose:()=>{o(),r.setOffsets()},title:"Reference sequence"},e.createElement(z,null,n?e.createElement(k,{color:"error"},`${n}`):v?e.createElement(B,null,"Retrieving reference sequence...",e.createElement(H,{className:a.ml,size:20,disableShrink:!0})):null,e.createElement(W,{"data-testid":"rubberband-sequence",variant:"outlined",multiline:!0,minRows:5,maxRows:10,disabled:q,className:a.dialogContent,fullWidth:!0,value:q?"Reference sequence too large to display, use the download FASTA button":f,slotProps:{input:{readOnly:!0,classes:{input:a.textAreaFont}}}}),e.createElement(J,null,e.createElement(N,{control:e.createElement($,{value:l,onChange:s=>{g(s.target.checked)}}),label:"Reverse sequence"}),e.createElement(N,{control:e.createElement($,{value:b,onChange:s=>{I(s.target.checked)}}),label:"Complement sequence"})),e.createElement(k,{style:{margin:10}},'Note: Check both boxes for the "reverse complement"')),e.createElement(K,null,e.createElement(x,{onClick:()=>{V(f),m(!0),setTimeout(()=>{m(!1)},500)},disabled:v||!!n||q,color:"primary",startIcon:e.createElement(X.ContentCopy,null)},E?"Copied":"Copy to clipboard"),e.createElement(x,{onClick:()=>{Y.saveAs(new Blob([f||""],{type:"text/x-fasta;charset=utf-8"}),"jbrowse_ref_seq.fa")},disabled:v||!!n,color:"primary",startIcon:e.createElement(re,null)},"Download FASTA"),e.createElement(x,{onClick:o,variant:"contained"},"Close")))});export{oe as default};
