import{G as p,H as f,b as S,z as m,r as l,I as E,cq as d,W as b}from"./main-D6SjkSWq.js";function v(){return p({mutationFn:C,onError:s=>f(s)})}function C(s){return S.post(`secure/auth/social/${s.service}/disconnect`,s).then(a=>a.data)}function L(){const{trans:s}=m(),a=v(),[i,r]=l.useState(!1),o=l.useCallback(t=>{const{status:n,callbackData:e}=t;if(n)switch(n.toUpperCase()){case"SUCCESS":return e!=null&&e.bootstrapData&&d(e.bootstrapData),t;case"REQUEST_PASSWORD":return r(!0),t;case"ERROR":const c=(e==null?void 0:e.errorMessage)||s({message:"An error occurred. Please try again later"});return E.danger(c),t;default:return t}},[s,d]);return{requestingPassword:i,setIsRequestingPassword:r,loginWithSocial:async t=>{const n=await g(`secure/auth/social/${t}/login`);return o(n)},connectSocial:async t=>{const n=t.includes("/")?t:`secure/auth/social/${t}/connect`,e=await g(n);return o(e)},disconnectSocial:a}}const w=550,h=650;let u;function g(s){const a=window.screen.width/2-h/2,i=window.screen.height/2-w/2;return new Promise(r=>{u=window.open(s,"Authenticate Account",`menubar=0, location=0, toolbar=0, titlebar=0, status=0, scrollbars=1, width=${h}, height=${w}, left=${a}, top=${i}`);const o=new BroadcastChannel("social-auth"),t=e=>{const c=b().settings.base_url;e.data.type==="social-auth"&&c.indexOf(e.origin)>-1&&(r(e.data),o.removeEventListener("message",t))};o.addEventListener("message",t);const n=setInterval(()=>{(!u||u.closed)&&(clearInterval(n),r({}),o.removeEventListener("message",t))},1e3)})}export{L as u};
