"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[3591],{53591:(e,t,a)=>{a.r(t),a.d(t,{default:()=>E});var n=a(66204),r=a(80846),o=a(88196),s=a(29520),l=a(32831),i=a(27513),c=a(80013),d=a(46338),h=a(62301),m=a(7146),w=a(38684),p=a(43306),u=a.n(p),f=a(90872),k=a(35421),b=a(24728),y=a(97990);const g=(0,w.ZL)()((()=>({flexItem:{margin:5}}))),E=(0,r.observer)((function({onClose:e,model:t}){const{classes:a}=g(),[r,w]=(0,n.useState)(""),[p,E]=(0,n.useState)(),[S,C]=(0,n.useState)(!0),U=(0,f.getSession)(t),{selectedBookmarks:R}=t,L=0===R.length,I=0===R.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.p)(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.Z,{style:{display:"flex",flexFlow:"column",gap:"5px"}},n.createElement(l.Z,{severity:"info"},L?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.Z,null,"Copy the URL below to share your bookmarks."),p?n.createElement(k.ErrorMessage,{error:p}):S?n.createElement(c.Z,null,"Generating short URL..."):n.createElement(d.Z,{label:"URL",value:r,InputProps:{readOnly:!0},variant:"filled",fullWidth:!0,onClick:e=>{e.target.select()}}),n.createElement(i.Z,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.Z,null,n.createElement(m.Z,{className:a.flexItem,"data-testid":"dialogShare",variant:"contained",color:"primary",disabled:S,startIcon:n.createElement(b.pt,null),onClick:async()=>{u()(r),U.notify("Copied to clipboard","success"),e()}},"Copy share link")))}))},97990:(e,t,a)=>{a.d(t,{h:()=>i,p:()=>l});var n=a(71932);const r=async(e,t)=>(await Promise.all([a.e(1034),a.e(5456),a.e(633)]).then(a.t.bind(a,55456,23))).encrypt(e,t).toString(),o=async(e,t)=>{const n=await Promise.all([a.e(1034),a.e(5456),a.e(633)]).then(a.t.bind(a,55456,23)),r=await Promise.all([a.e(1034),a.e(7926)]).then(a.t.bind(a,99693,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.JY)(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=3591.d180b2d4.chunk.js.map