(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5335],{17323:(e,n,t)=>{"use strict";t.r(n),t.d(n,{default:()=>r});var a=t(95155),i=t(12115);function r(){let[e,n]=(0,i.useState)(null),[t,r]=(0,i.useState)(""),[o,s]=(0,i.useState)("reading"),[l,c]=(0,i.useState)("");(0,i.useEffect)(()=>{let e=window.location.hash.match(/[#&]invite=([^&]+)/),t=e?decodeURIComponent(e[1]):"";if(!t)return void s("bad");let a=function(e){try{let n=atob(e.replace(/-/g,"+").replace(/_/g,"/")),t=Uint8Array.from(n,e=>e.charCodeAt(0)),a=JSON.parse(new TextDecoder().decode(t));if(1!==a.v||"string"!=typeof a.url)return null;return{url:a.url,org:"string"==typeof a.org?a.org:null,token:a.token,anonKey:a.anonKey}}catch(e){return null}}(t);if(!a||!a.url||!a.token)return void s("bad");r(t),n(a),s("ready")},[]);let d="";try{d=e?new URL(e.url).host:""}catch(e){d=""}async function h(){c(""),s("joining");try{let e=await fetch("/api/auth/join-bootstrap",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({invite:t})}),n=await e.json().catch(()=>({}));if(!e.ok)throw Error(n.message||"Couldn't reach that project. Check the link with whoever invited you.");window.location.href="/login?supabase=1&next="+encodeURIComponent("/onboarding/org")}catch(e){c(e.message),s("error")}}return"reading"===o?(0,a.jsx)("main",{className:"join-shell",children:(0,a.jsx)("p",{className:"account-meta",children:"Reading invite…"})}):"bad"===o?(0,a.jsx)("main",{className:"join-shell",children:(0,a.jsx)("p",{children:"This invite link is invalid or has expired. Ask the sender for a new one."})}):(0,a.jsxs)("main",{className:"join-shell",style:{maxWidth:480,margin:"0 auto",padding:"48px 16px"},children:[(0,a.jsx)("div",{style:{textAlign:"center",marginBottom:8},children:"◆ madarX"}),(0,a.jsx)("div",{className:"account-meta",style:{textAlign:"center",color:"var(--accent-600)",letterSpacing:"0.08em"},children:"JOIN ORGANIZATION"}),(0,a.jsxs)("h1",{style:{textAlign:"center"},children:["Join ",e.org||"this organization"]}),(0,a.jsxs)("div",{className:"admin-panel",children:[(0,a.jsxs)("div",{className:"admin-record",children:[(0,a.jsx)("span",{children:"Organization"}),(0,a.jsx)("strong",{children:e.org||"—"})]}),(0,a.jsxs)("div",{className:"admin-record",children:[(0,a.jsx)("span",{children:"Connects to"}),(0,a.jsx)("code",{style:{fontFamily:"monospace",padding:"2px 8px",border:"1px solid var(--accent-500)",borderRadius:6},children:d||e.url})]})]}),(0,a.jsxs)("p",{className:"account-meta",children:["This connects your local app to ",e.org||"this"," cloud workspace. Your existing local data stays on your machine."]}),l?(0,a.jsx)("p",{role:"alert",style:{color:"var(--accent-600)"},children:l}):null,(0,a.jsx)("button",{className:"admin-btn-primary",style:{width:"100%"},disabled:"joining"===o,onClick:h,children:"joining"===o?"Joining…":"Join ".concat(e.org||"organization")}),(0,a.jsx)("div",{style:{textAlign:"center",marginTop:12},children:(0,a.jsx)("a",{href:"/",className:"account-meta",children:"Cancel"})})]})}},38765:(e,n,t)=>{Promise.resolve().then(t.bind(t,17323))}},e=>{e.O(0,[8441,1255,7358],()=>e(e.s=38765)),_N_E=e.O()}]);