(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5295],{10677:(e,a,t)=>{"use strict";t.d(a,{default:()=>r});var n=t(95155),i=t(12115);function r(){let[e,a]=(0,i.useState)([]),[t,r]=(0,i.useState)("");return(0,i.useEffect)(()=>{r(localStorage.getItem("madarx.activeProjectId")||""),fetch("/api/projects").then(e=>e.json()).then(e=>a(e.projects||[])).catch(()=>{})},[]),(0,n.jsx)("div",{className:"project-switcher","data-project-switcher":!0,children:(0,n.jsxs)("select",{value:t,onChange:e=>{var a;r(a=e.target.value),a?localStorage.setItem("madarx.activeProjectId",a):localStorage.removeItem("madarx.activeProjectId"),window.dispatchEvent(new CustomEvent("madarx:project-change",{detail:{project_id:a||null}}))},"aria-label":"Active project",children:[(0,n.jsx)("option",{value:"",children:"All projects"}),e.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))]})})}},12447:(e,a,t)=>{Promise.resolve().then(t.bind(t,10677)),Promise.resolve().then(t.bind(t,57057))},20063:(e,a,t)=>{"use strict";var n=t(47260);t.o(n,"usePathname")&&t.d(a,{usePathname:function(){return n.usePathname}}),t.o(n,"useRouter")&&t.d(a,{useRouter:function(){return n.useRouter}}),t.o(n,"useSearchParams")&&t.d(a,{useSearchParams:function(){return n.useSearchParams}})},57057:(e,a,t)=>{"use strict";t.d(a,{default:()=>s});var n=t(95155),i=t(12115),r=t(20063);function s(e){let{email:a="",pendingInvites:t=[]}=e,s=(0,r.useRouter)(),[o,c]=(0,i.useState)(""),[l,d]=(0,i.useState)(""),[m,h]=(0,i.useState)(""),[u,p]=(0,i.useState)("");async function v(e){e.preventDefault(),p(""),h("create");try{let e=o.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,60)||"org",a=await fetch("/api/orgs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:o.trim(),slug:e})});if(!a.ok)throw Error((await a.json().catch(()=>({}))).error||"Could not create organization");s.push("/"),s.refresh()}catch(e){p(e.message)}finally{h("")}}async function j(e){e.preventDefault(),p(""),h("join");try{let e=await fetch("/api/orgs/join",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:l.trim()})}),a=await e.json().catch(()=>({}));if(!e.ok)throw Error(a.message||"This invite is invalid or has expired.");s.push("/"),s.refresh()}catch(e){p(e.message)}finally{h("")}}async function g(){p(""),h("accept");try{let e=await fetch("/api/orgs/invites/pending",{method:"POST"}),a=await e.json().catch(()=>({}));if(!e.ok)throw Error(a.message||a.error||"Couldn't accept the invite.");s.push("/"),s.refresh()}catch(e){p(e.message)}finally{h("")}}return(0,n.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16,maxWidth:560},children:[u?(0,n.jsx)("div",{className:"admin-panel",role:"alert",style:{borderColor:"var(--accent-500)"},children:u}):null,t.length>0?(0,n.jsxs)("div",{className:"admin-panel",children:[(0,n.jsx)("div",{className:"admin-panel-head",children:"Pending invitations"}),t.map(e=>(0,n.jsxs)("div",{className:"admin-record",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("strong",{children:e.org_name||e.org_id})," invited you \xb7 ",e.role]}),(0,n.jsx)("button",{className:"admin-btn-primary admin-btn-sm",disabled:"accept"===m,onClick:g,children:"accept"===m?"Joining…":"Accept"})]},e.id))]}):null,(0,n.jsxs)("form",{className:"admin-panel",onSubmit:v,children:[(0,n.jsx)("div",{className:"admin-panel-head",children:"Create an organization"}),(0,n.jsx)("p",{className:"account-meta",children:"Start fresh. You'll be the owner."}),(0,n.jsx)("label",{htmlFor:"org-name",style:{display:"block",marginBottom:6},children:"Organization name"}),(0,n.jsx)("input",{id:"org-name",value:o,onChange:e=>c(e.target.value),placeholder:"Acme Robotics",required:!0,style:{width:"100%",marginBottom:12}}),(0,n.jsx)("button",{className:"admin-btn-primary",type:"submit",disabled:"create"===m||!o.trim(),children:"create"===m?"Creating…":"Create org →"})]}),(0,n.jsxs)("form",{className:"admin-panel",onSubmit:j,children:[(0,n.jsx)("div",{className:"admin-panel-head",children:"Join with an invite"}),(0,n.jsx)("p",{className:"account-meta",children:"Paste an invite code, or open the invite link you were sent."}),(0,n.jsx)("label",{htmlFor:"invite-code",style:{display:"block",marginBottom:6},children:"Invite code"}),(0,n.jsx)("input",{id:"invite-code",value:l,onChange:e=>d(e.target.value),placeholder:"paste invite code",style:{width:"100%",marginBottom:12}}),(0,n.jsx)("button",{className:"admin-btn-primary",type:"submit",disabled:"join"===m||!l.trim(),children:"join"===m?"Joining…":"Join →"})]})]})}}},e=>{e.O(0,[8441,1255,7358],()=>e(e.s=12447)),_N_E=e.O()}]);