import{b as v,c as g,u as m,r as p,f as w,d as y,j as f}from"./index-CfKY7XrC.js";import{F as S}from"./full-page-spinner-CSuSQkVy.js";function u(t){return t?.trim().toLowerCase()||null}function b(t){return t?.methods??[]}function x(t,o){const r=u(o);if(!r)return null;for(const a of t){const n=b(a.auth_schema);if(!n.some(e=>e.type==="oauth"&&u(e.provider)===r&&Array.isArray(e.loginScopes)&&e.loginScopes.length>0))continue;const i=n.find(e=>e.type==="app_installation"&&u(e.provider)===r);if(i)return{connectorKey:a.key,provider:r,installShape:i.installShape??null}}return null}function R(){const{isAuthenticated:t,authReady:o,currentOwner:r,orgsReady:a}=v(),n=g(),s=m(),i=p.useRef(!1),e=new URLSearchParams(window.location.search).get("onboard_provider");return p.useEffect(()=>{if(o&&s.pathname==="/"){if(t&&r){const d=new URLSearchParams(window.location.hash.replace(/^#/,"")).get("worker");if(d){n({to:"/$owner/devices/$deviceId",params:{owner:r,deviceId:d},replace:!0});return}if(i.current)return;i.current=!0;const c=()=>void n({to:"/$owner",params:{owner:r},replace:!0});if(e){w(r).then(h=>{const l=x(h,e);if(l){window.location.assign(y(l.provider,{installShape:l.installShape}));return}c()}).catch(c);return}c();return}if(t){a&&n({to:"/account/settings",replace:!0});return}n({to:"/auth/login",search:{callbackUrl:void 0,mode:void 0,error:void 0,errorDescription:void 0,loginHint:void 0,invitationOrg:void 0,intent:void 0},replace:!0})}},[o,r,t,a,n,s.pathname,e]),f.jsx("div",{"data-public-loading":"true",children:f.jsx(S,{delayMs:0,className:"min-h-0 py-16"})})}export{R as component};
