(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2656],{3785:(e,r,t)=>{"use strict";t.d(r,{z:()=>s});var a=t(95155);function s(e){let{title:r,description:t,action:s,className:l=""}=e;return(0,a.jsxs)("div",{className:"mb-6 flex items-center justify-between gap-4 py-4 ".concat(l),children:[(0,a.jsxs)("div",{children:[(0,a.jsx)("h1",{className:"text-2xl font-semibold text-gray-900 dark:text-white",children:r}),t&&(0,a.jsx)("p",{className:"mt-1 text-sm text-gray-600 dark:text-white/70",children:t})]}),s&&(0,a.jsx)("div",{children:s})]})}},17657:(e,r,t)=>{"use strict";t.d(r,{A:()=>s});var a=t(95155);function s(e){let{title:r,description:t,icon:s,action:l}=e;return(0,a.jsxs)("div",{className:"flex h-[50vh] flex-col items-center justify-center space-y-4 text-center",children:[(0,a.jsx)(s,{className:"h-12 w-12 text-gray-400"}),(0,a.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:r}),(0,a.jsx)("p",{className:"max-w-sm text-gray-500 dark:text-gray-400",children:t}),l&&(0,a.jsx)("div",{className:"mt-4",children:l})]})}},18666:(e,r,t)=>{"use strict";t.r(r),t.d(r,{default:()=>b});var a=t(95155),s=t(12115),l=t(35695),o=t(12108),n=t(52371),i=t(18775),d=t(12644),c=t(22639),g=t(75679),u=t(42085),x=t(17657),h=t(70522),m=t(24717);function b(){let e=(0,l.useRouter)(),{data:r,status:t}=(0,o.useSession)(),{currentUser:b,isLoading:y}=(0,n.iZ)(),{isEnrolled:f}=(0,i.AS)(),[v,p]=(0,s.useState)([]),[k,j]=(0,s.useState)(!0),[w,N]=(0,s.useState)(null),[z,C]=(0,s.useState)(!1),[S,E]=(0,s.useState)("none");(0,s.useEffect)(()=>{var a,s;if("loading"===t)return;let l=(null==r||null==(a=r.user)?void 0:a.roles)||[],o=l.includes("Super Admin"),n=l.includes("Issuer");if(null==r||null==(s=r.user)||s.email,o){I(),e.replace("/sys-admin");return}if(y)return void E("checking");if(null==b?void 0:b.organization){let r=b.organization.id;if(n){if(!f){console.log("\uD83D\uDD04 Issuer user has not completed enrollment, redirecting to enrollment page"),e.replace("/main/".concat(r,"/biocodes/enrollment"));return}console.log("✅ Issuer user has completed enrollment, proceeding to overview"),e.replace("/main/".concat(r,"/biocodes"));return}e.replace("/main/".concat(r,"/overview"))}else E("no-org")},[t,b,y,f,e]);let I=async()=>{try{j(!0),N(null);let e=await d.hI.getOrganizations({limit:100,Sort:"createdDate"});(0,c.ny)(e)&&e.data?p(e.data.data||[]):N("Failed to load organizations")}catch(e){console.error("Error fetching organizations:",e),N("Failed to load organizations. Please try again.")}finally{j(!1)}},A=r=>{e.push("/main/".concat(r,"/overview"))};return"checking"===S?(0,a.jsx)("div",{className:"flex h-64 items-center justify-center",children:(0,a.jsx)("div",{className:"h-12 w-12 animate-spin rounded-full border-b-2 border-t-2 border-blue-500"})}):"no-org"===S?(0,a.jsxs)("div",{className:"flex flex-col items-center justify-center h-64",children:[(0,a.jsx)("div",{className:"mb-4 text-lg font-semibold text-red-600 dark:text-red-400",children:"You do not belong to any organization."}),(0,a.jsx)("div",{className:"text-gray-600 dark:text-gray-300",children:"Please contact your administrator."})]}):(0,a.jsx)("div",{children:(0,a.jsxs)("div",{className:"container p-4 mx-auto",children:[(0,a.jsx)(u.z,{title:"Organizations",description:"Select an organization to manage certificates, templates, and more",action:(0,a.jsxs)(h.$,{color:"primary",onClick:()=>e.push("/sys-admin/organizations"),children:[(0,a.jsx)(m.HiOfficeBuilding,{className:"mr-2 h-4 w-4"}),"Manage Organization"]})}),w&&(0,a.jsx)("div",{className:"mb-4 rounded-md bg-red-50 p-4 text-red-700 dark:bg-red-900/30 dark:text-red-400",children:w}),0!==v.length||k||w?(0,a.jsx)("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",children:v.map(e=>(0,a.jsx)(g.Z,{className:"cursor-pointer transition-all hover:shadow-md",onClick:()=>A(e.id),children:(0,a.jsxs)("div",{className:"p-5",children:[(0,a.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,a.jsxs)("div",{className:"relative h-12 w-12 shrink-0 overflow-hidden rounded-full",children:[e.logo?(0,a.jsx)("img",{src:e.logo,alt:e.name,className:"h-full w-full object-cover",onError:e=>{var r;let t=e.target;t.style.display="none";let a=null==(r=t.parentElement)?void 0:r.querySelector(".fallback-icon");a&&(a.style.display="flex")}}):null,(0,a.jsx)("div",{className:"fallback-icon absolute inset-0 flex items-center justify-center bg-blue-100 dark:bg-blue-900/30 ".concat(e.logo?"hidden":"flex"),children:(0,a.jsx)(m.HiOfficeBuilding,{className:"h-6 w-6 text-blue-600 dark:text-blue-400"})})]}),(0,a.jsxs)("div",{children:[(0,a.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white",children:e.name}),(0,a.jsxs)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Created"," ",new Date(e.createdDate).toLocaleDateString()]})]})]}),(0,a.jsxs)("div",{className:"grid grid-cols-2 gap-4 mt-4 text-sm",children:[(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:"Members"}),(0,a.jsx)("span",{className:"font-medium text-gray-900 dark:text-white",children:e.membersCount||0})]}),(0,a.jsxs)("div",{className:"flex flex-col",children:[(0,a.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:"Templates"}),(0,a.jsx)("span",{className:"font-medium text-gray-900 dark:text-white",children:e.templatesCount||0})]})]})]})},e.id))}):(0,a.jsx)(x.A,{icon:m.HiOfficeBuilding,title:"No organizations found",description:"Get started by creating your first organization",action:(0,a.jsxs)(h.$,{color:"primary",onClick:()=>e.push("/main/organizations"),children:[(0,a.jsx)(m.HiPlus,{className:"mr-2 h-4 w-4"}),"Create Organization"]})})]})})}},18775:(e,r,t)=>{"use strict";t.d(r,{AS:()=>s});var a=t(52371);function s(){var e;let{currentUser:r}=(0,a.iZ)(),t=!!(null==r?void 0:r.userEnrollment),s=!!(null==r||null==(e=r.userEnrollment)?void 0:e.biocodeId);return{isEnrolled:t&&s,hasUserEnrollment:t,hasBiocodeId:s,hasBiocodeImage:!!(null==r?void 0:r.biocodeImage),enrollmentData:(null==r?void 0:r.userEnrollment)||null,biocodeImage:(null==r?void 0:r.biocodeImage)||null}}},37783:(e,r,t)=>{Promise.resolve().then(t.bind(t,18666))},42085:(e,r,t)=>{"use strict";t.d(r,{z:()=>a.z});var a=t(3785)},52371:(e,r,t)=>{"use strict";t.d(r,{CurrentUserProvider:()=>d,iZ:()=>c});var a=t(95155),s=t(12115),l=t(12108),o=t(23388),n=t(22639);let i=(0,s.createContext)(void 0);function d(e){var r;let{children:t}=e,{data:d,status:c}=(0,l.useSession)(),[g,u]=(0,s.useState)(null),[x,h]=(0,s.useState)(!1),[m,b]=(0,s.useState)(null),y=async()=>{var e,r,t;if("authenticated"!==c||!d)return void u(null);let a=(null==(e=d.user)?void 0:e.roles)||[];if(!(a.includes("Admin")||a.includes("Issuer")))return void u(null);h(!0),b(null);try{console.log("\uD83D\uDD0D Fetching current user data...");let e=await o.D.getCurrentUser();(0,n.ny)(e)?(console.log("✅ Current user data fetched:",e.data),u(e.data)):(console.error("❌ Failed to fetch current user:",null==(r=e.status)?void 0:r.message),b((null==(t=e.status)?void 0:t.message)||"Failed to fetch user data"),u(null))}catch(e){console.error("❌ Error fetching current user:",e),b(e instanceof Error?e.message:"Unknown error"),u(null)}finally{h(!1)}};(0,s.useEffect)(()=>{y()},[d,c]);let f=e=>(null==g?void 0:g.role)===e,v=f("Admin"),p=f("Issuer"),k=(null==g||null==(r=g.organization)?void 0:r.id)||null;return(0,a.jsx)(i.Provider,{value:{currentUser:g,isLoading:x,error:m,refetchUser:y,hasRole:f,isAdmin:v,isIssuer:p,organizationId:k},children:t})}function c(){let e=(0,s.useContext)(i);if(void 0===e)throw Error("useCurrentUser must be used within a CurrentUserProvider");return e}},52596:(e,r,t)=>{"use strict";function a(){for(var e,r,t=0,a="",s=arguments.length;ta})},54252:(e,r,t)=>{"use strict";t.d(r,{$:()=>o});var a=t(95155),s=t(12115),l=t(52596);let o=(0,s.forwardRef)((e,r)=>{let{children:t,color:o="primary",size:n="md",variant:i="solid",fullWidth:d=!1,isLoading:c=!1,leftIcon:g,rightIcon:u,className:x,disabled:h,preventDoubleClick:m=!0,onClick:b,...y}=e,f=(0,s.useRef)(0);return(0,a.jsxs)("button",{ref:r,disabled:h||c,onClick:e=>{if(h||c){e.preventDefault(),e.stopPropagation();return}if(m){let r=Date.now();if(r-f.current<500){e.preventDefault(),e.stopPropagation();return}f.current=r}b&&b(e)},className:(0,l.$)("inline-flex items-center justify-center rounded-lg font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-900",{primary:{solid:"bg-primary-600 text-white hover:bg-primary-700 focus:ring-primary-500 dark:bg-primary-600 dark:hover:bg-primary-700",outline:"border border-primary-600 text-primary-600 hover:bg-primary-50 focus:ring-primary-500 dark:border-primary-500 dark:text-primary-500 dark:hover:bg-gray-800",ghost:"text-primary-600 hover:bg-primary-50 focus:ring-primary-500 dark:text-primary-500 dark:hover:bg-gray-800"},secondary:{solid:"bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-200 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600",outline:"border border-gray-300 text-gray-700 hover:bg-gray-50 focus:ring-gray-200 dark:border-gray-600 dark:text-gray-300 dark:hover:bg-gray-800",ghost:"text-gray-700 hover:bg-gray-100 focus:ring-gray-200 dark:text-gray-300 dark:hover:bg-gray-800"},success:{solid:"bg-green-600 text-white hover:bg-green-700 focus:ring-green-500 dark:bg-green-600 dark:hover:bg-green-700",outline:"border border-green-600 text-green-600 hover:bg-green-50 focus:ring-green-500 dark:border-green-500 dark:text-green-500 dark:hover:bg-gray-800",ghost:"text-green-600 hover:bg-green-50 focus:ring-green-500 dark:text-green-500 dark:hover:bg-gray-800"},danger:{solid:"bg-red-600 text-white hover:bg-red-700 focus:ring-red-500 dark:bg-red-600 dark:hover:bg-red-700",outline:"border border-red-600 text-red-600 hover:bg-red-50 focus:ring-red-500 dark:border-red-500 dark:text-red-500 dark:hover:bg-gray-800",ghost:"text-red-600 hover:bg-red-50 focus:ring-red-500 dark:text-red-500 dark:hover:bg-gray-800"},warning:{solid:"bg-yellow-500 text-white hover:bg-yellow-600 focus:ring-yellow-400 dark:bg-yellow-600 dark:hover:bg-yellow-700",outline:"border border-yellow-500 text-yellow-500 hover:bg-yellow-50 focus:ring-yellow-400 dark:border-yellow-400 dark:text-yellow-400 dark:hover:bg-gray-800",ghost:"text-yellow-500 hover:bg-yellow-50 focus:ring-yellow-400 dark:text-yellow-400 dark:hover:bg-gray-800"},info:{solid:"bg-blue-500 text-white hover:bg-blue-600 focus:ring-blue-400 dark:bg-blue-600 dark:hover:bg-blue-700",outline:"border border-blue-500 text-blue-500 hover:bg-blue-50 focus:ring-blue-400 dark:border-blue-400 dark:text-blue-400 dark:hover:bg-gray-800",ghost:"text-blue-500 hover:bg-blue-50 focus:ring-blue-400 dark:text-blue-400 dark:hover:bg-gray-800"},light:{solid:"bg-gray-50 text-gray-900 hover:bg-gray-100 focus:ring-gray-100 dark:bg-gray-600 dark:text-white dark:hover:bg-gray-500",outline:"border border-gray-200 text-gray-900 hover:bg-gray-50 focus:ring-gray-100 dark:border-gray-700 dark:text-white dark:hover:bg-gray-800",ghost:"text-gray-900 hover:bg-gray-50 focus:ring-gray-100 dark:text-white dark:hover:bg-gray-800"},dark:{solid:"bg-gray-900 text-white hover:bg-gray-800 focus:ring-gray-800 dark:bg-gray-800 dark:hover:bg-gray-700",outline:"border border-gray-900 text-gray-900 hover:bg-gray-100 focus:ring-gray-800 dark:border-gray-700 dark:text-white dark:hover:bg-gray-700",ghost:"text-gray-900 hover:bg-gray-100 focus:ring-gray-800 dark:text-white dark:hover:bg-gray-700"}}[o][i],{xs:"px-2 py-1 text-xs",sm:"px-3 py-1.5 text-sm",md:"px-4 py-2 text-sm",lg:"px-5 py-2.5 text-base",xl:"px-6 py-3 text-base"}[n],d?"w-full":"",(h||c)&&"opacity-50 cursor-not-allowed pointer-events-none",x),...y,children:[c&&(0,a.jsxs)("div",{className:"mr-2 relative",children:[(0,a.jsxs)("svg",{className:"h-4 w-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,a.jsx)("circle",{className:"opacity-20",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3"}),(0,a.jsx)("path",{className:"opacity-90",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),(0,a.jsx)("div",{className:"absolute inset-0 h-4 w-4 bg-current opacity-10 rounded-full blur-sm animate-pulse"})]}),!c&&g&&(0,a.jsx)("span",{className:"mr-2",children:g}),t,!c&&u&&(0,a.jsx)("span",{className:"ml-2",children:u})]})});o.displayName="Button"},70522:(e,r,t)=>{"use strict";t.d(r,{$:()=>a.$});var a=t(54252)},75679:(e,r,t)=>{"use strict";t.d(r,{Z:()=>s});var a=t(95155);t(12115);let s=e=>{let{children:r,className:t="",onClick:s,imageSrc:l,title:o,subtitle:n,footer:i}=e;return(0,a.jsxs)("div",{className:"\n rounded-2xl\n border border-gray-200 dark:border-slate-800\n p-0\n overflow-hidden\n ".concat(t,"\n "),onClick:s,children:[l&&(0,a.jsx)("div",{className:"w-full h-40 p-2",children:(0,a.jsx)("img",{src:l,alt:"Card banner",className:"w-full h-40 object-contain object-center"})}),(0,a.jsxs)("div",{className:"p-6 flex flex-col gap-2",children:[o&&(0,a.jsx)("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:o}),n&&(0,a.jsx)("p",{className:"text-base text-blue-600 dark:text-blue-200",children:n}),(0,a.jsx)("div",{className:"flex-1",children:r})]}),i&&(0,a.jsx)("div",{className:"border-t border-gray-200 dark:border-slate-700 px-6 py-4",children:i})]})}}},e=>{var r=r=>e(e.s=r);e.O(0,[4777,9268,2108,5525,8694,2960,3428,601,5577,2644,8441,1684,7358],()=>r(37783)),_N_E=e.O()}]);