(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1059],{5816:(e,r,t)=>{"use strict";t.r(r),t.d(r,{default:()=>w});var a=t(95155),i=t(12115),n=t(10351),s=t(61211),o=t(18259),l=t(65269),d=t(93208),c=t(12108),u=t(35695),g=t(15152),m=t(23911),h=t(52371),f=t(12644),x=t(22639),p=t(32960),v=t(24717);let b=[{id:"general",label:"GENERAL",icon:v.HiCollection,href:"",isGroup:!0},{id:"dashboard",label:"Dashboard",icon:v.HiDesktopComputer,href:"/overview",parentId:"general"},{id:"organization",label:"ORGANIZATION",icon:v.HiOfficeBuilding,href:"",isGroup:!0},{id:"settings",label:"Settings",icon:v.HiCog,href:"/settings",parentId:"organization"},{id:"members",label:"Members",icon:v.HiUserGroup,href:"/members",parentId:"organization"}],y=[{id:"dashboard",label:"Dashboard",icon:v.HiDesktopComputer,href:"/overview"},{id:"e-stamp",label:"E-STAMP",icon:v.HiFingerPrint,href:"",isGroup:!0},{id:"manage-categories",label:"Portfolios",icon:v.HiCollection,href:"/certificate-categories",parentId:"e-stamp"},{id:"manage-types",label:"Certificate Templates",icon:v.HiTemplate,href:"/certificate-types",parentId:"e-stamp"},{id:"stamp-certificate",label:"Stamp Certificates",icon:v.HiShieldCheck,href:"/biocodes",parentId:"e-stamp"},{id:"e-certificate",label:"E-CERTIFICATE",icon:v.HiBadgeCheck,href:"",isGroup:!0},{id:"manage-categories",label:"Portfolios",icon:v.HiClipboardList,href:"/certificate-categories",parentId:"e-certificate"},{id:"design-template",label:"Editor Templates",icon:v.HiColorSwatch,href:"/certificate-templates",parentId:"e-certificate"},{id:"certificate-programs",label:"Certificate Programs",icon:v.HiCalendar,href:"/certificate-programs",parentId:"e-certificate"},{id:"certificates",label:"Issued Certificates",icon:v.HiDocumentText,href:"/certificates",parentId:"e-certificate"},{id:"integration",label:"Settings",icon:v.HiCog,href:"",isGroup:!0},{id:"api-key",label:"API Key",icon:v.HiKey,href:"/integration/api-keys",parentId:"integration"},{id:"documentation",label:"Documentation",icon:v.HiBookOpen,href:"/integration/documentation",parentId:"integration"}],j=[{id:"e-stamp",label:"E-STAMP",icon:v.HiFingerPrint,href:"",isGroup:!0},{id:"stamp-certificate",label:"Stamp Certificates",icon:v.HiShieldCheck,href:"/biocodes",parentId:"e-stamp"}],k={SUPER_ADMIN:"Super Admin",ADMIN:"Admin",ISSUER:"Issuer"},N=i.memo(e=>{let{userRole:r,organizations:t,orgId:n,onOrganizationSelect:s,onCreateOrganization:o,onSettingOrganization:l,onMembersClick:c}=e,{currentUser:g,isLoading:f,error:x}=(0,h.iZ)(),p=(null==g?void 0:g.organization)||null;return r===k.SUPER_ADMIN?(0,a.jsxs)("div",{className:"px-2 py-2",children:[(0,a.jsx)("div",{className:"mb-2",children:(0,a.jsx)("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Select Organization"})}),(0,a.jsx)("div",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:(0,a.jsx)(d.d,{organizations:t,selectedOrganizationId:n,onSelectOrganization:s,onCreateOrganization:o,variant:"default",onSettingOrganization:l})})]}):(0,a.jsxs)("div",{className:"px-2 py-2",children:[(0,a.jsx)("div",{className:"mb-2",children:(0,a.jsx)("h3",{className:"text-xs font-semibold text-gray-500 dark:text-gray-400 uppercase tracking-wide",children:"Organization"})}),(0,a.jsx)("div",{className:"text-sm font-medium text-gray-600 dark:text-gray-300",children:f?(0,a.jsx)(()=>(0,a.jsxs)("div",{className:"flex items-center gap-2",children:[(0,a.jsx)("div",{className:"h-6 w-6 animate-spin rounded-full border-b-2 border-blue-500"}),(0,a.jsx)("span",{children:"Loading organization..."})]}),{}):p?(0,a.jsx)(e=>{let{organization:t}=e,[n,s]=(0,i.useState)(!1),o=(0,i.useRef)(null),d=(0,u.useRouter)(),g=[k.ADMIN,k.SUPER_ADMIN].includes(r);[k.ADMIN,k.SUPER_ADMIN].includes(r);let h=[k.ADMIN,k.SUPER_ADMIN].includes(r),f=r!==k.ISSUER;return(0,i.useEffect)(()=>{let e=e=>{o.current&&!o.current.contains(e.target)&&s(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,a.jsxs)("div",{className:"relative",ref:o,children:[(0,a.jsxs)("div",{className:"flex items-center gap-2 border border-gray-200 dark:border-gray-700 p-2 rounded-md",children:[t.logo?(0,a.jsx)(m.gu,{src:t.logo,alt:"".concat(t.name," logo"),size:"sm",glossyBorder:!0}):(0,a.jsx)("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-gray-200/20 bg-gradient-to-b from-gray-600/50 to-gray-800/50 shadow-sm dark:border-gray-700/50 dark:from-gray-700/50 dark:to-gray-900/50",children:(0,a.jsx)(m.In,{name:"HiOfficeBuilding",className:"text-white",size:"sm"})}),(0,a.jsx)("span",{className:"font-medium flex-1",children:t.name}),f&&(0,a.jsx)("button",{onClick:()=>s(!n),className:"p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-md transition-colors","aria-label":"Organization menu",children:(0,a.jsx)("svg",{className:"w-4 h-4 text-gray-500 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"})})})]}),n&&(0,a.jsx)("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md shadow-lg z-50",children:(0,a.jsxs)("div",{className:"py-1",children:[g&&(0,a.jsxs)("button",{onClick:()=>{s(!1),l(t)},className:"w-full px-3 py-2 text-left text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 flex items-center gap-2",children:[(0,a.jsxs)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),"Settings"]}),h&&(0,a.jsxs)("button",{onClick:()=>{s(!1),c?c(t):d.push("/main/".concat(t.id,"/members"))},className:"w-full px-3 py-2 text-left text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 flex items-center gap-2",children:[(0,a.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,a.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197m13.5-9a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z"})}),"Members"]})]})})]})},{organization:p}):(0,a.jsx)(e=>{let{message:r}=e;return(0,a.jsx)("span",{className:"text-red-500 text-sm",children:r})},{message:"You do not belong to any organization."})})]})});function S(){var e,r,t,i,n;let s,o=(0,u.useRouter)(),d=(0,u.useParams)().orgId,{data:m}=(0,c.useSession)(),h=async()=>{console.log("Sidebar handleLogout called");try{await (0,c.signOut)({redirect:!1}),console.log("SignOut completed, redirecting..."),o.push("/authentication/sign-in")}catch(e){console.error("Logout error:",e),window.location.href="/authentication/sign-in"}},{data:v}=(0,p.I)({queryKey:["organizations"],queryFn:async()=>await f.hI.getOrganizations({limit:50}),enabled:null==m||null==(r=m.user)||null==(e=r.roles)?void 0:e.includes("Super Admin")}),S=v&&(0,x.ny)(v)?v.data.data:[],w=(null==m||null==(t=m.user)?void 0:t.roles)&&m.user.roles.length>0?m.user.roles[0]:void 0;return(0,a.jsx)("div",{className:"h-full",children:(0,a.jsxs)(l.Jp,{collapsible:!1,children:[(0,a.jsx)(l.Jp.Header,{title:"E-Certificate",children:(0,a.jsx)(N,{userRole:w,organizations:S,orgId:d,onOrganizationSelect:e=>{o.push("/main/".concat(e.id,"/overview"))},onCreateOrganization:()=>{o.push("/sys-admin/organizations")},onSettingOrganization:e=>{o.push("/main/".concat(e.id,"/settings"))},onMembersClick:e=>{o.push("/main/".concat(e.id,"/members"))}})}),d?(0,a.jsx)(l.Jp.Body,{items:w===k.SUPER_ADMIN||w===k.ADMIN||w===k.ISSUER?(s=[],("Super Admin"===w?s=b:"Admin"===w?s=y:"Issuer"===w&&(s=j),d)?s.map(e=>e.href&&!e.isGroup?{...e,href:"/main/".concat(d).concat(e.href.startsWith("/")?e.href:"/"+e.href)}:e):s):[]}):(0,a.jsx)("div",{className:"flex flex-col items-center justify-center h-full p-6 text-center text-gray-500 dark:text-gray-400",children:(0,a.jsx)("span",{className:"text-sm font-medium",children:"Please select an organization to continue"})}),(0,a.jsx)(l.Jp.Footer,{children:(0,a.jsx)("div",{className:"p-1.5",children:(0,a.jsx)(g.XC,{userName:null==m||null==(i=m.user)?void 0:i.name,userEmail:null==m||null==(n=m.user)?void 0:n.email,userRole:w,position:"top",showModeSwitch:"Super Admin"===w,modeSwitchLabel:"Admin Panel",onSwitchMode:()=>{o.push("/sys-admin")},onSignOut:h})})})]})})}function w(e){var r;let{children:t}=e,{data:l}=(0,c.useSession)();(0,u.useRouter)(),(null==l||null==(r=l.user)?void 0:r.roles)&&l.user.roles.length>0&&l.user.roles[0];let[d,g]=(0,i.useState)(!0);return(0,a.jsx)(o.W,{children:(0,a.jsx)(s.T,{children:(0,a.jsxs)("div",{className:"flex h-screen overflow-hidden bg-gray-50 dark:bg-gray-900",children:[(0,a.jsx)(S,{}),(0,a.jsxs)("div",{className:"flex flex-1 flex-col overflow-hidden",children:[(0,a.jsx)("div",{className:"flex items-center border-b border-gray-200 bg-white px-4 py-2 shadow-sm dark:border-gray-700 dark:bg-gray-800 lg:hidden",children:(0,a.jsx)("button",{className:"rounded-md p-2 text-gray-600 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-700",onClick:()=>g(!d),children:(0,a.jsx)(n.ND1,{className:"h-6 w-6"})})}),(0,a.jsx)("main",{className:"flex-1 overflow-auto p-6",children:t})]})]})})})}N.displayName="OrganizationContext"},18259:(e,r,t)=>{"use strict";t.d(r,{W:()=>s});var a=t(95155),i=t(12115);let n=(0,i.createContext)(void 0);function s(e){let{children:r}=e,[t,s]=(0,i.useState)(!1);return(0,a.jsx)(n.Provider,{value:{viewAsOrgAdmin:t,setViewAsOrgAdmin:s,toggleViewMode:()=>{s(e=>!e)}},children:r})}},44942:(e,r,t)=>{Promise.resolve().then(t.bind(t,5816))},52371:(e,r,t)=>{"use strict";t.d(r,{CurrentUserProvider:()=>d,iZ:()=>c});var a=t(95155),i=t(12115),n=t(12108),s=t(23388),o=t(22639);let l=(0,i.createContext)(void 0);function d(e){var r;let{children:t}=e,{data:d,status:c}=(0,n.useSession)(),[u,g]=(0,i.useState)(null),[m,h]=(0,i.useState)(!1),[f,x]=(0,i.useState)(null),p=async()=>{var e,r,t;if("authenticated"!==c||!d)return void g(null);let a=(null==(e=d.user)?void 0:e.roles)||[];if(!(a.includes("Admin")||a.includes("Issuer")))return void g(null);h(!0),x(null);try{console.log("\uD83D\uDD0D Fetching current user data...");let e=await s.D.getCurrentUser();(0,o.ny)(e)?(console.log("✅ Current user data fetched:",e.data),g(e.data)):(console.error("❌ Failed to fetch current user:",null==(r=e.status)?void 0:r.message),x((null==(t=e.status)?void 0:t.message)||"Failed to fetch user data"),g(null))}catch(e){console.error("❌ Error fetching current user:",e),x(e instanceof Error?e.message:"Unknown error"),g(null)}finally{h(!1)}};(0,i.useEffect)(()=>{p()},[d,c]);let v=e=>(null==u?void 0:u.role)===e,b=v("Admin"),y=v("Issuer"),j=(null==u||null==(r=u.organization)?void 0:r.id)||null;return(0,a.jsx)(l.Provider,{value:{currentUser:u,isLoading:m,error:f,refetchUser:p,hasRole:v,isAdmin:b,isIssuer:y,organizationId:j},children:t})}function c(){let e=(0,i.useContext)(l);if(void 0===e)throw Error("useCurrentUser must be used within a CurrentUserProvider");return e}},61211:(e,r,t)=>{"use strict";t.d(r,{T:()=>s,Z:()=>o});var a=t(95155),i=t(12115);let n=(0,i.createContext)(void 0);function s(e){let{children:r}=e,[t,s]=(0,i.useState)(null),[o,l]=(0,i.useState)(null);return(0,a.jsx)(n.Provider,{value:{selectedOrganizationId:t,selectedOrganization:o,setSelectedOrganizationId:s,setSelectedOrganization:l},children:r})}function o(){let e=(0,i.useContext)(n);if(void 0===e)throw Error("useOrganization must be used within an OrganizationProvider");return e}}},e=>{var r=r=>e(e.s=r);e.O(0,[8827,4777,9268,844,2108,5525,8694,2960,3428,4277,6766,6874,5765,601,5842,3911,5577,2644,8441,1684,7358],()=>r(44942)),_N_E=e.O()}]);