import{u,b5 as N,a4 as k,b6 as $,r as d,R as a,F as w,b as B,a2 as E,b7 as A}from"./rpcWorker-CVTx5FIM.js";import{B as C}from"./FeatureDetails-CfRe4vtU.js";import{n as R}from"./AlignmentsFeatureDetail-Ah8jH9Px.js";async function D({view:e,feature:n}){var s;const{assemblyManager:o}=u.getSession(e),r=n.get("CIGAR"),i=n.get("strand"),g=((s=n.get("tags"))===null||s===void 0?void 0:s.SA)||"",p=n.get("name"),t=N(r,1),f=await o.waitForAssembly(e.assemblyNames[0]);if(!f)throw new Error("assembly not found");const c=k(g,n.id(),i,p,!0),l=n.toJSON();l.clipPos=t,l.strand=1,l.mate={refName:p,start:t,end:t+$(r)};const y=[l,...c];return y.forEach((m,S)=>{m.refName=f.getCanonicalRefName(m.refName)||m.refName,m.syntenyId=S,m.mate.syntenyId=S,m.mate.uniqueId=`${m.uniqueId}_mate`}),y.sort((m,S)=>m.clipPos-S.clipPos),y}const F=d.lazy(()=>import("./BreakendSingleLevelOptionDialog-CY2T9tVv.js").then(function(e){return e.B})),M=d.lazy(()=>import("./BreakendSingleLevelOptionDialog-CY2T9tVv.js").then(function(e){return e.a}));function V({model:e,feature:n}){const{view:s}=e,[o,r]=d.useState(),[i,g]=d.useState();d.useEffect(()=>{(async()=>{try{const t=await D({view:s,feature:new u.SimpleFeature(n)});r(t)}catch(t){g(t),console.error(t)}})()},[n,s]);const p=[];if(o)for(let t=0;t<o.length-1;t++)p.push([o[t],o[t+1]]);return p.length?a.createElement("div",null,a.createElement(w,null,"Launch split view"),i?a.createElement(B.ErrorMessage,{error:i}):null,a.createElement("ul",null,p.map((t,f)=>{const[c,l]=t;return a.createElement("li",{key:`${JSON.stringify(t)}-${f}`},c.refName,":",u.toLocale(c.strand===1?c.end:c.start)," ->"," ",l.refName,":",u.toLocale(l.strand===1?l.start:l.end)," ",a.createElement(x,{model:e,f1:c,f2:l})," ",a.createElement(I,{model:e,f1:c,f2:l}))}))):null}function x({model:e,f1:n,f2:s}){return a.createElement(E,{href:"#",onClick:o=>{o.preventDefault();const r=u.getSession(e);r.queueDialog(i=>[F,{handleClose:i,session:r,feature:new u.SimpleFeature({...n,mate:s}),view:e.view,assemblyName:e.view.displayedRegions[0].assemblyName}])}},"(top/bottom)")}function I({model:e,f1:n,f2:s}){return a.createElement(E,{href:"#",onClick:o=>{o.preventDefault();const r=u.getSession(e);r.queueDialog(i=>[M,{handleClose:i,session:r,feature:new u.SimpleFeature({...n,mate:s}),view:e.view,assemblyName:e.view.displayedRegions[0].assemblyName}])}},"(single row)")}function O({tag:e,model:n}){return a.createElement("div",null,a.createElement(w,null,"List of supplementary alignment locations"),a.createElement("ul",null,e.split(";").filter(s=>!!s).map((s,o)=>{const[r,i,g,p]=s.split(","),t=A(p),f=Math.floor(t/5),c=+i,l=+i+t,y=c-f,m=l+f,S=`${r}:${Math.max(1,y)}-${m}`,h=c.toLocaleString("en-US"),v=l.toLocaleString("en-US"),L=`${r}:${h}-${v} (${g}) [${t}bp]`;return a.createElement("li",{key:`${S}-${o}`},a.createElement(E,{href:"#",onClick:async b=>{b.preventDefault(),R(S,n)}},L))})))}function z(e){const{model:n,tag:s,feature:o}=e,r=u.getSession(n),{pluginManager:i}=u.getEnv(r);let g=!1;try{g=!!i.getViewType("BreakpointSplitView")}catch{}return a.createElement(C,{...e,title:"Supplementary alignments"},a.createElement(O,{model:n,tag:s}),g?a.createElement(V,{model:n,feature:o}):null)}export{z as default};
