1import{bw as b,d as C,e as E,bx as T,r as u,j as t,o as v,n as R,E as _}from"./index-DipKtq1R.js";import{S as A}from"./shield-check-C4100_rI.js";const g="scheduling.m365.consent.state",F="scheduling.m365.consent.result",h="scheduling.m365.consent";function a(e){if(typeof e!="string")return;const o=e.trim();if(o.startsWith('"')&&o.endsWith('"'))try{const s=JSON.parse(o);return typeof s=="string"?s:String(s)}catch{return e}return e}function x(e,o){if(typeof window>"u")return;const s={ok:e.ok,error:e.ok?void 0:e.error,state:o,at:Date.now()};try{localStorage.setItem(F,JSON.stringify(s))}catch{}try{const c=new BroadcastChannel(h);c.postMessage(s),c.close()}catch{}try{window.opener&&!window.opener.closed&&window.opener.postMessage({type:h,payload:s},window.location.origin)}catch{}}function I(){if(!(typeof window>"u")){for(const e of[250,750,1500])window.setTimeout(()=>window.close(),e);window.setTimeout(()=>{window.closed||window.location.replace("/admin/scheduling?m365=connected")},2500)}}function z(){const e=b({from:"/auth/m365-consent"}),o=C(),s=E(T),[c,m]=u.useState({status:"verifying"});return u.useEffect(()=>{const p=a(e.handoff),w=a(e.ok),i=a(e.state),k=a(e.message),y=a(e.tenant),S=a(e.admin_consent),f=a(e.error),N=a(e.error_description),l=(n,r)=>{x(n,i),m(n.ok?{status:"success"}:{status:"error",message:n.error}),n.ok&&I()},j=(n,r)=>{if(!n||n===window.location.origin){l(r);return}const d=new URL("/auth/m365-consent",n);d.searchParams.set("handoff","1"),d.searchParams.set("ok",r.ok?"1":"0"),d.searchParams.set("state",i??""),r.ok||d.searchParams.set("message",r.error),window.location.replace(d.toString())};(async()=>{if(p==="1"){const r=localStorage.getItem(g)??sessionStorage.getItem(g);if(r&&i&&r!==i){l({ok:!1,error:"Security check failed (state mismatch). Start the connect flow again."});return}l(w==="1"?{ok:!0}:{ok:!1,error:k??"Couldn't complete consent."});return}if(!i){l({ok:!1,error:"Security check failed (missing state). Start the connect flow again."});return}const n=await s({data:{state:i,tenantId:y??null,adminConsent:S==="True",microsoftError:f?`${f}: ${N??"(no description)"}`:null}});j(n.returnOrigin,n.ok?{ok:!0}:{ok:!1,error:n.error})})().catch(n=>{x({ok:!1,error:n instanceof Error?n.message:"Unknown error"},i),m({status:"error",message:n instanceof Error?n.message:"Unknown error"})})},[e,s,o]),t.jsx("div",{className:"min-h-screen bg-foreground text-background flex items-center justify-center px-6 py-16",children:t.jsxs("div",{className:"max-w-md w-full text-center",children:[c.status==="verifying"&&t.jsxs(t.Fragment,{children:[t.jsx(v,{className:"size-8 mx-auto animate-spin text-cyan-soft"}),t.jsx("p",{className:"mt-4 font-display text-2xl",children:"Connecting Microsoft 365â¦"}),t.jsx("p",{className:"mt-2 text-sm text-background/70",children:"Verifying consent."})]}),c.status==="success"&&t.jsxs(t.Fragment,{children:[t.jsx(R,{className:"size-10 mx-auto text-cyan-soft"}),t.jsx("p",{className:"mt-4 font-display text-2xl",children:"Tenant connected."}),t.jsxs("p",{className:"mt-2 text-sm text-background/70 inline-flex items-center gap-2",children:[t.jsx(A,{className:"size-4"})," You can close this tab and return to Scheduling."]})]}),c.status==="error"&&t.jsxs(t.Fragment,{children:[t.jsx(_,{className:"size-10 mx-auto text-destructive"}),t.jsx("p",{className:"mt-4 font-display text-2xl",children:"Couldn't complete consent"}),t.jsx("p",{className:"mt-3 text-sm text-background/85 break-words",children:c.message}),t.jsx("button",{type:"button",onClick:()=>o({to:"/admin/scheduling"}),className:"mt-6 inline-flex items-center gap-2 rounded-full bg-cyan-soft/20 ring-1 ring-background/20 px-5 py-2.5 text-sm font-semibold text-background hover:bg-cyan-soft/30 transition-colors",children:"Back to Scheduling"})]})]})})}export{z as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.