try{let e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`a22dc743-d329-46e1-8a6b-dc86c98c2cb0`,e._sentryDebugIdIdentifier=`sentry-dbid-a22dc743-d329-46e1-8a6b-dc86c98c2cb0`)}catch{}import"./rolldown-runtime-eb2nym32.js";import{p as e}from"./vendor-misc-hfpbxrii.js";import{Hi as t,Mi as n,Ri as r,Yi as i,Zi as a,ia as o,na as s}from"./entry.client-dr7r6s9a.js";import{D as c,E as l}from"./workspace-leaf-files-mc5sghv7.js";import{t as u}from"./selectors-jy7eaal3.js";import{t as d}from"./BasePlugin-nelnyp3q.js";import{n as f,t as p}from"./actions-khgs3p0j.js";r();var m=n(),h={user:null},g=(t=h,n)=>{switch(n.type){case f.UpdateUser:return e(t,e=>{t.user!==n.user&&(e.user=n.user)});default:return t}},_=e=>u(e,c),v={getUser:e=>_(e).user},y=class extends d{stateKey=c;actions=p;authSelectors=v;authAction=p;hasConsumedSignInAction=!0;constructor(e,t){super(e,l,t),this.reduxEnvironment.registerReducer(this.stateKey,g)}destroy(){this.reduxEnvironment.removeReducer(this.stateKey)}updateUser(e){let t=this;return new Promise((n,r)=>t.reduxEnvironment.sagaMiddleware.run(l,function*(){try{let r=yield o(t.authSelectors.getUser);if(r===e){n();return}if(r&&e&&r.xuid===e.xuid&&r.ageGroup===e.ageGroup&&r.gamertag.uniqueGamertag===e.gamertag.uniqueGamertag){n();return}r&&e&&r.xuid!==e.xuid&&(yield a([t,t.getPlugins],l)).forEach(e=>e.dispatchSignOutAction(m.CommonAction.userSignedOut())),yield s(p.updateUser(e)),n()}catch(e){r(e)}}))}*handleActions(){let e=this;yield i([t([f.UpdateUser],function*(){yield a([e,e.handleUserChanges])})])}*handleUserChanges(){let e=yield a([this,this.getPlugins],l),t=yield o(this.authSelectors.getUser);t?e.forEach(e=>e.dispatchSignInAction(m.CommonAction.userSignedIn(t))):e.forEach(e=>e.dispatchSignOutAction(m.CommonAction.userSignedOut()))}};export{y as AuthPlugin};