import{o as B,r,u as c,Z as F,R as e,b as f,E as G,F as v,G as L,M as $,K as N,a as T,L as q,$ as M,a0 as C,a1 as I}from"./rpcWorker-CVTx5FIM.js";const V=B(function(S){const{model:i,handleClose:g}=S,[t,w]=r.useState(""),[o,b]=r.useState(),[A,D]=r.useState(!1),[E,h]=r.useState(),P=/^[A-Za-z][A-Za-z0-9]$/.exec(t),p=t.length===2&&!P,k=c.useDebounce(t,1e3),[u,x]=r.useState("");return r.useEffect(()=>{(async()=>{try{if(!p){h(void 0),D(!0);const a=await F({self:i,tag:k,blocks:c.getContainingView(i).staticBlocks});b(a)}}catch(a){console.error(a),h(a)}finally{D(!1)}})()},[i,p,k]),e.createElement(f.Dialog,{open:!0,onClose:g,title:"Group by"},e.createElement(G,null,e.createElement(v,null,'NOTE: this will create new session tracks with the "filter by" set to the values chosen here rather than affecting the current track state'),e.createElement(L,{fullWidth:!0,value:u,onChange:a=>{x(a.target.value)},label:"Group by...",select:!0},e.createElement($,{value:"strand"},"Strand"),e.createElement($,{value:"tag"},"Tag")),u==="tag"?e.createElement(e.Fragment,null,e.createElement(v,{color:"textSecondary"},"Examples: HP for haplotype, RG for read group, etc."),e.createElement(L,{value:t,onChange:a=>{w(a.target.value)},placeholder:"Enter tag name",error:p,helperText:p?"Not a valid tag":"",autoComplete:"off","data-testid":"group-tag-name",slotProps:{htmlInput:{maxLength:2,"data-testid":"group-tag-name-input"}}}),E?e.createElement(f.ErrorMessage,{error:E}):A?e.createElement(f.LoadingEllipses,{title:"Loading unique tags"}):o?e.createElement("div",null,e.createElement("div",null,"Found unique ",t," values:"),e.createElement("div",null,o.join(", "))):null):null),e.createElement(N,null,e.createElement(T,{variant:"contained",color:"primary",type:"submit",disabled:!o,autoFocus:!0,onClick:()=>{const a=c.getContainingTrack(i),n=structuredClone(q(a.configuration)),y=c.getSession(i),m=c.getContainingView(i);if(u==="tag"){if(o){const l=[...o,void 0];for(const s of l){const d=`${n.trackId}-${t}:${s}-${+Date.now()}-sessionTrack`;y.addTrackConf({...n,trackId:d,name:`${n.name} (-)`,displays:[{displayId:`${d}-LinearAlignmentsDisplay`,type:"LinearAlignmentsDisplay",pileupDisplay:{displayId:`${d}-LinearAlignmentsDisplay-LinearPileupDisplay`,type:"LinearPileupDisplay",filterBy:{...M,tagFilter:{tag:t,value:s}}}}]}),m.showTrack(d)}}}else if(u==="strand"){const l=`${n.trackId}-${t}:(-)-${+Date.now()}-sessionTrack`,s=`${n.trackId}-${t}:(+)-${+Date.now()}-sessionTrack`;y.addTrackConf({...n,trackId:l,name:`${n.name} (-)`,displays:[{displayId:`${l}-LinearAlignmentsDisplay`,type:"LinearAlignmentsDisplay",pileupDisplay:{displayId:`${l}-LinearAlignmentsDisplay-LinearPileupDisplay`,type:"LinearPileupDisplay",filterBy:C}},{displayId:`${l}-LinearSNPCoverageDisplay`,type:"LinearSNPCoverageDisplay",filterBy:C}]}),y.addTrackConf({...n,trackId:s,name:`${n.name} (+)`,displays:[{displayId:`${s}-LinearAlignmentsDisplay`,type:"LinearAlignmentsDisplay",pileupDisplay:{displayId:`${s}-LinearAlignmentsDisplay-LinearPileupDisplay`,type:"LinearPileupDisplay",filterBy:I}},{displayId:`${s}-LinearSNPCoverageDisplay`,type:"LinearSNPCoverageDisplay",filterBy:I}]}),m.showTrack(l),m.showTrack(s)}g()}},"Submit"),e.createElement(T,{variant:"contained",color:"secondary",onClick:()=>{g()}},"Cancel")))});export{V as default};
