"use strict";(self.webpackChunk_jbrowse_web=self.webpackChunk_jbrowse_web||[]).push([[6117],{53591:(e,s,t)=>{t.r(s),t.d(s,{default:()=>j});var o=t(41867),r=t(3762),a=t(31625),n=t(47409),i=t(77327),c=t(75258),l=t(51590),d=t(49133),h=t(27768),w=t(23801),p=t(47192),f=t(62877),m=t.n(f),k=t(90872),u=t(35421),b=t(24728),y=t(97990),g=t(80838);const x=(0,p.ZL)()((()=>({flexItem:{margin:5}}))),j=(0,r.observer)((function(e){let{onClose:s,model:t}=e;const{classes:r}=x(),[p,f]=(0,o.useState)(""),[j,S]=(0,o.useState)(),[C,U]=(0,o.useState)(!0),R=(0,k.getSession)(t),{selectedBookmarks:L}=t,v=0===L.length,I=0===L.length?t.allBookmarksModel:t.sharedBookmarksModel;return(0,o.useEffect)((()=>{let e=!1;return(async()=>{try{if(!(0,k.isSessionWithShareURL)(R))throw new Error("No shareURL configured");U(!0);const s=(0,a.getSnapshot)(I),t=new URL(window.location.href),o=await(0,y.p)(s,R.shareURL,t.href);if(!e){const e=new URLSearchParams(t.search);e.set("bookmarks","share-".concat(o.json.sessionId)),e.set("password",o.password),t.search=e.toString(),f(t.href),U(!1)}}catch(s){S(s)}finally{U(!1)}})(),()=>{e=!0}}),[I,R]),(0,g.jsxs)(u.Dialog,{open:!0,onClose:s,title:"Share bookmarks",children:[(0,g.jsxs)(n.Z,{style:{display:"flex",flexFlow:"column",gap:"5px"},children:[(0,g.jsx)(i.Z,{severity:"info",children:v?(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)("span",{children:"All bookmarks will be shared."}),(0,g.jsx)("br",{}),(0,g.jsx)("span",{children:"Use the checkboxes to select individual bookmarks to share."})]}):"Only selected bookmarks will be shared."}),(0,g.jsx)(c.Z,{children:"Copy the URL below to share your bookmarks."}),j?(0,g.jsx)(u.ErrorMessage,{error:j}):C?(0,g.jsx)(l.Z,{children:"Generating short URL..."}):(0,g.jsx)(d.Z,{label:"URL",value:p,InputProps:{readOnly:!0},variant:"filled",fullWidth:!0,onClick:e=>{e.target.select()}}),(0,g.jsx)(c.Z,{children:'The URL should be pasted into the "Import from share link" field in the "Import" form found in the "Bookmarked regions" drawer.'})]}),(0,g.jsx)(h.Z,{children:(0,g.jsx)(w.Z,{className:r.flexItem,"data-testid":"dialogShare",variant:"contained",color:"primary",disabled:C,startIcon:(0,g.jsx)(b.pt,{}),onClick:async()=>{m()(p),R.notify("Copied to clipboard","success"),s()},children:"Copy share link"})})]})}))},97990:(e,s,t)=>{t.d(s,{h:()=>c,p:()=>i});var o=t(42408);const r=async(e,s)=>(await Promise.all([t.e(7626),t.e(5607),t.e(633)]).then(t.t.bind(t,45607,23))).encrypt(e,s).toString(),a=async(e,s)=>{const o=await Promise.all([t.e(7626),t.e(5607),t.e(633)]).then(t.t.bind(t,45607,23)),r=await Promise.all([t.e(7626),t.e(6828)]).then(t.t.bind(t,87380,23));return o.decrypt(e,s).toString(r)};function n(e){try{return JSON.parse(e).message}catch(s){return e}}async function i(e,s,t){const a=await(0,o.JY)(JSON.stringify(e)),i=(c=5,window.btoa([...window.crypto.getRandomValues(new Uint8Array(2*c))].map((e=>String.fromCharCode(e))).join("")).replaceAll(/[+/]/g,"").slice(0,c));var c;const l=await r(a,i),d=new FormData;d.append("session",l),d.append("dateShared","".concat(Date.now())),d.append("referer",t);const h=await fetch("".concat(s,"share"),{method:"POST",mode:"cors",body:d});if(!h.ok){const e=await h.text();throw new Error(n(e))}return{json:await h.json(),encryptedSession:l,password:i}}async function c(e,s,t,o){const r=s.split("share-")[1],i="".concat(e,"?sessionId=").concat(encodeURIComponent(r)),c=await fetch(i,{signal:o});if(!c.ok){const e=await c.text();throw new Error(n(e))}const l=await c.json();return a(l.session,t)}}}]);
//# sourceMappingURL=6117.6e1d247c.chunk.js.map