"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[419],{20419:(e,t,a)=>{a.r(t),a.d(t,{default:()=>E});var n=a(7552),r=a(68446),o=a(36422),s=a(29499),l=a(9937),i=a(99123),c=a(36715),d=a(1343),h=a(58507),m=a(5401),w=a(75785),u=a(31409),p=a.n(u),f=a(99546),k=a(48735),b=a(90542),y=a(32984);const g=(0,w.n9)()((()=>({flexItem:{margin:5}}))),E=(0,r.observer)((function({onClose:e,model:t}){const{classes:a}=g(),[r,w]=(0,n.useState)(""),[u,E]=(0,n.useState)(),[S,C]=(0,n.useState)(!0),U=(0,f.getSession)(t),{selectedBookmarks:A}=t,R=0===A.length,I=0===A.length?t.allBookmarksModel:t.sharedBookmarksModel;return(0,n.useEffect)((()=>{let e=!1;return(async()=>{try{if(!(0,f.isSessionWithShareURL)(U))throw new Error("No shareURL configured");C(!0);const t=(0,o.getSnapshot)(I),a=new URL(window.location.href),n=await(0,y.J)(t,U.shareURL,a.href);if(!e){const e=new URLSearchParams(a.search);e.set("bookmarks",`share-${n.json.sessionId}`),e.set("password",n.password),a.search=e.toString(),w(a.href),C(!1)}}catch(e){E(e)}finally{C(!1)}})(),()=>{e=!0}}),[I,U]),n.createElement(k.Dialog,{open:!0,onClose:e,title:"Share bookmarks"},n.createElement(s.A,{style:{display:"flex",flexFlow:"column",gap:"5px"}},n.createElement(l.A,{severity:"info"},R?n.createElement(n.Fragment,null,n.createElement("span",null,"All bookmarks will be shared."),n.createElement("br",null),n.createElement("span",null,"Use the checkboxes to select individual bookmarks to share.")):"Only selected bookmarks will be shared."),n.createElement(i.A,null,"Copy the URL below to share your bookmarks."),u?n.createElement(k.ErrorMessage,{error:u}):S?n.createElement(c.A,null,"Generating short URL..."):n.createElement(d.A,{label:"URL",value:r,InputProps:{readOnly:!0},variant:"filled",fullWidth:!0,onClick:e=>{e.target.select()}}),n.createElement(i.A,null,'The URL should be pasted into the "Import from share link" field in the "Import" form found in the "Bookmarked regions" drawer.')),n.createElement(h.A,null,n.createElement(m.A,{className:a.flexItem,"data-testid":"dialogShare",variant:"contained",color:"primary",disabled:S,startIcon:n.createElement(b.PM,null),onClick:async()=>{p()(r),U.notify("Copied to clipboard","success"),e()}},"Copy share link")))}))},32984:(e,t,a)=>{a.d(t,{J:()=>l,Z:()=>i});var n=a(84495);const r=async(e,t)=>(await Promise.all([a.e(7753),a.e(9831),a.e(5156)]).then(a.t.bind(a,29831,23))).encrypt(e,t).toString(),o=async(e,t)=>{const n=await Promise.all([a.e(7753),a.e(9831),a.e(5156)]).then(a.t.bind(a,29831,23)),r=await Promise.all([a.e(7753),a.e(6235)]).then(a.t.bind(a,12598,23));return n.decrypt(e,t).toString(r)};function s(e){try{return JSON.parse(e).message}catch(t){return e}}async function l(e,t,a){const o=await(0,n.eW)(JSON.stringify(e)),l=(5,window.btoa([...window.crypto.getRandomValues(new Uint8Array(10))].map((e=>String.fromCharCode(e))).join("")).replaceAll(/[+/]/g,"").slice(0,5));const i=await r(o,l),c=new FormData;c.append("session",i),c.append("dateShared",`${Date.now()}`),c.append("referer",a);const d=await fetch(`${t}share`,{method:"POST",mode:"cors",body:c});if(!d.ok){const e=await d.text();throw new Error(s(e))}return{json:await d.json(),encryptedSession:i,password:l}}async function i(e,t,a,n){const r=t.split("share-")[1],l=`${e}?sessionId=${encodeURIComponent(r)}`,i=await fetch(l,{signal:n});if(!i.ok){const e=await i.text();throw new Error(s(e))}const c=await i.json();return o(c.session,a)}}}]);
//# sourceMappingURL=419.95e8e70d.chunk.js.map