"use strict";(self.webpackChunkrichie_education=self.webpackChunkrichie_education||[]).push([[65640],{65640:function(e,r,t){t.r(r),t.d(r,{default:function(){return S}}),t(26364),t(86632),t(10853),t(61928),t(54883),t(45007),t(68995),t(18821),t(54994),t(4845),t(39275),t(35054),t(80044),t(31807),t(3973),t(19701),t(80238),t(6208),t(12938),t(26425),t(32390),t(18183),t(19985);var n=t(89526),o=t(5615),u=t(70488),i=t(37925),c=t(93123),s=t(96580),a=t(95418),l=t(35114),f=t(47080),y=t(15462),p=t(67557),m=["children"];function v(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function h(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?v(Object(t),!0).forEach((function(r){b(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):v(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}function b(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function d(e,r,t,n,o,u,i){try{var c=e[u](i),s=c.value}catch(e){return void t(e)}c.done?r(s):Promise.resolve(s).then(n,o)}function g(e){return function(){var r=this,t=arguments;return new Promise((function(n,o){var u=e.apply(r,t);function i(e){d(u,n,o,i,c,"next",e)}function c(e){d(u,n,o,i,c,"throw",e)}i(void 0)}))}}function O(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}var j=function(e){var r,t,l=e.children,m=(r=(0,n.useState)(!1),t=2,function(e){if(Array.isArray(e))return e}(r)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,u=[],i=!0,c=!1;try{for(t=t.call(e);!(i=(n=t.next()).done)&&(u.push(n.value),!r||u.length!==r);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==t.return||t.return()}finally{if(c)throw o}}return u}}(r,t)||function(e,r){if(e){if("string"==typeof e)return O(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?O(e,r):void 0}}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),v=m[0],h=m[1],b=(0,o.useQuery)("user",u.$.me,{refetchOnWindowFocus:!0,refetchInterval:v,staleTime:a.o9.staleTimes.session,onError:function(){sessionStorage.removeItem(a.YL)},onSuccess:function(e){sessionStorage.removeItem(a.YL),e&&sessionStorage.setItem(a.YL,e.access_token)}}),d=b.data,j=b.isStale,S=(0,f.Z)(d),w=(0,o.useQueryClient)(),k=(0,c.J)(),P=(0,i.r)(),I=(0,s.y)(),x=(0,n.useCallback)((function(){w.clear(),sessionStorage.removeItem(a.o9.cacheStorage.key),sessionStorage.removeItem(a.YL),u.$.login()}),[w]),C=(0,n.useCallback)((function(){w.clear(),sessionStorage.removeItem(a.o9.cacheStorage.key),sessionStorage.removeItem(a.YL),u.$.register()}),[w]),E=(0,n.useCallback)((function(){sessionStorage.removeItem(a.YL),w.removeQueries({predicate:function(e){return e.options.queryKey.includes("user")&&"user"!==e.options.queryKey}}),w.setQueryData("user",null)}),[w]),A=(0,n.useCallback)(g(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,u.$.logout();case 2:E();case 3:case"end":return e.stop()}}),e)}))),[E]);(0,n.useEffect)((function(){d&&!j&&(k.methods.prefetch(),P.methods.prefetch(),I.methods.prefetch()),h(!!d&&a.o9.staleTimes.session)}),[d]);var L=(0,n.useMemo)((function(){return{user:d,destroy:A,login:x,register:C}}),[d,A,x,C]);return(0,n.useEffect)((function(){S!==d&&w.removeQueries({predicate:function(e){return e.options.queryKey.includes("user")&&"user"!==e.options.queryKey}})}),[d]),(0,p.jsx)(y.z.Provider,{value:L,children:l})},S=function(e){var r=e.children,t=function(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},u=Object.keys(e);for(n=0;n<u.length;n++)t=u[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(e);for(n=0;n<u.length;n++)t=u[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}(e,m);return(0,p.jsx)(l.Z,{children:(0,p.jsx)(j,h(h({},t),{},{children:r}))})}},47080:function(e,r,t){var n=t(89526);r.Z=function(e){var r=(0,n.useRef)(e);return(0,n.useEffect)((function(){r.current=e}),[e]),r.current}}}]);
//# sourceMappingURL=65640.d858f50dc55f2ee7cf0a.index.js.map