1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6808],{66808:(e,t,n)=>{n.d(t,{cs:()=>eu});var o=n(27541),i=n(98369),u=n(7620),r=n(77280),l=n(61529),s=n(96050),a=n(89569),d=n(38662),c=n(41082),g=n(50424),f=n(78783),m=n(73151),v=n(55602),p=n(2075),w=n(683),h=n(70669),I=n(63902),S=n(11987);let y=(0,f.KV)("InternalUser");function k(e){return new Promise(t=>{setTimeout(t,e)})}async function L(){let e=new AbortController,t=setTimeout(()=>{e.abort()},5e3);try{let t=await fetch("/api/wikit/users/me",{method:"POST",credentials:"same-origin",signal:e.signal});if(401===t.status)return{outcome:"dead",status:t.status};if(!t.ok)return{outcome:"unknown",status:t.status};let n=await t.json().catch(()=>null);if(!(null==n?void 0:n.ok)||!n.data)return{outcome:"unknown",status:t.status};return{outcome:"alive",status:t.status,user:n.data,wikitSession:n.wikitSession}}catch(e){return{outcome:"unknown"}}finally{clearTimeout(t)}}async function T(){let e=await L();return"dead"!==e.outcome?e:(await k(1500),L())}let O=null,b=!1,E=null,R=0,_=0;function C(e){if(O)return O;let t=function(){let e=k(500);return{waited:e,result:e.then(T)}}(),n={waited:t.waited,result:t.result.then(t=>("alive"===t.outcome&&(_=Date.now()+5e3),"dead"!==t.outcome&&y.warn("Unauthorized recheck",{outcome:"alive"===t.outcome?"recovered":"unknown",status:t.status,entry:e}),t)).finally(()=>{O===n&&(O=null)})};return O=n,n}function P(){return!b&&(b=!0,E=R,!0)}let D=null,F={generation:-1,count:0},U=null,A=0,K=new Set;function x(e){return K.add(e),()=>{K.delete(e)}}function M(){return A}function Q(){return(null==D?void 0:D.generation)===R?D:null}function j(){let e=Q();return e&&(e.handedOver=!0,D=null),e}let V=[1e4,2e4,4e4],z=[0,2e4,4e4],N=new Set,Z=null,H=null,W=null,Y=null;function $(){for(let e of N)return e.current;return null}function q(){return!1===navigator.onLine||"unreachable"===I.A.getState().reachability.state}function B(e,t){if("authenticated"!==e||!t)return"none";let n=t.providerConnectResult;return(null==n?void 0:n.success)===!1?"handOff":t.isInternalSession?"none":t.loginFailed?"elsewhere":t.needsInternalSwitch?"switch":"handOff"}function G(){let e=Z;e&&(Z=null,e.slotTimer&&clearTimeout(e.slotTimer),e.capTimer&&clearTimeout(e.capTimer))}function J(e){if(Z!==e||e.paused)return;e.slotTimer&&(clearTimeout(e.slotTimer),e.slotTimer=null);let t=e.slots[0];void 0!==t&&(e.slotTimer=setTimeout(()=>{if(e.slotTimer=null,e.slots.shift(),e.running){e.runQueued=!0;return}et(e)},Math.max(0,t-Date.now())))}async function X(e){let t=Date.now()+5e3,n=null,o=new Promise(e=>{n=setTimeout(()=>{e("timeout")},5e3)});try{let n=await Promise.race([e.update().catch(()=>null),o]);if("timeout"===n||null===n)return{outcome:"unknown"};if(void 0===n){for(;Date.now()<t;){await k(100);let t=e.snapshot();if("loading"!==t.status)return t.session?{outcome:"ok",session:t.session}:{outcome:"unknown"}}return{outcome:"unknown"}}return{outcome:"ok",session:n}}finally{n&&clearTimeout(n)}}async function ee(e){var t,n;let o=$();if(!o)return{outcome:"stopped",update:"skipped"};if(q())return{outcome:"offline",update:"skipped"};let i=await X(o);if(Z!==e)return{outcome:"stopped",update:i.outcome};let u=o.snapshot();if(u.loggedIn||u.isOwnLogoutInProgress||u.loginResolutionFailed)return{outcome:"stopped",update:i.outcome};let r=i.session?"authenticated":u.status,l=B(r,null!=(n=i.session)?n:u.session);if("switch"===l)return{outcome:"deferred",update:i.outcome};if("handOff"===l)return u.isLoggingIn&&o.setIsLoggingIn(!1),{outcome:"handedOff",update:i.outcome};if("elsewhere"===l||"unauthenticated"===r&&!u.isLoggingIn)return{outcome:"stopped",update:i.outcome};let s=Q();if(s&&e.waitedFetch!==s&&e.slots.length>0)return e.waitedFetch=s,{outcome:"waiting",update:i.outcome};let a=await T();if(Z!==e)return{outcome:"stopped",update:i.outcome};if("dead"===a.outcome)return{outcome:"dead",update:i.outcome};if("alive"!==a.outcome||!a.user)return{outcome:q()?"offline":"unknown",update:i.outcome};let d=o.snapshot();if(d.loggedIn)return{outcome:"stopped",update:i.outcome};if("authenticated"!==d.status||(null==(t=d.session)?void 0:t.isInternalSession)!==!0)return{outcome:"mismatch",update:i.outcome};let c=j();return _=Date.now()+5e3,o.applyAlive(a.user,a.wikitSession,c),{outcome:"applied",update:i.outcome}}async function et(e){e.running=!0;let t="unknown",n="skipped";try{({outcome:t,update:n}=await ee(e))}catch(e){y.error(e instanceof Error?e:"Login safety net recheck failed")}finally{e.running=!1}let o=Z===e;if(o||"applied"===t){var i,u,r,l;let o=null==(i=$())?void 0:i.snapshot();y.warn("Login safety net recheck",{status:null!=(l=null==o?void 0:o.status)?l:"unknown",isInternalSession:(null==o||null==(u=o.session)?void 0:u.isInternalSession)===!0,needsInternalSwitch:(null==o||null==(r=o.session)?void 0:r.needsInternalSwitch)===!0,loggedIn:(null==o?void 0:o.loggedIn)===!0,hasCurrentFetch:null!==Q(),isLoggingIn:(null==o?void 0:o.isLoggingIn)===!0,elapsedMs:Date.now()-e.startedAt,update:n,outcome:t})}o&&function(e,t){if("applied"===t||"stopped"===t||"handedOff"===t)return G();if("deferred"===t){G(),W=e.attemptId;return}if("dead"===t)return eo(e);if("offline"===t){e.paused=!0,e.runQueued=!1,e.slotTimer&&(clearTimeout(e.slotTimer),e.slotTimer=null);return}if(e.runQueued){e.runQueued=!1,et(e);return}if(e.slots.length>0)return J(e);eo(e)}(e,t)}async function en(e){if(Z!==e)return;let t=$(),n=null==t?void 0:t.snapshot();if(!t||!n||n.loggedIn)return void G();let o=B(n.status,n.session);if("switch"===o){G(),W=e.attemptId;return}if("handOff"===o||"elsewhere"===o){"handOff"===o&&n.isLoggingIn&&t.setIsLoggingIn(!1),G();return}await eo(e)}async function eo(e){var t;Z===e&&(G(),await (null==(t=$())?void 0:t.fail()))}function ei(e,t){(0,c.It)();let n=(0,m.ZK)(null!=e?e:window.location.pathname);if(t&&Object.keys(t).length>0){let e=new URLSearchParams(t);window.location.href="".concat(n,"?").concat(e.toString())}else window.location.href=n}function eu(){let{data:e,status:t,update:n}=(0,i.useSession)(),c=(0,S.default)(e=>e.internalUserInfo),f=(0,S.default)(e=>e.isOwnLogoutInProgress),m=(0,S.default)(e=>e.loginResolutionFailed),{setWikitSession:k,setIsInternalAuth:L}=(0,S.default)(),ee=(0,h.y)(),et=(0,u.useSyncExternalStore)(x,M,M),eo=(0,u.useRef)(null),eu=(0,u.useRef)(!1),{logout:er,isLoggingIn:el,clearFailedLoginSession:es,setIsLoggingIn:ea}=(0,s.c)(),{showPopup:ed,hidePopup:ec,isPopupOpen:eg}=(0,r.O)(),{showToast:ef}=(0,l.d)(),em=(0,o.usePathname)(),ev=e=>{ei(em,e)},ep=(0,u.useRef)(!1),ew={status:t,session:e,loggedIn:!!(null==c?void 0:c.loggedIn),isLoggingIn:el,isOwnLogoutInProgress:f,loginResolutionFailed:m,isPopupOpen:eg,logout:er,pathname:em},eh=(0,u.useRef)(ew);function eI(e,t,n){ee(e),L(!0),k(t);let o=sessionStorage.getItem("wikit_login_provider");o&&(0,w.YV)(o),n&&eu.current&&ef((0,a.si)({i18nKey:"login_succeeded"}),3e3),y.debug("User data loaded")}async function eS(){let n=!!sessionStorage.getItem("isLoggingIn");n&&sessionStorage.removeItem("isLoggingIn");let o=(null==U?void 0:U.generation)===R&&U.value,i=n||o,u=i&&eu.current&&!(null==c?void 0:c.loggedIn);if("authenticated"!==t||!(null==e?void 0:e.isInternalSession))return;let r=null==e?void 0:e.providerConnectResult;if((null==r?void 0:r.success)===!1)return;let l=R,s={generation:l,wasLoggingIn:i,handedOver:!1};D=s,U=null;let g=!1,f=()=>s.handedOver||l!==R,m=(e,t)=>
1{eI(e,t,i),g=!0};try{var v,w;let e;try{e=await (0,p.n)()}catch(t){y.error(t instanceof Error?t:"fetchUserData exception"),e={success:!1,needsConsent:!1,error:t instanceof Error?t:Error("Unknown error")}}if(e.success&&e.data){if(f())return void y.debug("Discarded user data from before logout");m(e.data,e.wikitSession);return}if(y.warn("Failed to fetch user data",{error:e.success?"no data":null!=(w=null==(v=e.error)?void 0:v.message)?w:"Unknown error"}),u){if(f())return;(0,d.O7)()&&((0,d.gU)()&&ef((0,a.si)({i18nKey:"login_failed"}),3e3),await es());return}let t=()=>!ep.current||eh.current.isOwnLogoutInProgress||f(),n=C("userFetch");if(await n.waited,t())return;let o=await n.result;if(t())return;if("alive"===o.outcome&&o.user)return void m(o.user,o.wikitSession);if(!P())return;let i=()=>{ei(eh.current.pathname,{toast:"login_multi_login_unavailable_guide"})};eh.current.isPopupOpen?(await eh.current.logout(),i()):eh.current.logout().then(i)}catch(e){y.error(e instanceof Error?e:"fetchUserData exception")}finally{D===s&&(D=null),g||f()||
1(U={generation:l,value:i}),A+=1,K.forEach(e=>{e()})}}eh.current=ew,(0,u.useEffect)(()=>(ep.current=!0,()=>{ep.current=!1}),[]);let ey=(0,u.useRef)(null);ey.current={snapshot:()=>{let e=eh.current;return{status:e.status,session:e.session,loggedIn:e.loggedIn,isLoggingIn:e.isLoggingIn,isOwnLogoutInProgress:e.isOwnLogoutInProgress,loginResolutionFailed:!!e.loginResolutionFailed}},update:()=>n(),setIsLoggingIn:ea,applyAlive:(e,t,n)=>{let o=!!sessionStorage.getItem("isLoggingIn");o&&sessionStorage.removeItem("isLoggingIn");let i=(null==U?void 0:U.generation)===R&&U.value;eI(e,t,o||!!(null==n?void 0:n.wasLoggingIn)||i)},fail:async()=>{if(!(0,d.O7)())return;let e=!(0,v.f)(window.location.pathname);!(q()&&e)&&(0,d.gU)()&&ef((0,a.si)({i18nKey:"login_failed"}),3e3),await es()}},(0,u.useEffect)(()=>(N.add(ey),()=>{N.delete(ey),0===N.size&&G()}),[]),(0,u.useEffect)(()=>(0,d.c$)(async()=>{var e,t;let n=await T();if("dead"===n.outcome)return"dead";if("alive"!==n.outcome||!n.user)return"unknown";let o=ey.current,i=o.snapshot();return"authenticated"===i.status&&(null==(e=i.session)?void 0:e.isInternalSession)||i.session&&(null==(t=(await X(o)).session)?void 0:t.isInternalSession)?(_=Date.now()+5e3,o.applyAlive(n.user,n.wikitSession,j()),"applied"):"alive"}),[]);let ek=(0,u.useSyncExternalStore)(d.t0,d.PA,d.PA);return(0,u.useEffect)(()=>{!function(){let e=$();if(!e)return G();let t=e.snapshot();if(t.loggedIn||t.isOwnLogoutInProgress||t.loginResolutionFailed||b&&E===R||!(0,d.jh)()){G(),W=null;return}if(Z&&Z.attemptId!==(0,d.w3)()&&G(),null!==W&&W!==(0,d.w3)()&&(W=null),null!==W){if("loading"===t.status||"switch"===B(t.status,t.session))return;W=null}let n="authenticated"===t.status&&(null==(r=t.session)?void 0:r.isInternalSession)===!0&&"none"===B(t.status,t.session),o=(0,d.HO)(),i=null!==o&&t.isLoggingIn;if(Z){n||i||"loading"===t.status||G();return}if(!n&&!i)return;let u=Date.now();var r,l=Y!==(0,d.w3)()&&i&&null!==o?Math.min(o,u):u;Y=(0,d.w3)();let s={attemptId:(0,d.w3)(),startedAt:l,slots:V.map(e=>l+e),slotTimer:null,capTimer:null,running:!1,runQueued:!1,paused:!1,waitedFetch:null};Z=s,s.capTimer=setTimeout(()=>{en(s)},Math.max(0,l+6e4-Date.now())),H||(H=I.A.subscribe((e,t)=>{if("reachable"===t.reachability.state||"reachable"!==e.reachability.state)return;let n=Z;if(!(null==n?void 0:n.paused))return;n.paused=!1;let o=Date.now(),i=n.startedAt+6e4;n.slots=z.map(e=>o+e).filter(e=>e<i),J(n)})),J(s)}()},[e,t,null==c?void 0:c.loggedIn,el,f,m,ek]),(0,u.useEffect)(()=>{if("loading"===t)return;if("unauthenticated"===t||!(null==e?void 0:e.isInternalSession)){eu.current=!0;return}let n=null==e?void 0:e.providerConnectResult;(null==n?void 0:n.success)===!1||f||m||(null==c?void 0:c.loggedIn)||Q()||b&&E===R||(F.generation!==R&&(F={generation:R,count:0}),!(F.count>=2)&&(F.count+=1,1)&&eS())},[e,t,null==c?void 0:c.loggedIn,f,m,et]),(0,u.useEffect)(()=>{f&&(R+=1)},[f]),(0,u.useEffect)(()=>{let e=()=>{if(!ep.current)return!0;let e=eh.current;return!!e.isLoggingIn||!!e.isOwnLogoutInProgress||!e.loggedIn||"authenticated"!==e.status},t=async()=>{if(e()||null===O&&Date.now()<_)return;let t=R,n=C("event");if(await n.waited,e()||t!==R)return;let{outcome:o}=await n.result;!e()&&t===R&&"dead"===o&&P()&&eh.current.logout().then(()=>{ei(eh.current.pathname,{toast:"login_multi_login_unavailable_guide"})})},n=()=>{t()};return window.addEventListener(g.L,n),()=>window.removeEventListener(g.L,n)},[]),(0,u.useEffect)(()=>{if("authenticated"!==t||el||(null==e?void 0:e.isInternalSession)||(null==e?void 0:e.needsInternalSwitch)||(null==e?void 0:e.loginFailed)||(null==e?void 0:e.providerConnectResult)||(null==e?void 0:e.needsSignupChallenge)||(null==c?void 0:c.loggedIn))return;let n=setTimeout(()=>{y.warn("Zombie session detected - forcing logout (WIKIT-4383)"),er().then(()=>{ev()})},1e4);return()=>clearTimeout(n)},[t,null==e?void 0:e.isInternalSession,null==e?void 0:e.needsInternalSwitch,null==e?void 0:e.loginFailed,null==e?void 0:e.providerConnectResult,null==e?void 0:e.needsSignupChallenge,el,null==c?void 0:c.loggedIn,er]),(0,u.useEffect)(()=>{"loading"!==t&&!el&&!f&&"unauthenticated"===t&&(null==c?void 0:c.loggedIn)&&(y.debug("Multi-tab logout detected"),er().then(()=>{ev({toast:"logout_succeeded"})}))},[t,null==c?void 0:c.loggedIn,er,el,null==e?void 0:e.providerConnectResult,f]),(0,u.useEffect)(()=>
1{if("loading"===t||"unauthenticated"===t||!(null==e?void 0:e.isInternalSession)||!(null==c?void 0:c.loggedIn))return;let o=null==e?void 0:e.providerConnectResult;if((null==o?void 0:o.success)&&o.provider&&Array.isArray(null==c?void 0:c.providers)){let e=o.provider.toUpperCase();if(eo.current===e)return;c.providers.map(e=>e.toUpperCase()).includes(e)?(eo.current=e,n({clearProviderConnectResult:!0})):(y.debug("Provider connected, refreshing user data",{provider:e}),Q()||(eo.current=e,eS().then(()=>{ef((0,a.si)({i18nKey:"login_social_linked",defaultValue:"%s ê³ì ì´ ì°ëëììµëë¤.",sprintf:[e]}),3e3),n({clearProviderConnectResult:!0})})))}},[null==e?void 0:e.providerConnectResult,null==e?void 0:e.isInternalSession,null==c?void 0:c.providers,null==c?void 0:c.loggedIn,t,ed,ec,n]),{internalLogined:!!(null==e?void 0:e.isInternalSession),isLoading:"loading"===t,fetchUserData:eS}}}}]);
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.