(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1931],{24654:function(){},98691:function(e,t,r){Promise.resolve().then(r.bind(r,16117))},99376:function(e,t,r){"use strict";var n=r(35475);r.o(n,"usePathname")&&r.d(t,{usePathname:function(){return n.usePathname}}),r.o(n,"useRouter")&&r.d(t,{useRouter:function(){return n.useRouter}}),r.o(n,"useSearchParams")&&r.d(t,{useSearchParams:function(){return n.useSearchParams}})},16117:function(e,t,r){"use strict";r.r(t),r.d(t,{default:function(){return f}});var n=r(57437),o=r(2265),i=r(99376),a=r(16865),u=r(48994);function s(){return(0,n.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-background",children:(0,n.jsx)("div",{className:"inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-primary border-r-transparent"})})}let l=e=>{var t;return(null===(t=e.options)||void 0===t?void 0:t.menuGroup)===!0};function c(){let e=(0,i.useRouter)(),{topLevel:t,childrenOf:r,allVisible:c,isLoading:f}=(0,u.D)();return(0,o.useEffect)(()=>{var n;if(f)return;let o=null===(n=(0,a.pw)())||void 0===n?void 0:n.id,i=o&&c.find(e=>{var t;return!l(e)&&Array.isArray(null===(t=e.options)||void 0===t?void 0:t.homeFor)&&e.options.homeFor.includes(o)})||void 0;if(!i)for(let e of t){let t=l(e)?r(e.id).find(e=>!l(e)):e;if(t){i=t;break}}e.replace(i?"/pages/?slug=".concat(encodeURIComponent(i.slug)):"/dashboard/")},[f,c,t,r,e]),(0,n.jsx)(s,{})}function f(){let e=(0,i.useRouter)(),[t,r]=(0,o.useState)(!1);return((0,o.useEffect)(()=>{(0,a.D3)()?e.replace("/dashboard/"):r(!0)},[e]),t)?(0,n.jsx)(c,{}):(0,n.jsx)(s,{})}},48994:function(e,t,r){"use strict";r.d(t,{D:function(){return s}});var n=r(2265),o=r(72135),i=r(16865);let a=["id","name","slug","icon","parent_Id","sort","roles","enabled","options","description","isPublic"],u=(e,t)=>{var r,n;return(null!==(r=e.sort)&&void 0!==r?r:0)-(null!==(n=t.sort)&&void 0!==n?n:0)||e.name.localeCompare(t.name)};function s(){let e=(0,i.D3)(),{data:t,isLoading:r}=(0,o.sm)({resource:"baasix_Page",filters:e?[]:[{field:"enabled",operator:"eq",value:!0}],sorters:[{field:"sort",order:"asc"}],pagination:{current:1,pageSize:200},meta:{fields:a}}),s=(0,n.useMemo)(()=>{var r,n;let o=null!==(n=null==t?void 0:t.data)&&void 0!==n?n:[],a=null===(r=(0,i.pw)())||void 0===r?void 0:r.id;return o.filter(t=>!!e||!Array.isArray(t.roles)||0===t.roles.length||!!a&&t.roles.includes(a)).sort(u)},[t,e]);return{topLevel:(0,n.useMemo)(()=>{let e=new Set(s.map(e=>e.id));return s.filter(t=>!t.parent_Id||!e.has(t.parent_Id))},[s]),childrenOf:(0,n.useCallback)(e=>s.filter(t=>t.parent_Id===e),[s]),allVisible:s,isAdmin:e,isLoading:r}}},16865:function(e,t,r){"use strict";r.d(t,{D3:function(){return g},KF:function(){return v},Vj:function(){return f},ez:function(){return c},k3:function(){return b},pw:function(){return p},vF:function(){return m}});let n="token",o="user",i="baasix_access_token",a="baasix_user",u="baasix_role",s="baasix_permissions",l="baasix_tenant_info";function c(e){if(e.token&&(localStorage.setItem(n,e.token),localStorage.setItem(i,e.token)),e.user){let t=JSON.stringify(e.user);localStorage.setItem(o,t),localStorage.setItem(a,t)}e.role&&localStorage.setItem(u,JSON.stringify(e.role)),e.permissions&&localStorage.setItem(s,JSON.stringify(e.permissions)),e.tenant&&localStorage.setItem(l,JSON.stringify(e.tenant))}function f(){for(let e of[n,o,i,a,u,s,l,"baasix_refresh_token","baasix_token_expiry","baasix_tenant"])localStorage.removeItem(e)}function d(e){try{let t=localStorage.getItem(e);return t?JSON.parse(t):null}catch(t){return console.warn('Failed to parse localStorage key "'.concat(e,'"')),null}}function m(){var e;let t=null!==(e=d(o))&&void 0!==e?e:d(a);return t&&"object"==typeof t&&"string"==typeof t.id&&t.id?t:null}function p(){return d(u)}function v(){return d(l)}function b(){var e;return null!==(e=d(s))&&void 0!==e?e:[]}function g(){var e;let t=p();return!t||(null===(e=t.name)||void 0===e?void 0:e.toLowerCase())==="administrator"}}},function(e){e.O(0,[7999,8042,2971,2117,1744],function(){return e(e.s=98691)}),_N_E=e.O()}]);