@atlashub/smartstack 2.13.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),ar=require("axios"),ne=require("react-i18next"),Ks=require("i18next"),lo=require("i18next-browser-languagedetector"),Q=require("react-router-dom"),io=require("@microsoft/signalr"),a=require("lucide-react"),Rl=require("react-error-boundary"),Cr=require("modern-screenshot"),Zs=require("react-dom"),nt=require("react-resizable-panels"),oo=require("libphonenumber-js"),Ie=require("recharts"),Ss=require("@dnd-kit/core"),mt=require("@dnd-kit/sortable"),co=require("@dnd-kit/utilities"),Sr=require("@tiptap/react"),mo=require("@tiptap/starter-kit"),xo=require("@tiptap/extension-link"),uo=require("@tiptap/extension-image"),po=require("@tiptap/extension-placeholder"),ho=require("@tiptap/extension-text-align"),bo=require("@tiptap/extension-underline"),vo=require("@tiptap/extension-text-style"),go=require("@tiptap/extension-color"),fo=require("@tiptap/extension-highlight"),jo=require("@monaco-editor/react");function Il(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>s[r]})}}return t.default=s,Object.freeze(t)}const Me=Il(io),es=Il(a),fs={none:"0px",small:"4px",medium:"8px",large:"12px",xlarge:"16px",xxlarge:"24px"},yo={none:"Carré",small:"Léger",medium:"Moyen",large:"Arrondi",xlarge:"Très arrondi",xxlarge:"Pill"},os={slate:{name:"Ardoise",shades:{50:"#f8fafc",100:"#f1f5f9",200:"#e2e8f0",300:"#cbd5e1",400:"#94a3b8",500:"#64748b",600:"#475569",700:"#334155",800:"#1e293b",900:"#0f172a",950:"#020617"}},gray:{name:"Gris",shades:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827",950:"#030712"}},zinc:{name:"Zinc",shades:{50:"#fafafa",100:"#f4f4f5",200:"#e4e4e7",300:"#d4d4d8",400:"#a1a1aa",500:"#71717a",600:"#52525b",700:"#3f3f46",800:"#27272a",900:"#18181b",950:"#09090b"}},stone:{name:"Pierre",shades:{50:"#fafaf9",100:"#f5f5f4",200:"#e7e5e4",300:"#d6d3d1",400:"#a8a29e",500:"#78716c",600:"#57534e",700:"#44403c",800:"#292524",900:"#1c1917",950:"#0c0a09"}},indigo:{name:"Indigo",shades:{50:"#eef2ff",100:"#e0e7ff",200:"#c7d2fe",300:"#a5b4fc",400:"#818cf8",500:"#6366f1",600:"#4f46e5",700:"#4338ca",800:"#3730a3",900:"#312e81",950:"#1e1b4b"}},violet:{name:"Violet",shades:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95",950:"#2e1065"}},blue:{name:"Bleu",shades:{50:"#eff6ff",100:"#dbeafe",200:"#bfdbfe",300:"#93c5fd",400:"#60a5fa",500:"#3b82f6",600:"#2563eb",700:"#1d4ed8",800:"#1e40af",900:"#1e3a8a",950:"#172554"}},cyan:{name:"Cyan",shades:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63",950:"#083344"}},teal:{name:"Teal",shades:{50:"#f0fdfa",100:"#ccfbf1",200:"#99f6e4",300:"#5eead4",400:"#2dd4bf",500:"#14b8a6",600:"#0d9488",700:"#0f766e",800:"#115e59",900:"#134e4a",950:"#042f2e"}},emerald:{name:"Émeraude",shades:{50:"#ecfdf5",100:"#d1fae5",200:"#a7f3d0",300:"#6ee7b7",400:"#34d399",500:"#10b981",600:"#059669",700:"#047857",800:"#065f46",900:"#064e3b",950:"#022c22"}},amber:{name:"Ambre",shades:{50:"#fffbeb",100:"#fef3c7",200:"#fde68a",300:"#fcd34d",400:"#fbbf24",500:"#f59e0b",600:"#d97706",700:"#b45309",800:"#92400e",900:"#78350f",950:"#451a03"}},orange:{name:"Orange",shades:{50:"#fff7ed",100:"#ffedd5",200:"#fed7aa",300:"#fdba74",400:"#fb923c",500:"#f97316",600:"#ea580c",700:"#c2410c",800:"#9a3412",900:"#7c2d12",950:"#431407"}},rose:{name:"Rose",shades:{50:"#fff1f2",100:"#ffe4e6",200:"#fecdd3",300:"#fda4af",400:"#fb7185",500:"#f43f5e",600:"#e11d48",700:"#be123c",800:"#9f1239",900:"#881337",950:"#4c0519"}},pink:{name:"Pink",shades:{50:"#fdf2f8",100:"#fce7f3",200:"#fbcfe8",300:"#f9a8d4",400:"#f472b6",500:"#ec4899",600:"#db2777",700:"#be185d",800:"#9d174d",900:"#831843",950:"#500724"}}},No={card:"large",button:"medium",badge:"medium",input:"medium",modal:"xlarge",menuItem:"medium"},_s={neutral:{name:"Neutre",icon:"⚪",colors:{light:{light:"#ffffff",medium:"#f4f4f5",dark:"#e4e4e7",border:"#d4d4d8"},dark:{light:"#1c1c1f",medium:"#27272a",dark:"#3f3f46",border:"#52525b"}}},ocean:{name:"Océan",icon:"🌊",colors:{light:{light:"#e0f2fe",medium:"#bae6fd",dark:"#7dd3fc",border:"#93c5fd"},dark:{light:"#141c24",medium:"#1a2836",dark:"#2a4a5e",border:"#3a5a70"}}},forest:{name:"Forêt",icon:"🌲",colors:{light:{light:"#d1fae5",medium:"#a7f3d0",dark:"#6ee7b7",border:"#86efac"},dark:{light:"#121d18",medium:"#182a22",dark:"#2a4a3a",border:"#3a5a4a"}}},sunset:{name:"Coucher de soleil",icon:"🌅",colors:{light:{light:"#fef3c7",medium:"#fde68a",dark:"#fbbf24",border:"#fcd34d"},dark:{light:"#1c1810",medium:"#2a2418",dark:"#4a3a24",border:"#5a4a34"}}},lavender:{name:"Lavande",icon:"💜",colors:{light:{light:"#ede9fe",medium:"#ddd6fe",dark:"#c4b5fd",border:"#c4b5fd"},dark:{light:"#1a1820",medium:"#24222e",dark:"#3a3650",border:"#4a4660"}}},rose:{name:"Rose",icon:"🌸",colors:{light:{light:"#fce7f3",medium:"#fbcfe8",dark:"#f9a8d4",border:"#f9a8d4"},dark:{light:"#1c1418",medium:"#2a1e24",dark:"#4a3040",border:"#5a4050"}}}},rr="neutral",Ws=s=>{const t=os[s]?.shades||os.indigo.shades;return{name:"Clair",primary:os.indigo.shades,accent:t,backgrounds:{app:"#fafafa",primary:"#ffffff",secondary:"#f4f4f5",tertiary:"#e4e4e7",card:"#ffffff",hover:"#f4f4f5",active:"#e4e4e7"},text:{primary:"#18181b",secondary:"#52525b",tertiary:"#71717a",muted:"#a1a1aa",inverse:"#fafafa"},border:{default:"#e4e4e7",subtle:"#f4f4f5",strong:"#d4d4d8"},status:{success:{bg:"#f0fdfa",text:"#0f766e",border:"#99f6e4",dot:"#14b8a6"},warning:{bg:"#fffbeb",text:"#b45309",border:"#fde68a",dot:"#f59e0b"},error:{bg:"#fff1f2",text:"#be123c",border:"#fecdd3",dot:"#f43f5e"},info:{bg:"#f0f9ff",text:"#0369a1",border:"#bae6fd",dot:"#0ea5e9"}},accentTransparent:{bg:`${t[50]}`,text:t[700],border:t[200]}}},Xs=s=>{const t=os[s]?.shades||os.indigo.shades;return{name:"Sombre",primary:os.indigo.shades,accent:t,backgrounds:{app:"#161618",primary:"#1c1c1f",secondary:"#232326",tertiary:"#2a2a2e",card:"#1c1c1f",hover:"#27272a",active:"#3f3f46"},text:{primary:"#fafafa",secondary:"#d4d4d8",tertiary:"#a1a1aa",muted:"#71717a",inverse:"#18181b"},border:{default:"#3f3f46",subtle:"#27272a",strong:"#52525b"},status:{success:{bg:"rgba(20, 184, 166, 0.15)",text:"#5eead4",border:"rgba(20, 184, 166, 0.3)",dot:"#14b8a6"},warning:{bg:"rgba(245, 158, 11, 0.15)",text:"#fbbf24",border:"rgba(245, 158, 11, 0.3)",dot:"#f59e0b"},error:{bg:"rgba(244, 63, 94, 0.15)",text:"#fb7185",border:"rgba(244, 63, 94, 0.3)",dot:"#f43f5e"},info:{bg:"rgba(14, 165, 233, 0.15)",text:"#7dd3fc",border:"rgba(14, 165, 233, 0.3)",dot:"#0ea5e9"}},accentTransparent:{bg:`rgba(${Tr(t[500])}, 0.15)`,text:t[300],border:`rgba(${Tr(t[500])}, 0.3)`}}};function Tr(s){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return t?`${parseInt(t[1],16)}, ${parseInt(t[2],16)}, ${parseInt(t[3],16)}`:"99, 102, 241"}const xt={mode:"dark",borderRadius:No,colors:{light:Ws("indigo"),dark:Xs("indigo")},accentColorKey:"indigo",itemPaletteKey:rr},wo=[{id:"default",name:"Par défaut",description:"Style SmartStack classique avec coins arrondis",icon:"✨",config:{borderRadius:{card:"large",button:"medium",badge:"medium",input:"medium",modal:"xlarge",menuItem:"medium"},accentColorKey:"indigo",itemPaletteKey:"neutral"}},{id:"minimal",name:"Minimal",description:"Style épuré et professionnel",icon:"⚪",config:{borderRadius:{card:"medium",button:"small",badge:"small",input:"small",modal:"medium",menuItem:"small"},accentColorKey:"slate",itemPaletteKey:"neutral"}},{id:"corporate",name:"Corporate",description:"Style sobre pour environnement professionnel",icon:"🏢",config:{borderRadius:{card:"small",button:"small",badge:"medium",input:"small",modal:"medium",menuItem:"small"},accentColorKey:"gray",itemPaletteKey:"neutral"}},{id:"ocean",name:"Océan",description:"Teintes bleues apaisantes",icon:"🌊",config:{borderRadius:{card:"large",button:"medium",badge:"medium",input:"medium",modal:"xlarge",menuItem:"medium"},accentColorKey:"cyan",itemPaletteKey:"ocean"}},{id:"forest",name:"Forêt",description:"Tons verts naturels",icon:"🌲",config:{borderRadius:{card:"medium",button:"medium",badge:"medium",input:"medium",modal:"large",menuItem:"medium"},accentColorKey:"emerald",itemPaletteKey:"forest"}},{id:"sunset",name:"Coucher de soleil",description:"Couleurs chaudes et accueillantes",icon:"🌅",config:{borderRadius:{card:"large",button:"large",badge:"xxlarge",input:"medium",modal:"xlarge",menuItem:"medium"},accentColorKey:"orange",itemPaletteKey:"sunset"}},{id:"lavender",name:"Lavande",description:"Tons violets élégants",icon:"💜",config:{borderRadius:{card:"xlarge",button:"large",badge:"xlarge",input:"large",modal:"xlarge",menuItem:"large"},accentColorKey:"violet",itemPaletteKey:"lavender"}},{id:"rose",name:"Rose",description:"Teintes roses douces",icon:"🌸",config:{borderRadius:{card:"xxlarge",button:"xlarge",badge:"xxlarge",input:"large",modal:"xxlarge",menuItem:"large"},accentColorKey:"pink",itemPaletteKey:"rose"}}],El="smartstack-theme-config";class jt extends Error{statusCode;details;constructor(t,r,n){super(t),this.name="AppError",this.statusCode=r,this.details=n}}class nr extends Error{constructor(t="Network error occurred"){super(t),this.name="NetworkError"}}class Dl extends Error{code;constructor(t="Authentication required",r){super(t),this.name="AuthenticationError",this.code=r}}class ko extends Error{constructor(t="Access denied"){super(t),this.name="ForbiddenError"}}const Co=10;class So{queue=[];recentErrors=[];isProcessing=!1;batchSize=10;batchDelay=2e3;async logError(t,r,n){const i=typeof t=="string"?t:t.message;let o=i;if(n?.url){const x=String(n.url),u=n.status?` [${n.status}]`:"";o=`${i}${u} - ${x}`}const c={message:o,stack:typeof t=="string"?void 0:t.stack,url:window.location.href,component:r,level:"Error",metadata:n};this.storeRecentError(c),this.queue.push({type:"error",data:c}),this.processQueue()}async logCritical(t,r,n){const i=typeof t=="string"?t:t.message;let o=i;if(n?.url){const u=String(n.url),d=n.status?` [${n.status}]`:"";o=`${i}${d} - ${u}`}const c={message:o,stack:typeof t=="string"?void 0:t.stack,url:window.location.href,component:r,level:"Critical",metadata:n};return this.storeRecentError(c),await this.sendErrorWithResponse(c)}getRecentErrors(){return[...this.recentErrors]}clearRecentErrors(){this.recentErrors=[]}storeRecentError(t){this.recentErrors.unshift({...t,timestamp:new Date}),this.recentErrors.length>Co&&this.recentErrors.pop()}async logEvent(t,r,n){const i={event:t,category:r,data:n};this.queue.push({type:"event",data:i}),this.processQueue()}async processQueue(){if(this.isProcessing||this.queue.length===0)return;this.isProcessing=!0,await new Promise(r=>setTimeout(r,this.batchDelay));const t=this.queue.splice(0,this.batchSize);for(const r of t)try{r.type==="error"?await this.sendError(r.data):await this.sendEvent(r.data)}catch{}this.isProcessing=!1,this.queue.length>0&&this.processQueue()}async sendError(t){const r=localStorage.getItem("token");await fetch("/api/logs/client-error",{method:"POST",headers:{"Content-Type":"application/json",...r&&{Authorization:`Bearer ${r}`}},body:JSON.stringify(t)})}async sendErrorWithResponse(t){const r=localStorage.getItem("token");try{const n=await fetch("/api/logs/client-error",{method:"POST",headers:{"Content-Type":"application/json",...r&&{Authorization:`Bearer ${r}`}},body:JSON.stringify(t)});return n.ok&&n.status===200&&(await n.json()).ticketNumber||null}catch{return null}}async sendEvent(t){const r=localStorage.getItem("token");await fetch("/api/logs/client-event",{method:"POST",headers:{"Content-Type":"application/json",...r&&{Authorization:`Bearer ${r}`}},body:JSON.stringify(t)})}}const qe=new So;window.onerror=(s,t,r,n,i)=>{qe.logError(i||String(s),"window.onerror",{source:t,lineno:r,colno:n})};window.onunhandledrejection=s=>{qe.logError(s.reason instanceof Error?s.reason:String(s.reason),"unhandledrejection")};const Be=ar.create({timeout:3e4,headers:{"Content-Type":"application/json"}});Be.interceptors.request.use(s=>{const t=localStorage.getItem("token");t&&s.headers&&(s.headers.Authorization=`Bearer ${t}`);const r=crypto.randomUUID();s.headers&&(s.headers["X-Correlation-ID"]=r);const n=localStorage.getItem("i18nextLng")||navigator.language||"fr";s.headers&&(s.headers["Accept-Language"]=n);const i=localStorage.getItem("currentTenantSlug");return i&&s.headers&&!s.headers["X-Tenant-Slug"]&&(s.headers["X-Tenant-Slug"]=i),s},s=>(qe.logError(s,"apiClient.request"),Promise.reject(s)));Be.interceptors.response.use(s=>s,async s=>{const t=s.config?.headers?.["X-Correlation-ID"];if(ar.isCancel(s)||s.code==="ERR_CANCELED")return Promise.reject(s);if(!s.response){const c=new nr("Impossible de se connecter au serveur. Vérifiez votre connexion internet.");return qe.logError(c,"apiClient.response",{correlationId:t}),Promise.reject(c)}const{status:r,data:n}=s.response,i=n?.message||s.message,o=n?.code;switch(r){case 401:{const c=new Dl(i,o);qe.logError(c,"apiClient.response",{correlationId:t,url:s.config?.url,code:o});const x=s.config?.url||"",d=["/api/user/preferences","/api/auth/session-info","/api/auth/refresh","/api/navigation/menu","/api/navigation/favorites"].some(m=>x.startsWith(m));if(!window.location.pathname.includes("/login")&&!d){localStorage.removeItem("token"),localStorage.removeItem("refreshToken"),localStorage.removeItem("user");const p=o==="SESSION_EXPIRED"?"/login?reason=session_expired":"/login";window.location.href=p}return Promise.reject(c)}case 403:{const c=new ko(i),x=["/api/platform/administration/tenants/tenant-analytics/track/"],u=s.config?.url||"";return x.some(m=>u.startsWith(m))||qe.logCritical(c,"apiClient.response",{correlationId:t,url:s.config?.url,method:s.config?.method}),Promise.reject(c)}case 404:return Promise.reject(new jt(i||"Resource not found",r));case 400:return Promise.reject(new jt(i||"Invalid request",r,n?.details));case 500:case 502:case 503:case 504:{const c=new jt(i||"Server error",r);return qe.logError(c,"apiClient.response",{correlationId:t,url:s.config?.url,status:r}),Promise.reject(c)}default:{const c=new jt(i,r,n?.details);return qe.logError(c,"apiClient.response",{correlationId:t,status:r}),Promise.reject(c)}}});const oe={get:(s,t)=>Be.get(s,t).then(r=>r.data),post:(s,t,r)=>Be.post(s,t,r).then(n=>n.data),put:(s,t,r)=>Be.put(s,t,r).then(n=>n.data),patch:(s,t,r)=>Be.patch(s,t,r).then(n=>n.data),delete:(s,t)=>Be.delete(s,t).then(r=>r.data)},Is={preferences:{get:()=>oe.get("/api/user/preferences"),updateTheme:s=>oe.put("/api/user/preferences/theme",s),updateLanguage:s=>oe.put("/api/user/preferences/language",s),updateNotifications:s=>oe.put("/api/user/preferences/notifications",s)},dashboard:{getAll:(s=30,t=10)=>oe.get(`/api/platform/user/dashboard/all?period=${s}&errorLimit=${t}`),getSessionAnalytics:(s=30)=>oe.get(`/api/platform/user/dashboard/session-analytics?period=${s}`),getLoginErrors:(s=10)=>oe.get(`/api/platform/user/dashboard/login-errors?limit=${s}`),getCurrentSession:()=>oe.get("/api/platform/user/dashboard/current-session"),getDeviceStats:()=>oe.get("/api/platform/user/dashboard/device-stats"),getWeeklyStats:(s=30)=>oe.get(`/api/platform/user/dashboard/weekly-stats?period=${s}`),getHourlyStats:(s=30)=>oe.get(`/api/platform/user/dashboard/hourly-stats?period=${s}`),getApplicationUsage:(s=30)=>oe.get(`/api/platform/user/dashboard/application-usage?period=${s}`)}},To=s=>({get:(t,r)=>Be.get(t,{...r,headers:s?{...r?.headers,"X-Tenant-Slug":s}:r?.headers}).then(n=>n.data),post:(t,r,n)=>Be.post(t,r,{...n,headers:s?{...n?.headers,"X-Tenant-Slug":s}:n?.headers}).then(i=>i.data),put:(t,r,n)=>Be.put(t,r,{...n,headers:s?{...n?.headers,"X-Tenant-Slug":s}:n?.headers}).then(i=>i.data),patch:(t,r,n)=>Be.patch(t,r,{...n,headers:s?{...n?.headers,"X-Tenant-Slug":s}:n?.headers}).then(i=>i.data),delete:(t,r)=>Be.delete(t,{...r,headers:s?{...r?.headers,"X-Tenant-Slug":s}:r?.headers}).then(n=>n.data)}),lt={PasswordResetMalfunction:1,FalsePositive:2,UrgentBusinessNeed:3,TechnicalSystemError:4,SupportTicketVerified:5},lr=s=>{const t=s?To(s):oe;return{users:{getAll:r=>t.get("/api/platform/administration/users",{params:r}),getById:r=>t.get(`/api/platform/administration/users/${r}`),create:r=>t.post("/api/platform/administration/users",r),update:(r,n)=>t.put(`/api/platform/administration/users/${r}`,n),sendPasswordResetLink:r=>t.post(`/api/platform/administration/users/${r}/send-password-reset`),resetPasswordDirect:(r,n)=>t.post(`/api/platform/administration/users/${r}/reset-password-direct`,n?{temporaryPassword:n}:{}),activate:r=>t.patch(`/api/platform/administration/users/${r}/activate`),deactivate:r=>t.patch(`/api/platform/administration/users/${r}/deactivate`),unlock:(r,n)=>t.post(`/api/platform/administration/users/${r}/unlock`,n),clearFailedAttempts:r=>t.post(`/api/platform/administration/users/${r}/clear-failed-attempts`),delete:r=>t.delete(`/api/platform/administration/users/${r}`),getSessions:r=>t.get(`/api/platform/administration/users/${r}/sessions`),endAllSessions:r=>t.post(`/api/platform/administration/users/${r}/sessions/end-all`),endSession:(r,n)=>t.delete(`/api/platform/administration/users/${r}/sessions/${n}`),getActivity:r=>t.get(`/api/platform/administration/users/${r}/activity`),getCustomRole:r=>t.get(`/api/platform/administration/users/${r}/custom-role`),createCustomRole:r=>t.post(`/api/platform/administration/users/${r}/custom-role`),deleteCustomRole:r=>t.delete(`/api/platform/administration/users/${r}/custom-role`),getHistory:(r,n=50)=>t.get(`/api/platform/administration/users/${r}/history`,{params:{limit:n}}),restoreFromHistory:(r,n)=>t.post(`/api/platform/administration/users/${r}/history/${n}/restore`),getOrganizationReferences:()=>t.get("/api/platform/administration/users/organization-references"),references:{getCompanies:r=>t.get("/api/platform/administration/users/references/companies",{params:r}),getDepartments:r=>t.get("/api/platform/administration/users/references/departments",{params:r}),getJobTitles:r=>t.get("/api/platform/administration/users/references/job-titles",{params:r}),getOffices:r=>t.get("/api/platform/administration/users/references/offices",{params:r}),createCompany:(r,n)=>t.post(`/api/platform/administration/users/references/companies${n?`?tenantId=${n}`:""}`,r),createDepartment:(r,n)=>t.post(`/api/platform/administration/users/references/departments${n?`?tenantId=${n}`:""}`,r),createJobTitle:(r,n)=>t.post(`/api/platform/administration/users/references/job-titles${n?`?tenantId=${n}`:""}`,r),createOffice:(r,n)=>t.post(`/api/platform/administration/users/references/offices${n?`?tenantId=${n}`:""}`,r),updateCompany:(r,n)=>t.put(`/api/platform/administration/users/references/companies/${r}`,n),updateDepartment:(r,n)=>t.put(`/api/platform/administration/users/references/departments/${r}`,n),updateJobTitle:(r,n)=>t.put(`/api/platform/administration/users/references/job-titles/${r}`,n),updateOffice:(r,n)=>t.put(`/api/platform/administration/users/references/offices/${r}`,n),activateCompany:r=>t.patch(`/api/platform/administration/users/references/companies/${r}/activate`),activateDepartment:r=>t.patch(`/api/platform/administration/users/references/departments/${r}/activate`),activateJobTitle:r=>t.patch(`/api/platform/administration/users/references/job-titles/${r}/activate`),activateOffice:r=>t.patch(`/api/platform/administration/users/references/offices/${r}/activate`),deactivateCompany:r=>t.patch(`/api/platform/administration/users/references/companies/${r}/deactivate`),deactivateDepartment:r=>t.patch(`/api/platform/administration/users/references/departments/${r}/deactivate`),deactivateJobTitle:r=>t.patch(`/api/platform/administration/users/references/job-titles/${r}/deactivate`),deactivateOffice:r=>t.patch(`/api/platform/administration/users/references/offices/${r}/deactivate`),deleteCompany:r=>t.delete(`/api/platform/administration/users/references/companies/${r}`),deleteDepartment:r=>t.delete(`/api/platform/administration/users/references/departments/${r}`),deleteJobTitle:r=>t.delete(`/api/platform/administration/users/references/job-titles/${r}`),deleteOffice:r=>t.delete(`/api/platform/administration/users/references/offices/${r}`)},updateProfile:(r,n)=>t.put(`/api/platform/administration/users/${r}/profile`,n),updateOrganization:(r,n)=>t.put(`/api/platform/administration/users/${r}/organization`,n),updateJobInfo:(r,n)=>t.put(`/api/platform/administration/users/${r}/job-info`,n),updatePhones:(r,n)=>t.put(`/api/platform/administration/users/${r}/phones`,n),updateAddress:(r,n)=>t.put(`/api/platform/administration/users/${r}/address`,n),updateContact:(r,n)=>t.put(`/api/platform/administration/users/${r}/contact`,n),getTenants:r=>t.get(`/api/platform/administration/users/${r}/tenants`),getGroups:r=>t.get(`/api/platform/administration/users/${r}/groups`),getConsolidatedRoles:(r,n)=>{const i=n?`/api/platform/administration/users/${r}/consolidated-roles?tenantId=${n}`:`/api/platform/administration/users/${r}/consolidated-roles`;return t.get(i)},getApplicationAccess:(r,n)=>{const i=n?`/api/platform/administration/users/${r}/application-access?tenantId=${n}`:`/api/platform/administration/users/${r}/application-access`;return t.get(i)}},roles:{getAll:r=>t.get("/api/platform/administration/permissions/roles",{params:r}),getAssignable:()=>t.get("/api/platform/administration/permissions/roles",{params:{excludeCategories:"Custom",minPermissionsCount:1}}),getByApplication:r=>t.get("/api/platform/administration/permissions/roles",{params:{applicationId:r,excludeCategories:"Custom",minPermissionsCount:1}}),getById:r=>t.get(`/api/platform/administration/permissions/roles/${r}`),create:r=>t.post("/api/platform/administration/permissions/roles",r),update:(r,n)=>t.put(`/api/platform/administration/permissions/roles/${r}`,n),delete:r=>t.delete(`/api/platform/administration/permissions/roles/${r}`),assignUser:(r,n)=>t.post(`/api/platform/administration/permissions/roles/${r}/users/${n}`),removeUser:(r,n)=>t.delete(`/api/platform/administration/permissions/roles/${r}/users/${n}`),getGroups:r=>t.get(`/api/platform/administration/permissions/roles/${r}/groups`),assignGroup:(r,n)=>t.post(`/api/platform/administration/permissions/roles/${r}/groups/${n}`),removeGroup:(r,n)=>t.delete(`/api/platform/administration/permissions/roles/${r}/groups/${n}`),getTranslations:r=>t.get(`/api/platform/administration/permissions/roles/${r}/translations`),upsertTranslation:(r,n,i)=>t.put(`/api/platform/administration/permissions/roles/${r}/translations/${n}`,i),deleteTranslation:(r,n)=>t.delete(`/api/platform/administration/permissions/roles/${r}/translations/${n}`)},permissions:{getAll:r=>t.get("/api/platform/administration/permissions",{params:r}),getById:r=>t.get(`/api/platform/administration/permissions/${r}`),getTree:()=>t.get("/api/platform/administration/permissions/tree"),getMatrix:()=>t.get("/api/platform/administration/permissions/matrix"),delete:r=>t.delete(`/api/platform/administration/permissions/${r}`)},applications:{getAll:r=>t.get("/api/platform/administration/applications",{params:r}),getById:r=>t.get(`/api/platform/administration/applications/${r}`),getContexts:()=>t.get("/api/platform/administration/applications/contexts"),update:(r,n)=>t.put(`/api/platform/administration/applications/${r}`,n),activate:r=>t.patch(`/api/platform/administration/applications/${r}/activate`),deactivate:r=>t.patch(`/api/platform/administration/applications/${r}/deactivate`),getModules:r=>t.get(`/api/platform/administration/applications/${r}/modules`),updateModule:(r,n,i)=>t.put(`/api/platform/administration/applications/${r}/modules/${n}`,i),getModuleSections:(r,n)=>t.get(`/api/platform/administration/applications/${r}/modules/${n}/sections`),reorderModules:(r,n)=>t.put(`/api/platform/administration/applications/${r}/modules/reorder`,{items:n}),reorderSections:(r,n,i)=>t.put(`/api/platform/administration/applications/${r}/modules/${n}/sections/reorder`,{items:i}),getTenants:r=>t.get(`/api/platform/administration/applications/${r}/tenants`),getAvailableTenants:r=>t.get(`/api/platform/administration/applications/${r}/tenants/available`),assignToTenant:(r,n,i)=>t.post(`/api/platform/administration/applications/${r}/tenants/${n}`,i?{accessLevel:i}:{}),removeFromTenant:(r,n)=>t.delete(`/api/platform/administration/applications/${r}/tenants/${n}`),updateTenantAccessLevel:(r,n,i)=>t.patch(`/api/platform/administration/applications/${r}/tenants/${n}/access-level`,{accessLevel:i}),bulkAssignTenants:(r,n)=>t.post(`/api/platform/administration/applications/${r}/tenants/bulk`,n)},dashboard:{getOverview:(r=30,n)=>t.get("/api/platform/administration/users/dashboard/overview",{params:{days:r},signal:n?.signal}),getByStatus:r=>t.get("/api/platform/administration/users/dashboard/by-status",{signal:r?.signal}),getByRole:r=>t.get("/api/platform/administration/users/dashboard/by-role",{signal:r?.signal}),getByType:r=>t.get("/api/platform/administration/users/dashboard/by-type",{signal:r?.signal}),getLoginActivity:(r=30,n)=>t.get("/api/platform/administration/users/dashboard/login-activity",{params:{days:r},signal:n?.signal}),getTrends:(r=30,n)=>t.get("/api/platform/administration/users/dashboard/trends",{params:{days:r},signal:n?.signal}),getRecentUsers:(r=10,n)=>t.get("/api/platform/administration/users/dashboard/recent-users",{params:{limit:r},signal:n?.signal}),getSecurityAlerts:(r=3,n=24,i)=>t.get("/api/platform/administration/users/dashboard/security-alerts",{params:{threshold:r,hours:n},signal:i?.signal}),getActiveSessions:r=>t.get("/api/platform/administration/users/dashboard/active-sessions",{signal:r?.signal}),getLatestActiveSessions:(r=5,n)=>t.get("/api/platform/administration/users/dashboard/latest-active-sessions",{params:{limit:r},signal:n?.signal})},settings:{getAll:()=>t.get("/api/platform/administration/configuration/settings"),getByCategory:r=>t.get(`/api/platform/administration/configuration/settings/${r}`),get:(r,n)=>t.get(`/api/platform/administration/configuration/settings/${r}/${n}`),update:(r,n,i)=>t.put(`/api/platform/administration/configuration/settings/${r}/${n}`,{value:i}),reset:(r,n)=>t.post(`/api/platform/administration/configuration/settings/${r}/${n}/reset`),getHistory:(r,n)=>t.get(`/api/platform/administration/configuration/settings/${r}/${n}/history`),getCategories:()=>t.get("/api/platform/administration/configuration/settings/categories")},tenants:{getConfig:()=>t.get("/api/platform/administration/tenants/config"),getAll:async r=>(await t.get("/api/platform/administration/tenants",{params:r})).items,getById:r=>t.get(`/api/platform/administration/tenants/${r}`),createB2C:r=>t.post("/api/platform/administration/tenants/b2c",r),createB2B:r=>t.post("/api/platform/administration/tenants/b2b",r),update:(r,n)=>t.put(`/api/platform/administration/tenants/${r}`,n),delete:r=>t.delete(`/api/platform/administration/tenants/${r}`),activate:r=>t.post(`/api/platform/administration/tenants/${r}/activate`),suspend:r=>t.post(`/api/platform/administration/tenants/${r}/suspend`),archive:r=>t.delete(`/api/platform/administration/tenants/${r}`),checkSlugAvailable:r=>t.get(`/api/platform/administration/tenants/check-slug/${r}`),getMembers:r=>t.get(`/api/platform/administration/tenants/${r}/members`),getMember:(r,n)=>t.get(`/api/platform/administration/tenants/${r}/members/${n}`),addMember:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/members`,n),removeMember:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/members/${n}`),setMemberDefault:(r,n)=>t.patch(`/api/platform/administration/tenants/${r}/members/${n}/set-default`),transferOwnership:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/members/transfer-ownership`,{toUserId:n}),assignRole:(r,n,i)=>t.post(`/api/platform/administration/tenants/${r}/members/${n}/roles/${i}`),removeRole:(r,n,i)=>t.delete(`/api/platform/administration/tenants/${r}/members/${n}/roles/${i}`),assignMemberRoles:(r,n,i)=>t.put(`/api/platform/administration/tenants/${r}/members/${n}/roles`,{roleIds:i}),getMemberCustomRole:(r,n)=>t.get(`/api/platform/administration/tenants/${r}/members/${n}/custom-role`),createMemberCustomRole:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/members/${n}/custom-role`),deleteMemberCustomRole:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/members/${n}/custom-role`),getTenantRoles:r=>t.get(`/api/platform/administration/tenants/${r}/roles`),getGroups:r=>t.get(`/api/platform/administration/tenants/${r}/groups`),getAvailableGroups:r=>t.get(`/api/platform/administration/tenants/${r}/groups/available`),addGroupToTenant:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/groups`,{groupId:n}),removeGroupFromTenant:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/groups/${n}`),getApplications:r=>t.get(`/api/platform/administration/tenants/${r}/applications`),getAvailableApplications:r=>t.get(`/api/platform/administration/tenants/${r}/applications/available`),assignApplication:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/applications/${n}`),removeApplication:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/applications/${n}`),bulkAssignApplications:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/applications/bulk`,n),toggleApplication:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/applications/${n}/toggle`,{isActive:i}),updateApplicationAccessLevel:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/applications/${n}/access-level`,{accessLevel:i}),getModules:r=>t.get(`/api/platform/administration/tenants/${r}/modules`),getAvailableModules:r=>t.get(`/api/platform/administration/tenants/${r}/modules/available`),assignModule:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/modules/${n}`),removeModule:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/modules/${n}`),toggleModule:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/modules/${n}/toggle`,{isActive:i}),getSections:r=>t.get(`/api/platform/administration/tenants/${r}/sections`),getAvailableSections:r=>t.get(`/api/platform/administration/tenants/${r}/sections/available`),assignSection:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/sections/${n}`),removeSection:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/sections/${n}`),toggleSection:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/sections/${n}/toggle`,{isActive:i}),getModulesWithSections:(r,n)=>t.get(`/api/platform/administration/tenants/${r}/applications/${n}/modules-tree`),linkOrganisation:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/organisation`,{organisationId:n}),unlinkOrganisation:r=>t.delete(`/api/platform/administration/tenants/${r}/organisation`)},templates:{getAll:()=>t.get("/api/platform/administration/tenants/templates"),getById:r=>t.get(`/api/platform/administration/tenants/templates/${r}`),create:r=>t.post("/api/platform/administration/tenants/templates",r),update:(r,n)=>t.put(`/api/platform/administration/tenants/templates/${r}`,n),delete:r=>t.delete(`/api/platform/administration/tenants/templates/${r}`),assignApplication:(r,n)=>t.post(`/api/platform/administration/tenants/templates/${r}/applications/${n}`),removeApplication:(r,n)=>t.delete(`/api/platform/administration/tenants/templates/${r}/applications/${n}`),bulkAssignApplications:(r,n)=>t.post(`/api/platform/administration/tenants/templates/${r}/applications/bulk`,n),getTenants:r=>t.get(`/api/platform/administration/tenants/templates/${r}/tenants`),getApplications:r=>t.get(`/api/platform/administration/tenants/templates/${r}/applications`),getAvailableApplications:r=>t.get(`/api/platform/administration/tenants/templates/${r}/applications/available`),updateApplicationAccessLevel:(r,n,i)=>t.patch(`/api/platform/administration/tenants/templates/${r}/applications/${n}/access-level`,{accessLevel:i}),getApplicationModules:(r,n)=>t.get(`/api/platform/administration/tenants/templates/${r}/applications/${n}/modules`),updateApplicationModules:(r,n,i)=>t.put(`/api/platform/administration/tenants/templates/${r}/applications/${n}/modules`,i)},organisations:{getAvailable:r=>t.get("/api/organisations/available",{params:r?{search:r}:void 0}),getById:r=>t.get(`/api/organisations/${r}`),create:r=>t.post("/api/organisations",r),lookup:(r,n)=>t.get("/api/organisations/lookup",{params:{countryCode:r,identifier:n}})},myTenants:{getAll:r=>t.get("/api/platform/administration/tenants/my",{params:r?{search:r}:void 0}),getDefault:()=>t.get("/api/platform/administration/tenants/my/default"),setDefault:r=>t.post(`/api/platform/administration/tenants/${r}/set-default`),clearDefault:()=>t.delete("/api/platform/administration/tenants/clear-default"),getFavorites:()=>t.get("/api/user/preferences/tenant-favorites"),addFavorite:r=>t.post(`/api/user/preferences/tenant-favorites/${r}`),removeFavorite:r=>t.delete(`/api/user/preferences/tenant-favorites/${r}`),recordRecent:r=>t.post(`/api/user/preferences/tenant-recent/${r}`)},preferences:{get:()=>t.get("/api/user/preferences"),getGlobal:()=>t.get("/api/user/preferences/global"),getForTenant:r=>t.get(`/api/user/preferences/for-tenant/${r}`),getThemeOverrides:()=>t.get("/api/user/preferences/theme-overrides"),deleteTenantOverride:()=>t.delete("/api/user/preferences/tenant-override"),applyToTenant:()=>t.post("/api/user/preferences/apply-to-tenant")}}},le=lr(),as=(s,t,r)=>{const n=s[t];return n?typeof n=="function"?n():Promise.resolve(n):new Promise((i,o)=>{(typeof queueMicrotask=="function"?queueMicrotask:setTimeout)(o.bind(null,new Error("Unknown variable dynamic import: "+t+(t.split("/").length!==r?". Note that variables only represent file names one level deep.":""))))})},Ll=async s=>{if(!s)return null;try{const[t,r,n,i,o,c,x,u,d,m,p,h,v]=await Promise.all([as(Object.assign({"./locales/de/common.json":()=>Promise.resolve().then(()=>require("./common-B6hOC7Z1.cjs")),"./locales/en/common.json":()=>Promise.resolve().then(()=>require("./common-WTcRPHwd.cjs")),"./locales/fr/common.json":()=>Promise.resolve().then(()=>require("./common-CrmmeiUS.cjs")),"./locales/it/common.json":()=>Promise.resolve().then(()=>require("./common-B7ae-mQA.cjs"))}),`./locales/${s}/common.json`,4),as(Object.assign({"./locales/de/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-BIfBA5zU.cjs")),"./locales/en/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-Djc1f5z5.cjs")),"./locales/fr/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-BVdU6a5A.cjs")),"./locales/it/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-BgT6W7T7.cjs"))}),`./locales/${s}/navigation.json`,4),as(Object.assign({"./locales/de/auth.json":()=>Promise.resolve().then(()=>require("./auth-C5zpZ9k7.cjs")),"./locales/en/auth.json":()=>Promise.resolve().then(()=>require("./auth-DL47kvnl.cjs")),"./locales/fr/auth.json":()=>Promise.resolve().then(()=>require("./auth-B-hELPDB.cjs")),"./locales/it/auth.json":()=>Promise.resolve().then(()=>require("./auth-CyPkCta2.cjs"))}),`./locales/${s}/auth.json`,4),as(Object.assign({"./locales/de/admin.json":()=>Promise.resolve().then(()=>require("./admin-wwcGfjWu.cjs")),"./locales/en/admin.json":()=>Promise.resolve().then(()=>require("./admin-CylPg5D5.cjs")),"./locales/fr/admin.json":()=>Promise.resolve().then(()=>require("./admin-4VkTpwkH.cjs")),"./locales/it/admin.json":()=>Promise.resolve().then(()=>require("./admin-CxYCOIEX.cjs"))}),`./locales/${s}/admin.json`,4),as(Object.assign({"./locales/de/support.json":()=>Promise.resolve().then(()=>require("./support-CzyyqmKL.cjs")),"./locales/en/support.json":()=>Promise.resolve().then(()=>require("./support-uf0CffL4.cjs")),"./locales/fr/support.json":()=>Promise.resolve().then(()=>require("./support-BeGp6i4F.cjs")),"./locales/it/support.json":()=>Promise.resolve().then(()=>require("./support-B1RXel78.cjs"))}),`./locales/${s}/support.json`,4),as(Object.assign({"./locales/de/docs.json":()=>Promise.resolve().then(()=>require("./docs-CikbZEP3.cjs")),"./locales/en/docs.json":()=>Promise.resolve().then(()=>require("./docs-eIYCBYJf.cjs")),"./locales/fr/docs.json":()=>Promise.resolve().then(()=>require("./docs-dAIQDVc3.cjs")),"./locales/it/docs.json":()=>Promise.resolve().then(()=>require("./docs-DaN5xRMQ.cjs"))}),`./locales/${s}/docs.json`,4),as(Object.assign({"./locales/de/ai.json":()=>Promise.resolve().then(()=>require("./ai-BIrcm_pp.cjs")),"./locales/en/ai.json":()=>Promise.resolve().then(()=>require("./ai-B8deAoMx.cjs")),"./locales/fr/ai.json":()=>Promise.resolve().then(()=>require("./ai-DqrFlpsS.cjs")),"./locales/it/ai.json":()=>Promise.resolve().then(()=>require("./ai-CnpjG8DZ.cjs"))}),`./locales/${s}/ai.json`,4),as(Object.assign({"./locales/de/communications.json":()=>Promise.resolve().then(()=>require("./communications-DBbKXpf1.cjs")),"./locales/en/communications.json":()=>Promise.resolve().then(()=>require("./communications-BPsS3Vfm.cjs")),"./locales/fr/communications.json":()=>Promise.resolve().then(()=>require("./communications-DElJaoVw.cjs")),"./locales/it/communications.json":()=>Promise.resolve().then(()=>require("./communications-BKaku0MU.cjs"))}),`./locales/${s}/communications.json`,4),as(Object.assign({"./locales/de/entra.json":()=>Promise.resolve().then(()=>require("./entra-BadKCc7Y.cjs")),"./locales/en/entra.json":()=>Promise.resolve().then(()=>require("./entra-CfLYpxKq.cjs")),"./locales/fr/entra.json":()=>Promise.resolve().then(()=>require("./entra-Bc0Dwf7d.cjs")),"./locales/it/entra.json":()=>Promise.resolve().then(()=>require("./entra-DDgx1JoT.cjs"))}),`./locales/${s}/entra.json`,4),as(Object.assign({"./locales/en/structure.json":()=>Promise.resolve().then(()=>require("./structure-BL5cd83u.cjs")),"./locales/fr/structure.json":()=>Promise.resolve().then(()=>require("./structure-BblXL_QG.cjs"))}),`./locales/${s}/structure.json`,4).catch(()=>({default:{}})),as(Object.assign({"./locales/de/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-DLJ9mTYQ.cjs")),"./locales/en/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-pkUX3R0G.cjs")),"./locales/fr/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-Di_IL1wh.cjs")),"./locales/it/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-B65OLntJ.cjs"))}),`./locales/${s}/preferences.json`,4).catch(()=>({default:{}})),as(Object.assign({"./locales/de/groups.json":()=>Promise.resolve().then(()=>require("./groups-BcmmnEo6.cjs")),"./locales/en/groups.json":()=>Promise.resolve().then(()=>require("./groups-BqOvsO0R.cjs")),"./locales/fr/groups.json":()=>Promise.resolve().then(()=>require("./groups-CzMRaBiO.cjs")),"./locales/it/groups.json":()=>Promise.resolve().then(()=>require("./groups-Blo6Xw1w.cjs"))}),`./locales/${s}/groups.json`,4).catch(()=>({default:{}})),as(Object.assign({"./locales/en/ba.json":()=>Promise.resolve().then(()=>require("./ba-9HglDm-t.cjs")),"./locales/fr/ba.json":()=>Promise.resolve().then(()=>require("./ba-CXlHUyjN.cjs"))}),`./locales/${s}/ba.json`,4).catch(()=>({default:{}}))]);return{common:t.default,navigation:r.default,auth:n.default,admin:i.default,support:o.default,docs:c.default,ai:x.default,communications:u.default,entra:d.default,structure:m.default||{},preferences:p.default||{},groups:h.default||{},ba:v.default||{}}}catch(t){return console.warn(`Failed to load language: ${s}`,t),null}},Ao={},Ro=()=>{const s=localStorage.getItem("i18nextLng");if(s&&["en","fr","de","it"].includes(s))return s;const t=navigator.language.split("-")[0];return["en","fr","de","it"].includes(t)?t:"en"},Ha=Ro();Ks.use(lo).use(ne.initReactI18next).init({resources:Ao,lng:Ha,fallbackLng:"en",defaultNS:"common",ns:["common","navigation","auth","admin","support","docs","ai","communications","entra","structure","preferences","groups","ba"],interpolation:{escapeValue:!1},detection:{order:["localStorage","navigator","htmlTag"],caches:["localStorage"]}});Ll(Ha).then(s=>{s&&Object.entries(s).forEach(([t,r])=>{Ks.addResourceBundle(Ha,t,r,!0,!0)})});const ir=async s=>{if(!Ks.hasResourceBundle(s,"common")){const t=await Ll(s);t&&Object.entries(t).forEach(([r,n])=>{Ks.addResourceBundle(s,r,n,!0,!0)})}return Ks.changeLanguage(s)},Pl=l.createContext(void 0);function Io(){if(typeof window>"u")return xt;try{const t=localStorage.getItem(El);if(t){const r=JSON.parse(t);return console.log("[ThemeContext] Loaded from localStorage:",{mode:r.mode,accentColorKey:r.accentColorKey,borderRadius:r.borderRadius,itemPaletteKey:r.itemPaletteKey}),{...xt,...r,borderRadius:{...xt.borderRadius,...r.borderRadius},itemPaletteKey:r.itemPaletteKey||rr,colors:{light:Ws(r.accentColorKey||"indigo"),dark:Xs(r.accentColorKey||"indigo")}}}}catch{console.warn("[ThemeContext] Failed to load theme config from localStorage")}const s=window.matchMedia("(prefers-color-scheme: dark)").matches;return console.log("[ThemeContext] No localStorage, using system preference:",s?"dark":"light"),{...xt,mode:s?"dark":"light"}}function yt(s){const t=s.accentColorKey||"indigo",r=s.borderRadius;return{mode:s.theme||"dark",accentColorKey:t,borderRadius:{card:r?.card||"large",button:r?.button||"medium",badge:r?.badge||"medium",input:r?.input||"medium",modal:r?.modal||"xlarge",menuItem:r?.menuItem||"medium"},itemPaletteKey:s.itemPaletteKey||rr,colors:{light:Ws(t),dark:Xs(t)}}}function Eo(s){const t=document.documentElement,r=s.mode==="dark"?s.colors.dark:s.colors.light,n=os[s.accentColorKey]?.shades||os.indigo.shades,i=_s[s.itemPaletteKey]||_s.neutral,o=s.mode==="dark"?i.colors.dark:i.colors.light;console.log("[applyThemeToDocument] Applying theme:",{accentColorKey:s.accentColorKey,itemPaletteKey:s.itemPaletteKey,mode:s.mode}),s.mode==="dark"?t.classList.add("dark"):t.classList.remove("dark"),t.style.setProperty("--radius-card",fs[s.borderRadius.card]),t.style.setProperty("--radius-button",fs[s.borderRadius.button]),t.style.setProperty("--radius-badge",fs[s.borderRadius.badge]),t.style.setProperty("--radius-input",fs[s.borderRadius.input]),t.style.setProperty("--radius-modal",fs[s.borderRadius.modal]),t.style.setProperty("--radius-menu-item",fs[s.borderRadius.menuItem]),Object.entries(n).forEach(([c,x])=>{t.style.setProperty(`--color-accent-${c}`,x)}),t.style.setProperty("--item-color-light",o.light),t.style.setProperty("--item-color-medium",o.medium),t.style.setProperty("--item-color-dark",o.dark),t.style.setProperty("--item-color-border",o.border),t.style.setProperty("--bg-app",r.backgrounds.app),t.style.setProperty("--bg-primary",r.backgrounds.primary),t.style.setProperty("--bg-secondary",r.backgrounds.secondary),t.style.setProperty("--bg-tertiary",r.backgrounds.tertiary),t.style.setProperty("--bg-card",r.backgrounds.card),t.style.setProperty("--bg-hover",r.backgrounds.hover),t.style.setProperty("--bg-active",r.backgrounds.active),t.style.setProperty("--text-primary",r.text.primary),t.style.setProperty("--text-secondary",r.text.secondary),t.style.setProperty("--text-tertiary",r.text.tertiary),t.style.setProperty("--text-muted",r.text.muted),t.style.setProperty("--text-inverse",r.text.inverse),t.style.setProperty("--border-color",r.border.default),t.style.setProperty("--border-subtle",r.border.subtle),t.style.setProperty("--border-strong",r.border.strong),t.style.setProperty("--success-bg",r.status.success.bg),t.style.setProperty("--success-text",r.status.success.text),t.style.setProperty("--success-border",r.status.success.border),t.style.setProperty("--success-dot",r.status.success.dot),t.style.setProperty("--warning-bg",r.status.warning.bg),t.style.setProperty("--warning-text",r.status.warning.text),t.style.setProperty("--warning-border",r.status.warning.border),t.style.setProperty("--warning-dot",r.status.warning.dot),t.style.setProperty("--error-bg",r.status.error.bg),t.style.setProperty("--error-text",r.status.error.text),t.style.setProperty("--error-border",r.status.error.border),t.style.setProperty("--error-dot",r.status.error.dot),t.style.setProperty("--info-bg",r.status.info.bg),t.style.setProperty("--info-text",r.status.info.text),t.style.setProperty("--info-border",r.status.info.border),t.style.setProperty("--info-dot",r.status.info.dot),t.style.setProperty("--accent-bg",r.accentTransparent.bg),t.style.setProperty("--accent-text",r.accentTransparent.text),t.style.setProperty("--accent-border",r.accentTransparent.border)}function $l({children:s}){const[t,r]=l.useState(Io),[n,i]=l.useState(!1),[o,c]=l.useState(null),[x,u]=l.useState(void 0),[d,m]=l.useState([]),{i18n:p}=ne.useTranslation(),h=l.useRef(null),v=l.useRef(!0),b=l.useRef(!1),g=l.useRef(!1),j=l.useCallback(async(X,O=void 0)=>{if(!localStorage.getItem("token")){console.log("[ThemeContext] Skipping server sync - no token");return}if(g.current){console.log("[ThemeContext] Skipping save - tenant switch in progress (in saveToServer)");return}let K=null;const $=localStorage.getItem("currentTenantId");if(O===void 0)$?(console.log("[ThemeContext] Scope not initialized, using current tenant:",$),K=$):(console.log("[ThemeContext] No tenant selected, saving to GLOBAL"),K=null);else{if(O!==null&&$&&O!==$){console.log("[ThemeContext] Aborting save - tenant mismatch (target: %s, current: %s)",O,$);return}K=O}try{i(!0),console.log("[ThemeContext] 🔄 SAVING theme to server:",{targetTenantId:K,mode:X.mode,accentColorKey:X.accentColorKey,itemPaletteKey:X.itemPaletteKey,borderRadius:X.borderRadius}),await Is.preferences.updateTheme({mode:X.mode,accentColorKey:X.accentColorKey,borderRadius:{card:X.borderRadius.card,button:X.borderRadius.button,badge:X.borderRadius.badge,input:X.borderRadius.input,modal:X.borderRadius.modal,menuItem:X.borderRadius.menuItem},itemPaletteKey:X.itemPaletteKey,targetTenantId:K}),console.log("[ThemeContext] ✅ Theme saved successfully to tenant:",K||"GLOBAL"),K&&!d.includes(K)&&m(E=>[...E,K])}catch(E){console.error("[ThemeContext] ❌ Failed to save theme to server:",{error:E,targetTenantId:K,mode:X.mode,accentColorKey:X.accentColorKey,localStorage_currentTenantId:localStorage.getItem("currentTenantId"),localStorage_currentTenantSlug:localStorage.getItem("currentTenantSlug")})}finally{i(!1)}},[d]),w=l.useCallback((X,O=void 0)=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{j(X,O)},1e3)},[j]);l.useLayoutEffect(()=>{Eo(t)},[t]),l.useEffect(()=>{const X={mode:t.mode,borderRadius:t.borderRadius,accentColorKey:t.accentColorKey,itemPaletteKey:t.itemPaletteKey};localStorage.setItem(El,JSON.stringify(X)),console.log("[ThemeContext] Config changed:",{mode:t.mode,accentColorKey:t.accentColorKey,itemPaletteKey:t.itemPaletteKey,isInitialLoad:v.current,isSwitchingTenant:g.current,selectedThemeTenant:x,isThemeScopeInitialized:b.current,currentTenantIdInStorage:localStorage.getItem("currentTenantId")}),g.current?console.log("[ThemeContext] Skipping save - tenant switch in progress"):v.current?console.log("[ThemeContext] Skipping save - initial load"):(console.log("[ThemeContext] Triggering debounced save to tenant:",x),w(t,x)),v.current=!1},[t,w,x]),l.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const f=l.useCallback(async X=>{const O=localStorage.getItem("token"),U=localStorage.getItem("currentTenantSlug");if(!O){console.log("[ThemeContext] No token found, skipping server load");return}const K=X==="global";if(!K&&!U){console.log("[ThemeContext] No tenant slug found, skipping server load (not global scope)");return}try{i(!0),console.log("[ThemeContext] Loading preferences from server...",{forceScope:X,loadGlobalOnly:K,tenantSlug:U||"GLOBAL"});const $=K?await le.preferences.getGlobal():await le.preferences.get();console.log("[ThemeContext] Received preferences from server:",{theme:$.theme,accentColorKey:$.accentColorKey,borderRadius:$.borderRadius,itemPaletteKey:$.itemPaletteKey,scope:$.scope}),c($.scope);const E=yt($);console.log("[ThemeContext] Converted to config:",{mode:E.mode,accentColorKey:E.accentColorKey,borderRadius:E.borderRadius,itemPaletteKey:E.itemPaletteKey}),v.current=!0,r(E),b.current=!0,console.log("[ThemeContext] Theme applied from server successfully (scope: %s)",$.scope.effectiveScope),$.language&&$.language!==p.language&&(ir($.language),document.documentElement.lang=$.language)}catch($){console.error("[ThemeContext] Failed to load theme from server:",$),console.warn("Using localStorage theme as fallback")}finally{i(!1)}},[p]),N=l.useCallback(async()=>{const X=localStorage.getItem("token"),O=localStorage.getItem("currentTenantSlug");if(!X||!O){console.log("[ThemeContext] Cannot apply to tenant - no auth or tenant context");return}try{i(!0),console.log("[ThemeContext] Creating tenant-specific preferences...");const U=await le.preferences.applyToTenant();c(U.scope),console.log("[ThemeContext] Tenant-specific preferences created successfully")}catch(U){throw console.error("[ThemeContext] Failed to create tenant-specific preferences:",U),U}finally{i(!1)}},[]),k=l.useCallback(async()=>{const X=localStorage.getItem("token"),O=localStorage.getItem("currentTenantSlug");if(!X||!O){console.log("[ThemeContext] Cannot reset to global - no auth or tenant context");return}try{i(!0),console.log("[ThemeContext] Deleting tenant-specific preferences...");const U=await le.preferences.deleteTenantOverride();c(U.scope);const K=yt(U);v.current=!0,r(K),console.log("[ThemeContext] Reverted to global preferences successfully")}catch(U){throw console.error("[ThemeContext] Failed to delete tenant-specific preferences:",U),U}finally{i(!1)}},[]),C=l.useCallback(async()=>{if(localStorage.getItem("token"))try{const O=await le.preferences.getThemeOverrides();m(O),console.log("[ThemeContext] Loaded tenant overrides:",O.length)}catch(O){console.error("[ThemeContext] Failed to load tenant overrides:",O)}},[]),y=l.useCallback(async(X,O=!1)=>{if(h.current&&(console.log("[ThemeContext] Clearing pending save due to tenant switch"),clearTimeout(h.current),h.current=null),g.current=!0,b.current=!0,v.current=!0,u(X),O){console.log("[ThemeContext] Scope set to",X||"GLOBAL","(skipLoad=true, not loading from server)"),g.current=!1;return}if(!localStorage.getItem("token")){g.current=!1;return}try{if(i(!0),X===null){console.log("[ThemeContext] Loading global-only preferences...");const K=await le.preferences.getGlobal();c(K.scope);const $=yt(K);v.current=!0,r($)}else{console.log("[ThemeContext] Loading preferences for tenant:",X);const K=await le.preferences.getForTenant(X);c(K.scope);const $=yt(K);v.current=!0,r($)}}catch(K){console.error("[ThemeContext] Failed to load preferences for tenant:",K)}finally{i(!1),g.current=!1}},[]),A=l.useCallback(()=>{r(X=>({...X,mode:X.mode==="light"?"dark":"light",colors:{light:Ws(X.accentColorKey),dark:Xs(X.accentColorKey)}}))},[]),D=l.useCallback(X=>{console.log("[ThemeContext] setMode called with:",X),r(O=>({...O,mode:X}))},[]),R=l.useCallback((X,O)=>{r(U=>({...U,borderRadius:{...U.borderRadius,[X]:O}}))},[]),L=l.useCallback(X=>{console.log("[ThemeContext] setAccentColor called with:",X),os[X]&&r(O=>({...O,accentColorKey:X,colors:{light:Ws(X),dark:Xs(X)}}))},[]),S=l.useCallback(X=>{_s[X]&&r(O=>({...O,itemPaletteKey:X}))},[]),T=l.useCallback(X=>{r(O=>{const U=X.accentColorKey||O.accentColorKey;return{...O,...X,borderRadius:{...O.borderRadius,...X.borderRadius},accentColorKey:U,itemPaletteKey:X.itemPaletteKey||O.itemPaletteKey,colors:{light:Ws(U),dark:Xs(U)}}})},[]),I=l.useCallback(()=>{r(xt)},[]),M=l.useCallback(X=>fs[t.borderRadius[X]],[t.borderRadius]);return e.jsx(Pl.Provider,{value:{config:t,mode:t.mode,toggleMode:A,setMode:D,setBorderRadius:R,setAccentColor:L,setItemPalette:S,applyPreset:T,resetToDefault:I,getBorderRadius:M,loadFromServer:f,isSyncing:n,scopeInfo:o,applyToTenant:N,resetToGlobal:k,selectedThemeTenant:x,setSelectedThemeTenant:y,tenantOverrides:d,loadTenantOverrides:C},children:s})}function et(){const s=l.useContext(Pl);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s}let it=null,Ds=null;const Do={async getFeatureConfig(s){return it||Ds||(Ds=(async()=>{try{return it=(await ar.get("/api/config/features",{timeout:1e4,signal:s,headers:{"Content-Type":"application/json"}})).data,it}finally{Ds=null}})(),Ds)},clearCache(){it=null,Ds=null}},Ml=l.createContext(void 0);function Lo({children:s}){const[t,r]=l.useState(null),[n,i]=l.useState(!0);l.useEffect(()=>{const c=new AbortController;return Do.getFeatureConfig(c.signal).then(x=>{c.signal.aborted||r(x)}).catch(x=>{x.name==="CanceledError"||c.signal.aborted||(console.error("Failed to load feature config:",x),r({multiTenantEnabled:!0,enableB2B:!0,enableB2C:!0,useUrlRouting:!0,systemTenantSlug:null,systemTenantName:null}))}).finally(()=>{c.signal.aborted||i(!1)}),()=>c.abort()},[]);const o={config:t,isLoading:n,isMultiTenant:t?.multiTenantEnabled??!0,isSingleTenant:t?!t.multiTenantEnabled:!1,isHybridMode:t?.multiTenantEnabled===!0&&t?.enableB2B===!1&&t?.enableB2C===!0,enableB2B:t?.enableB2B??!0,enableB2C:t?.enableB2C??!0,useUrlRouting:t?.useUrlRouting??!0,systemTenantSlug:t?.systemTenantSlug??null,systemTenantName:t?.systemTenantName??null};return e.jsx(Ml.Provider,{value:o,children:s})}function vt(){const s=l.useContext(Ml);if(!s)throw new Error("useFeatureConfig must be used within FeatureConfigProvider");return s}function Fl(s,t){const r=s.toLowerCase(),n=t.toLowerCase();if(r==="*"||r===n)return!0;if(r.endsWith(".*")){const i=r.slice(0,-2);return n.startsWith(i+".")||n===i}return!1}function Ul(s,t){return s.includes("*")||t.includes("Super Administrator")}const or=l.createContext(void 0),Ls="token",Ps="user";function Ar(s){const t=s.split("/").filter(Boolean);return t.length===0||["login","callback","logout","onboarding","system"].includes(t[0])?null:t[0]}function Bl({children:s}){const[t,r]=l.useState(()=>{if(typeof window<"u"){const v=localStorage.getItem(Ps);if(v)try{return JSON.parse(v)}catch{return null}}return null}),[n,i]=l.useState(!0),[o,c]=l.useState(()=>typeof window<"u"?Ar(window.location.pathname):null),x=[],u=l.useCallback((v,b)=>{localStorage.setItem(Ls,v),localStorage.setItem(Ps,JSON.stringify(b)),r(b)},[]),d=l.useCallback(async()=>{try{localStorage.getItem(Ls)&&await oe.post("/api/auth/logout")}catch{}localStorage.removeItem(Ls),localStorage.removeItem(Ps),r(null),window.location.href="/login"},[]),m=l.useCallback(v=>{c(v)},[]),p=l.useCallback(v=>{if(!t)return!1;if(Ul(t.permissions,t.roles)||t.permissions.includes(v))return!0;for(const b of t.permissions)if(Fl(b,v))return!0;return!1},[t]),h=l.useCallback(async()=>{if(localStorage.getItem(Ls))try{const b=await oe.get("/api/auth/me");r(b),localStorage.setItem(Ps,JSON.stringify(b))}catch(b){console.error("Failed to refresh permissions:",b)}},[]);return l.useEffect(()=>{localStorage.getItem(Ls)&&!t?oe.get("/api/auth/me").then(b=>{r(b),localStorage.setItem(Ps,JSON.stringify(b))}).catch(()=>{localStorage.removeItem(Ls),localStorage.removeItem(Ps)}).finally(()=>i(!1)):i(!1)},[t]),l.useEffect(()=>{const v=()=>{c(Ar(window.location.pathname))};return window.addEventListener("popstate",v),()=>window.removeEventListener("popstate",v)},[]),e.jsx(or.Provider,{value:{user:t,isAuthenticated:!!t,isLoading:n,availableContexts:x,currentContext:o,login:u,logout:d,setCurrentContext:m,hasPermission:p,refreshPermissions:h},children:s})}function Ke(){const s=l.useContext(or);if(s===void 0)throw new Error("useAuth must be used within an AuthProvider");return s}function Po(){return l.useContext(or)??null}const Ka={"business.support-client.my-tickets":{navRoute:"business.support-client.my-tickets",api:"/api/business/support-client/my-tickets",web:"/business/support-client/my-tickets",permissions:[],controller:"MyTickets",methods:["GET","POST"]},"platform.administration.ai.dashboard":{navRoute:"platform.administration.ai.dashboard",api:"/api/platform/administration/ai/dashboard",web:"/platform/administration/ai/dashboard",permissions:[],controller:"AiDashboard",methods:[]},"platform.administration.ai.instances":{navRoute:"platform.administration.ai.instances",api:"/api/platform/administration/ai/instances",web:"/platform/administration/ai/instances",permissions:[],controller:"AiProviderInstances",methods:["GET","POST"]},"platform.administration.ai.prompts":{navRoute:"platform.administration.ai.prompts",api:"/api/platform/administration/ai/prompts",web:"/platform/administration/ai/prompts",permissions:[],controller:"AiPrompts",methods:["GET","POST"]},"platform.administration.ai.schemas":{navRoute:"platform.administration.ai.schemas",api:"/api/platform/administration/ai/schemas",web:"/platform/administration/ai/schemas",permissions:[],controller:"AiSchemas",methods:["GET","POST"]},"platform.administration.ai.settings":{navRoute:"platform.administration.ai.settings",api:"/api/platform/administration/ai/settings",web:"/platform/administration/ai/settings",permissions:[],controller:"AiSettings",methods:[]},"platform.administration.applications":{navRoute:"platform.administration.applications",api:"/api/platform/administration/applications",web:"/platform/administration/applications",permissions:[],controller:"Applications",methods:["GET"]},"platform.administration.applications.application-analytics":{navRoute:"platform.administration.applications.application-analytics",api:"/api/platform/administration/applications/application-analytics",web:"/platform/administration/applications/application-analytics",permissions:[],controller:"ApplicationAnalytics",methods:[]},"platform.administration.communications.email-templates":{navRoute:"platform.administration.communications.email-templates",api:"/api/platform/administration/communications/email-templates",web:"/platform/administration/communications/email-templates",permissions:[],controller:"EmailTemplates",methods:["GET","POST"]},"platform.administration.communications.workflows":{navRoute:"platform.administration.communications.workflows",api:"/api/platform/administration/communications/workflows",web:"/platform/administration/communications/workflows",permissions:[],controller:"Workflows",methods:["GET","POST"]},"platform.administration.entra":{navRoute:"platform.administration.entra",api:"/api/platform/administration/entra",web:"/platform/administration/entra",permissions:[],controller:"Entra",methods:[]},"platform.administration.license":{navRoute:"platform.administration.license",api:"/api/platform/administration/license",web:"/platform/administration/license",permissions:[],controller:"License",methods:["GET"]},"platform.administration.permissions":{navRoute:"platform.administration.permissions",api:"/api/platform/administration/permissions",web:"/platform/administration/permissions",permissions:[],controller:"Permissions",methods:["GET","POST"]},"platform.administration.roles":{navRoute:"platform.administration.roles",api:"/api/platform/administration/roles",web:"/platform/administration/roles",permissions:[],controller:"Roles",methods:["GET","POST"]},"platform.administration.settings":{navRoute:"platform.administration.settings",api:"/api/platform/administration/settings",web:"/platform/administration/settings",permissions:[],controller:"Settings",methods:["GET"]},"platform.administration.users":{navRoute:"platform.administration.users",api:"/api/platform/administration/users",web:"/platform/administration/users",permissions:[],controller:"Users",methods:["GET","POST"]},"platform.administration.users.dashboard":{navRoute:"platform.administration.users.dashboard",api:"/api/platform/administration/users/dashboard",web:"/platform/administration/users/dashboard",permissions:[],controller:"UserDashboard",methods:[]},"platform.support.dashboard":{navRoute:"platform.support.dashboard",api:"/api/platform/support/dashboard",web:"/platform/support/dashboard",permissions:[],controller:"Dashboard",methods:[]},"platform.support.notifications":{navRoute:"platform.support.notifications",api:"/api/platform/support/notifications",web:"/platform/support/notifications",permissions:[],controller:"Notifications",methods:["GET"]},"platform.support.sla":{navRoute:"platform.support.sla",api:"/api/platform/support/sla",web:"/platform/support/sla",permissions:[],controller:"Sla",methods:[]},"platform.support.templates":{navRoute:"platform.support.templates",api:"/api/platform/support/templates",web:"/platform/support/templates",permissions:[],controller:"Templates",methods:["GET","POST"]},"platform.support.tickets":{navRoute:"platform.support.tickets",api:"/api/platform/support/tickets",web:"/platform/support/tickets",permissions:[],controller:"Tickets",methods:["GET","POST"]},"platform.user.application-tracking":{navRoute:"platform.user.application-tracking",api:"/api/platform/user/application-tracking",web:"/platform/user/application-tracking",permissions:[],controller:"ApplicationTracking",methods:[]},"platform.user.dashboard":{navRoute:"platform.user.dashboard",api:"/api/platform/user/dashboard",web:"/platform/user/dashboard",permissions:[],controller:"Dashboard",methods:[]},"platform.user.preferences":{navRoute:"platform.user.preferences",api:"/api/user/preferences",web:"/platform/user/preferences",permissions:[],controller:"Preferences",methods:["GET"]}},Ol=l.createContext(void 0);function ql({children:s}){const[t,r]=l.useState(null),[n,i]=l.useState(!0),[o,c]=l.useState(null),x=l.useRef(null),u=l.useCallback(async h=>{try{i(!0),c(null);const v=await oe.get(Ka["platform.administration.license"].api,{signal:h});h?.aborted||r(v)}catch(v){if(v instanceof Error&&v.name==="CanceledError"||h?.aborted)return;c(v instanceof Error?v.message:"Failed to load license info"),console.error("Failed to fetch license:",v)}finally{h?.aborted||i(!1)}},[]);l.useEffect(()=>{x.current?.abort();const h=new AbortController;return x.current=h,u(h.signal),()=>h.abort()},[u]);const d=l.useCallback(h=>t?t.enabledFeatures.includes("*")?!0:t.enabledFeatures.some(v=>v.toLowerCase()===h.toLowerCase()):!1,[t]),m=l.useCallback(async()=>{x.current?.abort();const h=new AbortController;x.current=h,await u(h.signal)},[u]),p=l.useCallback(async h=>{try{const v=await oe.post(`${Ka["platform.administration.license"].api}/activate`,{licenseKey:h});return v.success?(await m(),{success:!0}):{success:!1,error:v.errorMessage||"Activation failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Activation failed"}}},[m]);return e.jsx(Ol.Provider,{value:{license:t,isLoading:n,error:o,isFeatureEnabled:d,isReadOnlyMode:t?.isReadOnlyMode??!1,refreshLicense:m,activateLicense:p},children:s})}function _t(){const s=l.useContext(Ol);if(s===void 0)throw new Error("useLicense must be used within a LicenseProvider");return s}const Vl=l.createContext(void 0),xs="currentTenantId",hs="currentTenantSlug",bs="isGlobalView";function $o({children:s}){const{isAuthenticated:t,user:r,refreshPermissions:n}=Ke(),{isSingleTenant:i,isLoading:o}=vt(),[c,x]=l.useState(null),[u,d]=l.useState([]),[m,p]=l.useState(!0),[h,v]=l.useState(null),[b,g]=l.useState(()=>localStorage.getItem(bs)==="true"),j=l.useRef(!1),w=l.useRef(""),f=u.filter(I=>I.type==="Business"),N=u.find(I=>I.type==="Personal")||null,k=l.useCallback(I=>{if(d(I),I.length===0){x(null),g(!1),localStorage.removeItem(xs),localStorage.removeItem(hs),localStorage.removeItem(bs),p(!1);return}const M=localStorage.getItem(xs),X=M?I.find($=>$.id===M):null;if(X&&X.status==="Active"){x(X),g(!1),localStorage.setItem(xs,X.id),localStorage.setItem(hs,X.slug),localStorage.removeItem(bs),p(!1);return}if(localStorage.getItem(bs)==="true"){g(!0),x(null),p(!1);return}const U=I.find($=>$.isDefault&&$.status==="Active");if(U){x(U),g(!1),localStorage.setItem(xs,U.id),localStorage.setItem(hs,U.slug),localStorage.removeItem(bs),p(!1);return}const K=I.find($=>$.status==="Active");x(K||null),K&&(localStorage.setItem(xs,K.id),localStorage.setItem(hs,K.slug)),p(!1)},[]),C=l.useCallback(async I=>{const M=u.find(X=>X.id===I);if(!M)throw new Error("Tenant not found");if(M.status!=="Active")throw new Error("Cannot switch to inactive tenant");g(!1),localStorage.removeItem(bs),x(M),localStorage.setItem(xs,I),localStorage.setItem(hs,M.slug)},[u]),y=l.useCallback(()=>{g(!0),localStorage.setItem(bs,"true"),x(null),localStorage.removeItem(xs),localStorage.removeItem(hs)},[]),A=l.useCallback(()=>{g(!1),localStorage.removeItem(bs);const I=u.find(O=>O.isDefault&&O.status==="Active"),M=u.find(O=>O.status==="Active"),X=I||M||null;X&&(x(X),localStorage.setItem(xs,X.id),localStorage.setItem(hs,X.slug))},[u]),D=l.useCallback(async I=>{console.log("[TenantContext] setDefaultTenant called with:",I);try{await le.myTenants.setDefault(I),console.log("[TenantContext] setDefault API call succeeded"),d(M=>{const X=M.map(O=>({...O,isDefault:O.id===I}));return console.log("[TenantContext] Updated userTenants:",X.map(O=>({id:O.id,name:O.name,isDefault:O.isDefault}))),X}),await C(I)}catch(M){throw console.error("[TenantContext] Failed to set default tenant:",M),M}},[C]),R=l.useCallback(async()=>{try{await le.myTenants.clearDefault(),d(I=>I.map(M=>({...M,isDefault:!1}))),y()}catch(I){throw console.error("[TenantContext] Failed to clear default tenant:",I),I}},[y]),L=l.useCallback(async()=>{p(!0),v(null);try{await n()}catch(I){console.error("Failed to refresh tenants:",I),v("Failed to refresh tenants")}finally{p(!1)}},[n]);l.useEffect(()=>{if(!t||!r){j.current&&(d([]),x(null),p(!1),j.current=!1,w.current="");return}const I=r.tenants||[];console.log("[TenantContext] user.tenants from AuthContext:",{count:I.length,tenants:I.map(X=>({id:X.id,name:X.name,type:X.type,isDefault:X.isDefault}))});const M=I.map(X=>`${X.id}:${X.status}:${X.isDefault}`).sort((X,O)=>X.localeCompare(O)).join(",");(!j.current||M!==w.current)&&(j.current=!0,w.current=M,k(I))},[t,r,k]),l.useEffect(()=>{t||(x(null),d([]),localStorage.removeItem(xs),localStorage.removeItem(hs))},[t]);const S=r?Ul(r.permissions||[],r.roles||[]):!1,T={currentTenant:c,userTenants:u,b2bTenants:f,personalTenant:N,isLoading:m||o,error:h,switchTenant:C,setDefaultTenant:D,clearDefaultTenant:R,refreshTenants:L,hasMultipleTenants:!i&&u.filter(I=>I.status==="Active").length>1,isCurrentTenantOwner:c?.isOwner??!1,hasGlobalRoles:S,isGlobalView:b,enterGlobalView:y,exitGlobalView:A};return e.jsx(Vl.Provider,{value:T,children:s})}function ze(){const s=l.useContext(Vl);if(s===void 0)throw new Error("useTenant must be used within a TenantProvider");return s}const Nt=5,zl=l.createContext(null);function Gl({children:s}){const{i18n:t}=ne.useTranslation(),{isAuthenticated:r}=Ke(),{currentTenant:n,isLoading:i}=ze(),[o,c]=l.useState([]),[x,u]=l.useState(!1),[d,m]=l.useState(null),[p,h]=l.useState(!1),v=l.useCallback(()=>{h(!0)},[]),b=l.useCallback(()=>{h(!1)},[]),g=l.useCallback(async()=>{try{u(!0),m(null);const D=(await oe.get("/api/navigation/module-favorites")).map(R=>({id:R.id,code:R.code,label:R.label,icon:R.icon||"Star",route:R.route||"",applicationId:R.applicationId,applicationCode:R.applicationCode,applicationLabel:R.applicationLabel,displayOrder:R.displayOrder}));c(D)}catch(A){console.error("Failed to load favorite modules:",A),m("Erreur lors du chargement des favoris"),c([])}finally{u(!1)}},[]);l.useEffect(()=>{r&&!i?g():r||(c([]),m(null))},[r,i,n,g]),l.useEffect(()=>{const A=()=>{r&&!i&&g()};return t.on("languageChanged",A),()=>{t.off("languageChanged",A)}},[t,r,i,g]);const j=l.useCallback(async A=>{if(o.length>=Nt||o.some(D=>D.id===A.id))return!1;try{return m(null),await oe.post(`/api/navigation/module-favorites/${A.id}`),c(D=>[...D,{...A,displayOrder:D.length+1}]),!0}catch(D){return console.error("Failed to add favorite module:",D),await g(),!1}},[o,g]),w=l.useCallback(async A=>{try{return m(null),await oe.delete(`/api/navigation/module-favorites/${A}`),c(D=>D.filter(R=>R.id!==A)),!0}catch(D){return console.error("Failed to remove favorite module:",D),await g(),!1}},[g]),f=l.useCallback(A=>o.some(D=>D.id===A),[o]),N=l.useCallback(async A=>f(A.id)?await w(A.id):await j(A),[f,w,j]),k=l.useCallback(async A=>{const D=A.slice(0,Nt),R=D.map(S=>S.id),L=[...o];c(D.map((S,T)=>({...S,displayOrder:T+1})));try{return m(null),await oe.put("/api/navigation/module-favorites/reorder",R),!0}catch(S){return console.error("Failed to reorder favorite modules:",S),c(L),!1}},[o]),C=o.length<Nt;return e.jsx(zl.Provider,{value:{favorites:o,loading:x,error:d,addFavorite:j,removeFavorite:w,toggleFavorite:N,isFavorite:f,reorderFavorites:k,canAddMore:C,maxFavorites:Nt,reload:g,expandFavorites:p,triggerExpand:v,clearExpand:b,requiresTenant:!1},children:s})}function rs(){const s=l.useContext(zl);if(!s)throw new Error("useFavorites must be used within a FavoritesProvider");return s}const Hl="smartstack-sidebar-collapsed",Kl=l.createContext(void 0);function Mo(){if(typeof window>"u")return!1;try{return localStorage.getItem(Hl)==="true"}catch{return!1}}function _l({children:s}){const[t,r]=l.useState(Mo);l.useEffect(()=>{localStorage.setItem(Hl,String(t))},[t]);const n=l.useCallback(()=>{r(c=>!c)},[]),i=l.useCallback(c=>{r(c)},[]),o=t?64:256;return e.jsx(Kl.Provider,{value:{isCollapsed:t,toggleCollapsed:n,setCollapsed:i,sidebarWidth:o},children:s})}function st(){const s=l.useContext(Kl);if(s===void 0)throw new Error("useSidebar must be used within a SidebarProvider");return s}const Wl=l.createContext(void 0);function Fo(s){let t=s.split("/").filter(Boolean);return t.length>=2&&t[0]==="t"&&(t=t.slice(2)),t.length===0?{context:null,app:null,module:null}:["login","callback","logout","onboarding","system"].includes(t[0])?{context:null,app:null,module:null}:{context:t[0],app:t[1]||null,module:t[2]||null}}function cr({children:s}){const t=Q.useLocation(),{i18n:r}=ne.useTranslation(),{currentTenant:n,isLoading:i}=ze(),[o,c]=l.useState(null),[x,u]=l.useState([]),[d,m]=l.useState(!0),p=l.useRef(!1),h=l.useRef(void 0),v=l.useRef(!1),{context:b,app:g,module:j}=Fo(t.pathname),w=l.useCallback(async()=>{try{const T=await oe.get("/api/navigation/menu");c(T)}catch(T){console.error("Failed to fetch menu:",T)}},[]),f=l.useCallback(async()=>{try{const T=await oe.get("/api/navigation/favorites");u(T)}catch(T){console.error("Failed to fetch favorites:",T)}},[]),N=l.useCallback(async()=>{v.current||(v.current=!0,m(!0),await w(),n&&await f(),m(!1),v.current=!1)},[w,f,n]);l.useEffect(()=>{const T=localStorage.getItem("token"),I=n?.id;if(!(!T||i)&&!v.current){if(!p.current){p.current=!0,h.current=I,N();return}I!==h.current&&(h.current=I,N())}},[n?.id,i]),l.useEffect(()=>{const T=()=>{localStorage.getItem("token")&&N()};return r.on("languageChanged",T),()=>{r.off("languageChanged",T)}},[r,N]);const k=l.useCallback(T=>T.startsWith("core_")?T.slice(5):T.startsWith("ext_")?T.slice(4):T,[]),C=l.useCallback((T,I)=>T&&T.split("/").filter(Boolean)[I]||null,[]),y=l.useCallback(()=>o?.contexts.find(T=>k(T.code)===b),[o,b,k]),A=l.useCallback(()=>y()?.applications.find(I=>C(I.route,1)===g||k(I.code)===g),[y,g,C,k]),D=l.useCallback(()=>A()?.modules.find(I=>C(I.route,2)===j||k(I.code)===j),[A,j,C,k]),R=l.useCallback(T=>o?.contexts.find(M=>k(M.code)===T)?.applications||[],[o,k]),L=l.useCallback(T=>x.some(I=>I.id===T),[x]),S=l.useCallback(async T=>{try{L(T)?(await oe.delete(`/api/navigation/favorites/${T}`),u(I=>I.filter(M=>M.id!==T))):(await oe.post(`/api/navigation/favorites/${T}`,{}),await f())}catch(I){console.error("Failed to toggle favorite:",I)}},[L,f]);return e.jsx(Wl.Provider,{value:{menu:o,favorites:x,currentContextCode:b,currentAppCode:g,currentModuleCode:j,isLoading:d,getCurrentContext:y,getCurrentApplication:A,getCurrentModule:D,getApplicationsForContext:R,toggleFavorite:S,isFavorite:L,refreshMenu:N},children:s})}function Ze(){const s=l.useContext(Wl);if(s===void 0)throw new Error("useNavigation must be used within a NavigationProvider");return s}const Xl=l.createContext(null);function Ql({children:s}){const{isAuthenticated:t,refreshPermissions:r}=Ke(),{refreshMenu:n}=Ze(),i=l.useRef(null),[o,c]=l.useState(Me.HubConnectionState.Disconnected),x=l.useRef(new Set),u=l.useRef(new Set),d=l.useRef(!1),m=l.useCallback(async()=>{if(!d.current){d.current=!0;try{await Promise.all([r(),n()]),console.log("[SignalR] Permissions and menu refreshed")}catch(j){console.error("[SignalR] Failed to refresh permissions:",j)}finally{d.current=!1}}},[r,n]),p=l.useCallback(async()=>{const j=localStorage.getItem("token");if(!j){console.warn("[SignalR] No token available, skipping connection");return}if(!(i.current?.state===Me.HubConnectionState.Connected||i.current?.state===Me.HubConnectionState.Connecting))try{const w=new Me.HubConnectionBuilder().withUrl("/hubs/notifications",{accessTokenFactory:()=>j}).withAutomaticReconnect({nextRetryDelayInMilliseconds:f=>f.previousRetryCount===0?0:f.previousRetryCount===1?2e3:f.previousRetryCount===2?1e4:f.previousRetryCount<5?3e4:null}).configureLogging(Me.LogLevel.Warning).build();w.on("ReceiveNotification",f=>{x.current.forEach(N=>N(f))}),w.on("UnreadCountUpdate",f=>{u.current.forEach(N=>N(f))}),w.on("PermissionsChanged",m),w.onreconnecting(()=>{c(Me.HubConnectionState.Reconnecting)}),w.onreconnected(()=>{c(Me.HubConnectionState.Connected)}),w.onclose(()=>{c(Me.HubConnectionState.Disconnected)}),await w.start(),i.current=w,c(Me.HubConnectionState.Connected),console.log("[SignalR] Connected to notification hub")}catch(w){console.error("[SignalR] Failed to connect:",w),c(Me.HubConnectionState.Disconnected)}},[m]),h=l.useCallback(async()=>{if(i.current)try{await i.current.stop(),i.current=null,c(Me.HubConnectionState.Disconnected),console.log("[SignalR] Disconnected from notification hub")}catch(j){console.error("[SignalR] Failed to disconnect:",j)}},[]);l.useEffect(()=>(t?p():h(),()=>{h()}),[t,p,h]);const v=l.useCallback(j=>(x.current.add(j),()=>{x.current.delete(j)}),[]),b=l.useCallback(j=>(u.current.add(j),()=>{u.current.delete(j)}),[]),g={isConnected:o===Me.HubConnectionState.Connected,connectionState:o,onNotification:v,onUnreadCountUpdate:b};return e.jsx(Xl.Provider,{value:g,children:s})}function dr(){const s=l.useContext(Xl);if(!s)throw new Error("useSignalRContext must be used within a SignalRProvider");return s}const us={register:async s=>oe.post("/api/auth/register",s),confirmEmail:async s=>oe.post("/api/auth/confirm-email",{token:s}),resendConfirmation:async s=>oe.post("/api/auth/resend-confirmation",{email:s}),forgotPassword:async s=>oe.post("/api/auth/forgot-password",{email:s}),resetPassword:async(s,t)=>oe.post("/api/auth/reset-password",{token:s,newPassword:t}),login:async(s,t)=>{const r=await oe.post("/api/auth/login",{email:s,password:t});return r.token&&(localStorage.setItem("token",r.token),localStorage.setItem("refreshToken",r.refreshToken)),r},logout:async()=>{try{await oe.post("/api/auth/logout")}finally{localStorage.removeItem("token"),localStorage.removeItem("refreshToken"),localStorage.removeItem("user")}},changePassword:async(s,t)=>oe.post("/api/auth/change-password",{currentPassword:s,newPassword:t}),refreshSession:async()=>{const s=await oe.post("/api/auth/refresh");return s.token&&(localStorage.setItem("token",s.token),localStorage.setItem("refreshToken",s.refreshToken)),s},getSessionInfo:async s=>oe.get("/api/auth/session-info",{signal:s?.signal})};function Jl(s={}){const{checkIntervalMs:t=6e4,onSessionExpired:r,onWarningThreshold:n,enabled:i=!0}=s,[o,c]=l.useState({isActive:!0,timeRemainingSeconds:0,isWarning:!1,sessionInfo:null}),[x,u]=l.useState(!1),d=l.useRef(!1),m=l.useRef(null),p=l.useRef(null),h=l.useCallback(async b=>{if(!i)return;if(!localStorage.getItem("token")){c(j=>({...j,isActive:!1}));return}try{const j=await us.getSessionInfo({signal:b});if(b?.aborted)return;const w=Math.min(j.timeUntilIdleExpirySeconds,j.timeUntilAbsoluteExpirySeconds);c({isActive:!0,timeRemainingSeconds:w,isWarning:j.isWarningThreshold,sessionInfo:j}),j.isWarningThreshold&&!d.current&&(d.current=!0,n?.()),j.isWarningThreshold||(d.current=!1)}catch(j){if(j instanceof Error&&j.name==="CanceledError"||b?.aborted)return;c(w=>({...w,isActive:!1})),r?.()}},[i,r,n]),v=l.useCallback(async()=>{if(x)return!1;u(!0);try{return await us.refreshSession(),d.current=!1,await h(),!0}catch{return c(b=>({...b,isActive:!1})),!1}finally{u(!1)}},[x,h]);return l.useEffect(()=>{if(!i)return;p.current?.abort();const b=new AbortController;return p.current=b,h(b.signal),m.current=setInterval(()=>h(),t),()=>{b.abort(),m.current&&clearInterval(m.current)}},[i,t,h]),l.useEffect(()=>{if(!i)return;const b=()=>{o.isWarning&&h()},g=["mousedown","keydown","touchstart","scroll"];return g.forEach(j=>{window.addEventListener(j,b,{passive:!0})}),()=>{g.forEach(j=>{window.removeEventListener(j,b)})}},[i,o.isWarning,h]),{...o,isRefreshing:x,refreshSession:v,checkSession:h}}function Uo(s){if(s<=0)return"0:00";const t=Math.floor(s/60),r=s%60;if(t>=60){const n=Math.floor(t/60),i=t%60;return`${n}h ${i}min`}return`${t}:${r.toString().padStart(2,"0")}`}function Yl({isOpen:s,timeRemainingSeconds:t,onExtendSession:r,onLogout:n}){const{t:i}=ne.useTranslation("common"),[o,c]=l.useState(!1),[x,u]=l.useState(t);l.useEffect(()=>{u(t)},[t]),l.useEffect(()=>{if(!s||x<=0)return;const p=setInterval(()=>{u(h=>h<=1?(n(),0):h-1)},1e3);return()=>clearInterval(p)},[s,x,n]);const d=async()=>{c(!0);try{await r()||n()}finally{c(!1)}};if(!s)return null;const m=Math.max(0,Math.min(100,x/300*100));return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"relative w-full max-w-md bg-[var(--bg-card)] rounded-2xl shadow-2xl border border-amber-500/30 overflow-hidden animate-in fade-in zoom-in duration-200",children:[e.jsx("div",{className:"absolute top-0 left-0 h-1 bg-amber-500/30 w-full",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-amber-500 to-orange-500 transition-all duration-1000 ease-linear",style:{width:`${m}%`}})}),e.jsxs("div",{className:"p-6 pt-8",children:[e.jsxs("div",{className:"flex flex-col items-center text-center mb-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-amber-500/20 flex items-center justify-center mb-4",children:e.jsx(a.Clock,{className:"w-8 h-8 text-amber-500"})}),e.jsx("h2",{className:"text-xl font-semibold text-[var(--text-primary)] mb-2",children:i("session.warningTitle","Session Expiring")}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:i("session.warningMessage","Your session will expire due to inactivity.")}),e.jsx("div",{className:"text-4xl font-mono font-bold text-amber-500 tabular-nums",children:Uo(x)}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] mt-2",children:i("session.remainingTime","remaining")})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("button",{onClick:n,className:"flex-1 flex items-center justify-center gap-2 px-6 py-3 rounded-xl border border-[var(--border-color)] text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] transition-all font-medium",children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),i("session.logout","Logout")]}),e.jsxs("button",{onClick:d,disabled:o,className:"flex-1 flex items-center justify-center gap-2 px-6 py-3 rounded-xl font-medium transition-all bg-gradient-to-r from-amber-500 to-orange-500 text-white hover:from-amber-600 hover:to-orange-600 shadow-lg shadow-amber-500/30 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(a.RefreshCw,{className:`w-4 h-4 ${o?"animate-spin":""}`}),o?i("session.extending","Extending..."):i("session.extend","Continue Session")]})]})]})]})})}const Bo=l.createContext(void 0);function Zl({children:s}){const{isAuthenticated:t,logout:r}=Ke(),n=l.useCallback(()=>{localStorage.removeItem("token"),localStorage.removeItem("refreshToken"),localStorage.removeItem("user"),window.location.href="/login?reason=session_expired"},[]),{isActive:i,timeRemainingSeconds:o,isWarning:c,refreshSession:x}=Jl({enabled:t,checkIntervalMs:3e4,onSessionExpired:n}),u=l.useCallback(async()=>{try{await us.logout()}finally{r()}},[r]),d=l.useCallback(async()=>await x(),[x]);return e.jsxs(Bo.Provider,{value:{isSessionActive:i,timeRemainingSeconds:o,isWarning:c,refreshSession:x},children:[s,e.jsx(Yl,{isOpen:c&&t,timeRemainingSeconds:o,onExtendSession:d,onLogout:u})]})}const Oo=150;function qo({children:s}){const t=Po(),r=t?.isAuthenticated??!1,n=t?.isLoading??!0,{currentTenant:i,isLoading:o,isGlobalView:c}=ze(),{setSelectedThemeTenant:x,selectedThemeTenant:u,loadFromServer:d}=et(),m=l.useRef(null),p=l.useRef(!1),h=l.useRef(null),v=l.useRef(null),b=l.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),g=l.useCallback(()=>m.current==="global"?!1:(b(),console.log("[ThemeSync] Cancelling pending theme load - entering global view"),v.current=null,console.log("[ThemeSync] Entering global view, loading global preferences"),m.current="global",p.current=!0,d("global"),x(null,!0),!0),[b,d,x]),j=l.useCallback((N,k)=>{v.current=N,console.log("[ThemeSync] Tenant changed, waiting for stabilization:",k),h.current=setTimeout(()=>{v.current===N?(console.log("[ThemeSync] Tenant stabilized, loading preferences for:",k),m.current=N,p.current=!0,v.current=null,x(N,!1)):console.log("[ThemeSync] Tenant changed during stabilization, skipping load for:",k),h.current=null},Oo)},[x]),w=l.useCallback(()=>{if(!i)return;const N=i.id!==m.current,k=v.current!==null&&v.current!==i.id;!N&&!k||(b(),console.log("[ThemeSync] Cancelling pending theme load for:",v.current),N?j(i.id,i.slug):(console.log("[ThemeSync] User switched back to original tenant, cancelling pending load"),v.current=null))},[i,b,j]),f=l.useCallback(()=>{console.log("[ThemeSync] User logged out, resetting tenant tracking"),b(),m.current=null,v.current=null,p.current=!1},[b]);return l.useEffect(()=>{if(console.log("[ThemeSync] State changed:",{isAuthenticated:r,authLoading:n,tenantLoading:o,hasTenant:!!i,currentTenantId:i?.id,isGlobalView:c,lastTenantId:m.current,pendingTenantId:v.current,hasInitialLoad:p.current,selectedThemeTenant:u}),!r){f();return}if(!(n||o)){if(c&&!i){g();return}i&&w()}},[r,n,o,i,c,g,w,f]),l.useEffect(()=>()=>{b()},[b]),e.jsx(e.Fragment,{children:s})}function Vo(s){const t=s.message.toLowerCase(),r=s.name.toLowerCase();return t.includes("network")||t.includes("fetch")||t.includes("failed to fetch")||t.includes("econnrefused")||t.includes("timeout")?"network":t.includes("401")||t.includes("403")||t.includes("unauthorized")||t.includes("forbidden")||t.includes("permission")?"permission":t.includes("404")||t.includes("not found")?"notFound":r.includes("validation")||t.includes("validation")||t.includes("invalid")?"validation":"technical"}function zo(){const s=Date.now().toString(36),t=Math.random().toString(36).substring(2,6);return`ERR-${s}-${t}`.toUpperCase()}const Go={network:{icon:a.WifiOff,color:"text-orange-500",bgColor:"bg-orange-500/10"},permission:{icon:a.ShieldX,color:"text-red-500",bgColor:"bg-red-500/10"},notFound:{icon:a.FileWarning,color:"text-yellow-500",bgColor:"bg-yellow-500/10"},validation:{icon:a.AlertTriangle,color:"text-amber-500",bgColor:"bg-amber-500/10"},technical:{icon:a.Bug,color:"text-red-500",bgColor:"bg-red-500/10"}};function ei({error:s,resetErrorBoundary:t}){const{t:r}=ne.useTranslation("common"),[n,i]=l.useState(!1),[o]=l.useState(()=>zo()),c=Vo(s),x=Go[c],u=x.icon,d=()=>{window.history.length>2&&document.referrer?window.location.href=document.referrer:window.history.length>2?(window.history.back(),setTimeout(()=>window.location.reload(),50)):window.location.href="/"};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)] p-4",children:e.jsx("div",{className:"max-w-lg w-full p-8 bg-[var(--bg-card)] border border-[var(--border-color)] rounded-2xl shadow-xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsx("div",{className:`w-16 h-16 rounded-full ${x.bgColor} flex items-center justify-center mb-6`,children:e.jsx(u,{className:`w-8 h-8 ${x.color}`})}),e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)] mb-2",children:r(`errors.${c}.title`,r("errors.technical.title"))}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:r(`errors.${c}.description`,r("errors.technical.description"))}),e.jsxs("div",{className:"mb-6 px-3 py-1.5 bg-[var(--bg-tertiary)] rounded-lg border border-[var(--border-color)]",children:[e.jsxs("span",{className:"text-xs text-[var(--text-tertiary)]",children:[r("errors.errorId"),": "]}),e.jsx("span",{className:"text-xs font-mono text-[var(--text-secondary)]",children:o})]}),!1,e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 w-full",children:[e.jsxs("button",{onClick:t,className:"flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white font-medium transition-all",children:[e.jsx(a.RefreshCw,{className:"w-4 h-4"}),r("errors.retry")]}),e.jsxs("button",{onClick:d,className:"flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] border border-[var(--border-color)] text-[var(--text-primary)] font-medium transition-all",children:[e.jsx(a.ArrowLeft,{className:"w-4 h-4"}),r("errors.goBack")]}),e.jsxs("a",{href:"/",className:"flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] border border-[var(--border-color)] text-[var(--text-primary)] font-medium transition-all",children:[e.jsx(a.Home,{className:"w-4 h-4"}),r("errors.home")]})]}),e.jsxs("p",{className:"mt-6 text-sm text-[var(--text-tertiary)]",children:[r("errors.persistsHelp")," ",e.jsx("a",{href:"mailto:support@smartstack.app",className:"text-[var(--color-accent-500)] hover:underline",children:r("errors.contactSupport")})]})]})})})}function Ho(s,t){qe.logCritical(s,"GlobalErrorBoundary",{componentStack:t.componentStack})}function Ko(){window.location.reload()}function si({children:s}){return e.jsx(Rl.ErrorBoundary,{FallbackComponent:ei,onError:Ho,onReset:Ko,children:s})}const mr=Ka["platform.user.application-tracking"].api,_o="00000000-0000-0000-0000-000000000000",Rr=s=>!!s&&s!==_o,ti=s=>{const t=s.match(/^\/t\/[^/]+(\/.*)$/);return t?t[1]:s},Wo=s=>{const t=ti(s);return t.startsWith("/platform/")||t.startsWith("/personal/")||t.startsWith("/business/")},ai=(s,t)=>{if(!s||typeof s!="object"||!("status"in s))return!0;const r=s.status;return!t.includes(r??-1)},Xo=async(s,t)=>{const r=new Date,n=Math.floor((r.getTime()-t.getTime())/1e3);try{await oe.post(`${mr}/end`,{accessId:s,endedAt:r.toISOString(),durationSeconds:n})}catch(i){ai(i,[401,408])&&console.error("Failed to end page tracking:",i)}},Qo=async s=>{const t=new Date;try{return(await oe.post(`${mr}/start`,{route:s,accessedAt:t.toISOString()})).accessId}catch(r){return ai(r,[401])&&console.error("Failed to track page access:",r),null}},Jo=(s,t)=>{const r=localStorage.getItem("token");if(!r)return;const n=new Date,i=Math.floor((n.getTime()-t.getTime())/1e3);fetch(`${mr}/end`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({accessId:s,endedAt:n.toISOString(),durationSeconds:i}),keepalive:!0}).catch(()=>{})};function ri(){const s=Q.useLocation(),t=l.useRef(new Date),r=l.useRef(null),n=l.useRef(!1);l.useEffect(()=>n.current?void 0:((async()=>{const o=ti(s.pathname);Wo(o)&&(n.current=!0,Rr(r.current)&&await Xo(r.current,t.current),t.current=new Date,r.current=await Qo(o),n.current=!1)})(),()=>{Rr(r.current)&&Jo(r.current,t.current)}),[s.pathname])}function Yo(){return ri(),null}function Zo(){return Q.useInRouterContext()?e.jsx(Yo,{}):null}const ot="/api/platform/administration/tenants/tenant-analytics",bt={getDashboardStats:async(s=30)=>await oe.get(`${ot}/dashboard`,{params:{period:s}}),getTopTenants:async(s=10,t=30,r="access")=>await oe.get(`${ot}/top-tenants`,{params:{limit:s,period:t,sortBy:r}}),getTrends:async(s=30)=>await oe.get(`${ot}/trends`,{params:{period:s}}),trackStart:async s=>await oe.post(`${ot}/track/start`,{tenantId:s}),trackEnd:async s=>{await oe.post(`${ot}/track/end`,{accessId:s})}},ec="/api/platform/administration/tenants/tenant-analytics";function sc(){const{currentTenant:s}=ze(),{isAuthenticated:t}=Ke(),r=l.useRef(null),n=l.useRef(null),i=l.useRef(!1);l.useEffect(()=>{if(!t)return;const o=window.location.pathname;if(o.startsWith("/auth/")||o.startsWith("/login"))return;const c=s?.id??null;return c===n.current||i.current?void 0:(i.current=!0,(async()=>{if(r.current){try{await bt.trackEnd(r.current)}catch{}r.current=null}if(n.current=c,c)try{const u=await bt.trackStart(c);r.current=u.accessId}catch{r.current=null}i.current=!1})(),()=>{if(r.current){const u=localStorage.getItem("token");if(!u)return;fetch(`${ec}/track/end`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify({accessId:r.current}),keepalive:!0}).catch(()=>{}),r.current=null,n.current=null}})},[s?.id,t])}function tc(){return sc(),null}const Wt=l.createContext(null);function ni(){const s=l.useContext(Wt);if(!s)throw new Error("useSlotFill must be used within a SlotFillProvider");return s}function li({children:s,initialFills:t}){const r=l.useMemo(()=>{const i=new Map;return t&&Object.entries(t).forEach(([o,c])=>{const x=i.get(o)||[];Array.isArray(c)?i.set(o,[...x,...c]):i.set(o,[...x,c])}),i},[t]),n=l.useMemo(()=>({fills:r,registerFill:(i,o)=>{const c=r.get(i)||[];r.set(i,[...c,o])},unregisterFill:(i,o)=>{const c=r.get(i)||[];r.set(i,c.filter(x=>x!==o))},getSlotContent:i=>r.get(i)||[]}),[r]);return e.jsx(Wt.Provider,{value:n,children:s})}function ls({name:s,context:t={},children:r,fallback:n,wrapper:i}){const c=l.useContext(Wt)?.getSlotContent(s)||[],x=l.useMemo(()=>({slotName:s,context:t}),[s,t]),u=l.useMemo(()=>c.length===0?n||null:c.map((m,p)=>{const h=`${s}-${p}`;return e.jsx(l.Fragment,{children:oi(m,x)},h)}),[c,s,x,n]),d=e.jsxs(e.Fragment,{children:[u,r]});return i?e.jsx(i,{children:d}):e.jsx(e.Fragment,{children:d})}function ii({slot:s,children:t}){const{registerFill:r,unregisterFill:n}=ni();return l.useMemo(()=>(r(s,t),()=>n(s,t)),[s,t,r,n]),null}function oi(s,t){if(s==null)return null;if(Array.isArray(s))return e.jsx(e.Fragment,{children:s.map((r,n)=>e.jsx(l.Fragment,{children:oi(r,t)},`slot-item-${n}`))});if(l.isValidElement(s))return s;if(typeof s=="function"){const r=s;return e.jsx(r,{...t})}return s}function ac(s){return(l.useContext(Wt)?.getSlotContent(s)?.length||0)>0}function rc(s){function t(n){return e.jsx(ls,{...n,name:s})}t.displayName=`Slot(${s})`;function r({children:n}){return e.jsx(ii,{slot:s,children:n})}return r.displayName=`Fill(${s})`,{Slot:t,Fill:r,slotName:s}}const ci=l.createContext(null);function gt(){const s=l.useContext(ci);return s||{config:{},getPage:()=>{},getSlotContent:()=>{},getTableColumns:()=>[],getFormFields:()=>[],hasExtension:()=>!1}}function Xt(s){const{getPage:t}=gt();return t(s)}function di(s){const{getTableColumns:t}=gt();return t(s)}function nc(s){const{getFormFields:t}=gt();return t(s)}function lc(s){const{hasExtension:t}=gt();return t(s)}function mi({config:s={},children:t}){const r=l.useMemo(()=>{const{pages:n={},slots:i={},tableColumns:o={},formFields:c={}}=s;return{config:s,getPage:x=>n[x],getSlotContent:x=>i[x],getTableColumns:x=>o[x]||[],getFormFields:x=>c[x]||[],hasExtension:x=>x in n||x in i||x in o||x in c}},[s]);return e.jsx(ci.Provider,{value:r,children:e.jsx(li,{initialFills:s.slots,children:t})})}const ic=l.createContext(null);function oc({config:s,children:t}){typeof window<"u"&&(window.__SMARTSTACK_CONFIG__=s);const r=l.useMemo(()=>({config:s}),[s]);return e.jsx(ic.Provider,{value:r,children:e.jsx(si,{children:e.jsx(mi,{config:s.extensions,children:e.jsx($l,{children:e.jsx(Lo,{children:e.jsx(Bl,{children:e.jsx(ql,{children:e.jsx($o,{children:e.jsx(cr,{children:e.jsx(Ql,{children:e.jsx(Gl,{children:e.jsx(_l,{children:e.jsx(Zl,{children:e.jsxs(qo,{children:[e.jsx(Zo,{}),e.jsx(tc,{}),t]})})})})})})})})})})})})})})}function da({to:s,replace:t=!0}){const{slug:r}=Q.useParams(),n=r?`/t/${r}${s}`:s;return e.jsx(Q.Navigate,{to:n,replace:t})}function ms(){const{mode:s,toggleMode:t}=et(),n=(s==="dark"?"dark":"light")==="light";return e.jsx("button",{onClick:t,className:"relative p-2 bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-all duration-300 group",style:{borderRadius:"var(--radius-button)"},"aria-label":`Basculer vers le mode ${n?"sombre":"clair"}`,children:e.jsxs("div",{className:"relative w-6 h-6",children:[e.jsx(a.Sun,{className:`absolute inset-0 w-6 h-6 text-amber-500 transition-all duration-300 ${n?"opacity-100 rotate-0 scale-100":"opacity-0 rotate-90 scale-0"}`}),e.jsx(a.Moon,{className:`absolute inset-0 w-6 h-6 text-[var(--color-accent-400)] transition-all duration-300 ${n?"opacity-0 -rotate-90 scale-0":"opacity-100 rotate-0 scale-100"}`})]})})}const ma=[{code:"en",label:"English",short:"EN"},{code:"fr",label:"Français",short:"FR"},{code:"de",label:"Deutsch",short:"DE"},{code:"it",label:"Italiano",short:"IT"}];function tt(){const{i18n:s}=ne.useTranslation(),{isAuthenticated:t}=Ke(),[r,n]=l.useState(!1),i=l.useRef(null),o=s.language?.split("-")[0]||"en",c=ma.find(u=>u.code===o)||ma[0],x=async u=>{if(await ir(u),document.documentElement.lang=u,n(!1),t)try{await Is.preferences.updateLanguage({language:u})}catch(d){console.warn("Failed to save language preference to server",d)}};return l.useEffect(()=>{const u=d=>{i.current&&!i.current.contains(d.target)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]),e.jsxs("div",{ref:i,className:"relative",children:[e.jsx("button",{onClick:()=>n(!r),className:"relative p-2 bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-all duration-300",style:{borderRadius:"var(--radius-button)"},"aria-label":"Change language",children:e.jsx("span",{className:"flex items-center justify-center w-6 h-6 text-xs font-bold text-[var(--text-secondary)]",children:c.short})}),r&&e.jsx("div",{className:"absolute right-0 mt-2 py-1 bg-[var(--bg-tertiary)] border border-[var(--border-color)] shadow-lg shadow-[var(--shadow-color)] z-50 overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:ma.map(u=>{const d=u.code===o;return e.jsxs("button",{onClick:()=>x(u.code),className:`w-full flex items-center gap-3 px-4 py-2.5 text-left transition-colors whitespace-nowrap ${d?"bg-primary-600/10 text-primary-500":"text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] hover:text-[var(--text-primary)]"}`,children:[e.jsx("span",{className:"text-xs font-bold w-6",children:u.short}),e.jsx("span",{className:"text-sm font-medium",children:u.label}),d&&e.jsx(a.Check,{className:"w-4 h-4 ml-auto text-primary-500"})]},u.code)})})]})}function xi(s,t){if(!t.useUrlRouting||!t.slug)return pt(s);if(s.startsWith(`/t/${t.slug}`))return s;const r=pt(s);return`/t/${t.slug}${r}`}function Ir(s){const t=s.match(/^\/t\/([^/]+)/);return t?t[1]:null}function pt(s){return s.replace(/^\/t\/[^/]+/,"")||"/"}function ws(){const{currentTenant:s}=ze(),{useUrlRouting:t}=vt();return l.useCallback(r=>xi(r,{slug:s?.slug,useUrlRouting:t}),[s?.slug,t])}const cc={personal:a.User,platform:a.Shield,business:a.Briefcase};function dc(s){return s.startsWith("core_")?s.slice(5):s.startsWith("ext_")?s.slice(4):s}function mc({name:s,className:t}){const n=es[s];return n?e.jsx(n,{className:t}):e.jsx(a.Star,{className:t})}const Er={background:"linear-gradient(to bottom right, var(--color-accent-500), var(--color-accent-600))"},xc={personal:{background:"linear-gradient(to bottom right, var(--color-accent-500), var(--color-accent-600))"},platform:{background:"linear-gradient(to bottom right, rgb(245, 158, 11), rgb(217, 119, 6))"},business:{background:"linear-gradient(to bottom right, rgb(16, 185, 129), rgb(5, 150, 105))"}},Dr={personal:{bg:{backgroundColor:"var(--accent-bg)",borderColor:"var(--accent-border)"},textClass:"text-[var(--color-accent-600)] border"},platform:{bg:{backgroundColor:"rgb(245 158 11 / 0.1)",borderColor:"rgb(245 158 11 / 0.2)"},textClass:"text-amber-500 border"},business:{bg:{backgroundColor:"rgb(16 185 129 / 0.1)",borderColor:"rgb(16 185 129 / 0.2)"},textClass:"text-emerald-500 border"}};function uc(s){let t=s;if(s.startsWith("/t/")){const r=s.split("/").filter(Boolean);r.length>=3&&(t="/"+r.slice(2).join("/"))}return t.startsWith("/platform")?"platform":t.startsWith("/business")?"business":"personal"}function Qt(){const{t:s}=ne.useTranslation("navigation"),{user:t,logout:r}=Ke(),{menu:n,refreshMenu:i,getApplicationsForContext:o}=Ze(),{refreshTenants:c}=ze(),x=Q.useLocation(),u=Q.useNavigate(),d=ws(),[m,p]=l.useState(!1),[h,v]=l.useState(!1),b=l.useRef(null),g=async()=>{v(!0);try{await oe.post("/api/navigation/invalidate-cache"),await Promise.all([i(),c()])}catch(A){console.error("Failed to refresh cache:",A)}finally{v(!1),p(!1)}},j=uc(x.pathname),w=(n?.contexts||[]).map(A=>{const D=dc(A.code);return{code:D,label:A.label,icon:A.icon||"",route:A.route||`/${D}`,color:D==="platform"?"amber":D==="business"?"emerald":"primary"}}),N=o("personal").flatMap(A=>A.modules);l.useEffect(()=>{function A(D){b.current&&!b.current.contains(D.target)&&p(!1)}return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[]),l.useEffect(()=>{function A(D){D.key==="Escape"&&p(!1)}return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[]);const k=()=>{if(!t)return"?";const A=t.firstName?.[0]||"",D=t.lastName?.[0]||"";return(A+D).toUpperCase()||t.email[0].toUpperCase()},C=()=>t?t.firstName||t.lastName?`${t.firstName||""} ${t.lastName||""}`.trim():t.email.split("@")[0]:"",y=(A,D)=>{p(!1),D!==j&&u(d(A))};return e.jsxs("div",{ref:b,className:"relative",children:[e.jsxs("button",{onClick:()=>p(!m),className:"flex items-center gap-2 p-1.5 pr-3 bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-all duration-200 group",style:{borderRadius:"var(--radius-button)"},"aria-expanded":m,"aria-haspopup":"true",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-medium shadow-sm",style:Er,children:k()}),e.jsx(a.ChevronDown,{className:`w-4 h-4 text-[var(--text-tertiary)] transition-transform duration-200 ${m?"rotate-180":""}`})]}),e.jsx("div",{className:`absolute right-0 mt-2 w-72 origin-top-right transition-all duration-200 ease-out ${m?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"p-4 bg-gradient-to-br from-[var(--bg-secondary)] to-[var(--bg-tertiary)]",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center text-white text-lg font-semibold shadow-lg",style:Er,children:k()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-[var(--text-primary)] truncate",children:C()}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] truncate",children:t?.email})]})]})}),w.length>1&&e.jsxs("div",{className:"p-2 border-b border-[var(--border-color)]",children:[e.jsx("p",{className:"px-3 py-1.5 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider",children:s("avatarMenu.switchContext")}),e.jsx("div",{className:"space-y-1 mt-1",children:w.map(A=>{const D=cc[A.code]||a.User,R=A.code===j;return e.jsxs("button",{onClick:()=>y(A.route,A.code),className:`w-full flex items-center gap-3 px-3 py-2.5 transition-all duration-150 ${R?Dr[A.code].textClass:"hover:bg-[var(--bg-tertiary)]"}`,style:{borderRadius:"var(--radius-menu-item)",...R?Dr[A.code].bg:{}},children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${R?"text-white shadow-sm":"bg-[var(--bg-tertiary)] text-[var(--text-secondary)]"}`,style:R?xc[A.code]:{},children:e.jsx(D,{className:"w-4 h-4"})}),e.jsx("span",{className:`flex-1 text-left font-medium ${R?"":"text-[var(--text-primary)]"}`,children:A.label}),R&&e.jsx(a.Check,{className:"w-4 h-4"})]},A.code)})})]}),e.jsxs("div",{className:"p-2",children:[N.map(A=>e.jsxs(Q.Link,{to:d(A.route||"#"),onClick:()=>p(!1),className:"flex items-center gap-3 px-3 py-2.5 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-tertiary)] flex items-center justify-center text-[var(--text-secondary)]",children:A.icon?e.jsx(mc,{name:A.icon,className:"w-4 h-4"}):e.jsx(a.Star,{className:"w-4 h-4"})}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:A.label})]},A.id)),e.jsxs("button",{onClick:g,disabled:h,className:"w-full flex items-center gap-3 px-3 py-2.5 hover:bg-[var(--bg-tertiary)] transition-colors disabled:opacity-50",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-tertiary)] flex items-center justify-center text-[var(--text-secondary)]",children:e.jsx(a.RefreshCw,{className:`w-4 h-4 ${h?"animate-spin":""}`})}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:s("avatarMenu.refreshCache")})]})]}),e.jsx("div",{className:"p-2 border-t border-[var(--border-color)]",children:e.jsxs("button",{onClick:()=>{p(!1),r()},className:"w-full flex items-center gap-3 px-3 py-2.5 hover:bg-red-500/10 transition-colors group",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-tertiary)] group-hover:bg-red-500/20 flex items-center justify-center text-[var(--text-secondary)] group-hover:text-red-500 transition-colors",children:e.jsx(a.LogOut,{className:"w-4 h-4"})}),e.jsx("span",{className:"font-medium text-[var(--text-primary)] group-hover:text-red-500 transition-colors",children:s("avatarMenu.logout")})]})})]})})]})}function xr(){const{t:s}=ne.useTranslation("navigation"),{isAuthenticated:t}=Ke(),[r,n]=l.useState(!1);return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("a",{href:"/",className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 rounded-xl animated-gradient flex items-center justify-center",children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[!1,e.jsx(tt,{}),e.jsx(ms,{}),t?e.jsx(Qt,{}):e.jsx("a",{href:"/login",className:"hidden md:inline-flex px-4 py-2 rounded-xl bg-primary-600 hover:bg-primary-700 text-white font-medium transition-colors",children:s("header.login")}),e.jsx("button",{onClick:()=>n(!r),className:"md:hidden p-2 rounded-lg hover:bg-[var(--bg-tertiary)] transition-colors",children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"md:hidden py-4 border-t border-[var(--border-color)]",children:e.jsx("div",{className:"flex flex-col gap-4",children:!t&&e.jsx("a",{href:"/login",className:"px-4 py-2 rounded-xl bg-primary-600 hover:bg-primary-700 text-white font-medium transition-colors text-center",children:s("header.login")})})})]})})}function ur(){const s=new Date().getFullYear();return e.jsx("footer",{className:"bg-[var(--bg-secondary)] border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-8",children:[e.jsxs("div",{className:"md:col-span-1",children:[e.jsxs("a",{href:"/",className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl animated-gradient flex items-center justify-center",children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsx("p",{className:"text-[var(--text-tertiary)] text-sm",children:"Le socle moderne pour vos applications d'entreprise."})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] mb-4",children:"Produit"}),e.jsxs("ul",{className:"space-y-2",children:[e.jsx("li",{children:e.jsx("a",{href:"#features",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Fonctionnalités"})}),e.jsx("li",{children:e.jsx("a",{href:"#modules",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Modules"})}),e.jsx("li",{children:e.jsx("a",{href:"#pricing",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Tarifs"})})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] mb-4",children:"Entreprise"}),e.jsxs("ul",{className:"space-y-2",children:[e.jsx("li",{children:e.jsx("a",{href:"#about",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"À propos"})}),e.jsx("li",{children:e.jsx("a",{href:"#contact",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Contact"})}),e.jsx("li",{children:e.jsx("a",{href:"#careers",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Carrières"})})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] mb-4",children:"Légal"}),e.jsxs("ul",{className:"space-y-2",children:[e.jsx("li",{children:e.jsx("a",{href:"#privacy",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Confidentialité"})}),e.jsx("li",{children:e.jsx("a",{href:"#terms",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Conditions"})}),e.jsx("li",{children:e.jsx("a",{href:"#security",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Sécurité"})})]})]})]}),e.jsxs("div",{className:"mt-12 pt-8 border-t border-[var(--border-color)] flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("p",{className:"text-[var(--text-tertiary)] text-sm",children:["© ",s," SmartStack. Tous droits réservés."]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("a",{href:"https://github.com",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(a.Github,{className:"w-5 h-5"})}),e.jsx("a",{href:"https://twitter.com",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(a.Twitter,{className:"w-5 h-5"})}),e.jsx("a",{href:"https://linkedin.com",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(a.Linkedin,{className:"w-5 h-5"})})]})]})]})})}function ui(){return e.jsx(cr,{children:e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)] flex flex-col",children:[e.jsx(xr,{}),e.jsx("main",{className:"flex-1 pt-16",children:e.jsx(Q.Outlet,{})}),e.jsx(ur,{})]})})}const pc={settings:a.Settings,users:a.Users,key:a.Key,briefcase:a.Briefcase,folder:a.FolderOpen,file:a.FileText,box:a.Box};function hc(s){return s&&pc[s.toLowerCase()]||a.Box}function Lr({app:s,isFavorite:t,onToggleFavorite:r,onSelect:n}){const i=hc(s.icon);return e.jsxs("div",{className:"group relative",children:[e.jsxs("button",{onClick:n,className:"w-full flex flex-col items-center gap-2 p-3 hover:bg-[var(--bg-tertiary)] transition-all duration-200",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-[var(--color-accent-500)]/20 to-[var(--color-accent-600)]/20 flex items-center justify-center group-hover:from-[var(--color-accent-500)]/30 group-hover:to-[var(--color-accent-600)]/30 transition-all",style:{borderRadius:"var(--radius-card)"},children:e.jsx(i,{className:"w-6 h-6 text-[var(--color-accent-500)]"})}),e.jsx("span",{className:"text-xs font-medium text-[var(--text-primary)] text-center line-clamp-2",children:s.label})]}),e.jsx("button",{onClick:o=>{o.stopPropagation(),r()},className:`absolute top-1 right-1 p-1.5 transition-all duration-200 ${t?"text-amber-500 bg-amber-500/10":"text-[var(--text-tertiary)] opacity-0 group-hover:opacity-100 hover:bg-[var(--bg-secondary)]"}`,style:{borderRadius:"var(--radius-button)"},title:t?"Retirer des favoris":"Ajouter aux favoris",children:e.jsx(a.Star,{className:`w-4 h-4 ${t?"fill-current":""}`})})]})}function pr(){const{t:s}=ne.useTranslation("navigation"),{favorites:t,getApplicationsForContext:r,currentContextCode:n,toggleFavorite:i,isFavorite:o}=Ze(),[c,x]=l.useState(!1),u=l.useRef(null),d=Q.useNavigate(),m=ws(),p=n?r(n):[];l.useEffect(()=>{function v(b){u.current&&!u.current.contains(b.target)&&x(!1)}return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),l.useEffect(()=>{function v(b){b.key==="Escape"&&x(!1)}return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const h=v=>{x(!1),v.route&&d(m(v.route))};return e.jsxs("div",{ref:u,className:"relative",children:[e.jsx("button",{onClick:()=>x(!c),className:"p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},"aria-expanded":c,"aria-haspopup":"true",title:s("appSwitcher.title","Applications"),children:e.jsx(a.LayoutGrid,{className:"w-5 h-5 text-[var(--text-secondary)]"})}),e.jsx("div",{className:`absolute right-0 mt-2 w-80 origin-top-right transition-all duration-200 ease-out ${c?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[t.length>0&&e.jsxs("div",{className:"p-3 border-b border-[var(--border-color)]",children:[e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-2",children:[e.jsx(a.Star,{className:"w-3 h-3 text-amber-500 fill-amber-500"}),s("appSwitcher.favorites","Favoris")]}),e.jsx("div",{className:"grid grid-cols-3 gap-1 mt-2",children:t.slice(0,6).map(v=>e.jsx(Lr,{app:v,isFavorite:!0,onToggleFavorite:()=>i(v.id),onSelect:()=>{x(!1),v.route&&d(m(v.route))}},v.id))})]}),e.jsxs("div",{className:"p-3",children:[e.jsx("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider",children:s("appSwitcher.allApps","Toutes les applications")}),p.length>0?e.jsx("div",{className:"grid grid-cols-3 gap-1 mt-2 max-h-64 overflow-y-auto",children:p.map(v=>e.jsx(Lr,{app:v,isFavorite:o(v.id),onToggleFavorite:()=>i(v.id),onSelect:()=>h(v)},v.id))}):e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] text-center py-6",children:s("appSwitcher.noApps","Aucune application disponible")})]})]})})]})}const bc={Pending:"bg-blue-500",Active:"bg-emerald-500",Suspended:"bg-amber-500",Archived:"bg-gray-400"},vc={Pending:"En attente",Active:"Actif",Suspended:"Suspendu",Archived:"Archivé"};function xa({tenant:s,isSelected:t,isFavorite:r,hasThemeOverride:n,onSelect:i,onToggleFavorite:o,showStatus:c=!0}){const x=s.type==="Business",u=s.status==="Active",d=(m,p)=>m?"bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)]":p?"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]";return e.jsxs("div",{className:"flex items-center group",children:[e.jsxs("button",{onClick:i,disabled:!u,className:`flex-1 flex items-center gap-3 px-3 py-2.5 text-left transition-all duration-150 ${d(t,u)}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:`flex-shrink-0 w-8 h-8 flex items-center justify-center ${x?"bg-blue-500/10":"bg-violet-500/10"}`,style:{borderRadius:"var(--radius-card)"},children:x?e.jsx(a.Building2,{className:"w-4 h-4 text-blue-500"}):e.jsx(a.User,{className:"w-4 h-4 text-violet-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:s.name}),n&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-[var(--color-accent-500)]",title:"Thème personnalisé"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:"text-xs text-[var(--text-tertiary)] truncate",children:s.organisationName||s.slug}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${bc[s.status]}`}),s.status!=="Active"&&e.jsx("span",{className:"text-xs text-[var(--text-tertiary)]",children:vc[s.status]})]})]})]}),t&&e.jsx(a.Check,{className:"w-4 h-4 text-[var(--color-accent-500)] flex-shrink-0"})]}),o&&u&&e.jsx("button",{onClick:m=>{m.stopPropagation(),o()},className:`p-2 transition-colors ${r?"text-amber-500":"text-[var(--text-tertiary)] opacity-0 group-hover:opacity-100 hover:text-amber-500"}`,title:r?"Retirer des favoris":"Ajouter aux favoris",children:e.jsx(a.Star,{className:`w-4 h-4 ${r?"fill-amber-500":""}`})})]})}const pi="tenant_recents",_a=5;function hi(){try{return JSON.parse(localStorage.getItem(pi)||"[]")}catch{return[]}}function gc(s){const t=hi().filter(r=>r!==s);t.unshift(s),localStorage.setItem(pi,JSON.stringify(t.slice(0,_a)))}const fc=(s,t,r,n)=>{if(n)return;const i=o=>{s.current&&!s.current.contains(o.target)&&(t(!1),r(""))};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},jc=(s,t,r)=>{if(r)return;const n=i=>{i.key==="Escape"&&(s(!1),t(""))};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)};function hr(){const{t:s}=ne.useTranslation("navigation"),{refreshMenu:t}=Ze(),{isSingleTenant:r}=vt(),{currentTenant:n,userTenants:i,switchTenant:o,isLoading:c,hasMultipleTenants:x,hasGlobalRoles:u,isGlobalView:d,enterGlobalView:m}=ze(),{tenantOverrides:p,loadTenantOverrides:h}=et(),[v,b]=l.useState(!1),[g,j]=l.useState(""),[w,f]=l.useState([]),[N]=l.useState(()=>hi()),k=l.useRef(null),C=l.useRef(null);l.useEffect(()=>{v&&!r&&(le.myTenants.getFavorites().then(f).catch(console.error),h())},[v,r,h]),l.useEffect(()=>{v&&C.current&&!r&&setTimeout(()=>C.current?.focus(),100)},[v,r]),l.useEffect(()=>fc(k,b,j,r),[r]),l.useEffect(()=>jc(b,j,r),[r]);const y=l.useCallback(async M=>{if(M===n?.id&&!d){b(!1);return}try{gc(M),le.myTenants.recordRecent(M).catch(console.error),await o(M),b(!1),j(""),await t()}catch(X){console.error("Failed to switch tenant:",X)}},[n?.id,d,o,t]),A=l.useCallback(async()=>{m(),b(!1),j(""),await t()},[m,t]),D=l.useCallback(async M=>{const X=w.includes(M);try{if(X){const O=await le.myTenants.removeFavorite(M);f(O)}else{const O=await le.myTenants.addFavorite(M);f(O)}}catch(O){console.error("Failed to toggle favorite:",O)}},[w]),R=l.useMemo(()=>{if(!g.trim())return i;const M=g.toLowerCase();return i.filter(X=>X.name.toLowerCase().includes(M)||X.slug.toLowerCase().includes(M)||X.organisationName&&X.organisationName.toLowerCase().includes(M))},[i,g]),L=l.useMemo(()=>R.filter(M=>w.includes(M.id)&&M.status==="Active"),[R,w]),S=l.useMemo(()=>g.trim()?[]:N.map(M=>i.find(X=>X.id===M)).filter(M=>!!M&&M.status==="Active"&&!w.includes(M.id)).slice(0,_a),[N,i,w,g]),T=l.useMemo(()=>{const M=new Set([...w,...N.slice(0,_a)]);return R.filter(X=>!M.has(X.id))},[R,w,N]);if(r||c)return null;if(!(x||u)&&n){const M=n.type==="Business";return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-[var(--bg-secondary)] border border-[var(--border-color)]",style:{borderRadius:"var(--radius-button)"},children:[M?e.jsx(a.Building2,{className:"w-4 h-4 text-blue-500"}):e.jsx(a.User,{className:"w-4 h-4 text-violet-500"}),e.jsx("span",{className:"text-sm font-medium text-[var(--text-primary)]",children:n.name})]})}return e.jsxs("div",{ref:k,className:"relative",children:[e.jsxs("button",{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-1.5 border transition-colors ${d?"bg-emerald-500/10 border-emerald-500/30 hover:bg-emerald-500/20":"bg-[var(--bg-secondary)] border-[var(--border-color)] hover:bg-[var(--bg-tertiary)]"}`,style:{borderRadius:"var(--radius-button)"},"aria-expanded":v,"aria-haspopup":"true",children:[d?e.jsxs(e.Fragment,{children:[e.jsx(a.Globe,{className:"w-4 h-4 text-emerald-600"}),e.jsx("span",{className:"text-sm font-medium text-emerald-700",children:s("tenants.selector.global","Global")})]}):n?e.jsxs(e.Fragment,{children:[n.type==="Business"?e.jsx(a.Building2,{className:"w-4 h-4 text-blue-500"}):e.jsx(a.User,{className:"w-4 h-4 text-violet-500"}),e.jsx("span",{className:"text-sm font-medium text-[var(--text-primary)] max-w-[120px] truncate",children:n.name})]}):e.jsxs(e.Fragment,{children:[e.jsx(a.Building2,{className:"w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("span",{className:"text-sm font-medium text-[var(--text-secondary)]",children:s("tenants.selector.select","Select")})]}),e.jsx(a.ChevronDown,{className:`w-4 h-4 text-[var(--text-tertiary)] transition-transform ${v?"rotate-180":""}`})]}),e.jsx("div",{className:`absolute left-0 mt-2 w-80 origin-top-left transition-all duration-200 ease-out z-50 ${v?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"p-2 border-b border-[var(--border-color)]",children:e.jsxs("div",{className:"relative",children:[e.jsx(a.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("input",{ref:C,type:"text",value:g,onChange:M=>j(M.target.value),placeholder:s("tenants.selector.search","Rechercher..."),className:"w-full pl-9 pr-3 py-2 text-sm bg-[var(--bg-secondary)] border border-[var(--border-color)] focus:border-[var(--color-accent-500)] focus:outline-none",style:{borderRadius:"var(--radius-input)"}})]})}),e.jsxs("div",{className:"max-h-80 overflow-y-auto",children:[u&&!g&&e.jsx("div",{className:"p-2 border-b border-[var(--border-color)]",children:e.jsxs("button",{onClick:A,className:`w-full flex items-center gap-3 px-3 py-2.5 text-left transition-all duration-150 ${d?"bg-emerald-500/10 text-emerald-700":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 bg-emerald-500/10 flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Globe,{className:"w-4 h-4 text-emerald-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium",children:s("tenants.selector.global","Global")}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] mt-0.5",children:s("tenants.selector.globalDesc","Voir tous les tenants")})]}),d&&e.jsx(a.Check,{className:"w-4 h-4 text-emerald-600 flex-shrink-0"})]})}),L.length>0&&e.jsxs("div",{className:"p-2",children:[e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(a.Star,{className:"w-3 h-3 text-amber-500"}),s("tenants.selector.favorites","Favoris")]}),e.jsx("div",{className:"mt-1",children:L.map(M=>e.jsx(xa,{tenant:M,isSelected:!d&&n?.id===M.id,isFavorite:!0,hasThemeOverride:p.includes(M.id),onSelect:()=>y(M.id),onToggleFavorite:()=>D(M.id)},M.id))})]}),S.length>0&&e.jsxs("div",{className:`p-2 ${L.length>0?"border-t border-[var(--border-color)]":""}`,children:[e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(a.Clock,{className:"w-3 h-3"}),s("tenants.selector.recent","Récents")]}),e.jsx("div",{className:"mt-1",children:S.map(M=>e.jsx(xa,{tenant:M,isSelected:!d&&n?.id===M.id,isFavorite:w.includes(M.id),hasThemeOverride:p.includes(M.id),onSelect:()=>y(M.id),onToggleFavorite:()=>D(M.id)},M.id))})]}),T.length>0&&e.jsxs("div",{className:`p-2 ${L.length>0||S.length>0?"border-t border-[var(--border-color)]":""}`,children:[!g&&e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(a.Building2,{className:"w-3 h-3"}),s("tenants.selector.all","Tous")]}),e.jsx("div",{className:"mt-1 max-h-40 overflow-y-auto",children:T.map(M=>e.jsx(xa,{tenant:M,isSelected:!d&&n?.id===M.id,isFavorite:w.includes(M.id),hasThemeOverride:p.includes(M.id),onSelect:()=>y(M.id),onToggleFavorite:()=>D(M.id)},M.id))})]}),g&&R.length===0&&e.jsx("div",{className:"p-4 text-center text-sm text-[var(--text-tertiary)]",children:s("tenants.selector.noResults","Aucun résultat")})]}),e.jsx("div",{className:"p-2 border-t border-[var(--border-color)]",children:e.jsxs(Q.Link,{to:"/personal/myspace/tenants",className:"flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},onClick:()=>b(!1),children:[e.jsx(a.Eye,{className:"w-4 h-4"}),s("tenants.selector.viewAll","Voir tous mes espaces")," (",i.length,")"]})})]})})]})}const Ts={getOverview:(s=30)=>oe.get("/api/platform/support/dashboard/overview",{params:{days:s}}),getByStatus:()=>oe.get("/api/platform/support/dashboard/by-status"),getByPriority:()=>oe.get("/api/platform/support/dashboard/by-priority"),getByType:(s=30)=>oe.get("/api/platform/support/dashboard/by-type",{params:{days:s}}),getAgentWorkload:()=>oe.get("/api/platform/support/dashboard/agent-workload"),getTrends:(s=30)=>oe.get("/api/platform/support/dashboard/trends",{params:{days:s}}),getSatisfactionStats:(s=30)=>oe.get("/api/platform/support/dashboard/satisfaction",{params:{days:s}}),getSlaCompliance:(s=30)=>oe.get("/api/platform/support/dashboard/sla-compliance",{params:{days:s}})},js={getConfigurations:()=>oe.get("/api/platform/support/sla/configurations"),updateConfiguration:(s,t)=>oe.put(`/api/platform/support/sla/configurations/${s}`,t),getEscalationRules:()=>oe.get("/api/platform/support/sla/escalation-rules"),getBreachedTickets:(s=!0,t=!0)=>oe.get("/api/platform/support/sla/breached",{params:{responseBreached:s,resolutionBreached:t}}),getTicketsApproachingBreach:(s=60)=>oe.get("/api/platform/support/sla/approaching-breach",{params:{warningMinutes:s}}),getMetrics:(s,t)=>oe.get("/api/platform/support/sla/metrics",{params:{fromDate:s,toDate:t}}),escalateTicket:(s,t,r)=>oe.post(`/api/platform/support/sla/tickets/${s}/escalate`,{level:t,reason:r})},ns={getAll:(s=1,t=20,r,n)=>oe.get("/api/platform/support/notifications",{params:{page:s,pageSize:t,isRead:r,tenantId:n}}),getUnread:(s=10)=>oe.get("/api/platform/support/notifications/unread",{params:{limit:s}}),getUnreadCount:()=>oe.get("/api/platform/support/notifications/unread/count"),markAsRead:s=>oe.patch(`/api/platform/support/notifications/${s}/read`),markAllAsRead:()=>oe.patch("/api/platform/support/notifications/read-all"),delete:s=>oe.delete(`/api/platform/support/notifications/${s}`),deleteAll:()=>oe.delete("/api/platform/support/notifications/all"),getPreferences:()=>oe.get("/api/platform/support/notifications/preferences"),updatePreferences:s=>oe.put("/api/platform/support/notifications/preferences",s)},As={getAll:(s,t=!0)=>oe.get("/api/platform/support/templates",{params:{category:s,activeOnly:t}}),getById:s=>oe.get(`/api/platform/support/templates/${s}`),getCategories:()=>oe.get("/api/platform/support/templates/categories"),getByCategory:s=>oe.get(`/api/platform/support/templates/by-category/${s}`),create:s=>oe.post("/api/platform/support/templates",s),update:(s,t)=>oe.put(`/api/platform/support/templates/${s}`,t),activate:s=>oe.patch(`/api/platform/support/templates/${s}/activate`),deactivate:s=>oe.patch(`/api/platform/support/templates/${s}/deactivate`),delete:s=>oe.delete(`/api/platform/support/templates/${s}`),render:(s,t)=>oe.post(`/api/platform/support/templates/${s}/render`,{variables:t})};function bi(s,t){return s?t===s?"current":"other":"global"}const gs={STARTED:"EntraSyncStarted",COMPLETED:"EntraSyncCompleted",FAILED:"EntraSyncFailed"};function yc(s,t,r){if(r){const i=t.relatedEntityId,o=s.filter(c=>!(c.type===gs.STARTED&&c.relatedEntityId===i));return[t,...o].slice(0,10)}return s.some(i=>i.id===t.id)?s:[t,...s].slice(0,10)}function Jt(){const s=Q.useNavigate(),{currentTenant:t,hasMultipleTenants:r}=ze(),[n,i]=l.useState(!1),[o,c]=l.useState(0),[x,u]=l.useState([]),[d,m]=l.useState(!1),p=l.useRef(null),{isConnected:h,onNotification:v,onUnreadCountUpdate:b}=dr(),[,g]=l.useState(0);l.useEffect(()=>{if(!x.some(T=>T.type===gs.STARTED&&!T.isRead))return;const S=setInterval(()=>{g(T=>T+1)},1e3);return()=>clearInterval(S)},[x]),l.useEffect(()=>{const L=v(T=>{const I={id:T.id,type:T.type,title:T.title,message:T.message,relatedEntityType:T.relatedEntityType,relatedEntityId:T.relatedEntityId,actionUrl:T.actionUrl,isRead:T.isRead,readAt:T.readAt,createdAt:T.createdAt,tenantId:T.tenantId,tenantName:T.tenantName,tenantSlug:T.tenantSlug},M=T.type===gs.COMPLETED||T.type===gs.FAILED;u(X=>yc(X,I,M))}),S=b(T=>{c(T)});return()=>{L(),S()}},[v,b]);const j=l.useCallback(async()=>{try{const L=await ns.getUnreadCount();c(L.count)}catch(L){console.error("Failed to load unread count:",L)}},[]),w=l.useCallback(async()=>{try{m(!0);const L=await ns.getUnread(10);u(L)}catch(L){console.error("Failed to load notifications:",L)}finally{m(!1)}},[]);l.useEffect(()=>{j()},[j]),l.useEffect(()=>{n&&w()},[n,w]),l.useEffect(()=>{const L=S=>{p.current&&!p.current.contains(S.target)&&i(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[]);const f=async(L,S)=>{S.stopPropagation();try{await ns.markAsRead(L),u(T=>T.map(I=>I.id===L?{...I,isRead:!0}:I)),c(T=>Math.max(0,T-1))}catch(T){console.error("Failed to mark as read:",T)}},N=async()=>{try{await ns.markAllAsRead(),u(L=>L.map(S=>({...S,isRead:!0}))),c(0)}catch(L){console.error("Failed to mark all as read:",L)}},k=async(L,S)=>{S.stopPropagation();try{await ns.delete(L);const T=x.find(I=>I.id===L);u(I=>I.filter(M=>M.id!==L)),T&&!T.isRead&&c(I=>Math.max(0,I-1))}catch(T){console.error("Failed to delete notification:",T)}},C=L=>{L.isRead||(ns.markAsRead(L.id),c(S=>Math.max(0,S-1))),i(!1),L.actionUrl&&s(L.actionUrl)},y=L=>{switch(L){case"TicketCreated":return"🎫";case"TicketAssigned":return"👤";case"TicketStatusChanged":case"StatusChanged":return"🔄";case"TicketCommented":case"CommentAdded":return"💬";case"TicketResolved":return"✅";case"TicketClosed":return"🔒";case"TicketUpdated":return"📝";case"SlaResponseBreached":case"SlaResolutionBreached":return"⚠️";case"SlaWarning":return"⏰";case"TicketEscalated":return"📈";case"SatisfactionRequested":return"⭐";case"GroupMemberAdded":return"👥";case"GroupMemberRemoved":return"🚪";case"RoleAssigned":return"🎭";case"RoleRemoved":return"🚫";case"RolePermissionsChanged":return"🔑";case"AccountUpdated":return"👤";case"SystemAnnouncement":return"📢";case gs.STARTED:return null;case gs.COMPLETED:return"✅";case gs.FAILED:return"❌";default:return"📌"}},A=L=>{const S=new Date(L).getTime(),T=Date.now(),I=Math.floor((T-S)/1e3),M=Math.floor(I/60),X=I%60;return`${M.toString().padStart(2,"0")}:${X.toString().padStart(2,"0")}`},D=L=>{const S=new Date(L),I=new Date().getTime()-S.getTime(),M=Math.floor(I/6e4),X=Math.floor(M/60),O=Math.floor(X/24);return M<1?"Just now":M<60?`${M}m ago`:X<24?`${X}h ago`:O<7?`${O}d ago`:S.toLocaleDateString()},R=L=>{if(!r)return null;const S=bi(L.tenantId,t?.id??null);return S==="global"?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 border border-purple-200 dark:border-purple-700",children:"System"}):S==="current"?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-[var(--bg-secondary)] text-[var(--text-secondary)] border border-[var(--border-color)] truncate max-w-[120px]",children:L.tenantName}):e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 border border-blue-200 dark:border-blue-700 font-medium truncate max-w-[120px]",children:L.tenantName})};return e.jsxs("div",{className:"relative",ref:p,children:[e.jsxs("button",{onClick:()=>i(!n),className:"relative p-2 rounded-lg hover:bg-[var(--bg-hover)] transition-colors","aria-label":"Notifications",children:[e.jsx(a.Bell,{className:"w-5 h-5"}),o>0&&e.jsx("span",{className:"absolute -top-1 -right-1 w-5 h-5 bg-red-500 text-white text-xs font-bold rounded-full flex items-center justify-center",children:o>9?"9+":o})]}),n&&e.jsxs("div",{className:"absolute right-0 mt-2 w-96 bg-[var(--bg-primary)] rounded-lg shadow-xl border border-[var(--border-color)] z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-[var(--border-color)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:"Notifications"}),h?e.jsx("span",{title:"Real-time connected",children:e.jsx(a.Wifi,{className:"w-3 h-3 text-green-500"})}):e.jsx("span",{title:"Offline mode",children:e.jsx(a.WifiOff,{className:"w-3 h-3 text-gray-400"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o>0&&e.jsxs("button",{onClick:N,className:"text-sm text-[var(--color-primary-600)] hover:underline flex items-center gap-1",children:[e.jsx(a.CheckCheck,{className:"w-4 h-4"}),"Mark all read"]}),e.jsx("button",{onClick:()=>i(!1),className:"p-1 rounded hover:bg-[var(--bg-hover)]",children:e.jsx(a.X,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"max-h-96 overflow-y-auto",children:d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(a.Loader2,{className:"w-6 h-6 animate-spin text-[var(--color-primary-600)]"})}):x.length>0?x.map(L=>{const S=L.type===gs.STARTED&&!L.isRead,T=y(L.type);return e.jsx("div",{onClick:()=>C(L),onKeyDown:I=>{(I.key==="Enter"||I.key===" ")&&C(L)},role:"button",tabIndex:0,className:`p-4 border-b border-[var(--border-color)] cursor-pointer hover:bg-[var(--bg-hover)] transition-colors ${L.isRead?"":"bg-blue-50/50 dark:bg-blue-900/10"} ${S?"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20":""}`,children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"text-xl flex-shrink-0",children:S?e.jsx(a.RefreshCw,{className:"w-5 h-5 text-[var(--color-accent-600)] animate-spin"}):T}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:`text-sm ${L.isRead?"":"font-semibold"}`,children:L.title}),R(L)]}),S?e.jsxs("span",{className:"text-xs font-mono font-bold text-[var(--color-accent-600)] flex-shrink-0 bg-[var(--color-accent-100)] px-2 py-0.5 rounded",children:["⏱ ",A(L.createdAt)]}):e.jsx("span",{className:"text-xs text-[var(--text-secondary)] flex-shrink-0",children:D(L.createdAt)})]}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] line-clamp-2 mt-1",children:L.message})]}),e.jsxs("div",{className:"flex flex-col gap-1 flex-shrink-0",children:[!L.isRead&&!S&&e.jsx("button",{onClick:I=>f(L.id,I),className:"p-1 rounded hover:bg-[var(--bg-secondary)]",title:"Mark as read",children:e.jsx(a.Check,{className:"w-4 h-4 text-green-600"})}),!S&&e.jsx("button",{onClick:I=>k(L.id,I),className:"p-1 rounded hover:bg-[var(--bg-secondary)]",title:"Delete",children:e.jsx(a.Trash2,{className:"w-4 h-4 text-red-500"})})]})]})},L.id)}):e.jsxs("div",{className:"py-8 text-center text-[var(--text-secondary)]",children:[e.jsx(a.Bell,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No notifications"})]})}),e.jsx("div",{className:"p-3 border-t border-[var(--border-color)] text-center",children:e.jsx("button",{onClick:()=>{i(!1),s("/notifications")},className:"text-sm text-[var(--color-primary-600)] hover:underline",children:"View all notifications"})})]})]})}const wt="support_error_context";class Nc{async captureContext(){const t={url:window.location.href,timestamp:new Date,recentErrors:qe.getRecentErrors(),browserInfo:{userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,screenWidth:window.screen.width,screenHeight:window.screen.height}};try{const r=await this.captureScreenshot();t.screenshot=r}catch(r){console.warn("[ErrorContextService] Failed to capture screenshot:",r)}return t}async captureScreenshot(){try{console.log("[ErrorContextService] Capturing screenshot with modern-screenshot, scale:",1);const r=await Cr.domToJpeg(document.body,{scale:1,quality:.85,backgroundColor:"#1a1a2e",style:{transform:"none"},filter:n=>{if(n instanceof HTMLElement){const i=n.tagName?.toUpperCase();return i!=="IFRAME"&&i!=="VIDEO"}return!0}});return console.log("[ErrorContextService] Screenshot captured, size:",Math.round(r.length/1024),"KB"),r.length>4*1024*1024?(console.log("[ErrorContextService] Screenshot too large, recompressing..."),await this.recompressScreenshot(r,.7)):r}catch(t){console.error("[ErrorContextService] Screenshot capture failed:",t);try{console.log("[ErrorContextService] Trying fallback screenshot capture...");const r=await Cr.domToJpeg(document.body,{scale:.75,quality:.8,backgroundColor:"#1a1a2e"});return console.log("[ErrorContextService] Fallback screenshot captured, size:",Math.round(r.length/1024),"KB"),r}catch(r){console.error("[ErrorContextService] Fallback also failed:",r);return}}}async recompressScreenshot(t,r){return new Promise(n=>{const i=new Image;i.onload=()=>{const o=document.createElement("canvas");o.width=i.width,o.height=i.height;const c=o.getContext("2d");if(c){c.drawImage(i,0,0);const x=o.toDataURL("image/jpeg",r);console.log("[ErrorContextService] Recompressed to:",Math.round(x.length/1024),"KB"),n(x)}else n(t)},i.onerror=()=>n(t),i.src=t})}saveContext(t){try{const r=JSON.stringify(t);console.log("[ErrorContextService] Saving context, total size:",Math.round(r.length/1024),"KB");try{sessionStorage.setItem(wt,r),console.log("[ErrorContextService] Context saved successfully")}catch{console.warn("[ErrorContextService] SessionStorage quota exceeded, saving without screenshot");const i={...t,screenshot:void 0};sessionStorage.setItem(wt,JSON.stringify(i))}}catch(r){console.error("[ErrorContextService] Failed to save context:",r)}}loadContext(){try{const t=sessionStorage.getItem(wt);if(console.log("[ErrorContextService] Loading context, data exists:",!!t,"size:",t?Math.round(t.length/1024):0,"KB"),t){const r=JSON.parse(t);return r.timestamp=new Date(r.timestamp),r.recentErrors=r.recentErrors.map(n=>({...n,timestamp:new Date(n.timestamp)})),console.log("[ErrorContextService] Context loaded, screenshot exists:",!!r.screenshot,"screenshot size:",r.screenshot?Math.round(r.screenshot.length/1024):0,"KB"),r.screenshot&&!r.screenshot.startsWith("data:image/")&&(console.warn("[ErrorContextService] Invalid screenshot data URL, clearing it"),r.screenshot=void 0),r}}catch(t){console.warn("[ErrorContextService] Failed to load context:",t)}return null}clearContext(){sessionStorage.removeItem(wt)}formatErrorsForDescription(t){return t.length===0?"":t.slice(0,5).map((n,i)=>{const o=n.timestamp.toLocaleTimeString();return`${i+1}. [${o}] ${n.message}${n.component?` (${n.component})`:""}`}).join(`
2
- `)}}const ys=new Nc,ua="ticket_drafts",Pr=5,$r=7;class wc{getDrafts(){try{const t=localStorage.getItem(ua);return t?JSON.parse(t).map(n=>({...n,createdAt:new Date(n.createdAt),updatedAt:new Date(n.updatedAt)})):[]}catch(t){return console.warn("[TicketDraftService] Failed to load drafts:",t),[]}}saveDrafts(t){try{const r=t.map(i=>({...i,createdAt:i.createdAt.toISOString(),updatedAt:i.updatedAt.toISOString()})),n=JSON.stringify(r);return console.log("[TicketDraftService] Saving drafts, total size:",Math.round(n.length/1024),"KB"),localStorage.setItem(ua,n),!0}catch(r){if(console.error("[TicketDraftService] Failed to save drafts:",r),r instanceof DOMException&&r.name==="QuotaExceededError"){console.warn("[TicketDraftService] Quota exceeded, trying without screenshots and attachments...");try{const n=t.map(i=>({...i,screenshot:void 0,attachments:void 0,createdAt:i.createdAt.toISOString(),updatedAt:i.updatedAt.toISOString()}));return localStorage.setItem(ua,JSON.stringify(n)),console.warn("[TicketDraftService] Saved without screenshots and attachments"),!0}catch(n){console.error("[TicketDraftService] Still failed without large data:",n)}}return!1}}cleanupExpiredDrafts(){const t=this.getDrafts(),r=new Date,n=$r*24*60*60*1e3,i=t.filter(o=>r.getTime()-o.updatedAt.getTime()<n);i.length!==t.length&&(console.log("[TicketDraftService] Cleaned up",t.length-i.length,"expired drafts"),this.saveDrafts(i))}getAllDrafts(){return this.cleanupExpiredDrafts(),this.getDrafts().sort((t,r)=>r.updatedAt.getTime()-t.updatedAt.getTime())}getDraft(t){return this.getAllDrafts().find(n=>n.id===t)||null}createDraft(){const t=this.getAllDrafts();if(t.length>=Pr){const o=t[t.length-1];this.deleteDraft(o.id)}const r=new Date,n={id:crypto.randomUUID(),type:null,title:"",description:"",priority:"Medium",includeScreenshot:!0,includeErrorLogs:!0,createdAt:r,updatedAt:r},i=[n,...this.getDrafts().slice(0,Pr-1)];return this.saveDrafts(i),console.log("[TicketDraftService] Created new draft:",n.id),n}updateDraft(t,r){const n=this.getDrafts(),i=n.findIndex(x=>x.id===t);if(i===-1)return console.warn("[TicketDraftService] Draft not found:",t),{success:!1,draft:null};const o={...n[i],...r,updatedAt:new Date};console.log("[TicketDraftService] Updating draft:",t,{type:o.type,title:o.title?.substring(0,30),descriptionLength:o.description?.length,priority:o.priority,hasScreenshot:!!o.screenshot,screenshotSize:o.screenshot?Math.round(o.screenshot.length/1024):0,hasErrorContext:!!o.errorContext,attachmentsCount:o.attachments?.length||0,attachmentsTotalSize:o.attachments?.reduce((x,u)=>x+u.size,0)||0}),n[i]=o;const c=this.saveDrafts(n);return{success:c,draft:c?o:null}}deleteDraft(t){const r=this.getDrafts(),n=r.filter(i=>i.id!==t);return n.length===r.length?!1:(this.saveDrafts(n),console.log("[TicketDraftService] Deleted draft:",t),!0)}getDraftCount(){return this.getAllDrafts().length}hasDrafts(){return this.getDraftCount()>0}getTimeUntilExpiration(t){const r=$r*24*60*60*1e3,n=t.updatedAt.getTime()+r,i=Math.max(0,n-Date.now()),o=Math.floor(i/(1440*60*1e3)),c=Math.floor(i%(1440*60*1e3)/(3600*1e3));return{days:o,hours:c}}}const Ye=new wc;function Yt({variant:s="icon",className:t=""}){const{t:r}=ne.useTranslation(["common","support"]),n=Q.useNavigate(),[i,o]=l.useState(!1),[c,x]=l.useState(!1),[u,d]=l.useState([]),m=l.useRef(null);l.useEffect(()=>{c&&d(Ye.getAllDrafts())},[c]),l.useEffect(()=>{const w=f=>{m.current&&!m.current.contains(f.target)&&x(!1)};return c&&document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[c]);const p=async w=>{o(!0),x(!1);const N=(w?Ye.getDraft(w):null)?.screenshot;let k=null;if(N)console.log("[CreateTicketButton] Resuming draft with existing screenshot, skipping capture"),ys.clearContext();else try{console.log("[CreateTicketButton] Starting context capture..."),k=await ys.captureContext(),console.log("[CreateTicketButton] Context captured, screenshot:",!!k.screenshot,"size:",k.screenshot?Math.round(k.screenshot.length/1024):0,"KB"),ys.saveContext(k),console.log("[CreateTicketButton] Context saved to sessionStorage")}catch(C){console.warn("[CreateTicketButton] Failed to capture error context:",C)}if(o(!1),w)n(`/platform/support/tickets/new?draft=${w}`);else{const C=Ye.createDraft();k&&(console.log("[CreateTicketButton] Saving captured context directly to draft:",C.id),Ye.updateDraft(C.id,{screenshot:k.screenshot,errorContext:{url:k.url,timestamp:k.timestamp.toISOString(),recentErrors:k.recentErrors.map(y=>({...y,timestamp:y.timestamp.toISOString()})),browserInfo:k.browserInfo}})),n(`/platform/support/tickets/new?draft=${C.id}`)}},h=async()=>{const w=Ye.getAllDrafts();w.length>0?(d(w),x(!0)):await p()},v=(w,f)=>{w.stopPropagation(),Ye.deleteDraft(f);const N=Ye.getAllDrafts();d(N),N.length===0&&x(!1)},b=w=>w.title?w.title.length>30?w.title.substring(0,30)+"...":w.title:w.type?r(`support:tickets.types.${w.type}`):r("common:drafts.untitled"),g=w=>{const N=new Date().getTime()-w.getTime(),k=Math.floor(N/6e4),C=Math.floor(N/36e5),y=Math.floor(N/864e5);return k<1?r("common:drafts.justNow"):k<60?r("common:drafts.minutesAgo",{count:k}):C<24?r("common:drafts.hoursAgo",{count:C}):r("common:drafts.daysAgo",{count:y})},j=()=>e.jsxs("div",{ref:m,className:"absolute right-0 top-full mt-2 w-80 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-xl z-50",children:[e.jsxs("div",{className:"p-3 border-b border-[var(--border-color)]",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("common:drafts.existingDrafts")}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)] mt-1",children:r("common:drafts.selectOrCreate")})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto",children:u.map(w=>{const f=Ye.getTimeUntilExpiration(w);return e.jsxs("div",{onClick:()=>p(w.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&p(w.id),className:"w-full p-3 flex items-start gap-3 hover:bg-[var(--bg-hover)] transition-colors text-left border-b border-[var(--border-color)] last:border-b-0 cursor-pointer",children:[e.jsx(a.FileEdit,{className:"w-4 h-4 text-[var(--text-secondary)] mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:b(w)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--text-secondary)] mt-1",children:[e.jsx(a.Clock,{className:"w-3 h-3"}),e.jsx("span",{children:g(w.updatedAt)}),e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"•"}),e.jsx("span",{className:"text-[var(--warning-text)]",children:f.days>0?r("common:drafts.expiresInDays",{count:f.days}):r("common:drafts.expiresInHours",{count:f.hours})})]})]}),e.jsx("button",{onClick:N=>v(N,w.id),className:"p-1.5 rounded hover:bg-[var(--error-bg)] text-[var(--text-secondary)] hover:text-[var(--error-text)] transition-colors",title:r("common:actions.delete"),children:e.jsx(a.Trash2,{className:"w-4 h-4"})})]},w.id)})}),e.jsx("div",{className:"p-2 border-t border-[var(--border-color)]",children:e.jsxs("button",{onClick:()=>p(),className:"w-full flex items-center justify-center gap-2 px-4 py-2 bg-[var(--color-primary-600)] text-white rounded-lg hover:bg-[var(--color-primary-700)] transition-colors text-sm",children:[e.jsx(a.Plus,{className:"w-4 h-4"}),r("common:drafts.createNew")]})})]});return s==="icon"?e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:h,disabled:i,className:`p-2 rounded-lg hover:bg-[var(--bg-hover)] transition-colors disabled:opacity-50 ${t}`,title:r("common:actions.createTicket"),children:i?e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}):e.jsx(a.Headset,{className:"w-5 h-5"})}),c&&j()]}):e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:h,disabled:i,className:`flex items-center gap-2 px-4 py-2 bg-[var(--color-primary-600)] text-white rounded-lg hover:bg-[var(--color-primary-700)] transition-colors disabled:opacity-50 ${t}`,children:[i?e.jsx(a.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsx(a.Headset,{className:"w-4 h-4"}),r("common:actions.createTicket")]}),c&&j()]})}function vi({onMenuToggle:s}){const{t}=ne.useTranslation(["admin","navigation"]),[r,n]=l.useState(!1),i=ws(),{getApplicationsForContext:o}=Ze(),{logout:c}=Ke(),u=o("platform").flatMap(d=>d.modules);return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[s&&e.jsx("button",{onClick:s,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.Menu,{className:"w-5 h-5"})}),e.jsxs(Q.Link,{to:i("/platform"),className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 animated-gradient flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 ml-4 px-2.5 py-1 border border-emerald-500/30 bg-emerald-500/10",style:{borderRadius:"var(--radius-badge)"},children:[e.jsx(a.Shield,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:"text-xs font-medium text-emerald-500",children:t("admin:header.indicator")})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(pr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(tt,{}),e.jsx(ms,{}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 pl-3 border-l border-[var(--border-color)]",children:[!1,e.jsx(Yt,{}),e.jsx(Jt,{}),e.jsx(Qt,{})]}),e.jsx("button",{onClick:()=>n(!r),className:"sm:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"sm:hidden py-4 border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[u.map(d=>e.jsx(Q.Link,{to:i(d.route||"#"),className:"px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:d.label},d.id)),e.jsx("hr",{className:"my-2 border-[var(--border-color)]"}),e.jsxs("button",{onClick:()=>{n(!1),c()},className:"flex items-center gap-2 px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors text-red-500",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),t("navigation:header.logout")]})]})})]})})}function Wa({name:s,className:t}){const n=es[s];return n?e.jsx(n,{className:t}):e.jsx(a.Star,{className:t})}function Xa(s){if(!s)return a.Box;const t=es;if(t[s])return t[s];const r=s.toLowerCase(),n=Object.keys(t).find(i=>i.toLowerCase()===r);return n?t[n]:a.Box}function kc({module:s,isActive:t,isCollapsed:r,onClose:n,buildUrl:i}){const[o,c]=l.useState(!1),[x,u]=l.useState({top:0,left:0}),d=l.useRef(null),m=l.useRef(null),p=()=>{if(r){if(d.current&&(clearTimeout(d.current),d.current=null),m.current){const v=m.current.getBoundingClientRect();u({top:v.top,left:v.right+8})}c(!0)}},h=()=>{r&&(d.current=setTimeout(()=>{c(!1)},150))};return l.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]),e.jsxs("div",{ref:m,className:"relative",onMouseEnter:p,onMouseLeave:h,children:[e.jsxs(Q.Link,{to:i(s.route),onClick:n,className:`flex items-center transition-colors ${r?"justify-center px-2 py-2":"gap-3 px-3 py-2"} ${t?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},title:r?`${s.label} (${s.applicationLabel})`:void 0,children:[e.jsx(Wa,{name:s.icon,className:"w-4 h-4 flex-shrink-0"}),!r&&e.jsx("span",{className:"text-sm font-medium truncate",children:s.label})]}),r&&o&&Zs.createPortal(e.jsx("div",{className:"fixed z-[9999] pointer-events-auto",style:{top:x.top,left:x.left},onMouseEnter:p,onMouseLeave:h,children:e.jsx("div",{className:"px-3 py-2 bg-[var(--bg-secondary)] border border-[var(--border-color)] shadow-lg whitespace-nowrap",style:{borderRadius:"var(--radius-menu-item)"},children:e.jsx("span",{className:"text-sm font-medium text-[var(--text-primary)]",children:s.label})})}),document.body)]})}function Cc({module:s,isExpanded:t,onToggle:r,onNavigate:n,currentPath:i,isCollapsed:o}){const[c,x]=l.useState(!1),[u,d]=l.useState({top:0,left:0}),[m,p]=l.useState(new Set),h=l.useRef(null),v=l.useRef(null),b=Xa(s.icon),g=s.route?i===s.route:i.includes(`/${s.code}`),j=(s.sections?.length??0)>0,w=s.label;l.useEffect(()=>{if(!s.sections)return;const y=s.sections.find(A=>A.resources?.some(D=>D.route&&i.startsWith(D.route)));y&&!m.has(y.id)&&p(A=>new Set([...A,y.id]))},[i,s.sections,m]);const f=y=>{p(A=>{const D=new Set(A);return D.has(y)?D.delete(y):D.add(y),D})},N=()=>{if(o){if(h.current&&(clearTimeout(h.current),h.current=null),v.current){const y=v.current.getBoundingClientRect();d({top:y.top,left:y.right+8})}x(!0)}},k=()=>{o&&(h.current=setTimeout(()=>{x(!1)},150))};l.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const C=()=>{j&&!o?r():s.route&&n(s.route)};return e.jsxs("div",{ref:v,className:"relative",onMouseEnter:N,onMouseLeave:k,children:[e.jsxs("button",{onClick:C,className:`w-full flex items-center transition-all duration-200 ${o?"justify-center px-2 py-2.5":"gap-3 px-3 py-2.5"} ${g?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},title:o&&!j?w:void 0,children:[e.jsx(b,{className:"w-5 h-5 flex-shrink-0"}),!o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-left font-medium text-sm truncate",children:w}),j&&(t?e.jsx(a.ChevronDown,{className:"w-4 h-4 text-[var(--text-tertiary)] flex-shrink-0"}):e.jsx(a.ChevronRight,{className:"w-4 h-4 text-[var(--text-tertiary)] flex-shrink-0"}))]})]}),o&&c&&Zs.createPortal(e.jsx("div",{className:"fixed z-[9999] pointer-events-auto",style:{top:u.top,left:u.left},onMouseEnter:N,onMouseLeave:k,children:e.jsxs("div",{className:"min-w-[200px] bg-[var(--bg-secondary)] border border-[var(--border-color)] shadow-lg",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"px-3 py-2 border-b border-[var(--border-color)]",children:e.jsx("span",{className:"text-sm font-semibold text-[var(--text-primary)]",children:w})}),e.jsx("div",{className:"p-1.5",children:j?s.sections.map(y=>{const A=Xa(y.icon),D=y.route&&i===y.route;return e.jsxs("button",{onClick:()=>y.route&&n(y.route),className:`w-full flex items-center gap-2.5 px-2.5 py-2 transition-colors ${D?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(A,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{className:"text-sm",children:y.label})]},y.id)}):s.route&&e.jsxs("button",{onClick:()=>n(s.route),className:"w-full flex items-center gap-2.5 px-2.5 py-2 hover:bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(b,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{className:"text-sm",children:"Ouvrir"})]})})]})}),document.body),!o&&t&&j&&e.jsx("div",{className:"ml-4 pl-4 border-l border-[var(--border-color)] mt-1 space-y-1",children:s.sections.map(y=>e.jsx(Sc,{section:y,currentPath:i,onNavigate:n,isCollapsed:o,isExpanded:m.has(y.id),onToggle:()=>f(y.id)},y.id))})]})}function Sc({section:s,currentPath:t,onNavigate:r,isCollapsed:n,isExpanded:i,onToggle:o}){const c=Xa(s.icon),x=s.route&&(t===s.route||t.startsWith(s.route+"/")),u=(s.resources?.length??0)>0,d=s.label,m=p=>{p.preventDefault(),s.route&&r(s.route),u&&o()};return n?null:e.jsxs("div",{children:[e.jsxs("button",{onClick:m,className:`w-full flex items-center gap-3 px-3 py-2 transition-all duration-200 ${x?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(c,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{className:"flex-1 text-sm text-left",children:d}),u&&(i?e.jsx(a.ChevronDown,{className:"w-3.5 h-3.5 text-[var(--text-tertiary)] flex-shrink-0"}):e.jsx(a.ChevronRight,{className:"w-3.5 h-3.5 text-[var(--text-tertiary)] flex-shrink-0"}))]}),i&&u&&e.jsx("div",{className:"ml-4 pl-3 border-l border-[var(--border-color)] mt-1 space-y-0.5",children:s.resources.map(p=>e.jsx(Tc,{resource:p,currentPath:t,onNavigate:r},p.id))})]})}function Tc({resource:s,currentPath:t,onNavigate:r}){const n=s.route&&t.startsWith(s.route),i=o=>{o.preventDefault(),s.route&&r(s.route)};return e.jsxs("button",{onClick:i,className:`w-full flex items-center gap-2.5 px-2.5 py-1.5 transition-all duration-200 ${n?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-current flex-shrink-0"}),e.jsx("span",{className:"text-xs text-left",children:s.label})]})}const Ac=(s,t)=>s?s.modules.find(n=>n.sections?.length?n.sections.some(i=>i.route&&t.pathname===i.route):!1)||s.modules.find(n=>n.route&&t.pathname.startsWith(n.route)&&(n.sections?.length??0)>0):null;function Zt({isOpen:s,onClose:t}){const{t:r}=ne.useTranslation(["navigation","common"]),n=Q.useLocation(),i=Q.useNavigate(),{getCurrentApplication:o,isLoading:c,currentContextCode:x}=Ze(),{favorites:u,loading:d}=rs(),{expandFavorites:m,clearExpand:p}=rs(),{isCollapsed:h,toggleCollapsed:v}=st(),b=ws(),[g,j]=l.useState(new Set),[w,f]=l.useState(!1);l.useEffect(()=>{m&&(queueMicrotask(()=>{f(!1)}),p())},[m,p]);const N=o();l.useEffect(()=>{if(!N)return;const A=Ac(N,n);A&&!g.has(A.id)&&queueMicrotask(()=>{j(D=>new Set([...D,A.id]))})},[n.pathname,N,g]);const k=A=>{j(D=>{const R=new Set(D);return R.has(A)?R.delete(A):R.add(A),R})},C=A=>{i(b(A)),t()},y=N?.label??"";return N?e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:t}),e.jsxs("aside",{className:`group/sidebar fixed top-16 bottom-0 left-0 bg-[var(--bg-primary)] border-r border-[var(--border-color)] transform transition-all duration-300 z-50 overflow-visible ${h?"w-16":"w-64"} ${s?"translate-x-0":"-translate-x-full lg:translate-x-0"}`,children:[e.jsxs("button",{onClick:v,className:"hidden lg:flex absolute top-1/2 -translate-y-1/2 w-3 h-16 items-center justify-center group/toggle transition-all duration-200 z-[9999]",style:{right:"-12px"},title:h?r("sidebar.expand","Agrandir le menu"):r("sidebar.collapse","Réduire le menu"),children:[e.jsx("div",{className:"absolute left-0 w-[3px] h-full bg-[var(--border-color)] group-hover/toggle:bg-[var(--color-accent-500)] transition-colors duration-200 rounded-full"}),e.jsx("div",{className:"absolute right-0 w-4 h-4 flex items-center justify-center bg-[var(--bg-secondary)] border border-[var(--border-color)] group-hover/toggle:border-[var(--color-accent-500)] group-hover/toggle:text-[var(--color-accent-500)] text-[var(--text-muted)] rounded-full shadow-sm transition-all duration-200",children:h?e.jsx(a.ChevronRight,{className:"w-3 h-3"}):e.jsx(a.ChevronLeft,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:`${h?"p-2":"p-4"}`,children:[e.jsxs("div",{className:"flex items-center justify-between group/header",children:[h?e.jsx("div",{className:"w-full flex justify-center",children:e.jsx("div",{className:"w-10 h-10 flex items-center justify-center bg-gradient-to-br from-[var(--color-accent-500)] to-[var(--color-accent-700)] text-white shadow-sm",style:{borderRadius:"var(--radius-button)"},title:y,children:e.jsx(Wa,{name:N.icon||"LayoutGrid",className:"w-5 h-5"})})}):e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"w-10 h-10 flex-shrink-0 flex items-center justify-center bg-gradient-to-br from-[var(--color-accent-500)] to-[var(--color-accent-700)] text-white shadow-sm",style:{borderRadius:"var(--radius-button)"},children:e.jsx(Wa,{name:N.icon||"LayoutGrid",className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"font-semibold text-[var(--text-primary)] truncate",children:y}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:e.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 text-[10px] font-medium bg-[var(--bg-tertiary)] text-[var(--text-secondary)]",style:{borderRadius:"4px"},children:[N.modules.length," ",N.modules.length===1?"module":"modules"]})})]})]}),e.jsx("button",{onClick:t,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.X,{className:"w-5 h-5"})})]}),e.jsx("div",{className:`mt-3 h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent ${h?"mx-1":""}`})]}),e.jsxs("nav",{className:`flex-1 overflow-y-auto overflow-x-hidden space-y-1 ${h?"p-2 pt-3":"p-3"}`,children:[!d&&u.length>0&&e.jsxs("div",{className:"mb-4",children:[!h&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 mb-1",children:[e.jsxs("button",{onClick:()=>f(!w),className:"flex items-center gap-2 text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider hover:text-[var(--text-primary)] transition-colors",children:[e.jsx("div",{className:`transition-transform duration-200 ${w?"":"rotate-90"}`,children:e.jsx(a.ChevronRight,{className:"w-3.5 h-3.5"})}),e.jsx(a.Star,{className:"w-3.5 h-3.5 text-amber-500"}),r("common:favorites.quickAccess")]}),e.jsx(Q.Link,{to:b("/personal/myspace/preferences?tab=favorites"),onClick:t,className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},title:r("common:favorites.manage"),children:e.jsx(a.Settings,{className:"w-3.5 h-3.5"})})]}),(h||!w)&&e.jsx("div",{className:"space-y-0.5",children:u.map(A=>e.jsx(kc,{module:A,isActive:n.pathname===A.route,isCollapsed:h,onClose:t,buildUrl:b},A.id))}),!h&&e.jsxs("div",{className:"mt-4 pt-4",children:[e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent mb-3"}),e.jsxs("div",{className:"flex items-center gap-2 px-3",children:[e.jsx("div",{className:"w-1 h-3.5 bg-gradient-to-b from-[var(--color-accent-500)] to-[var(--color-accent-300)] rounded-full"}),e.jsx("span",{className:"text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider",children:r("sidebar.navigation","Navigation")})]})]}),h&&e.jsx("div",{className:"my-3 mx-1",children:e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent"})})]}),c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"w-6 h-6 border-2 border-[var(--color-accent-500)] border-t-transparent rounded-full animate-spin"})}):N.modules.length>0?N.modules.map(A=>e.jsx(Cc,{module:A,isExpanded:g.has(A.id),onToggle:()=>k(A.id),onNavigate:C,currentPath:n.pathname,isCollapsed:h},A.id)):!h&&e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] text-center py-8",children:r("sidebar.noModules","Aucun module disponible")})]}),!h&&e.jsxs("div",{className:"p-3",children:[e.jsx("div",{className:"mb-3 h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent"}),e.jsxs("button",{onClick:()=>C(`/${x||"platform"}`),className:"w-full flex items-center gap-2 px-3 py-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-all",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.ChevronLeft,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:r("sidebar.backToApps","Retour aux applications")})]})]})]})]})]}):null}const gi="smartstack-doc-panel-size",fi=l.createContext(void 0);function Rc(){if(typeof window>"u")return 33;try{const s=localStorage.getItem(gi);if(s){const t=parseFloat(s);if(t>=20&&t<=60)return t}}catch{}return 33}const kt={users:"/system/docs/user/modules","users/dashboard":"/system/docs/user/modules","users/list":"/system/docs/user/modules","users/create":"/system/docs/user/modules",permissions:"/system/docs/user/modules","permissions/roles":"/system/docs/user/modules","permissions/permissions":"/system/docs/user/modules",applications:"/system/docs/user/architecture",workflows:"/system/docs/user/support-templates","workflows/list":"/system/docs/user/support-templates","workflows/create":"/system/docs/user/support-templates","workflows/triggers":"/system/docs/user/support-templates","workflows/history":"/system/docs/user/support-templates","workflows/email-templates":"/system/docs/user/support-templates","workflows/email-templates/email":"/system/docs/user/support-templates","workflows/email-templates/sms":"/system/docs/user/support-templates","workflows/email-templates/create":"/system/docs/user/support-templates",ai:"/system/docs/user/ai","ai/providers":"/system/docs/user/ai","ai/models":"/system/docs/user/ai","ai/prompts":"/system/docs/user/ai","entra-id":"/system/docs/user/modules","entra-id/configuration":"/system/docs/user/modules","entra-id/sync":"/system/docs/user/modules",settings:"/system/docs/user/settings",dashboard:"/system/docs/user/support-dashboard",tickets:"/system/docs/user/support-tickets","my-tickets":"/system/docs/user/support-my-tickets","sla-config":"/system/docs/user/support-sla","escalation-config":"/system/docs/user/support-escalation",profile:"/system/docs/user/modules",preferences:"/system/docs/user/modules"},Mr={administration:"/system/docs/user/modules",support:"/system/docs/user/support-dashboard",ai:"/system/docs/user/ai",myspace:"/system/docs/user/modules","support-client":"/system/docs/user/support"};function Fr(s){const t=s.split("/").filter(Boolean);if(t.length>=3){const r=t.slice(2);for(let n=r.length;n>0;n--){const i=r.slice(0,n).join("/");if(kt[i])return kt[i]}if(t[1]==="support"){const n=`support/${r[0]}`;if(kt[n])return kt[n]}}if(t.length>=2){const r=t[1];if(Mr[r])return Mr[r]}return"/system/docs/user"}function br({children:s}){const[t,r]=l.useState(!1),[n,i]=l.useState(Rc),[o,c]=l.useState(null),x=Q.useLocation(),u=l.useRef(x.pathname);l.useEffect(()=>{u.current!==x.pathname&&(u.current=x.pathname,r(!1))},[x.pathname]),l.useEffect(()=>{n>=20&&n<=60&&localStorage.setItem(gi,String(n))},[n]);const d=l.useCallback(v=>{const b=v||Fr(x.pathname);c(b),r(!0)},[x.pathname]),m=l.useCallback(()=>{r(!1)},[]),p=l.useCallback(()=>{if(t)r(!1);else{const v=Fr(x.pathname);c(v),r(!0)}},[t,x.pathname]),h=l.useCallback(v=>{v>=20&&v<=60&&i(v)},[]);return e.jsx(fi.Provider,{value:{isOpen:t,panelSize:n,docUrl:o,openDocPanel:d,closeDocPanel:m,toggleDocPanel:p,setPanelSize:h},children:s})}function ea(){const s=l.useContext(fi);if(s===void 0)throw new Error("useDocPanel must be used within a DocPanelProvider");return s}const Ur=60,Ic=33;function Ec(){const{t:s}=ne.useTranslation("common"),{isOpen:t,docUrl:r,closeDocPanel:n,panelSize:i,setPanelSize:o}=ea();if(!t||!r)return null;const c=r.startsWith("http")?r:window.location.origin+r,x=c.includes("?")?"&":"?",u=`${c}${x}embedded=true`,d=i>=Ur-1,m=()=>{o(d?Ic:Ur)};return e.jsxs("div",{className:"h-full flex flex-col bg-[var(--bg-primary)] border-l border-[var(--border-color)]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--border-color)] bg-[var(--bg-secondary)]",children:[e.jsx("h3",{className:"font-semibold text-sm flex items-center gap-2",children:s("docPanel.title")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:m,className:"p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",title:s(d?"docPanel.minimize":"docPanel.maximize"),children:d?e.jsx(a.Minimize2,{className:"w-4 h-4"}):e.jsx(a.Maximize2,{className:"w-4 h-4"})}),e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",title:s("docPanel.openInNewTab"),children:e.jsx(a.ExternalLink,{className:"w-4 h-4"})}),e.jsx("button",{onClick:n,className:"p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",title:s("docPanel.close"),children:e.jsx(a.X,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("iframe",{src:u,title:s("docPanel.title"),className:"w-full h-full border-0"})})]})}function ji({children:s}){const{isOpen:t,panelSize:r,setPanelSize:n}=ea(),[i,o]=nt.useGroupCallbackRef(),c=l.useRef(r),[x,u]=l.useState(!1);if(l.useEffect(()=>{u(!!i)},[i]),l.useEffect(()=>{i&&x&&c.current!==r&&(i.setLayout({"main-content":100-r,"doc-panel":r}),c.current=r)},[r,i,x]),!t)return e.jsx(e.Fragment,{children:s});const d=p=>{c.current=p.asPercentage,n(p.asPercentage)},m={"main-content":100-r,"doc-panel":r};return e.jsxs(nt.Group,{orientation:"horizontal",className:"h-full",defaultLayout:m,groupRef:o,children:[e.jsx(nt.Panel,{id:"main-content",minSize:40,maxSize:80,children:e.jsx("div",{className:"w-full h-full overflow-auto",children:s})}),e.jsx(nt.Separator,{className:"w-1 bg-[var(--border-color)] hover:bg-[var(--color-primary-400)] transition-colors cursor-col-resize group/separator relative",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover/separator:bg-[var(--color-primary-100)]/20"})}),e.jsx(nt.Panel,{id:"doc-panel",minSize:20,maxSize:60,onResize:d,children:e.jsx(Ec,{})})]})}function yi(){const{t:s}=ne.useTranslation("common"),{isOpen:t,openDocPanel:r}=ea();return t?null:e.jsxs("button",{onClick:()=>r(),className:"hidden lg:flex fixed right-0 top-1/2 -translate-y-1/2 w-3 h-16 items-center justify-center group/toggle transition-all duration-200 z-[100]",title:s("docPanel.open"),"aria-label":s("docPanel.open"),children:[e.jsx("div",{className:"absolute right-0 w-[3px] h-full bg-[var(--border-color)] group-hover/toggle:bg-[var(--color-primary-500)] transition-colors duration-200 rounded-full"}),e.jsx("div",{className:"absolute left-0 -translate-x-full w-6 h-6 flex items-center justify-center bg-[var(--bg-secondary)] border border-[var(--border-color)] group-hover/toggle:border-[var(--color-primary-500)] group-hover/toggle:text-[var(--color-primary-500)] text-[var(--text-muted)] rounded-full shadow-sm transition-all duration-200",children:e.jsx(a.BookOpen,{className:"w-3 h-3"})}),e.jsx("div",{className:"absolute right-6 top-1/2 -translate-y-1/2 px-2 py-1 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-md shadow-lg opacity-0 group-hover/toggle:opacity-100 transition-opacity duration-200 pointer-events-none whitespace-nowrap text-xs font-medium text-[var(--text-primary)]",children:s("docPanel.title")})]})}function Dc(){const[s,t]=l.useState(!1),{currentAppCode:r}=Ze(),{isCollapsed:n}=st(),i=!!r;return e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:[e.jsx(vi,{onMenuToggle:()=>t(!s)}),i&&e.jsx(Zt,{isOpen:s,onClose:()=>t(!1)}),e.jsx("main",{className:`pt-16 transition-all duration-300 h-[calc(100vh-4rem)] ${i?n?"lg:pl-16":"lg:pl-64":""}`,children:e.jsx(ji,{children:e.jsx("div",{className:"p-4 sm:p-6 lg:px-10 h-full overflow-auto",children:e.jsx(Q.Outlet,{})})})}),e.jsx(yi,{})]})}function ut(){return e.jsx(br,{children:e.jsx(Dc,{})})}function Ni({onMenuToggle:s}){const{t}=ne.useTranslation(["business","navigation"]),[r,n]=l.useState(!1),{getApplicationsForContext:i}=Ze(),o=ws(),{logout:c}=Ke(),x=i("business");return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[s&&e.jsx("button",{onClick:s,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.Menu,{className:"w-5 h-5"})}),e.jsxs(Q.Link,{to:o("/business"),className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 animated-gradient flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 ml-4 px-2.5 py-1 bg-teal-500/10 border border-teal-500/30",style:{borderRadius:"var(--radius-badge)"},children:[e.jsx(a.Briefcase,{className:"w-3.5 h-3.5 text-teal-500"}),e.jsx("span",{className:"text-xs font-medium text-teal-500",children:"Business"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(pr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(tt,{}),e.jsx(ms,{}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 pl-3 border-l border-[var(--border-color)]",children:[!1,e.jsx(Yt,{}),e.jsx(Jt,{}),e.jsx(Qt,{})]}),e.jsx("button",{onClick:()=>n(!r),className:"sm:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"sm:hidden py-4 border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[x.map(u=>e.jsx(Q.Link,{to:o(u.route||"#"),className:"px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:u.label},u.id)),e.jsx("hr",{className:"my-2 border-[var(--border-color)]"}),e.jsxs("button",{onClick:()=>{n(!1),c()},className:"flex items-center gap-2 px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors text-red-500",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),t("navigation:header.logout")]})]})})]})})}function Lc(){const[s,t]=l.useState(!1),{currentAppCode:r}=Ze(),{isCollapsed:n}=st(),i=!!r;return e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:[e.jsx(Ni,{onMenuToggle:()=>t(!s)}),i&&e.jsx(Zt,{isOpen:s,onClose:()=>t(!1)}),e.jsx("main",{className:`pt-16 transition-all duration-300 ${i?n?"lg:pl-16":"lg:pl-64":""}`,children:e.jsx("div",{className:"p-4 sm:p-6 lg:px-10 h-full overflow-auto",children:e.jsx(Q.Outlet,{})})})]})}function Qa(){return e.jsx(Lc,{})}function wi({onMenuToggle:s}){const{t}=ne.useTranslation("navigation"),[r,n]=l.useState(!1),{getApplicationsForContext:i}=Ze(),{logout:o}=Ke(),c=ws(),x=i("personal").flatMap(u=>u.modules);return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[s&&e.jsx("button",{onClick:s,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.Menu,{className:"w-5 h-5"})}),e.jsxs(Q.Link,{to:c("/personal/myspace"),className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 animated-gradient flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]})]}),e.jsx("div",{className:"hidden md:flex items-center gap-6",children:e.jsxs(Q.Link,{to:c("/personal/myspace"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(a.Home,{className:"w-4 h-4"}),t("breadcrumb.myspace")]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(tt,{}),e.jsx(ms,{}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 pl-3 border-l border-[var(--border-color)]",children:[!1,e.jsx(Yt,{}),e.jsx(Jt,{}),e.jsx(Qt,{})]}),e.jsx("button",{onClick:()=>n(!r),className:"sm:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"sm:hidden py-4 border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[x.map(u=>e.jsx(Q.Link,{to:c(u.route||"#"),className:"px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:u.label},u.id)),e.jsx("hr",{className:"my-2 border-[var(--border-color)]"}),e.jsxs("button",{onClick:()=>{n(!1),o()},className:"flex items-center gap-2 px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors text-red-500",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),t("header.logout")]})]})})]})})}function Pc(){const[s,t]=l.useState(!1),{currentAppCode:r}=Ze(),{isCollapsed:n}=st(),i=!!r;return e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:[e.jsx(wi,{onMenuToggle:()=>t(!s)}),i&&e.jsx(Zt,{isOpen:s,onClose:()=>t(!1)}),e.jsx("main",{className:`pt-16 transition-all duration-300 h-[calc(100vh-4rem)] ${i?n?"lg:pl-16":"lg:pl-64":""}`,children:e.jsx(ji,{children:e.jsx("div",{className:"p-4 sm:p-6 lg:px-10 h-full overflow-auto",children:e.jsx(Q.Outlet,{})})})}),e.jsx(yi,{})]})}function Ja(){return e.jsx(br,{children:e.jsx(Pc,{})})}const $c=[{title:"Infrastructure",description:"Architecture technique, structure du projet et technologies utilisees",href:"/system/docs/developer/infrastructure",category:"developer",tags:[".NET 10","React 19","EF Core","SQL Server","architecture"],icon:a.Server},{title:"Installation",description:"Guide complet pour installer et configurer l'environnement de developpement",href:"/system/docs/developer/installation",category:"developer",tags:["setup","configuration","prerequisites","npm","dotnet","CLI","MCP"],icon:a.Download},{title:"Base de donnees",description:"Modele conceptuel de donnees avec schemas, tables et relations",href:"/system/docs/developer/database",category:"developer",tags:["MCD","Schemas","Relations","SQL","EF Core","migrations","ERD","diagramme","nav","auth","usr","support","ten","ai","wkf","cfg","entra","ref","loc","lic","Contexts","Applications","Modules","Sections","Resources","ContextMaintenance","Users","Roles","UserRoles","Permissions","RolePermissions","RefreshTokens","Sessions","Profiles","Preferences","Tickets","TicketComments","TicketAttachments","TicketTemplates","Notifications","Tenants","TenantApplications","TenantUsers","Providers","Models","Prompts","PromptVersions","PromptExecutions","Workflows","WorkflowSteps","WorkflowExecutions","EmailTemplates","Settings","SettingCategories","Groups","GroupMembers","SyncStates","Companies","Departments","Positions","Languages","Translations","Licenses","LicenseFeatures","Status","Type","Priority","TenantId","UserId","RoleId","PermissionId","CreatedAt","UpdatedAt","CreatedBy","UpdatedBy","IsDeleted","DeletedAt","TenantStatus","TicketStatus","TicketPriority","TicketType","UserType","Theme","Pending","Active","Suspended","Archived","Open","InProgress","Resolved","Closed","Low","Medium","High","Critical","Bug","FeatureRequest","Support","Question"],icon:a.Database},{title:"Architecture Dual-DbContext",description:"Separation Core/Extensions pour la distribution NuGet et les projets client",href:"/system/docs/developer/dual-dbcontext",category:"developer",tags:["CoreDbContext","ExtensionsDbContext","NuGet","Migrations","schema"],icon:a.Layers},{title:"FK Cross-Schema",description:"Comment referencer les entites Core depuis vos entites Extensions",href:"/system/docs/developer/cross-schema-fk",category:"developer",tags:["ICoreDataService","GUID FK","No Navigation","foreign key"],icon:a.Link2},{title:"Mode Multi-Tenant",description:"Configuration Single-Tenant vs Multi-Tenant et migration entre les modes",href:"/system/docs/developer/multi-tenant-mode",category:"developer",tags:["Single-Tenant","Multi-Tenant","Configuration","tenant","workspace"],icon:a.Building2},{title:"Integration Microsoft Teams",description:"Embarquer SmartStack dans Teams via Website Tab sans developpement",href:"/system/docs/developer/teams-integration",category:"developer",tags:["Microsoft Teams","Teams","Website Tab","iframe","SSO","embedding"],icon:a.Monitor},{title:"Architecture",description:"Vue d'ensemble de l'architecture fonctionnelle de SmartStack",href:"/system/docs/user/architecture",category:"user",tags:["architecture","modules","navigation","contextes"],icon:a.Layers},{title:"Modules",description:"Liste des modules disponibles et leur configuration",href:"/system/docs/user/modules",category:"user",tags:["modules","fonctionnalites","features"],icon:a.FileText},{title:"Module Support",description:"Documentation complete du module de ticketing et support client",href:"/system/docs/user/support",category:"user",tags:["tickets","support","SLA","escalation","templates"],icon:a.Headphones},{title:"Intelligence Artificielle",description:"Configuration des providers IA, prompts et integrations",href:"/system/docs/user/ai",category:"user",tags:["IA","AI","prompts","OpenAI","Claude","providers"],icon:a.Bot},{title:"Parametres Systeme",description:"Configuration globale et parametres de la plateforme",href:"/system/docs/user/settings",category:"user",tags:["settings","configuration","parametres","systeme"],icon:a.Settings},{title:"Presentation SmartStack",description:"Presentation interactive de la plateforme SmartStack",href:"/system/docs/presentation",category:"user",tags:["presentation","slides","demo","overview"],icon:a.Presentation}];function Mc({className:s="",placeholder:t="Rechercher...",onResultClick:r}){const[n,i]=l.useState(""),[o,c]=l.useState(!1),[x,u]=l.useState(0),d=l.useRef(null),m=l.useRef(null),p=Q.useNavigate(),h=l.useMemo(()=>{if(!n.trim())return[];const w=n.toLowerCase().split(" ").filter(Boolean);return $c.filter(f=>{const N=[f.title,f.description,...f.tags,f.category].join(" ").toLowerCase();return w.every(k=>N.includes(k))})},[n]);l.useEffect(()=>{u(0)},[h]);const v=w=>{if(!(!o||h.length===0))switch(w.key){case"ArrowDown":w.preventDefault(),u(f=>(f+1)%h.length);break;case"ArrowUp":w.preventDefault(),u(f=>(f-1+h.length)%h.length);break;case"Enter":w.preventDefault(),h[x]&&b(h[x]);break;case"Escape":c(!1),i(""),d.current?.blur();break}},b=w=>{p(w.href),i(""),c(!1),r?.()};l.useEffect(()=>{const w=f=>{m.current&&!m.current.contains(f.target)&&d.current&&!d.current.contains(f.target)&&c(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const g=w=>w==="developer"?"Developpeur":"Utilisateur",j=w=>w==="developer"?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400";return e.jsxs("div",{className:`relative ${s}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx(a.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("input",{ref:d,type:"text",value:n,onChange:w=>{i(w.target.value),c(!0)},onFocus:()=>c(!0),onKeyDown:v,placeholder:t,className:"w-full pl-9 pr-8 py-2 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--color-primary-400)] focus:border-transparent"}),n&&e.jsx("button",{onClick:()=>{i(""),d.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-[var(--bg-hover)]",children:e.jsx(a.X,{className:"w-3 h-3 text-[var(--text-tertiary)]"})})]}),o&&n.trim()&&e.jsxs("div",{ref:m,className:"absolute top-full left-0 right-0 mt-1 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-lg overflow-hidden z-50 max-h-80 overflow-y-auto",children:[h.length===0?e.jsxs("div",{className:"p-4 text-center text-[var(--text-secondary)] text-sm",children:['Aucun resultat pour "',n,'"']}):e.jsx("div",{className:"py-1",children:h.map((w,f)=>{const N=w.icon;return e.jsxs("button",{onClick:()=>b(w),onMouseEnter:()=>u(f),className:`w-full flex items-start gap-3 px-3 py-2 text-left transition-colors ${f===x?"bg-[var(--color-primary-600)]/10":"hover:bg-[var(--bg-hover)]"}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 ${f===x?"bg-[var(--color-primary-600)] text-white":"bg-[var(--bg-secondary)]"}`,children:e.jsx(N,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:w.title}),e.jsx("span",{className:`px-1.5 py-0.5 text-xs rounded ${j(w.category)}`,children:g(w.category)})]}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)] truncate mt-0.5",children:w.description})]}),e.jsx(a.ArrowRight,{className:`w-4 h-4 flex-shrink-0 mt-2 ${f===x?"text-[var(--color-primary-600)]":"text-[var(--text-tertiary)]"}`})]},w.href)})}),e.jsxs("div",{className:"px-3 py-2 border-t border-[var(--border-color)] bg-[var(--bg-secondary)] text-xs text-[var(--text-tertiary)] flex items-center gap-4",children:[e.jsxs("span",{children:[e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-[var(--bg-primary)] border border-[var(--border-color)]",children:"↑↓"})," naviguer"]}),e.jsxs("span",{children:[e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-[var(--bg-primary)] border border-[var(--border-color)]",children:"↵"})," ouvrir"]}),e.jsxs("span",{children:[e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-[var(--bg-primary)] border border-[var(--border-color)]",children:"esc"})," fermer"]})]})]})]})}const Fc=[{title:"Accueil",href:"/system/docs",icon:a.Book},{title:"Developpeur",href:"/system/docs/developer",icon:a.Code,children:[{title:"Infrastructure",href:"/system/docs/developer/infrastructure"},{title:"Installation",href:"/system/docs/developer/installation"},{title:"Base de donnees",href:"/system/docs/developer/database"},{title:"Dual-DbContext",href:"/system/docs/developer/dual-dbcontext"},{title:"FK Cross-Schema",href:"/system/docs/developer/cross-schema-fk"},{title:"Tenant",href:"/system/docs/developer/tenants",children:[{title:"Mode Multi-Tenant",href:"/system/docs/developer/tenants/multi-tenant-mode"},{title:"Tenant B2C",href:"/system/docs/developer/tenants/b2c"}]},{title:"Integration Teams",href:"/system/docs/developer/teams-integration"},{title:"Tests de Securite",href:"/system/docs/developer/testing/security"}]},{title:"Utilisateur",href:"/system/docs/user",icon:a.Users,children:[{title:"Architecture",href:"/system/docs/user/architecture"},{title:"Modules",href:"/system/docs/user/modules"}]},{title:"Analyse metier",href:"/system/docs/ba",icon:a.BarChart3}];function pa({item:s,isChild:t=!1,depth:r=0}){const i=Q.useLocation().pathname===s.href,o="icon"in s?s.icon:null;return e.jsxs(Q.NavLink,{to:s.href,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${i?"bg-[var(--color-primary-600)] text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] hover:text-[var(--text-primary)]"} ${t?"ml-6":""} ${r>1?"ml-12":""}`,children:[o&&e.jsx(o,{className:"w-4 h-4"}),!o&&t&&e.jsx(a.ChevronRight,{className:"w-3 h-3"}),s.title]})}function ki(){const[s,t]=l.useState(!1),r=Q.useLocation(),[n]=Q.useSearchParams(),i=n.get("embedded")==="true",o=m=>r.pathname===m.href?!0:"children"in m&&Array.isArray(m.children)?m.children.some(p=>r.pathname===p.href?!0:"children"in p&&Array.isArray(p.children)?p.children.some(h=>r.pathname===h.href):!1):!1,c=m=>r.pathname===m.href?!0:m.children?m.children.some(p=>r.pathname===p.href):!1,x=m=>m.children&&c(m)?e.jsx("div",{className:"mt-1 space-y-1",children:m.children.map(p=>e.jsx(pa,{item:p,isChild:!0,depth:2},p.href))}):null,u=m=>m.children&&o(m)?e.jsx("div",{className:"mt-1 space-y-1",children:m.children.map(p=>e.jsxs("div",{children:[e.jsx(pa,{item:p,isChild:!0}),x(p)]},p.href))}):null,d=()=>e.jsx("nav",{className:"space-y-1",children:Fc.map(m=>e.jsxs("div",{children:[e.jsx(pa,{item:m}),u(m)]},m.href))});return i?e.jsx("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:e.jsx("main",{className:"p-4 lg:p-6",children:e.jsx("div",{className:"max-w-4xl mx-auto",children:e.jsx(Q.Outlet,{})})})}):e.jsx(cr,{children:e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)] flex flex-col",children:[e.jsx(xr,{}),e.jsxs("div",{className:"flex-1 flex pt-16",children:[e.jsx("button",{className:"lg:hidden fixed bottom-4 right-4 z-50 p-3 rounded-full bg-[var(--color-primary-600)] text-white shadow-lg",onClick:()=>t(!s),children:s?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})}),s&&e.jsx("div",{className:"lg:hidden fixed inset-0 z-40 bg-black/50",onClick:()=>t(!1)}),e.jsx("aside",{className:`fixed lg:sticky top-16 z-40 lg:z-0 h-[calc(100vh-4rem)] w-64 bg-[var(--bg-secondary)] border-r border-[var(--border-color)] overflow-y-auto transition-transform lg:translate-x-0 ${s?"translate-x-0":"-translate-x-full"}`,children:e.jsxs("div",{className:"p-4",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx(a.Book,{className:"w-5 h-5 text-[var(--color-primary-600)]"}),"Documentation"]}),e.jsx(Mc,{className:"mb-4",placeholder:"Rechercher dans la doc...",onResultClick:()=>t(!1)}),e.jsx(d,{})]})}),e.jsx("main",{className:"flex-1 min-w-0 p-6 lg:p-8",children:e.jsx("div",{className:"max-w-4xl mx-auto",children:e.jsx(Q.Outlet,{})})})]}),e.jsx(ur,{})]})})}function Br(){const{slug:s}=Q.useParams(),t=Q.useNavigate(),r=Q.useLocation(),{currentTenant:n,userTenants:i,switchTenant:o,isLoading:c}=ze(),{useUrlRouting:x,isLoading:u}=vt(),d=l.useRef(!1),m=l.useRef(null),p=l.useRef(null);return l.useEffect(()=>{if(c||u||!x)return;const h=s||Ir(r.pathname),v=h!==p.current;if(p.current=h,!!v&&h&&h!==n?.slug){const b=i.find(g=>g.slug===h&&g.status==="Active");if(b)console.log("[TenantRouteWrapper] URL slug changed, switching to:",h),m.current=h,o(b.id).then(()=>{m.current=null}).catch(g=>{m.current=null,console.error("[TenantRouteWrapper] Failed to switch tenant:",g)});else if(console.warn("[TenantRouteWrapper] Invalid tenant slug in URL:",h),n){const g=pt(r.pathname);t(`/t/${n.slug}${g}`,{replace:!0})}else t("/",{replace:!0})}},[s,r.pathname,n?.slug,i,x,c,u,o,t]),l.useEffect(()=>{if(c||u||d.current)return;const h=r.pathname,v=Ir(h);if(!x&&v){console.log("[TenantRouteWrapper] No URL routing, stripping slug from URL"),d.current=!0;const b=pt(h);t(b,{replace:!0}),setTimeout(()=>{d.current=!1},100);return}if(x&&n&&!v&&h!=="/"&&!h.startsWith("/login")&&!h.startsWith("/auth")&&!h.startsWith("/public")){console.log("[TenantRouteWrapper] URL routing mode, adding slug to URL"),d.current=!0;const g=xi(h,{slug:n.slug,useUrlRouting:!0});t(g,{replace:!0}),setTimeout(()=>{d.current=!1},100);return}if(x&&n&&v&&v!==n.slug&&v!==m.current){console.log("[TenantRouteWrapper] URL slug mismatch, updating to:",n.slug),d.current=!0;const b=pt(h);t(`/t/${n.slug}${b}`,{replace:!0}),setTimeout(()=>{d.current=!1},100);return}},[r.pathname,n?.slug,x,c,u,t]),e.jsx(Q.Outlet,{})}const Uc=(s,t)=>{const r=t.exec(s);return r?r[1]:""},Bc=[{detect:s=>s.includes("edg/")||s.includes("edge/"),name:"Edge",pattern:/Edg(?:e)?\/(\d+)/i},{detect:s=>s.includes("opr/")||s.includes("opera"),name:"Opera",pattern:/(?:OPR|Opera)\/(\d+)/i},{detect:s=>s.includes("chrome")&&!s.includes("edg"),name:"Chrome",pattern:/Chrome\/(\d+)/i},{detect:s=>s.includes("safari")&&!s.includes("chrome"),name:"Safari",pattern:/Version\/(\d+)/i},{detect:s=>s.includes("firefox"),name:"Firefox",pattern:/Firefox\/(\d+)/i},{detect:s=>s.includes("msie")||s.includes("trident"),name:"Internet Explorer",pattern:/(?:MSIE |rv:)(\d+)/i}],Oc=(s,t)=>{const r=Bc.find(n=>n.detect(s));return r?{browser:r.name,version:Uc(t,r.pattern)}:{browser:"Unknown",version:""}},qc={"windows nt 10":"10/11","windows nt 6.3":"8.1","windows nt 6.2":"8","windows nt 6.1":"7"},Vc=s=>{for(const[t,r]of Object.entries(qc))if(s.includes(t))return r;return""},zc=[{detect:s=>s.includes("windows nt"),name:"Windows",getVersion:s=>Vc(s)},{detect:s=>s.includes("windows"),name:"Windows",getVersion:()=>""},{detect:s=>s.includes("iphone"),name:"iOS",getVersion:(s,t)=>{const r=t.match(/OS (\d+)_/i);return r?r[1]:""}},{detect:s=>s.includes("ipad"),name:"iPadOS",getVersion:(s,t)=>{const r=t.match(/OS (\d+)_/i);return r?r[1]:""}},{detect:s=>s.includes("mac os x"),name:"macOS",getVersion:(s,t)=>{const r=t.match(/Mac OS X (\d+)[._](\d+)/i);return r?`${r[1]}.${r[2]}`:""}},{detect:s=>s.includes("android"),name:"Android",getVersion:(s,t)=>{const r=t.match(/Android (\d+)/i);return r?r[1]:""}},{detect:s=>s.includes("linux"),name:"Linux",getVersion:()=>""},{detect:s=>s.includes("cros"),name:"Chrome OS",getVersion:()=>""}],Gc=(s,t)=>{const r=zc.find(n=>n.detect(s));if(r){const n=r.getVersion(s,t);return{os:r.name,version:n}}return{os:"Unknown",version:""}},Hc=s=>/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk)/i.test(s)?"Tablet":/(android|webos|iphone|ipod|blackberry|iemobile|opera mini|mobile|phone)/i.test(s)?"Mobile":"Desktop";function Ci(s){if(!s)return{browser:"Unknown",browserVersion:"",os:"Unknown",osVersion:"",device:"Unknown",formatted:"Unknown"};const t=s.toLowerCase(),{browser:r,version:n}=Oc(t,s),{os:i,version:o}=Gc(t,s),c=Hc(t),x=i!=="Unknown"?`${r} ${n?n+" ":""}sur ${i}${o?" "+o:""}`:r;return{browser:r,browserVersion:n,os:i,osVersion:o,device:c,formatted:x}}function Si(){const s=navigator.userAgent.toLowerCase();return/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(s)?"tablet":/(android|webos|iphone|ipod|blackberry|iemobile|opera mini|mobile|phone)/.test(s)?"mobile":/(windows|macintosh|linux|x11)/.test(s)?"desktop":"unknown"}async function Ti(){try{const s=await fetch("https://api.ipify.org?format=json",{method:"GET",signal:AbortSignal.timeout(5e3)});return s.ok?(await s.json()).ip||null:(console.warn("Failed to fetch IP address from ipify.org"),null)}catch(s){return console.warn("Unable to fetch client IP address:",s),null}}const Kc=[{icon:a.Shield,title:"Sécurité avancée",description:"Authentification multi-facteurs et contrôle d'accès granulaire"},{icon:a.Zap,title:"Performance optimale",description:"Interface rapide et réactive pour une productivité maximale"},{icon:a.Users,title:"Collaboration",description:"Gestion des équipes et permissions centralisée"},{icon:a.BarChart3,title:"Analytics",description:"Tableaux de bord et rapports en temps réel"}],_c=s=>{switch(s){case"ACCOUNT_DISABLED":return e.jsx(a.UserX,{className:"w-5 h-5 flex-shrink-0"});case"ACCOUNT_LOCKED":return e.jsx(a.Clock,{className:"w-5 h-5 flex-shrink-0"});case"EXTERNAL_AUTH_REQUIRED":return e.jsx(a.KeyRound,{className:"w-5 h-5 flex-shrink-0"});case"NETWORK_ERROR":return e.jsx(a.WifiOff,{className:"w-5 h-5 flex-shrink-0"});default:return e.jsx(a.AlertCircle,{className:"w-5 h-5 flex-shrink-0"})}},Wc=s=>{switch(s){case"ACCOUNT_DISABLED":return"bg-orange-500/10 border-orange-500/20 text-orange-600 dark:text-orange-400";case"ACCOUNT_LOCKED":return"bg-amber-500/10 border-amber-500/20 text-amber-600 dark:text-amber-400";case"EXTERNAL_AUTH_REQUIRED":return"bg-blue-500/10 border-blue-500/20 text-blue-600 dark:text-blue-400";case"NETWORK_ERROR":return"bg-gray-500/10 border-gray-500/20 text-gray-600 dark:text-gray-400";default:return"bg-red-500/10 border-red-500/20 text-red-500"}};function Xc(){const[s,t]=l.useState(""),[r,n]=l.useState(""),[i,o]=l.useState(!1),[c,x]=l.useState(!1),[u,d]=l.useState("auth"),[m,p]=l.useState(null),h=async v=>{v.preventDefault(),p(null),d("auth"),x(!0);try{qe.logEvent("login_attempt","auth",{email:s});const b=Si(),g=await Ti(),j=await oe.post("/api/auth/login",{email:s,password:r,deviceType:b,clientIp:g});localStorage.setItem("token",j.token),localStorage.setItem("user",JSON.stringify(j.user)),qe.logEvent("login_success","auth",{email:s}),d("prefs");try{if(!(await oe.get("/api/onboarding/status")).hasCompletedOnboarding){window.location.href="/auth/onboarding";return}}catch{}try{const w=await Is.preferences.get(),f={mode:w.theme||"dark",accentColorKey:w.accentColorKey||"indigo",borderRadius:w.borderRadius||{},itemPaletteKey:w.itemPaletteKey||"neutral"};localStorage.setItem("smartstack-theme-config",JSON.stringify(f)),w.language&&localStorage.setItem("i18nextLng",w.language)}catch{}window.location.href="/personal/myspace"}catch(b){if(b instanceof nr)p({message:b.message,code:"NETWORK_ERROR"});else if(b instanceof Dl)p({message:b.message,code:b.code});else{const g=b instanceof Error?b.message:"Une erreur inattendue est survenue";p({message:g})}qe.logError(b instanceof Error?b:new Error(String(b)),"LoginPage.handleSubmit",{email:s})}finally{x(!1)}};return e.jsxs("div",{className:"min-h-screen flex",children:[e.jsxs("div",{className:"hidden lg:flex lg:w-1/2 xl:w-[55%] relative overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 animated-gradient"}),e.jsx("div",{className:"absolute inset-0 opacity-10",style:{backgroundImage:"radial-gradient(circle at 1px 1px, white 1px, transparent 0)",backgroundSize:"40px 40px"}}),e.jsx("div",{className:"absolute top-20 left-20 w-72 h-72 bg-white/10 rounded-full blur-3xl animate-pulse"}),e.jsx("div",{className:"absolute bottom-20 right-20 w-96 h-96 bg-white/10 rounded-full blur-3xl animate-pulse",style:{animationDelay:"1s"}}),e.jsx("div",{className:"absolute top-1/2 left-1/3 w-64 h-64 bg-white/5 rounded-full blur-2xl animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"relative z-10 flex flex-col justify-between p-12 xl:p-16 text-white w-full",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 backdrop-blur-sm rounded-xl flex items-center justify-center",children:e.jsx(a.Layers,{className:"w-7 h-7 text-white"})}),e.jsx("span",{className:"text-2xl font-bold",children:"SmartStack"})]}),e.jsxs("div",{className:"max-w-lg",children:[e.jsx("h1",{className:"text-4xl xl:text-5xl font-bold leading-tight mb-6",children:"Votre plateforme de gestion unifiée"}),e.jsx("p",{className:"text-xl text-white/80 mb-12",children:"Simplifiez vos processus, centralisez vos données et boostez la productivité de votre équipe."}),e.jsx("div",{className:"grid grid-cols-2 gap-6",children:Kc.map(v=>e.jsxs("div",{className:"bg-white/10 backdrop-blur-sm rounded-2xl p-5 hover:bg-white/15 transition-colors",children:[e.jsx(v.icon,{className:"w-8 h-8 mb-3 text-white/90"}),e.jsx("h3",{className:"font-semibold mb-1",children:v.title}),e.jsx("p",{className:"text-sm text-white/70",children:v.description})]},v.title))})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex -space-x-3",children:[1,2,3,4].map(v=>e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/20 border-2 border-white/30 flex items-center justify-center text-sm font-medium",children:String.fromCharCode(64+v)},v))}),e.jsxs("p",{className:"text-white/80",children:[e.jsx("span",{className:"font-semibold text-white",children:"+500"})," entreprises nous font confiance"]})]})]})]}),e.jsxs("div",{className:"w-full lg:w-1/2 xl:w-[45%] flex flex-col relative bg-[var(--bg-primary)]",children:[e.jsx("div",{className:"lg:hidden absolute inset-0",children:e.jsxs("div",{className:"absolute inset-0 overflow-hidden",children:[e.jsx("div",{className:"absolute -top-40 -right-40 w-96 h-96 rounded-full bg-primary-500/20 blur-3xl animate-pulse"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-96 h-96 rounded-full bg-accent-500/20 blur-3xl animate-pulse",style:{animationDelay:"1s"}})]})}),e.jsxs("div",{className:"absolute top-6 right-6 z-10 flex items-center gap-2",children:[e.jsx("a",{href:"/",className:"p-2 rounded-lg bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-colors",title:"Retour à l'accueil",children:e.jsx(a.Home,{className:"w-5 h-5 text-[var(--text-secondary)]"})}),e.jsx(ms,{})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-6 sm:p-8 lg:p-12",children:e.jsxs("div",{className:"w-full max-w-md relative",children:[e.jsxs("div",{className:"lg:hidden flex flex-col items-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl animated-gradient flex items-center justify-center mb-4 shadow-lg",children:e.jsx(a.Layers,{className:"w-8 h-8 text-white"})}),e.jsx("h1",{className:"text-2xl font-bold",children:"SmartStack"})]}),e.jsxs("div",{className:"hidden lg:block mb-8",children:[e.jsx("h2",{className:"text-3xl font-bold mb-2",children:"Bienvenue"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:"Connectez-vous à votre compte pour continuer"})]}),m&&e.jsxs("div",{className:`mb-6 p-4 rounded-xl border text-sm flex items-start gap-3 ${Wc(m.code)}`,children:[_c(m.code),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:m.message}),m.code==="ACCOUNT_DISABLED"&&e.jsx("p",{className:"text-xs mt-1 opacity-80",children:"Contactez le support si vous pensez qu'il s'agit d'une erreur."}),m.code==="EXTERNAL_AUTH_REQUIRED"&&e.jsx("p",{className:"text-xs mt-1 opacity-80",children:"Utilisez les boutons Microsoft ou Google ci-dessous."})]})]}),e.jsxs("form",{onSubmit:h,className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium mb-2",children:"Adresse email"}),e.jsxs("div",{className:"relative",children:[e.jsx(a.Mail,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-[var(--text-tertiary)]"}),e.jsx("input",{id:"email",type:"email",value:s,onChange:v=>t(v.target.value),placeholder:"vous@exemple.com",required:!0,className:"w-full pl-12 pr-4 py-3.5 rounded-xl bg-[var(--bg-tertiary)] border border-[var(--border-color)] focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 outline-none transition-all placeholder:text-[var(--text-tertiary)]"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium mb-2",children:"Mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx(a.Lock,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-[var(--text-tertiary)]"}),e.jsx("input",{id:"password",type:i?"text":"password",value:r,onChange:v=>n(v.target.value),placeholder:"••••••••",required:!0,className:"w-full pl-12 pr-12 py-3.5 rounded-xl bg-[var(--bg-tertiary)] border border-[var(--border-color)] focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 outline-none transition-all placeholder:text-[var(--text-tertiary)]"}),e.jsx("button",{type:"button",onClick:()=>o(!i),className:"absolute right-4 top-1/2 -translate-y-1/2 text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:i?e.jsx(a.EyeOff,{className:"w-5 h-5"}):e.jsx(a.Eye,{className:"w-5 h-5"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)] bg-[var(--bg-tertiary)] text-primary-600 focus:ring-primary-500/20"}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:"Se souvenir de moi"})]}),e.jsx("a",{href:"/forgot-password",className:"text-primary-500 hover:text-primary-600 font-medium transition-colors",children:"Mot de passe oublié ?"})]}),e.jsx("button",{type:"submit",disabled:c,className:"w-full py-3.5 px-4 rounded-xl bg-primary-600 hover:bg-primary-700 disabled:bg-primary-600/50 text-white font-semibold transition-all shadow-lg shadow-primary-500/25 hover:shadow-primary-500/40 disabled:shadow-none flex items-center justify-center gap-2",children:c?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}),u==="auth"?"Connexion en cours...":"Chargement des préférences..."]}):"Se connecter"})]}),e.jsxs("div",{className:"relative my-8",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-[var(--border-color)]"})}),e.jsx("div",{className:"relative flex justify-center text-sm",children:e.jsx("span",{className:"px-4 bg-[var(--bg-primary)] text-[var(--text-tertiary)]",children:"Ou continuer avec"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("button",{type:"button",onClick:()=>window.location.href="/api/auth/microsoft",className:"flex items-center justify-center gap-3 py-3.5 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] font-medium transition-all",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 21 21",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"1",y:"1",width:"9",height:"9",fill:"#F25022"}),e.jsx("rect",{x:"11",y:"1",width:"9",height:"9",fill:"#7FBA00"}),e.jsx("rect",{x:"1",y:"11",width:"9",height:"9",fill:"#00A4EF"}),e.jsx("rect",{x:"11",y:"11",width:"9",height:"9",fill:"#FFB900"})]}),"Microsoft"]}),e.jsxs("button",{type:"button",onClick:()=>window.location.href="/api/auth/google",className:"flex items-center justify-center gap-3 py-3.5 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] font-medium transition-all",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),e.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),e.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),e.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Google"]})]}),e.jsxs("p",{className:"text-center text-[var(--text-secondary)] mt-8",children:["Nouveau sur SmartStack ?"," ",e.jsx("a",{href:"/register",className:"text-primary-500 hover:text-primary-600 font-semibold transition-colors",children:"Créer un compte"})]})]})}),e.jsx("div",{className:"p-6 text-center",children:e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)]",children:["© ",new Date().getFullYear()," SmartStack. Tous droits réservés."]})})]})]})}function Qc(){const[s,t]=l.useState(""),[r,n]=l.useState(""),[i,o]=l.useState(""),[c,x]=l.useState(""),[u,d]=l.useState(""),[m,p]=l.useState(!1),[h,v]=l.useState(!1),[b,g]=l.useState(!1),[j,w]=l.useState(null),[f,N]=l.useState(null),k=()=>!s||!r||!i||!c||!u?(w("Tous les champs sont requis"),!1):r!==i?(w("Les mots de passe ne correspondent pas"),!1):r.length<8?(w("Le mot de passe doit contenir au moins 8 caractères"),!1):!0,C=async y=>{if(y.preventDefault(),w(null),N(null),!!k()){g(!0);try{qe.logEvent("register_attempt","auth",{email:s});const A=await us.register({email:s,password:r,firstName:c,lastName:u});qe.logEvent("register_success","auth",{email:s}),N(A.message),t(""),n(""),o(""),x(""),d("")}catch(A){if(A instanceof nr)w(A.message);else{const D=A instanceof Error?A.message:"Une erreur inattendue est survenue";w(D)}qe.logError(A instanceof Error?A:new Error(String(A)),"RegisterPage.handleSubmit",{email:s})}finally{g(!1)}}};return e.jsxs("div",{className:"min-h-screen flex",children:[e.jsxs("div",{className:"hidden lg:flex lg:w-1/2 bg-gradient-to-br from-blue-600 via-purple-600 to-indigo-600 p-12 text-white flex-col justify-between relative overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 opacity-10",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 2px 2px, white 1px, transparent 0)",backgroundSize:"40px 40px"}})}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-12",children:[e.jsx("div",{className:"p-2 bg-white/20 backdrop-blur-sm rounded-lg",children:e.jsx("div",{className:"w-8 h-8 flex items-center justify-center",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:"w-6 h-6",children:e.jsx("path",{d:"M12 2L2 7V17L12 22L22 17V7L12 2ZM12 4.5L19 8.27V15.73L12 19.5L5 15.73V8.27L12 4.5Z"})})})}),e.jsx("div",{className:"text-2xl font-bold tracking-tight",children:"SmartStack"})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("h1",{className:"text-4xl font-bold leading-tight",children:["Créez votre compte",e.jsx("br",{}),e.jsx("span",{className:"text-white/80",children:"et rejoignez-nous"})]}),e.jsx("p",{className:"text-white/80 text-lg max-w-md",children:"Accédez à une plateforme complète de gestion avec authentification sécurisée et tableau de bord personnalisé."})]})]}),e.jsxs("div",{className:"relative z-10 text-sm text-white/60",children:["© ",new Date().getFullYear()," SmartStack. Tous droits réservés."]})]}),e.jsx("div",{className:"w-full lg:w-1/2 flex items-center justify-center p-8 bg-white dark:bg-gray-900",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900 dark:text-white mb-2",children:"Créer un compte"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Remplissez vos informations pour commencer"})]}),f&&e.jsxs("div",{className:"mb-6 p-4 bg-green-500/10 border border-green-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.CheckCircle2,{className:"w-5 h-5 text-green-600 dark:text-green-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-green-600 dark:text-green-400",children:f}),e.jsx("p",{className:"text-xs text-green-600/80 dark:text-green-400/80 mt-1",children:"Consultez vos emails pour confirmer votre adresse."})]})]}),j&&e.jsxs("div",{className:"mb-6 p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-500 flex-1",children:j})]}),e.jsxs("form",{onSubmit:C,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"firstName",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Prénom"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.User,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"firstName",type:"text",value:c,onChange:y=>x(y.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"Jean",required:!0,autoComplete:"given-name",disabled:b})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"lastName",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Nom"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.User,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"lastName",type:"text",value:u,onChange:y=>d(y.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"Dupont",required:!0,autoComplete:"family-name",disabled:b})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Adresse email"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Mail,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"email",type:"email",value:s,onChange:y=>t(y.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"vous@exemple.com",required:!0,autoComplete:"email",disabled:b})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"password",type:m?"text":"password",value:r,onChange:y=>n(y.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:b}),e.jsx("button",{type:"button",onClick:()=>p(!m),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",tabIndex:-1,children:m?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Minimum 8 caractères"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmPassword",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Confirmer le mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"confirmPassword",type:h?"text":"password",value:i,onChange:y=>o(y.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:b}),e.jsx("button",{type:"button",onClick:()=>v(!h),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",tabIndex:-1,children:h?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]})]}),e.jsx("button",{type:"submit",disabled:b,className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:b?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"h-5 w-5 animate-spin"}),"Création en cours..."]}):e.jsx(e.Fragment,{children:"Créer mon compte"})})]}),e.jsx("div",{className:"mt-6 text-center space-y-2",children:e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Vous avez déjà un compte ?"," ",e.jsx(Q.Link,{to:"/login",className:"text-blue-600 dark:text-blue-400 hover:underline font-medium",children:"Se connecter"})]})})]})})]})}function Jc(){const[s]=Q.useSearchParams(),t=s.get("token"),[r,n]=l.useState("loading"),[i,o]=l.useState(""),[c,x]=l.useState(""),[u,d]=l.useState(""),[m,p]=l.useState(!1),[h,v]=l.useState("");l.useEffect(()=>{if(!t){n("error"),o("Lien de confirmation invalide. Aucun token fourni.");return}(async()=>{try{const j=await us.confirmEmail(t);n("success"),o(j.message),x(j.email)}catch(j){const w=j,f=j?.code;n(f==="TOKEN_EXPIRED"?"expired":f==="TOKEN_ALREADY_USED"?"already_used":"error"),o(w?.message||"Une erreur est survenue lors de la confirmation.")}})()},[t]);const b=async g=>{if(g.preventDefault(),!!u){p(!0),v("");try{const j=await us.resendConfirmation(u);v(j.message)}catch(j){v(j?.message||"Erreur lors de l'envoi.")}finally{p(!1)}}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-8",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[r==="loading"&&e.jsxs("div",{className:"text-center",children:[e.jsx(a.Loader2,{className:"w-16 h-16 text-blue-500 animate-spin mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Confirmation en cours..."}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Veuillez patienter pendant que nous vérifions votre email."})]}),r==="success"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Email confirmé !"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:i}),c&&e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-6",children:["Compte : ",e.jsx("strong",{children:c})]}),e.jsx(Q.Link,{to:"/login",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 transition-all",children:"Se connecter"})]}),(r==="error"||r==="expired"||r==="already_used")&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:`w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4 ${r==="already_used"?"bg-amber-100 dark:bg-amber-900/30":"bg-red-100 dark:bg-red-900/30"}`,children:r==="already_used"?e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-amber-600 dark:text-amber-400"}):e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:[r==="expired"&&"Lien expiré",r==="already_used"&&"Lien déjà utilisé",r==="error"&&"Erreur de confirmation"]}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:i}),(r==="expired"||r==="error")&&e.jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:"Demander un nouveau lien de confirmation :"}),e.jsxs("form",{onSubmit:b,className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Mail,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{type:"email",value:u,onChange:g=>d(g.target.value),placeholder:"Votre email",className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",required:!0})]}),e.jsxs("button",{type:"submit",disabled:m,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 disabled:opacity-50 transition-colors",children:[m?e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}):e.jsx(a.RefreshCw,{className:"w-5 h-5"}),"Renvoyer le lien"]})]}),h&&e.jsx("p",{className:"mt-3 text-sm text-green-600 dark:text-green-400",children:h})]}),r==="already_used"&&e.jsx(Q.Link,{to:"/login",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 transition-all",children:"Se connecter"})]})]}),e.jsx("p",{className:"text-center text-sm text-gray-500 dark:text-gray-400 mt-6",children:e.jsx(Q.Link,{to:"/login",className:"hover:underline",children:"Retour à la connexion"})})]})})}function Yc(){const[s,t]=l.useState(""),[r,n]=l.useState(!1),[i,o]=l.useState(null),[c,x]=l.useState(!1),u=async d=>{d.preventDefault(),o(null),n(!0);try{await us.forgotPassword(s),x(!0)}catch(m){o(m?.message||"Une erreur est survenue")}finally{n(!1)}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-8",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[c?e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Email envoyé !"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:["Si un compte existe avec l'adresse ",e.jsx("strong",{children:s}),", vous recevrez un lien de réinitialisation."]}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"N'oubliez pas de vérifier vos spams."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.Mail,{className:"w-8 h-8 text-blue-600 dark:text-blue-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Mot de passe oublié ?"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Entrez votre email et nous vous enverrons un lien pour réinitialiser votre mot de passe."})]}),i&&e.jsxs("div",{className:"mb-6 p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-500",children:i})]}),e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Adresse email"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Mail,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"email",type:"email",value:s,onChange:d=>t(d.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"vous@exemple.com",required:!0,autoComplete:"email",disabled:r})]})]}),e.jsx("button",{type:"submit",disabled:r,className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 disabled:opacity-50 transition-all",children:r?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"h-5 w-5 animate-spin"}),"Envoi en cours..."]}):"Envoyer le lien"})]})]}),e.jsx("div",{className:"mt-6 pt-6 border-t border-gray-200 dark:border-gray-700",children:e.jsxs(Q.Link,{to:"/login",className:"flex items-center justify-center gap-2 text-sm text-gray-600 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-400 transition-colors",children:[e.jsx(a.ArrowLeft,{className:"w-4 h-4"}),"Retour à la connexion"]})})]})]})})}function Zc(){const[s]=Q.useSearchParams(),t=Q.useNavigate(),r=s.get("token"),[n,i]=l.useState(""),[o,c]=l.useState(""),[x,u]=l.useState(!1),[d,m]=l.useState(!1),[p,h]=l.useState(!1),[v,b]=l.useState("form"),[g,j]=l.useState(null);l.useEffect(()=>{r||(b("invalid_token"),j("Lien de réinitialisation invalide. Aucun token fourni."))},[r]);const w=()=>n.length<8?(j("Le mot de passe doit contenir au moins 8 caractères"),!1):n!==o?(j("Les mots de passe ne correspondent pas"),!1):!0,f=async N=>{if(N.preventDefault(),j(null),!(!w()||!r)){h(!0);try{await us.resetPassword(r,n),b("success")}catch(k){const C=k,y=k?.code;y==="TOKEN_EXPIRED"||y==="TOKEN_ALREADY_USED"||y==="INVALID_TOKEN"?(b("error"),j(C?.message||"Le lien de réinitialisation est invalide ou a expiré.")):j(C?.message||"Une erreur est survenue")}finally{h(!1)}}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-8",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[v==="invalid_token"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Lien invalide"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:g}),e.jsx(Q.Link,{to:"/forgot-password",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",children:"Demander un nouveau lien"})]}),v==="error"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Lien expiré"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:g}),e.jsx(Q.Link,{to:"/forgot-password",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",children:"Demander un nouveau lien"})]}),v==="success"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Mot de passe réinitialisé !"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"Votre mot de passe a été modifié avec succès. Vous pouvez maintenant vous connecter."}),e.jsx("button",{onClick:()=>t("/login"),className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 transition-all",children:"Se connecter"})]}),v==="form"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.Lock,{className:"w-8 h-8 text-blue-600 dark:text-blue-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Nouveau mot de passe"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Choisissez un nouveau mot de passe sécurisé."})]}),g&&e.jsxs("div",{className:"mb-6 p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-500",children:g})]}),e.jsxs("form",{onSubmit:f,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Nouveau mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"password",type:x?"text":"password",value:n,onChange:N=>i(N.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:p}),e.jsx("button",{type:"button",onClick:()=>u(!x),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",tabIndex:-1,children:x?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Minimum 8 caractères"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmPassword",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Confirmer le mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"confirmPassword",type:d?"text":"password",value:o,onChange:N=>c(N.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:p}),e.jsx("button",{type:"button",onClick:()=>m(!d),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",tabIndex:-1,children:d?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]})]}),e.jsx("button",{type:"submit",disabled:p,className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 disabled:opacity-50 transition-all",children:p?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"h-5 w-5 animate-spin"}),"Réinitialisation..."]}):"Réinitialiser le mot de passe"})]})]}),e.jsx("div",{className:"mt-6 pt-6 border-t border-gray-200 dark:border-gray-700",children:e.jsx(Q.Link,{to:"/login",className:"flex items-center justify-center text-sm text-gray-600 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-400 transition-colors",children:"Retour à la connexion"})})]})]})})}function ed(){const{t:s}=ne.useTranslation(),t=Q.useNavigate(),[r,n]=l.useState(""),[i,o]=l.useState(""),[c,x]=l.useState(""),[u,d]=l.useState(!1),[m,p]=l.useState(!1),[h,v]=l.useState(!1),[b,g]=l.useState(null),[j,w]=l.useState(!1),N=(y=>{const A=[];return y.length<8&&A.push("Au moins 8 caractères"),/[A-Z]/.test(y)||A.push("Au moins une majuscule"),/[a-z]/.test(y)||A.push("Au moins une minuscule"),/[0-9]/.test(y)||A.push("Au moins un chiffre"),A})(i),k=i===c&&N.length===0&&r.length>0,C=async y=>{if(y.preventDefault(),!!k){v(!0),g(null);try{await us.changePassword(r,i),w(!0),setTimeout(()=>{t("/")},2e3)}catch(A){A instanceof Error?g(A.message):g("Une erreur est survenue")}finally{v(!1)}}};return j?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 p-4",children:e.jsxs("div",{className:"w-full max-w-md bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle,{className:"w-8 h-8 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Mot de passe modifié"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Vous allez être redirigé vers l'accueil..."})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 p-4",children:e.jsx("div",{className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 bg-amber-100 dark:bg-amber-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.Lock,{className:"w-8 h-8 text-amber-600 dark:text-amber-400"})}),e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:s("auth.forceChangePassword.title","Changement de mot de passe requis")}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:s("auth.forceChangePassword.description","Pour des raisons de sécurité, vous devez définir un nouveau mot de passe.")})]}),b&&e.jsxs("div",{className:"mb-6 p-4 rounded-xl bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 flex items-center gap-2",children:[e.jsx(a.AlertTriangle,{className:"w-5 h-5 flex-shrink-0"}),e.jsx("span",{children:b})]}),e.jsxs("form",{onSubmit:C,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:s("auth.forceChangePassword.currentPassword","Mot de passe actuel (temporaire)")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:u?"text":"password",required:!0,value:r,onChange:y=>n(y.target.value),className:"w-full px-4 py-3 rounded-xl border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Entrez le mot de passe fourni par l'administrateur"}),e.jsx("button",{type:"button",onClick:()=>d(!u),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:u?e.jsx(a.EyeOff,{className:"w-5 h-5"}):e.jsx(a.Eye,{className:"w-5 h-5"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:s("auth.forceChangePassword.newPassword","Nouveau mot de passe")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:m?"text":"password",required:!0,value:i,onChange:y=>o(y.target.value),className:"w-full px-4 py-3 rounded-xl border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Choisissez un nouveau mot de passe"}),e.jsx("button",{type:"button",onClick:()=>p(!m),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:m?e.jsx(a.EyeOff,{className:"w-5 h-5"}):e.jsx(a.Eye,{className:"w-5 h-5"})})]}),i&&e.jsx("div",{className:"mt-2 space-y-1",children:["Au moins 8 caractères","Au moins une majuscule","Au moins une minuscule","Au moins un chiffre"].map((y,A)=>{const D=[i.length>=8,/[A-Z]/.test(i),/[a-z]/.test(i),/[0-9]/.test(i)];return e.jsxs("div",{className:`flex items-center gap-2 text-sm ${D[A]?"text-green-600":"text-gray-500"}`,children:[D[A]?e.jsx(a.CheckCircle,{className:"w-4 h-4"}):e.jsx("div",{className:"w-4 h-4 rounded-full border border-current"}),y]},`pwd-req-${A}`)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:s("auth.forceChangePassword.confirmPassword","Confirmer le nouveau mot de passe")}),e.jsx("input",{type:"password",required:!0,value:c,onChange:y=>x(y.target.value),className:`w-full px-4 py-3 rounded-xl border ${c&&c!==i?"border-red-500 focus:ring-red-500":"border-gray-300 dark:border-gray-600 focus:ring-blue-500"} bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2`,placeholder:"Confirmez votre nouveau mot de passe"}),c&&c!==i&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:"Les mots de passe ne correspondent pas"})]}),e.jsx("button",{type:"submit",disabled:!k||h,className:"w-full py-3 px-4 rounded-xl bg-blue-600 hover:bg-blue-700 text-white font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Modification en cours..."})]}):e.jsx("span",{children:s("auth.forceChangePassword.submit","Définir mon nouveau mot de passe")})})]})]})})})}const sd={auth_failed:"L'authentification a échoué. Veuillez réessayer.",no_email:"Impossible de récupérer votre adresse email depuis le fournisseur.",account_disabled:"Votre compte est désactivé. Contactez l'administrateur.",account_locked:"Votre compte est verrouillé. Contactez l'administrateur.",internal_error:"Une erreur interne est survenue. Veuillez réessayer."};function td(){const[s]=Q.useSearchParams(),t=Q.useNavigate(),[r,n]=l.useState("processing"),[i,o]=l.useState("");l.useEffect(()=>{const u=s.get("token"),d=s.get("refreshToken"),m=s.get("error");if(m){n("error"),o(sd[m]||"Une erreur est survenue lors de l'authentification.");return}u&&d?c(u):(n("error"),o("Paramètres d'authentification manquants."))},[s]);const c=async(u,d)=>{try{localStorage.setItem("token",u);try{const h=await Ti(),v=Si();(h||v)&&await fetch("/api/auth/update-session-client-info",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify({clientIp:h,deviceType:v})})}catch(h){console.warn("Failed to update session client info:",h)}const m=await fetch("/api/auth/me",{headers:{Authorization:`Bearer ${u}`}});if(!m.ok)throw new Error("Failed to fetch user info");const p=await m.json();localStorage.setItem("user",JSON.stringify(p));try{const h=await fetch("/api/onboarding/status",{headers:{Authorization:`Bearer ${u}`}});if(h.ok&&!(await h.json()).hasCompletedOnboarding){n("success"),setTimeout(()=>{window.location.href="/auth/onboarding"},1500);return}}catch{}try{const h=await Is.preferences.get(),v={mode:h.theme||"dark",accentColorKey:h.accentColorKey||"indigo",borderRadius:h.borderRadius||{},itemPaletteKey:h.itemPaletteKey||"neutral"};localStorage.setItem("smartstack-theme-config",JSON.stringify(v)),h.language&&localStorage.setItem("i18nextLng",h.language)}catch{}n("success"),setTimeout(()=>{window.location.href="/personal/myspace"},1500)}catch(m){console.error("Auth callback error:",m),n("error"),o("Erreur lors de la finalisation de l'authentification.")}},x=()=>{t("/login")};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)]",children:e.jsx("div",{className:"max-w-md w-full mx-4",children:e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-2xl p-8 shadow-lg border border-[var(--border-color)]",children:[r==="processing"&&e.jsxs("div",{className:"text-center",children:[e.jsx(a.Loader2,{className:"w-16 h-16 mx-auto text-[var(--color-accent-500)] animate-spin mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Authentification en cours..."}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:"Veuillez patienter pendant que nous finalisons votre connexion."})]}),r==="success"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mb-4",children:e.jsx(a.CheckCircle,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Connexion réussie !"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:"Vous allez être redirigé vers votre espace personnel..."})]}),r==="error"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mb-4",children:e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Échec de l'authentification"}),e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 rounded-lg p-4 mb-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:i})]})}),e.jsx("button",{onClick:x,className:"btn btn-primary w-full",children:"Retourner à la connexion"})]})]})})})}const Or=[{code:"fr",name:"Francais",flag:"🇫🇷"},{code:"en",name:"English",flag:"🇬🇧"},{code:"de",name:"Deutsch",flag:"🇩🇪"},{code:"it",name:"Italiano",flag:"🇮🇹"}],ha=[{value:"light",labelKey:"themeLight",icon:"☀️"},{value:"dark",labelKey:"themeDark",icon:"🌙"},{value:"system",labelKey:"themeSystem",icon:"💻"}],ba=[{key:"indigo",color:"#6366f1",name:"Indigo"},{key:"blue",color:"#3b82f6",name:"Blue"},{key:"emerald",color:"#10b981",name:"Emerald"},{key:"amber",color:"#f59e0b",name:"Amber"},{key:"rose",color:"#f43f5e",name:"Rose"},{key:"purple",color:"#a855f7",name:"Purple"}];function ad(){const{t:s,i18n:t}=ne.useTranslation("auth"),r=Q.useNavigate(),[n,i]=l.useState("language"),[o,c]=l.useState(t.language?.substring(0,2)||"fr"),[x,u]=l.useState("dark"),[d,m]=l.useState("indigo"),[p,h]=l.useState(!1),[v,b]=l.useState(null),[g,j]=l.useState(!1);l.useEffect(()=>{(async()=>{try{(await oe.get("/api/onboarding/status")).hasCompletedOnboarding&&r("/personal/myspace",{replace:!0})}catch{}})()},[r]),l.useEffect(()=>{o&&o!==t.language?.substring(0,2)&&ir(o)},[o,t]);const w=[{key:"language",labelKey:"stepLanguage",icon:e.jsx(a.Globe,{className:"w-5 h-5"})},{key:"theme",labelKey:"stepTheme",icon:e.jsx(a.Palette,{className:"w-5 h-5"})},{key:"complete",labelKey:"stepComplete",icon:e.jsx(a.Sparkles,{className:"w-5 h-5"})}],f=w.findIndex(y=>y.key===n),N=()=>{const y=f+1;y<w.length&&i(w[y].key)},k=()=>{const y=f-1;y>=0&&i(w[y].key)},C=async()=>{h(!0),b(null);try{await oe.post("/api/onboarding/complete",{language:o,theme:x,accentColorKey:d}),localStorage.setItem("i18nextLng",o),localStorage.setItem("smartstack-theme-config",JSON.stringify({mode:x,accentColorKey:d,borderRadius:{},itemPaletteKey:"neutral"})),j(!0),setTimeout(()=>{window.location.href="/personal/myspace"},2e3)}catch(y){console.error("Onboarding error:",y),b(s("onboarding.errorMessage"))}finally{h(!1)}};return g?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)]",children:e.jsx("div",{className:"max-w-md w-full mx-4",children:e.jsx("div",{className:"bg-[var(--bg-secondary)] rounded-2xl p-8 shadow-lg border border-[var(--border-color)]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-20 h-20 mx-auto bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mb-6",children:e.jsx(a.CheckCircle,{className:"w-12 h-12 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-2xl font-bold mb-3",children:s("onboarding.successTitle")}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("onboarding.successMessage")}),e.jsx("div",{className:"mt-6",children:e.jsx(a.Loader2,{className:"w-6 h-6 mx-auto text-[var(--color-accent-500)] animate-spin"})})]})})})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)] p-4",children:e.jsxs("div",{className:"max-w-lg w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"flex items-center justify-center gap-2 mb-4",children:e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-blue-500 to-purple-600 rounded-xl flex items-center justify-center",children:e.jsx("span",{className:"text-white text-xl font-bold",children:"S"})})}),e.jsx("h1",{className:"text-3xl font-bold mb-2",children:s("onboarding.title")}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("onboarding.subtitle")})]}),e.jsx("div",{className:"flex justify-center mb-8",children:e.jsx("div",{className:"flex items-center gap-2",children:w.map((y,A)=>e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center transition-all ${A<=f?"bg-[var(--color-accent-500)] text-white":"bg-[var(--bg-tertiary)] text-[var(--text-secondary)]"}`,children:y.icon}),A<w.length-1&&e.jsx("div",{className:`w-12 h-1 mx-1 rounded transition-all ${A<f?"bg-[var(--color-accent-500)]":"bg-[var(--bg-tertiary)]"}`})]},y.key))})}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-2xl p-8 shadow-lg border border-[var(--border-color)]",children:[n==="language"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold mb-6 text-center",children:s("onboarding.languageLabel")}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:Or.map(y=>e.jsxs("button",{onClick:()=>c(y.code),className:`p-4 rounded-xl border-2 transition-all ${o===y.code?"border-[var(--color-accent-500)] bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20":"border-[var(--border-color)] hover:border-[var(--color-accent-300)]"}`,children:[e.jsx("span",{className:"text-3xl mb-2 block",children:y.flag}),e.jsx("span",{className:"font-medium",children:y.name})]},y.code))})]}),n==="theme"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold mb-6 text-center",children:s("onboarding.themeLabel")}),e.jsx("div",{className:"grid grid-cols-3 gap-3 mb-8",children:ha.map(y=>e.jsxs("button",{onClick:()=>u(y.value),className:`p-4 rounded-xl border-2 transition-all ${x===y.value?"border-[var(--color-accent-500)] bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20":"border-[var(--border-color)] hover:border-[var(--color-accent-300)]"}`,children:[e.jsx("span",{className:"text-2xl mb-2 block",children:y.icon}),e.jsx("span",{className:"text-sm font-medium",children:s(`onboarding.${y.labelKey}`)})]},y.value))}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3 text-[var(--text-secondary)]",children:s("onboarding.accentColorLabel")}),e.jsx("div",{className:"flex justify-center gap-3",children:ba.map(y=>e.jsx("button",{onClick:()=>m(y.key),className:`w-10 h-10 rounded-full transition-all ${d===y.key?"ring-2 ring-offset-2 ring-[var(--color-accent-500)] ring-offset-[var(--bg-secondary)]":"hover:scale-110"}`,style:{backgroundColor:y.color},title:y.name},y.key))})]})]}),n==="complete"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-20 h-20 mx-auto bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)]/30 rounded-full flex items-center justify-center mb-6",children:e.jsx(a.Sparkles,{className:"w-10 h-10 text-[var(--color-accent-500)]"})}),e.jsx("h2",{className:"text-xl font-semibold mb-4",children:s("onboarding.stepComplete")}),e.jsxs("div",{className:"text-[var(--text-secondary)] mb-6 space-y-2",children:[e.jsx("p",{children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(a.Globe,{className:"w-4 h-4"}),Or.find(y=>y.code===o)?.name]})}),e.jsx("p",{children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(a.Palette,{className:"w-4 h-4"}),ha.find(y=>y.value===x)?.icon," ",s(`onboarding.${ha.find(y=>y.value===x)?.labelKey}`)]})}),e.jsx("p",{children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{className:"w-4 h-4 rounded-full",style:{backgroundColor:ba.find(y=>y.key===d)?.color}}),ba.find(y=>y.key===d)?.name]})})]}),v&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-300 rounded-lg p-3 mb-4 text-sm",children:v})]}),e.jsxs("div",{className:"flex justify-between mt-8",children:[f>0?e.jsxs("button",{onClick:k,className:"flex items-center gap-2 px-4 py-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(a.ArrowLeft,{className:"w-4 h-4"}),s("onboarding.back")]}):e.jsx("div",{}),n==="complete"?e.jsx("button",{onClick:C,disabled:p,className:"flex items-center gap-2 px-6 py-2 bg-[var(--color-accent-500)] hover:bg-[var(--color-accent-600)] text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:p?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"w-4 h-4 animate-spin"}),s("onboarding.completing")]}):e.jsxs(e.Fragment,{children:[s("onboarding.complete"),e.jsx(a.CheckCircle,{className:"w-4 h-4"})]})}):e.jsxs("button",{onClick:N,className:"flex items-center gap-2 px-6 py-2 bg-[var(--color-accent-500)] hover:bg-[var(--color-accent-600)] text-white rounded-lg font-medium transition-colors",children:[s("onboarding.continue"),e.jsx(a.ArrowRight,{className:"w-4 h-4"})]})]})]})]})})}function De({items:s,className:t=""}){return e.jsx("nav",{"aria-label":"Breadcrumb",className:`flex items-center gap-1 text-sm ${t}`,children:s.map((r,n)=>{const i=n===s.length-1,o=n===0;return e.jsxs("div",{className:"flex items-center gap-1",children:[n>0&&e.jsx(a.ChevronRight,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),i?e.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--text-primary)] font-medium",children:[r.icon,r.label]}):r.href?e.jsxs(Q.Link,{to:r.href,className:"flex items-center gap-1.5 text-[var(--text-secondary)] hover:text-[var(--color-accent-600)] transition-colors",children:[o&&!r.icon&&e.jsx(a.Home,{className:"w-4 h-4"}),r.icon,r.label]}):e.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--text-secondary)]",children:[r.icon,r.label]})]},`${n}-${r.label}`)})})}const rd={settings:a.Settings,users:a.Users,key:a.Key,briefcase:a.Briefcase,folder:a.FolderOpen,file:a.FileText,box:a.Box};function nd(s){return s&&rd[s.toLowerCase()]||a.Box}function qr({app:s,isFavorite:t,onToggleFavorite:r,buildUrl:n}){const i=nd(s.icon);return e.jsx("div",{className:"group relative bg-[var(--bg-card)] rounded-2xl border border-[var(--border-color)] overflow-hidden hover:border-primary-500/50 transition-all duration-300 hover:shadow-lg hover:shadow-primary-500/10",children:e.jsxs(Q.Link,{to:s.route?n(s.route):"#",className:"block p-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-gradient-to-br from-primary-500/20 to-primary-600/20 flex items-center justify-center group-hover:from-primary-500/30 group-hover:to-primary-600/30 transition-all",children:e.jsx(i,{className:"w-7 h-7 text-primary-500"})}),e.jsx("button",{onClick:o=>{o.preventDefault(),o.stopPropagation(),r()},className:`p-2 rounded-lg transition-all duration-200 ${t?"text-amber-500 bg-amber-500/10":"text-[var(--text-tertiary)] opacity-0 group-hover:opacity-100 hover:bg-[var(--bg-tertiary)]"}`,title:t?"Retirer des favoris":"Ajouter aux favoris",children:e.jsx(a.Star,{className:`w-5 h-5 ${t?"fill-current":""}`})})]}),e.jsx("h3",{className:"text-lg font-semibold text-[var(--text-primary)] mb-2",children:s.label}),e.jsxs("p",{className:"text-sm text-[var(--text-secondary)] mb-4",children:[s.modules.length," ",s.modules.length===1?"module":"modules"]}),e.jsxs("div",{className:"flex items-center gap-2 text-primary-500 text-sm font-medium opacity-0 group-hover:opacity-100 transition-opacity",children:["Ouvrir",e.jsx(a.ArrowRight,{className:"w-4 h-4"})]})]})})}function ld(){const{t:s}=ne.useTranslation("admin"),{favorites:t,getApplicationsForContext:r,toggleFavorite:n,isFavorite:i,isLoading:o}=Ze(),c=ws(),x=r("platform");return o?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("div",{className:"w-8 h-8 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}):e.jsxs("div",{className:"space-y-8",children:[e.jsx(De,{items:[{label:s("applications.title","Applications")}]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s("applications.title","Applications")}),e.jsx("p",{className:"text-[var(--text-secondary)] mt-1",children:s("applications.subtitle","Sélectionnez une application pour commencer")})]}),t.length>0&&e.jsxs("section",{children:[e.jsxs("h2",{className:"text-lg font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(a.Star,{className:"w-5 h-5 text-amber-500 fill-amber-500"}),s("applications.favorites","Favoris")]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:t.map(u=>{const d=x.find(m=>m.id===u.id);return d?e.jsx(qr,{app:d,isFavorite:!0,onToggleFavorite:()=>n(d.id),buildUrl:c},d.id):null})})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--text-primary)] mb-4",children:s("applications.all","Toutes les applications")}),x.length>0?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:x.map(u=>e.jsx(qr,{app:u,isFavorite:i(u.id),onToggleFavorite:()=>n(u.id),buildUrl:c},u.id))}):e.jsxs("div",{className:"text-center py-12 bg-[var(--bg-card)] rounded-2xl border border-[var(--border-color)]",children:[e.jsx(a.Box,{className:"w-12 h-12 text-[var(--text-tertiary)] mx-auto mb-4"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("applications.noApps","Aucune application disponible")})]})]})]})}const Js={getDashboardStats:async()=>await oe.get("/api/platform/administration/applications/application-analytics/dashboard"),getApplicationAnalytics:async s=>await oe.get(`/api/platform/administration/applications/application-analytics/${s}/analytics`),getApplicationActivity:async(s,t=1,r=20)=>await oe.get(`/api/platform/administration/applications/application-analytics/${s}/recent-activity`,{params:{page:t,pageSize:r}}),getDeviceStats:async(s=30,t)=>await oe.get("/api/platform/administration/applications/application-analytics/device-stats",{params:{period:s},signal:t?.signal}),getEngagementMetrics:async(s=30,t)=>await oe.get("/api/platform/administration/applications/application-analytics/engagement",{params:{period:s},signal:t?.signal}),getTopModules:async(s=10,t=30)=>await oe.get("/api/platform/administration/applications/application-analytics/modules/top",{params:{limit:s,period:t}}),getHierarchyData:async(s=0,t,r,n=30)=>{const i={level:s,period:n};return t&&(i.contextId=t),r&&(i.applicationId=r),await oe.get("/api/platform/administration/applications/application-analytics/hierarchy",{params:i})},getTrendsByApplication:async(s=30)=>await oe.get("/api/platform/administration/applications/application-analytics/trends-by-application",{params:{period:s}})},Vr={Desktop:e.jsx(a.Monitor,{className:"w-4 h-4"}),Mobile:e.jsx(a.Smartphone,{className:"w-4 h-4"}),Tablet:e.jsx(a.Tablet,{className:"w-4 h-4"}),Unknown:e.jsx(a.Monitor,{className:"w-4 h-4 opacity-50"})},zr=["#3b82f6","#22c55e","#f59e0b","#6b7280"],Gr=["#3b82f6","#8b5cf6","#22c55e","#f59e0b","#ef4444"],id=({data:s})=>!s||!s.byDeviceType?.length&&!s.byBrowser?.length?e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"No device data available"}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"By Device Type"}),e.jsx("div",{className:"space-y-3",children:s.byDeviceType.map((t,r)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 w-28",children:[Vr[t.deviceType]||Vr.Unknown,e.jsx("span",{className:"text-sm",children:t.deviceType})]}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${t.percentage}%`,backgroundColor:zr[r%zr.length]}})}),e.jsxs("div",{className:"w-20 text-right",children:[e.jsx("span",{className:"font-medium",children:t.count}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] ml-1",children:["(",t.percentage.toFixed(1),"%)"]})]})]},t.deviceType))})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"By Browser"}),e.jsx("div",{className:"space-y-3",children:s.byBrowser.map((t,r)=>{const n=Math.max(...s.byBrowser.map(o=>o.count),1),i=t.count/n*100;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-24 text-sm",children:t.browser}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${i}%`,backgroundColor:Gr[r%Gr.length]}})}),e.jsx("div",{className:"w-12 text-right font-medium",children:t.count})]},t.browser)})})]})]}),Hr=["#ef4444","#f59e0b","#22c55e","#3b82f6"],od=({data:s})=>{if(!s)return e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"No engagement data available"});const t=Math.max(...s.sessionDistribution.map(n=>n.count),1),r=Math.max(...s.peakUsageHours.map(n=>n.accessCount),1);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"Session Duration Distribution"}),e.jsx("div",{className:"space-y-3",children:s.sessionDistribution.map((n,i)=>{const o=n.count/t*100;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-20 text-sm",children:n.label}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${o}%`,backgroundColor:Hr[i%Hr.length]}})}),e.jsxs("div",{className:"w-16 text-right",children:[e.jsx("span",{className:"font-medium",children:n.count}),e.jsx("span",{className:"text-xs text-[var(--text-secondary)] ml-1",children:"sessions"})]})]},n.bucket)})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"Peak Usage Hours"}),e.jsx("div",{className:"flex items-end gap-1 h-32 overflow-x-auto pb-2",children:s.peakUsageHours.map(n=>{const i=n.accessCount/r*100;return e.jsxs("div",{className:"flex-1 min-w-[20px] flex flex-col items-center gap-1",children:[e.jsx("div",{className:"w-full bg-gradient-to-t from-blue-500 to-cyan-500 rounded-t transition-all duration-300 hover:opacity-80",style:{height:`${i}%`,minHeight:n.accessCount>0?"4px":"0"},title:`${n.hour}h: ${n.accessCount} accesses`}),n.hour%3===0&&e.jsxs("span",{className:"text-xs text-[var(--text-secondary)]",children:[n.hour,"h"]})]},n.hour)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 pt-4 border-t border-[var(--border-color)]",children:[e.jsxs("div",{className:"text-center p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:s.dailyActiveUsers}),e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mt-1",children:"Daily Active Users"})]}),e.jsxs("div",{className:"text-center p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsxs("div",{className:"text-2xl font-bold text-green-600",children:[(s.retentionRate*100).toFixed(1),"%"]}),e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mt-1",children:"Retention Rate"})]})]})]})},cd={Active:"#22c55e",Inactive:"#ef4444"};function Kr(){const{t:s}=ne.useTranslation(["admin","navigation"]),t=Q.useNavigate(),{currentTenant:r,isGlobalView:n}=ze(),[i,o]=l.useState(!0),[c,x]=l.useState(!1),[u,d]=l.useState(30),[m,p]=l.useState(null),[h,v]=l.useState([]),[b,g]=l.useState([]),[j,w]=l.useState([]),[f,N]=l.useState([]),[k,C]=l.useState([]),[y,A]=l.useState(null),[D,R]=l.useState(null),[L,S]=l.useState(null),[T,I]=l.useState(null),M=l.useRef(null),X=l.useCallback(async U=>{try{I(null);const[K,$,E,q,F,V,P,B,J]=await Promise.all([le.dashboard.getOverview(u,{signal:U}),le.dashboard.getByStatus({signal:U}),le.dashboard.getByRole({signal:U}),le.dashboard.getTrends(u,{signal:U}),le.dashboard.getLatestActiveSessions(5,{signal:U}),le.dashboard.getSecurityAlerts(3,24,{signal:U}),le.dashboard.getActiveSessions({signal:U}),Js.getDeviceStats(u,{signal:U}),Js.getEngagementMetrics(u,{signal:U})]);U?.aborted||(p(K??null),v($??[]),g(E??[]),w(q??[]),N(F??[]),C(V??[]),A(P??null),R(B??null),S(J??null))}catch(K){if(K instanceof Error&&K.name==="CanceledError")return;console.error("Failed to load dashboard data:",K);const $=K;$.response?.status===401?I("Session expirée. Veuillez vous reconnecter."):$.response?.status===403?I("Vous n'avez pas les permissions nécessaires pour accéder au dashboard."):I("Erreur lors du chargement des données. Vérifiez que l'API est accessible.")}finally{U?.aborted||(o(!1),x(!1))}},[u,r?.id,n]);l.useEffect(()=>{M.current?.abort();const U=new AbortController;return M.current=U,X(U.signal),()=>{U.abort()}},[X]);const O=()=>{M.current?.abort();const U=new AbortController;M.current=U,x(!0),X(U.signal)};return i?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(De,{items:[{label:s("header.title")},{label:s("dashboard.title")}]}),T&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(a.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium",children:T})}),e.jsx("button",{onClick:O,className:"text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-200",children:e.jsx(a.RefreshCw,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(a.Users,{className:"w-6 h-6"}),s("admin:header.title")]}),e.jsx("p",{className:"text-[var(--text-secondary)] mt-1",children:"Vue d'ensemble de la gestion des utilisateurs"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("select",{value:u,onChange:U=>d(Number(U.target.value)),className:"input",children:[e.jsx("option",{value:7,children:"7 derniers jours"}),e.jsx("option",{value:30,children:"30 derniers jours"}),e.jsx("option",{value:90,children:"90 derniers jours"})]}),e.jsxs("button",{onClick:O,disabled:c,className:"btn btn-secondary flex items-center gap-2",children:[e.jsx(a.RefreshCw,{className:`w-4 h-4 ${c?"animate-spin":""}`}),"Actualiser"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:[e.jsx($s,{title:"Total Utilisateurs",value:m?.totalUsers??0,icon:e.jsx(a.Users,{className:"w-5 h-5"}),color:"blue"}),e.jsx($s,{title:"Actifs",value:m?.activeUsers??0,icon:e.jsx(a.UserCheck,{className:"w-5 h-5"}),color:"green"}),e.jsx($s,{title:"Inactifs",value:m?.inactiveUsers??0,icon:e.jsx(a.UserX,{className:"w-5 h-5"}),color:"red"}),e.jsx($s,{title:"Nouveaux",value:m?.newUsers??0,icon:e.jsx(a.UserPlus,{className:"w-5 h-5"}),color:"blue",subtitle:`${u} derniers jours`}),e.jsx($s,{title:"Sessions",value:m?.totalSessions??0,icon:e.jsx(a.Activity,{className:"w-5 h-5"}),color:"green",subtitle:`${u} derniers jours`}),e.jsx($s,{title:"Connexions Echouées",value:m?.failedLogins??0,icon:e.jsx(a.AlertTriangle,{className:"w-5 h-5"}),color:m&&m.failedLogins>10?"red":"yellow",subtitle:`${u} derniers jours`})]}),(k?.length??0)>0&&e.jsxs("div",{className:"card p-4 border-l-4 border-red-500",children:[e.jsxs("h3",{className:"font-semibold text-red-600 flex items-center gap-2 mb-3",children:[e.jsx(a.AlertTriangle,{className:"w-5 h-5"}),"Alertes Sécurité (",k?.length??0,")"]}),e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:(k??[]).slice(0,5).map(U=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-red-50 dark:bg-red-900/20 rounded cursor-pointer hover:bg-red-100 dark:hover:bg-red-900/30",onClick:()=>t(`/platform/administration/users/${U.userId}`),children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:U.fullName}),e.jsx("span",{className:"ml-2 text-sm text-[var(--text-secondary)]",children:U.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-red-600 font-medium",children:[U.failedAttempts," échecs"]}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)]",children:[U.ipAddresses?.length??0," IP(s)"]})]})]},U.userId))})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.UserCheck,{className:"w-5 h-5"}),"Utilisateurs par Statut"]}),e.jsx("div",{className:"space-y-3",children:(h??[]).map(U=>{const K=(h??[]).reduce((E,q)=>E+q.count,0),$=K>0?U.count/K*100:0;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-24 text-sm",children:U.status==="Active"?"Actifs":"Inactifs"}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${$}%`,backgroundColor:cd[U.status]||"#6b7280"}})}),e.jsxs("div",{className:"w-20 text-right",children:[e.jsx("span",{className:"font-medium",children:U.count}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] ml-1",children:["(",$.toFixed(0),"%)"]})]})]},U.status)})})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Key,{className:"w-5 h-5"}),"Utilisateurs par Rôle"]}),e.jsx("div",{className:"space-y-3",children:(b?.length??0)>0?(b??[]).map((U,K)=>{const $=Math.max(...(b??[]).map(F=>F.count),1),E=U.count/$*100,q=["#3b82f6","#8b5cf6","#22c55e","#f59e0b","#ef4444"];return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-32 text-sm truncate",title:U.roleName,children:U.roleName}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${E}%`,backgroundColor:q[K%q.length]}})}),e.jsx("div",{className:"w-12 text-right font-medium",children:U.count})]},U.roleName)}):e.jsx("div",{className:"text-center py-4 text-[var(--text-secondary)]",children:"Aucun rôle configuré"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Shield,{className:"w-5 h-5"}),"Configuration Système"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-purple-600",children:m?.totalRoles??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Rôles"})]}),e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-green-600",children:m?.totalPermissions??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Permissions"})]}),e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-blue-600",children:m?.usersLoggedInRecently??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Connectés récemment"})]}),e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-orange-600",children:y?.totalActiveSessions??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Sessions actives"})]})]})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Monitor,{className:"w-5 h-5"}),"Sessions Actives"]}),y&&((y.byBrowser?.length??0)>0||(y.byCountry?.length??0)>0)?e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2",children:"Par Navigateur"}),e.jsx("div",{className:"space-y-2",children:(y.byBrowser??[]).map(U=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{children:U.browser}),e.jsx("span",{className:"font-medium",children:U.count})]},U.browser))})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2 flex items-center gap-1",children:[e.jsx(a.Globe,{className:"w-4 h-4"})," Par Pays"]}),e.jsx("div",{className:"space-y-2",children:(y.byCountry?.length??0)>0?(y.byCountry??[]).map(U=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{children:U.country}),e.jsx("span",{className:"font-medium",children:U.count})]},U.country)):e.jsx("span",{className:"text-[var(--text-secondary)] text-sm",children:"Non disponible"})})]})]}):e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"Aucune session active"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Monitor,{className:"w-5 h-5"}),"Appareils & Navigateurs"]}),e.jsx(id,{data:D})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Activity,{className:"w-5 h-5"}),"Engagement Utilisateurs"]}),e.jsx(od,{data:L})]})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.TrendingUp,{className:"w-5 h-5"}),"Tendances (",u," derniers jours)"]}),e.jsx("div",{className:"h-64",children:e.jsx(dd,{data:j??[]})})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Clock,{className:"w-5 h-5"}),"Dernières Sessions Actives"]}),(f?.length??0)>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[var(--border-color)]",children:[e.jsx("th",{className:"text-left p-3 font-medium",children:"Utilisateur"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"Durée"})]})}),e.jsx("tbody",{children:(f??[]).map(U=>e.jsxs("tr",{className:"border-b border-[var(--border-color)] hover:bg-[var(--bg-secondary)] cursor-pointer",onClick:()=>t(`/platform/administration/users/${U.userId}`),children:[e.jsx("td",{className:"p-3 font-medium",children:U.fullName}),e.jsx("td",{className:"p-3 text-right",children:e.jsx("span",{className:"px-2 py-1 rounded text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400",children:U.duration})})]},U.userId+U.loginAt))})]})}):e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"Aucune session active"})]})]})}function $s({title:s,value:t,icon:r,color:n,subtitle:i}){const o={blue:"bg-blue-50 text-blue-600 border-blue-200 dark:bg-blue-900/20 dark:border-blue-800",green:"bg-green-50 text-green-600 border-green-200 dark:bg-green-900/20 dark:border-green-800",yellow:"bg-yellow-50 text-yellow-600 border-yellow-200 dark:bg-yellow-900/20 dark:border-yellow-800",red:"bg-red-50 text-red-600 border-red-200 dark:bg-red-900/20 dark:border-red-800"};return e.jsxs("div",{className:`card p-4 border ${o[n]}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium opacity-80",children:s}),r]}),e.jsx("div",{className:"text-2xl font-bold",children:t}),i&&e.jsx("div",{className:"text-xs opacity-70 mt-1",children:i})]})}function dd({data:s}){if(s.length===0)return e.jsx("div",{className:"flex items-center justify-center h-full text-[var(--text-secondary)]",children:"Aucune donnée de tendance disponible"});const t=Math.max(...s.flatMap(r=>[r.newUsers,r.logins]),1);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-blue-500"}),e.jsx("span",{className:"text-sm",children:"Nouveaux utilisateurs"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-green-500"}),e.jsx("span",{className:"text-sm",children:"Connexions"})]})]}),e.jsx("div",{className:"flex-1 flex items-end gap-1 overflow-x-auto pb-4",children:s.map(r=>e.jsxs("div",{className:"flex-1 min-w-[20px] flex gap-0.5",children:[e.jsx("div",{className:"flex-1 bg-blue-500 rounded-t transition-all duration-300 hover:opacity-80",style:{height:`${r.newUsers/t*100}%`,minHeight:r.newUsers>0?"4px":"0"},title:`Nouveaux: ${r.newUsers}`}),e.jsx("div",{className:"flex-1 bg-green-500 rounded-t transition-all duration-300 hover:opacity-80",style:{height:`${r.logins/t*100}%`,minHeight:r.logins>0?"4px":"0"},title:`Connexions: ${r.logins}`})]},`${r.date}`))}),e.jsxs("div",{className:"flex justify-between text-xs text-[var(--text-secondary)] mt-2",children:[e.jsx("span",{children:s[0]&&new Date(s[0].date).toLocaleDateString("fr-FR")}),e.jsx("span",{children:s[s.length-1]&&new Date(s[s.length-1].date).toLocaleDateString("fr-FR")})]})]})}function md({data:s,viewMode:t,onViewModeChange:r,renderTable:n,renderCards:i,renderKanban:o,showTableView:c=!0,showCardsView:x=!0,showKanbanView:u=!0,tableLabel:d="Table",cardsLabel:m="Cards",kanbanLabel:p="Kanban"}){const[h,v]=l.useState("table"),b=t??h,g=r??v,j=[{mode:"table",label:d,icon:a.LayoutList,show:c},{mode:"cards",label:m,icon:a.LayoutGrid,show:x},{mode:"kanban",label:p,icon:a.Columns3,show:u}].filter(w=>w.show);return e.jsxs("div",{className:"space-y-4",children:[j.length>1&&e.jsx("div",{className:"flex items-center gap-1 p-1 rounded-[var(--radius-button)] bg-[var(--bg-secondary)] w-fit",children:j.map(({mode:w,label:f,icon:N})=>e.jsxs("button",{onClick:()=>g(w),className:`px-3 py-1.5 rounded-[var(--radius-button)] text-sm font-medium flex items-center gap-2 transition-all ${b===w?"bg-[var(--color-accent-600)] text-white shadow-sm":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"}`,children:[e.jsx(N,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:f})]},w))}),e.jsxs("div",{children:[b==="table"&&n&&n(s),b==="cards"&&i&&i(s),b==="kanban"&&o&&o(s)]})]})}function Es({viewMode:s,onChange:t,showTable:r=!0,showCards:n=!0,showKanban:i=!0,tableLabel:o="Table",cardsLabel:c="Cards",kanbanLabel:x="Kanban"}){const u=[{mode:"table",label:o,icon:a.LayoutList,show:r},{mode:"cards",label:c,icon:a.LayoutGrid,show:n},{mode:"kanban",label:x,icon:a.Columns3,show:i}].filter(d=>d.show);return u.length<=1?null:e.jsx("div",{className:"flex items-center gap-1 p-1 rounded-[var(--radius-button)] bg-[var(--bg-secondary)] border border-[var(--border-color)]",children:u.map(({mode:d,label:m,icon:p})=>e.jsxs("button",{onClick:()=>t(d),className:`px-3 py-1.5 rounded-[var(--radius-button)] text-sm font-medium flex items-center gap-2 transition-all ${s===d?"bg-[var(--color-accent-600)] text-white shadow-sm":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"}`,children:[e.jsx(p,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:m})]},d))})}const _r=["from-violet-500 to-purple-500","from-blue-500 to-cyan-500","from-emerald-500 to-teal-500","from-orange-500 to-amber-500","from-pink-500 to-rose-500","from-indigo-500 to-blue-500","from-fuchsia-500 to-pink-500","from-cyan-500 to-blue-500"];function xd(s){let t=0;for(let r=0;r<s.length;r++)t=s.charCodeAt(r)+((t<<5)-t);return _r[Math.abs(t)%_r.length]}function ud(s){return s.split(" ").map(t=>t[0]).join("").toUpperCase().slice(0,2)}function Ct({name:s,size:t="md",className:r=""}){const n={xs:"w-6 h-6 text-xs",sm:"w-8 h-8 text-xs",md:"w-10 h-10 text-sm",lg:"w-12 h-12 text-base",xl:"w-16 h-16 text-lg"},i={xs:"",sm:"shadow-md",md:"shadow-lg shadow-primary-500/20",lg:"shadow-lg shadow-primary-500/20",xl:"shadow-xl shadow-primary-500/25"};return e.jsx("div",{className:`${n[t]} ${i[t]} rounded-full bg-gradient-to-br ${xd(s)} flex items-center justify-center text-white font-semibold ${r}`,children:ud(s)})}function cs({status:s,label:t,showDot:r=!0,size:n="md"}){const i={active:"bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",inactive:"bg-[var(--bg-tertiary)] text-[var(--text-tertiary)] border-[var(--border-color)]",pending:"bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",warning:"bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",error:"bg-[var(--error-bg)] text-[var(--error-text)] border-[var(--error-border)]"},o={active:"bg-[var(--success-dot)]",inactive:"bg-[var(--text-muted)]",pending:"bg-[var(--warning-dot)]",warning:"bg-[var(--warning-dot)]",error:"bg-[var(--error-dot)]"},c={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-xs"};return e.jsxs("span",{className:`inline-flex items-center gap-1.5 ${c[n]} rounded-[var(--radius-badge)] font-medium border ${i[s]}`,children:[r&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o[s]}`}),t]})}function St({role:s,variant:t="default",icon:r}){const n={accent:"bg-[var(--accent-bg)] text-[var(--accent-text)] border-[var(--accent-border)]",default:"bg-[var(--bg-secondary)] text-[var(--text-secondary)] border-[var(--border-color)]"};return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[var(--radius-badge)] text-xs font-medium border ${n[t]}`,children:[r,s]})}function Ya({title:s,count:t,color:r,children:n,isDragOver:i,onDragOver:o,onDragLeave:c,onDrop:x}){const u={success:"bg-[var(--success-dot)]",warning:"bg-[var(--warning-dot)]",error:"bg-[var(--error-dot)]",default:"bg-[var(--text-muted)]"};return e.jsxs("div",{className:`min-w-[280px] flex-1 rounded-lg p-2 transition-colors ${i?"bg-[var(--color-accent-500)]/10 ring-2 ring-[var(--color-accent-500)]/50":""}`,onDragOver:o,onDragLeave:c,onDrop:x,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${u[r]}`}),e.jsx("h3",{className:"font-semibold text-[var(--text-primary)]",children:s}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:t})]}),e.jsx("div",{className:"space-y-3 min-h-[100px]",children:n})]})}function Za({children:s,onClick:t,draggable:r=!0,isDragging:n,onDragStart:i,onDragEnd:o}){return e.jsx("div",{draggable:r,onClick:t,onDragStart:i,onDragEnd:o,className:`bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)] p-4 transition-all hover:shadow-md hover:border-[var(--color-accent-500)]/30 cursor-grab active:cursor-grabbing ${n?"opacity-50 scale-95":""}`,children:s})}function ks({page:s,totalPages:t,totalCount:r,pageSize:n=20,onPageChange:i,itemLabel:o="éléments",showInfo:c=!0,showFirstLast:x=!0}){const u=(s-1)*n+1,d=Math.min(s*n,r),m=()=>{const p=[];if(t<=7)for(let h=1;h<=t;h++)p.push(h);else{p.push(1),s>3&&p.push("ellipsis");const h=Math.max(2,s-1),v=Math.min(t-1,s+1);for(let b=h;b<=v;b++)p.includes(b)||p.push(b);s<t-2&&p.push("ellipsis"),p.includes(t)||p.push(t)}return p};return e.jsx("div",{className:"card p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[c&&e.jsxs("div",{className:"text-sm text-[var(--text-secondary)]",children:["Affichage de"," ",e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:u})," ","à"," ",e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:d})," ","sur"," ",e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:r})," ",o]}),t>1&&e.jsxs("div",{className:"flex items-center gap-1",children:[x&&e.jsx("button",{onClick:()=>i(1),disabled:s===1,className:"hidden sm:flex btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Première page",children:e.jsx(a.ChevronsLeft,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>i(Math.max(1,s-1)),disabled:s===1,className:"btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Page précédente",children:e.jsx(a.ChevronLeft,{className:"w-5 h-5"})}),e.jsx("div",{className:"flex items-center gap-1",children:m().map((p,h)=>p==="ellipsis"?e.jsx("span",{className:"px-2 text-[var(--text-muted)]",children:"..."},`ellipsis-${h}`):e.jsx("button",{onClick:()=>i(p),className:`w-10 h-10 rounded-[var(--radius-button)] text-sm font-medium transition-all ${s===p?"bg-[var(--color-accent-600)] text-white shadow-lg shadow-[var(--color-accent-500)]/30":"btn btn-secondary hover:bg-[var(--bg-hover)]"}`,children:p},`page-${p}`))}),e.jsx("button",{onClick:()=>i(Math.min(t,s+1)),disabled:s===t,className:"btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Page suivante",children:e.jsx(a.ChevronRight,{className:"w-5 h-5"})}),x&&e.jsx("button",{onClick:()=>i(t),disabled:s===t,className:"hidden sm:flex btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Dernière page",children:e.jsx(a.ChevronsRight,{className:"w-4 h-4"})})]})]})})}class pd{pages=new Map;register(t,r,n=[]){this.pages.set(t,{key:t,defaultComponent:r,slots:n})}get(t){return this.pages.get(t)}getAll(){return Array.from(this.pages.values())}has(t){return this.pages.has(t)}getSlots(t){return this.pages.get(t)?.slots||[]}}const Ai=new pd;function hd(s,t){function r(n){const i=Xt(s);return i?e.jsx(i,{...n}):e.jsx(t,{...n})}return r.displayName=`Overridable(${s})`,r}function bd(s){const t=Xt(s),r=Ai.get(s);return t||r?.defaultComponent}function vd({pageKey:s,defaultComponent:t,params:r}){const n=Xt(s),i={pageKey:s,params:r};return n?e.jsx(n,{...i}):e.jsx(t,{...i})}const gd={USERS_LIST:"platform.administration.users",USERS_DETAIL:"platform.administration.users.detail",ROLES_LIST:"platform.administration.permissions.roles",ROLES_DETAIL:"platform.administration.permissions.roles.detail",PERMISSIONS_LIST:"platform.administration.permissions.permissions",PERMISSIONS_DETAIL:"platform.administration.permissions.permissions.detail",ASSIGNMENTS:"platform.administration.permissions.assignments",AI_DASHBOARD:"platform.administration.ai.dashboard",AI_PROMPTS_LIST:"platform.administration.ai.prompts",AI_PROMPTS_DETAIL:"platform.administration.ai.prompts.detail",WORKFLOWS_LIST:"platform.administration.workflows.list",WORKFLOWS_DETAIL:"platform.administration.workflows.detail",EMAIL_TEMPLATES_LIST:"platform.administration.workflows.email-templates",EMAIL_TEMPLATES_DETAIL:"platform.administration.workflows.email-templates.detail",TICKETS_LIST:"platform.support.tickets",TICKETS_DETAIL:"platform.support.tickets.detail",SUPPORT_DASHBOARD:"platform.support.dashboard",USER_PROFILE:"personal.myspace.profile",USER_PREFERENCES:"personal.myspace.preferences",USER_DASHBOARD:"personal.myspace.dashboard",MY_TICKETS_LIST:"business.support-client.my-tickets",MY_TICKETS_DETAIL:"business.support-client.my-tickets.detail"};function fd(){const{currentTenant:s,hasGlobalRoles:t,isGlobalView:r}=ze(),{currentModuleCode:n,getCurrentModule:i,isLoading:o,menu:c}=Ze();return t&&!r&&s&&n&&!o&&c?{isRestrictedModule:!i(),tenantName:s?.name||null}:{isRestrictedModule:!1,tenantName:null}}function jd(){const{t:s}=ne.useTranslation("admin"),{isRestrictedModule:t,tenantName:r}=fd();return t?e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 border bg-amber-500/10 border-amber-500/20",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 flex items-center justify-center bg-amber-500/10",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.AlertTriangle,{className:"w-4 h-4 text-amber-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium text-amber-700",children:s("scope.banner.restrictedModule","Module restreint")}),e.jsx("p",{className:"text-xs text-amber-600/70 mt-0.5",children:s("scope.banner.restrictedModuleDesc",`Le tenant "{{tenantName}}" n'a pas accès à ce module. Données affichées grâce à vos privilèges administrateur.`,{tenantName:r})})]})]}):null}function yd(s,t){const[r,n]=l.useState(s);return l.useEffect(()=>{const i=setTimeout(()=>n(s),t);return()=>clearTimeout(i)},[s,t]),r}const Nd={search:"",status:"all",roleId:"",source:"all",userType:"",sortBy:"lastname",sortDesc:!1};function Wr(){const{t:s}=ne.useTranslation("admin"),t=Q.useNavigate(),[r,n]=Q.useSearchParams(),i=di("users"),{currentTenant:o,isGlobalView:c}=ze(),{hasPermission:x}=Ke(),u=x("platform.administration.users.create"),d=x("platform.administration.users.update"),m=x("platform.administration.users.delete"),p=l.useMemo(()=>({search:r.get("search")||"",status:r.get("status")||"all",roleId:r.get("roleId")||"",source:r.get("source")||"all",userType:r.get("userType")||"",sortBy:r.get("sortBy")||"lastname",sortDesc:r.get("sortDesc")==="true"}),[]),[h,v]=l.useState([]),[b,g]=l.useState([]),[j,w]=l.useState(!0),[f,N]=l.useState(p),[k,C]=l.useState(!1),[y,A]=l.useState(parseInt(r.get("page")||"1")),[D,R]=l.useState(1),[L,S]=l.useState(0),[T,I]=l.useState(!1),[M,X]=l.useState(null),[O,U]=l.useState({email:"",password:"",firstName:"",lastName:"",roleIds:[]}),[K,$]=l.useState(!1),[E,q]=l.useState(null),[F,V]=l.useState("table");l.useEffect(()=>{const ee={search:r.get("search")||"",status:r.get("status")||"all",roleId:r.get("roleId")||"",source:r.get("source")||"all",userType:r.get("userType")||"",sortBy:r.get("sortBy")||"lastname",sortDesc:r.get("sortDesc")==="true"};JSON.stringify(ee)!==JSON.stringify(f)&&N(ee);const ge=parseInt(r.get("page")||"1");ge!==y&&A(ge)},[r]);const P=yd(f.search,300),B=l.useMemo(()=>{let ee=0;return f.status!=="all"&&ee++,f.roleId&&ee++,f.source!=="all"&&ee++,f.userType&&ee++,ee},[f]),J=l.useCallback(async()=>{try{w(!0);const ee=await le.users.getAll({page:y,pageSize:20,search:P||void 0,isActive:f.status==="all"?void 0:f.status==="active",entraOnly:f.source==="entra"?!0:void 0,roleId:f.roleId||void 0,userType:f.userType||void 0,sortBy:f.sortBy||void 0,sortDesc:f.sortDesc});v(ee.items),R(ee.totalPages),S(ee.totalCount)}catch(ee){console.error("Failed to load users:",ee)}finally{w(!1)}},[y,P,f.status,f.source,f.roleId,f.userType,f.sortBy,f.sortDesc,o?.id,c]);l.useEffect(()=>{const ee=new URLSearchParams;f.search&&ee.set("search",f.search),f.status!=="all"&&ee.set("status",f.status),f.roleId&&ee.set("roleId",f.roleId),f.source!=="all"&&ee.set("source",f.source),f.userType&&ee.set("userType",f.userType),f.sortBy!=="lastname"&&ee.set("sortBy",f.sortBy),f.sortDesc&&ee.set("sortDesc","true"),y>1&&ee.set("page",y.toString()),n(ee,{replace:!0})},[f,y,n]);const W=async()=>{try{const ee=await le.roles.getAll();g(ee)}catch(ee){console.error("Failed to load roles:",ee)}};l.useEffect(()=>{J()},[J]),l.useEffect(()=>{W()},[]);const re=()=>{N(Nd),A(1)},te=(ee,ge)=>{N(Re=>({...Re,[ee]:ge})),A(1)},ce=()=>{X(null),U({email:"",password:"",firstName:"",lastName:"",roleIds:[]}),q(null),I(!0)},he=async ee=>{try{const ge=await le.users.getById(ee.id);X(ee),U({email:ge.email,password:"",firstName:ge.firstName,lastName:ge.lastName,roleIds:ge.roles.map(Re=>Re.id)}),q(null),I(!0)}catch(ge){console.error("Failed to load user details:",ge)}},z=async ee=>{ee.preventDefault(),$(!0),q(null);try{if(M){const ge={email:O.email!==M.email?O.email:void 0,firstName:O.firstName,lastName:O.lastName,roleIds:O.roleIds};await le.users.update(M.id,ge)}else await le.users.create(O);I(!1),J()}catch(ge){const Re=ge instanceof Error?ge.message:"An error occurred";q(Re)}finally{$(!1)}},H=async(ee,ge)=>{ge?.stopPropagation();try{ee.isActive?await le.users.deactivate(ee.id):await le.users.activate(ee.id),J()}catch(Re){console.error("Failed to toggle user status:",Re)}},je=async(ee,ge)=>{if(ge?.stopPropagation(),!!confirm(s("users.confirmDelete",{name:ee.fullName})))try{await le.users.delete(ee.id),J()}catch(Re){console.error("Failed to delete user:",Re)}},xe=ee=>{U(ge=>({...ge,roleIds:ge.roleIds?.includes(ee)?ge.roleIds.filter(Re=>Re!==ee):[...ge.roleIds||[],ee]}))},we=h.filter(ee=>ee.isActive),Ne=h.filter(ee=>!ee.isActive),fe=Math.floor(we.length*.3),de=(ee,ge)=>ee?ge?"text-[var(--text-tertiary)] hover:text-[var(--warning-text)] hover:bg-[var(--warning-bg)]":"text-[var(--text-tertiary)] hover:text-[var(--success-text)] hover:bg-[var(--success-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]",se=(ee,ge,Re)=>ee?Re(ge?"users.deactivate":"users.activate"):Re("common.noPermission","Permission insuffisante"),ie=ee=>ee?"text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]",be=(ee,ge)=>ee?ge("common.edit"):ge("common.noPermission","Permission insuffisante"),_=ee=>ee?"text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]",ae=(ee,ge)=>ee?ge("common.delete"):ge("common.noPermission","Permission insuffisante"),ve=ee=>{const ge={Direct:"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300",Group:"bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300",Both:"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300"},Re={Direct:s("users.membershipDirect","Direct"),Group:s("users.membershipGroup","Via groupe"),Both:s("users.membershipBoth","Mixte")};return{color:ge[ee]||"",label:Re[ee]||""}},pe=()=>e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[var(--bg-secondary)]",children:[e.jsx("th",{className:"w-12 px-4 py-3",children:e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)]"})}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider",children:s("users.columns.name")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden md:table-cell",children:s("users.columns.email")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden lg:table-cell",children:s("users.columns.role")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider",children:s("users.columns.status")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden xl:table-cell",children:s("users.columns.source","Source")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden xl:table-cell",children:s("users.columns.group","Groupe")}),i.map(ee=>e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden xl:table-cell",style:ee.width?{width:ee.width}:void 0,children:ee.label},ee.key)),e.jsx("th",{className:"w-32 px-4 py-3"})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border-color)]",children:j?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"px-6 py-16 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-primary-500"}),e.jsx("span",{className:"text-sm text-[var(--text-secondary)]",children:"Chargement..."})]})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"px-6 py-16 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-[var(--bg-secondary)] flex items-center justify-center",children:e.jsx(a.Search,{className:"w-8 h-8 text-[var(--text-tertiary)]"})}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s("users.noUsers")})]})})}):h.map(ee=>e.jsxs("tr",{className:"group hover:bg-[var(--bg-hover)] transition-all cursor-pointer",onClick:()=>t(`/platform/administration/users/${ee.id}`),children:[e.jsx("td",{className:"px-4 py-3",onClick:ge=>ge.stopPropagation(),children:e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)]"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-4 h-4 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-2.5 h-2.5 text-white"})})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-medium text-[var(--text-primary)] group-hover:text-primary-600 transition-colors truncate",children:ee.fullName}),ee.entraObjectId&&e.jsxs("span",{className:"hidden sm:inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400",children:[e.jsx(a.Cloud,{className:"w-2.5 h-2.5"}),"AAD"]})]}),e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)] truncate md:hidden flex items-center gap-1",children:[e.jsx(a.Mail,{className:"w-3 h-3"}),ee.email]})]})]})}),e.jsx("td",{className:"px-4 py-3 hidden md:table-cell",children:e.jsxs("div",{className:"flex items-center gap-2 text-[var(--text-secondary)]",children:[e.jsx(a.Mail,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("span",{className:"truncate",children:ee.email})]})}),e.jsx("td",{className:"px-4 py-3 hidden lg:table-cell",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ee.roles.length>0?ee.roles.map((ge,Re)=>e.jsx(St,{role:ge,variant:ge.toLowerCase().includes("admin")?"accent":"default",icon:e.jsx(a.Shield,{className:"w-3 h-3"})},`${ge}-${Re}`)):e.jsx("span",{className:"text-sm text-[var(--text-tertiary)] italic",children:"Aucun rôle"})})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(cs,{status:ee.isActive?"active":"inactive",label:ee.isActive?s("users.status.active"):s("users.status.inactive")})}),e.jsx("td",{className:"px-4 py-3 hidden xl:table-cell",children:(()=>{const{color:ge,label:Re}=ve(ee.membershipSource);return e.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium ${ge}`,children:Re})})()}),e.jsx("td",{className:"px-4 py-3 hidden xl:table-cell",children:ee.primaryGroupId?e.jsxs("button",{onClick:ge=>{ge.stopPropagation(),t(`/platform/administration/groups/${ee.primaryGroupId}`)},className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-xs font-medium bg-[var(--bg-secondary)] hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-primary-600 transition-colors",children:[e.jsx(a.Users,{className:"w-3 h-3"}),ee.primaryGroupName]}):e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})}),i.map(ge=>e.jsx("td",{className:"px-4 py-3 hidden xl:table-cell text-[var(--text-secondary)]",children:ge.render(ee,{tableId:"users",rowIndex:h.indexOf(ee)})},ge.key)),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:ge=>ge.stopPropagation(),children:[e.jsx("button",{onClick:()=>t(`/platform/administration/users/${ee.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("users.view"),children:e.jsx(a.Eye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>{ge.stopPropagation(),he(ee)},disabled:!d,className:`p-2 rounded-lg transition-all ${d?"text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]"}`,title:d?s("common.edit"):s("common.noPermission","Permission insuffisante"),children:e.jsx(a.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>H(ee,ge),disabled:!d,className:`p-2 rounded-lg transition-all ${de(d,ee.isActive)}`,title:se(d,ee.isActive,s),children:ee.isActive?e.jsx(a.UserX,{className:"w-4 h-4"}):e.jsx(a.UserCheck,{className:"w-4 h-4"})}),ee.userType!=="System"&&ee.userType!=="LocalAdmin"&&e.jsx("button",{onClick:ge=>je(ee,ge),disabled:!m,className:`p-2 rounded-lg transition-all ${m?"text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]"}`,title:m?s("common.delete"):s("common.noPermission","Permission insuffisante"),children:e.jsx(a.Trash2,{className:"w-4 h-4"})}),e.jsx(ls,{name:"users.table.row.actions",context:{user:ee,reload:J}})]})})]},ee.id))})]})}),Se=()=>e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:j?e.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-16",children:[e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-primary-500"}),e.jsx("span",{className:"mt-3 text-sm text-[var(--text-secondary)]",children:"Chargement..."})]}):h.length===0?e.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg bg-[var(--bg-secondary)] flex items-center justify-center mb-3",children:e.jsx(a.Search,{className:"w-8 h-8 text-[var(--text-tertiary)]"})}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s("users.noUsers")})]}):h.map(ee=>e.jsxs("div",{onClick:()=>t(`/platform/administration/users/${ee.id}`),className:"bg-[var(--bg-card)] border-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)] rounded-[var(--radius-card)] overflow-hidden transition-all hover:shadow-lg hover:border-[var(--color-accent-400)] cursor-pointer flex flex-col",children:[e.jsx("div",{className:"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 p-4 border-b border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName,size:"lg",className:"rounded-lg"}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-5 h-5 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--text-primary)] truncate",children:ee.fullName}),e.jsxs("p",{className:"text-xs text-[var(--text-tertiary)] truncate flex items-center gap-1",children:[e.jsx(a.Mail,{className:"w-3 h-3"}),ee.email]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 text-xs rounded-full font-medium ${ee.isActive?"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:ee.isActive?s("users.status.active"):s("users.status.inactive")}),ee.entraObjectId&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400",children:[e.jsx(a.Cloud,{className:"w-2.5 h-2.5"}),"AAD"]})]})]})}),e.jsxs("div",{className:"p-4 flex flex-col flex-1",children:[e.jsxs("div",{className:"flex flex-wrap gap-1 mb-3",children:[ee.roles.length>0?ee.roles.slice(0,2).map(ge=>e.jsx(St,{role:ge,variant:ge.toLowerCase().includes("admin")?"accent":"default",icon:e.jsx(a.Shield,{className:"w-3 h-3"})},ge)):e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"Aucun rôle"}),ee.roles.length>2&&e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-md bg-[var(--bg-secondary)] text-[var(--text-muted)]",children:["+",ee.roles.length-2]})]}),e.jsx(ls,{name:"users.card.content",context:{user:ee}}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center justify-end gap-1 pt-3 border-t border-[var(--border-color)]",onClick:ge=>ge.stopPropagation(),children:[e.jsx("button",{onClick:()=>t(`/platform/administration/users/${ee.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("users.view"),children:e.jsx(a.Eye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>{ge.stopPropagation(),he(ee)},disabled:!d,className:`p-2 rounded-lg transition-all ${ie(d)}`,title:be(d,s),children:e.jsx(a.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>H(ee,ge),disabled:!d,className:`p-2 rounded-lg transition-all ${de(d,ee.isActive)}`,title:se(d,ee.isActive,s),children:ee.isActive?e.jsx(a.UserX,{className:"w-4 h-4"}):e.jsx(a.UserCheck,{className:"w-4 h-4"})}),ee.userType!=="System"&&ee.userType!=="LocalAdmin"&&e.jsx("button",{onClick:ge=>je(ee,ge),disabled:!m,className:`p-2 rounded-lg transition-all ${_(m)}`,title:ae(m,s),children:e.jsx(a.Trash2,{className:"w-4 h-4"})})]})]})]},ee.id))}),ke=()=>e.jsx("div",{className:"flex gap-6 overflow-x-auto pb-4",children:j?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center py-16",children:[e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-primary-500"}),e.jsx("span",{className:"mt-3 text-sm text-[var(--text-secondary)]",children:"Chargement..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ya,{title:"Actifs",count:we.length,color:"success",children:we.map(ee=>e.jsxs(Za,{onClick:()=>t(`/platform/administration/users/${ee.id}`),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName,size:"sm"}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-3.5 h-3.5 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-2 h-2 text-white"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:ee.fullName}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] truncate",children:ee.email})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[ee.roles.length>0?e.jsx(St,{role:ee.roles[0],variant:ee.roles[0].toLowerCase().includes("admin")?"accent":"default"}):e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"-"}),e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"En ligne"})]})]},ee.id))}),e.jsxs(Ya,{title:"Inactifs",count:Ne.length,color:"error",children:[Ne.map(ee=>e.jsxs(Za,{onClick:()=>t(`/platform/administration/users/${ee.id}`),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName,size:"sm"}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-3.5 h-3.5 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-2 h-2 text-white"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:ee.fullName}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] truncate",children:ee.email})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[ee.roles.length>0?e.jsx(St,{role:ee.roles[0]}):e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"-"}),e.jsx("button",{onClick:ge=>H(ee,ge),disabled:!d,className:`text-xs px-2 py-1 rounded transition-opacity ${d?"bg-[var(--success-bg)] text-[var(--success-text)] hover:opacity-80":"opacity-50 cursor-not-allowed bg-[var(--bg-secondary)] text-[var(--text-tertiary)]"}`,title:d?void 0:s("common.noPermission","Permission insuffisante"),children:"Réactiver"})]})]},ee.id)),Ne.length===0&&e.jsxs("div",{className:"border border-dashed border-[var(--border-color)] rounded-lg p-6 text-center",children:[e.jsx(a.UserCheck,{className:"w-6 h-6 mx-auto mb-2 text-[var(--text-muted)]"}),e.jsx("p",{className:"text-xs text-[var(--text-muted)]",children:"Aucun utilisateur inactif"})]})]})]})});return e.jsxs("div",{className:"space-y-6",children:[e.jsx(De,{items:[{label:s("header.title"),href:"/platform/administration"},{label:s("users.title")}]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s("users.title")}),e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)] mt-1",children:[L," utilisateurs • ",fe," en ligne"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ls,{name:"users.header.actions",context:{users:h,totalCount:L,reload:J}}),e.jsxs("button",{onClick:ce,disabled:!u,className:`btn btn-primary ${u?"":"opacity-50 cursor-not-allowed"}`,title:u?void 0:s("common.noPermission","Permission insuffisante"),children:[e.jsx(a.Plus,{className:"w-4 h-4"}),s("users.create")]})]})]}),e.jsx(jd,{}),e.jsx("div",{className:"card p-4",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[!f.search&&e.jsx(a.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-muted)] pointer-events-none"}),e.jsx("input",{type:"text",value:f.search,onChange:ee=>te("search",ee.target.value),placeholder:s("users.filters.searchPlaceholder"),className:"input w-full",style:f.search?void 0:{paddingLeft:"2.5rem"}}),f.search&&e.jsx("button",{onClick:()=>te("search",""),className:"absolute right-3 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-[var(--bg-secondary)]",children:e.jsx(a.X,{className:"w-3 h-3 text-[var(--text-tertiary)]"})})]}),e.jsxs("button",{onClick:()=>C(!k),className:`btn ${k?"btn-primary":"btn-secondary"} relative`,children:[e.jsx(a.Filter,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:s("users.filters.title")}),B>0&&e.jsx("span",{className:"absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-[var(--color-accent-500)] text-white text-xs flex items-center justify-center",children:B})]}),B>0&&e.jsx("button",{onClick:re,className:"btn btn-ghost text-[var(--text-tertiary)] hover:text-[var(--text-primary)]",title:s("users.filters.reset"),children:e.jsx(a.RotateCcw,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"hidden md:block",children:e.jsx(Es,{viewMode:F,onChange:V,tableLabel:"Table",cardsLabel:"Cards",kanbanLabel:"Kanban"})})]}),k&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-4 pt-4 border-t border-[var(--border-color)]",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.status")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.status,onChange:ee=>te("status",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"all",children:s("users.filters.allStatuses")}),e.jsx("option",{value:"active",children:s("users.filters.activeOnly")}),e.jsx("option",{value:"inactive",children:s("users.filters.inactiveOnly")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.role")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.roleId,onChange:ee=>te("roleId",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"",children:s("users.filters.allRoles")}),b.map(ee=>e.jsx("option",{value:ee.id,children:ee.name},ee.id))]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.source")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.source,onChange:ee=>te("source",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"all",children:s("users.filters.allSources")}),e.jsx("option",{value:"entra",children:s("users.filters.entraOnly")}),e.jsx("option",{value:"local",children:s("users.filters.localOnly")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.userType")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.userType,onChange:ee=>te("userType",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"",children:s("users.filters.allTypes")}),e.jsx("option",{value:"User",children:s("users.filters.typeUser")}),e.jsx("option",{value:"System",children:s("users.filters.typeSystem")}),e.jsx("option",{value:"LocalAdmin",children:s("users.filters.typeLocalAdmin")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.sortBy")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsxs("select",{value:f.sortBy,onChange:ee=>te("sortBy",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"lastname",children:s("users.filters.sortName")}),e.jsx("option",{value:"email",children:s("users.filters.sortEmail")}),e.jsx("option",{value:"lastlogin",children:s("users.filters.sortLastLogin")}),e.jsx("option",{value:"createdat",children:s("users.filters.sortCreatedAt")}),e.jsx("option",{value:"status",children:s("users.filters.sortStatus")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]}),e.jsx("button",{onClick:()=>te("sortDesc",!f.sortDesc),className:`btn ${f.sortDesc?"btn-primary":"btn-secondary"} px-2.5`,title:f.sortDesc?s("users.filters.sortDesc"):s("users.filters.sortAsc"),children:e.jsx(a.ArrowUpDown,{className:"w-4 h-4"})})]})]})]}),B>0&&!k&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--text-tertiary)]",children:[e.jsx(a.Filter,{className:"w-4 h-4"}),e.jsx("span",{children:s("users.filters.activeFilters",{count:B})}),e.jsx("button",{onClick:()=>C(!0),className:"text-[var(--color-accent-600)] hover:underline",children:s("users.filters.title")})]})]})}),e.jsx("div",{className:"md:hidden",children:Se()}),e.jsxs("div",{className:"hidden md:block",children:[F==="table"&&pe(),F==="cards"&&Se(),F==="kanban"&&ke()]}),F!=="kanban"&&e.jsx(ks,{page:y,totalPages:D,totalCount:L,pageSize:20,onPageChange:A,itemLabel:"utilisateurs"}),T&&e.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",children:e.jsxs("div",{className:"card w-full max-w-lg p-6 m-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-xl font-bold text-[var(--text-primary)]",children:s(M?"users.edit":"users.create")}),e.jsx("button",{onClick:()=>I(!1),className:"btn btn-ghost p-2",children:e.jsx(a.X,{className:"w-5 h-5"})})]}),E&&e.jsx("div",{className:"mb-4 p-3 rounded-lg bg-[var(--error-bg)] text-[var(--error-text)] text-sm border border-[var(--error-border)]",children:E}),e.jsxs("form",{onSubmit:z,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.form.firstName")}),e.jsx("input",{type:"text",required:!0,value:O.firstName,onChange:ee=>U(ge=>({...ge,firstName:ee.target.value})),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.form.lastName")}),e.jsx("input",{type:"text",required:!0,value:O.lastName,onChange:ee=>U(ge=>({...ge,lastName:ee.target.value})),className:"input w-full"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.columns.email")}),e.jsx("input",{type:"email",required:!0,value:O.email,onChange:ee=>U(ge=>({...ge,email:ee.target.value})),className:"input w-full"})]}),!M&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.form.password")}),e.jsx("input",{type:"password",required:!M,value:O.password,onChange:ee=>U(ge=>({...ge,password:ee.target.value})),autoComplete:"new-password",className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-2",children:s("users.form.roles")}),e.jsx("div",{className:"space-y-2 max-h-48 overflow-y-auto p-3 border border-[var(--border-color)] rounded-lg bg-[var(--bg-secondary)]",children:b.map(ee=>e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-2 rounded-lg hover:bg-[var(--bg-hover)] transition-colors",children:[e.jsx("input",{type:"checkbox",checked:O.roleIds?.includes(ee.id)||!1,onChange:()=>xe(ee.id),className:"w-4 h-4 rounded border-[var(--border-color)] text-primary-600 focus:ring-primary-500"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[var(--text-primary)] font-medium",children:ee.name}),ee.description&&e.jsx("p",{className:"text-xs text-[var(--text-tertiary)]",children:ee.description})]})]},ee.id))})]}),e.jsx(ls,{name:"users.form.fields.after",context:{formData:O,onChange:(ee,ge)=>{if(ee.startsWith("ext.")){const Re=ee.substring(4);U(Fe=>({...Fe,ext:{...Fe.ext||{},[Re]:ge}}))}else U(Re=>({...Re,[ee]:ge}))},disabled:K,isEditing:!!M,user:M}}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx("button",{type:"button",onClick:()=>I(!1),className:"btn btn-secondary",children:s("common.cancel")}),e.jsxs("button",{type:"submit",disabled:K,className:"btn btn-primary disabled:opacity-50",children:[K&&e.jsx(a.Loader2,{className:"w-4 h-4 animate-spin"}),s(M?"common.save":"common.create")]})]})]})]})})]})}function vr({value:s,onChange:t,adminTenants:r,userTenantMemberships:n=[],disabled:i=!1,showNotMemberWarning:o=!1}){const{t:c}=ne.useTranslation("admin"),[x,u]=l.useState(!1),[d,m]=l.useState(""),[p,h]=l.useState("all"),v=l.useRef(null),b=l.useRef(null);l.useEffect(()=>{function D(R){v.current&&!v.current.contains(R.target)&&u(!1)}return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]),l.useEffect(()=>{function D(R){R.key==="Escape"&&u(!1)}return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[]),l.useEffect(()=>{x&&b.current&&setTimeout(()=>b.current?.focus(),50)},[x]);const g=l.useMemo(()=>{const D=new Map;return n.forEach(R=>D.set(R.tenantId,R)),D},[n]),{b2bTenants:j,b2cTenants:w,filteredTenants:f}=l.useMemo(()=>{const D=r.filter(S=>S.tenantType==="Business"),R=r.filter(S=>S.tenantType==="Personal");let L=r;if(p==="b2b"?L=D:p==="b2c"&&(L=R),d.trim()){const S=d.toLowerCase().trim();L=L.filter(T=>T.tenantName.toLowerCase().includes(S))}return{b2bTenants:D,b2cTenants:R,filteredTenants:L}},[r,p,d]),N=s==="global",k=N?null:s,C=()=>{t("global"),u(!1),m("")},y=D=>{const R=g.get(D.tenantId);t({tenantId:D.tenantId,tenantSlug:D.tenantSlug,tenantUserId:R?.tenantUserId||"",tenantName:D.tenantName}),u(!1),m("")};if(r.length===0)return null;const A=D=>{const R=!N&&k?.tenantId===D.tenantId,L=D.tenantType==="Business",S=g.has(D.tenantId);return e.jsxs("button",{type:"button",onClick:()=>y(D),className:`w-full flex items-center gap-3 px-3 py-2.5 text-left transition-colors ${R?"bg-blue-500/10 text-blue-700":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,role:"option","aria-selected":R,children:[e.jsx("div",{className:`flex-shrink-0 w-8 h-8 flex items-center justify-center ${L?"bg-blue-500/10":"bg-violet-500/10"}`,style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Building2,{className:`w-4 h-4 ${L?"text-blue-500":"text-violet-500"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:D.tenantName}),S&&e.jsxs("span",{className:"flex-shrink-0 text-xs px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-600",children:[e.jsx(a.User,{className:"w-3 h-3 inline mr-0.5"}),c("userRoles.scope.selector.member","Membre")]})]}),e.jsx("span",{className:"text-xs text-[var(--text-tertiary)]",children:L?c("userRoles.scope.selector.b2b","Business"):c("userRoles.scope.selector.b2c","Personnel")})]}),R&&e.jsx(a.Check,{className:"w-4 h-4 text-blue-600 flex-shrink-0"})]},D.tenantId)};return e.jsxs("div",{ref:v,className:"relative inline-block",children:[e.jsxs("button",{type:"button",onClick:()=>!i&&u(!x),disabled:i,className:`flex items-center gap-2 px-3 py-2 text-sm font-medium border transition-colors ${N?"bg-emerald-500/10 border-emerald-500/30 text-emerald-700 hover:bg-emerald-500/20":"bg-blue-500/10 border-blue-500/30 text-blue-700 hover:bg-blue-500/20"} ${i?"opacity-50 cursor-not-allowed":""}`,style:{borderRadius:"var(--radius-button)"},"aria-expanded":x,"aria-haspopup":"listbox",children:[N?e.jsxs(e.Fragment,{children:[e.jsx(a.Globe,{className:"w-4 h-4"}),e.jsx("span",{children:c("userRoles.scope.selector.global","Global (plateforme)")})]}):e.jsxs(e.Fragment,{children:[e.jsx(a.Building2,{className:"w-4 h-4"}),e.jsx("span",{className:"max-w-[150px] truncate",children:k?.tenantName})]}),e.jsx(a.ChevronDown,{className:`w-4 h-4 transition-transform ${x?"rotate-180":""}`})]}),e.jsx("div",{className:`absolute left-0 mt-1 w-80 z-50 transition-all duration-150 ease-out ${x?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-1 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"px-3 py-2 border-b border-[var(--border-color)] bg-[var(--bg-secondary)]",children:e.jsxs("div",{className:"relative",children:[e.jsx(a.Search,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-muted)]"}),e.jsx("input",{ref:b,type:"text",value:d,onChange:D=>m(D.target.value),placeholder:c("userRoles.scope.selector.search","Rechercher un tenant..."),className:"w-full pl-8 pr-3 py-1.5 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-md text-[var(--text-primary)] placeholder-[var(--text-muted)] focus:outline-none focus:ring-1 focus:ring-[var(--color-accent-500)]"})]})}),e.jsxs("div",{className:"flex items-center gap-1 px-3 py-2 border-b border-[var(--border-color)] bg-[var(--bg-tertiary)]",role:"tablist",children:[e.jsxs("button",{type:"button",onClick:()=>h("all"),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${p==="all"?"bg-[var(--color-accent-600)] text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,role:"tab","aria-selected":p==="all",children:[c("userRoles.scope.selector.filterAll","Tous")," (",r.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>h("b2b"),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${p==="b2b"?"bg-blue-600 text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,role:"tab","aria-selected":p==="b2b",children:[c("userRoles.scope.selector.filterB2B","B2B")," (",j.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>h("b2c"),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${p==="b2c"?"bg-violet-600 text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,role:"tab","aria-selected":p==="b2c",children:[c("userRoles.scope.selector.filterB2C","B2C")," (",w.length,")"]})]}),e.jsxs("div",{className:"py-1 max-h-72 overflow-y-auto",role:"listbox",children:[e.jsxs("button",{type:"button",onClick:C,className:`w-full flex items-center gap-3 px-3 py-2.5 text-left transition-colors ${N?"bg-emerald-500/10 text-emerald-700":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,role:"option","aria-selected":N,children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 flex items-center justify-center bg-emerald-500/10",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Globe,{className:"w-4 h-4 text-emerald-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium block",children:c("userRoles.scope.selector.global","Global (plateforme)")}),e.jsx("span",{className:"text-xs text-[var(--text-tertiary)]",children:c("userRoles.scope.selector.globalDesc","Rôles applicables sur toute la plateforme")})]}),N&&e.jsx(a.Check,{className:"w-4 h-4 text-emerald-600 flex-shrink-0"})]}),f.length>0&&e.jsx("div",{className:"border-t border-[var(--border-color)] my-1"}),f.length>0?f.map(A):e.jsx("div",{className:"px-3 py-4 text-center text-sm text-[var(--text-muted)]",children:c("userRoles.scope.selector.noResults","Aucun tenant trouvé")})]})]})}),o&&!N&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-sm text-amber-600",children:[e.jsx(a.AlertTriangle,{className:"w-4 h-4"}),e.jsx("span",{children:c("userRoles.scope.notMember","L'utilisateur n'est pas membre de ce tenant")})]})]})}function gr({columns:s,items:t,getItemId:r,getItemColumn:n,onMoveItem:i,renderCard:o,loading:c=!1,onAddItem:x,onCardClick:u,cardActions:d,emptyColumnMessage:m="Aucun élément",className:p="",columnMinWidth:h="280px",disabled:v=!1}){const[b,g]=l.useState(null),[j,w]=l.useState(null),[f,N]=l.useState(null),k=l.useCallback(T=>{T.onClick(),N(null)},[]),C=l.useCallback((T,I)=>e.jsxs("button",{onClick:M=>{M.stopPropagation(),k(T)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-left hover:bg-[var(--bg-tertiary)]",children:[T.icon,T.label]},I),[k]),y=l.useCallback(T=>t.filter(I=>n(I)===T),[t,n]),A=(T,I)=>{v||(g(I),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",I))},D=(T,I)=>{v||!b||(T.preventDefault(),T.dataTransfer.dropEffect="move",w(I))},R=()=>{w(null)},L=(T,I)=>{if(v)return;T.preventDefault();const M=T.dataTransfer.getData("text/plain");M&&i(M,I),g(null),w(null)},S=()=>{g(null),w(null)};return c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-500)]"})}):e.jsx("div",{className:`flex gap-4 overflow-x-auto pb-4 ${p}`,children:s.map(T=>{const I=y(T.id),M=j===T.id,X=T.maxItems!==void 0&&I.length>=T.maxItems;return e.jsxs("div",{className:`flex-shrink-0 flex flex-col rounded-lg bg-[var(--bg-secondary)] border border-[var(--border-color)] ${M?"ring-2 ring-[var(--color-primary-500)]":""}`,style:{minWidth:h,maxWidth:h},onDragOver:O=>D(O,T.id),onDragLeave:R,onDrop:O=>L(O,T.id),children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-[var(--border-color)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[T.color&&e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:T.color}}),e.jsx("h3",{className:"font-semibold text-sm text-[var(--text-primary)]",children:T.title}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] px-1.5 py-0.5 rounded-full bg-[var(--bg-tertiary)]",children:[I.length,T.maxItems!==void 0&&` / ${T.maxItems}`]})]}),x&&T.canAddItem!==!1&&!X&&e.jsx("button",{onClick:()=>x(T.id),className:"btn btn-ghost p-1 hover:bg-[var(--bg-tertiary)]",title:"Ajouter","aria-label":`Ajouter à ${T.title}`,children:e.jsx(a.Plus,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex-1 p-2 space-y-2 overflow-y-auto max-h-[calc(100vh-300px)]",children:[I.length===0?e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)] text-sm",children:m}):I.map((O,U)=>{const K=r(O),$=b===K,E=d?.(O);return e.jsxs("div",{draggable:!v,onDragStart:q=>A(q,K),onDragEnd:S,onClick:()=>u?.(O),className:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("react"),ar=require("axios"),ne=require("react-i18next"),Ks=require("i18next"),lo=require("i18next-browser-languagedetector"),Q=require("react-router-dom"),io=require("@microsoft/signalr"),a=require("lucide-react"),Rl=require("react-error-boundary"),Cr=require("modern-screenshot"),Zs=require("react-dom"),nt=require("react-resizable-panels"),oo=require("libphonenumber-js"),Ie=require("recharts"),Ss=require("@dnd-kit/core"),mt=require("@dnd-kit/sortable"),co=require("@dnd-kit/utilities"),Sr=require("@tiptap/react"),mo=require("@tiptap/starter-kit"),xo=require("@tiptap/extension-link"),uo=require("@tiptap/extension-image"),po=require("@tiptap/extension-placeholder"),ho=require("@tiptap/extension-text-align"),bo=require("@tiptap/extension-underline"),vo=require("@tiptap/extension-text-style"),go=require("@tiptap/extension-color"),fo=require("@tiptap/extension-highlight"),jo=require("@monaco-editor/react");function Il(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const n=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:()=>s[r]})}}return t.default=s,Object.freeze(t)}const Me=Il(io),es=Il(a),fs={none:"0px",small:"4px",medium:"8px",large:"12px",xlarge:"16px",xxlarge:"24px"},yo={none:"Carré",small:"Léger",medium:"Moyen",large:"Arrondi",xlarge:"Très arrondi",xxlarge:"Pill"},os={slate:{name:"Ardoise",shades:{50:"#f8fafc",100:"#f1f5f9",200:"#e2e8f0",300:"#cbd5e1",400:"#94a3b8",500:"#64748b",600:"#475569",700:"#334155",800:"#1e293b",900:"#0f172a",950:"#020617"}},gray:{name:"Gris",shades:{50:"#f9fafb",100:"#f3f4f6",200:"#e5e7eb",300:"#d1d5db",400:"#9ca3af",500:"#6b7280",600:"#4b5563",700:"#374151",800:"#1f2937",900:"#111827",950:"#030712"}},zinc:{name:"Zinc",shades:{50:"#fafafa",100:"#f4f4f5",200:"#e4e4e7",300:"#d4d4d8",400:"#a1a1aa",500:"#71717a",600:"#52525b",700:"#3f3f46",800:"#27272a",900:"#18181b",950:"#09090b"}},stone:{name:"Pierre",shades:{50:"#fafaf9",100:"#f5f5f4",200:"#e7e5e4",300:"#d6d3d1",400:"#a8a29e",500:"#78716c",600:"#57534e",700:"#44403c",800:"#292524",900:"#1c1917",950:"#0c0a09"}},indigo:{name:"Indigo",shades:{50:"#eef2ff",100:"#e0e7ff",200:"#c7d2fe",300:"#a5b4fc",400:"#818cf8",500:"#6366f1",600:"#4f46e5",700:"#4338ca",800:"#3730a3",900:"#312e81",950:"#1e1b4b"}},violet:{name:"Violet",shades:{50:"#f5f3ff",100:"#ede9fe",200:"#ddd6fe",300:"#c4b5fd",400:"#a78bfa",500:"#8b5cf6",600:"#7c3aed",700:"#6d28d9",800:"#5b21b6",900:"#4c1d95",950:"#2e1065"}},blue:{name:"Bleu",shades:{50:"#eff6ff",100:"#dbeafe",200:"#bfdbfe",300:"#93c5fd",400:"#60a5fa",500:"#3b82f6",600:"#2563eb",700:"#1d4ed8",800:"#1e40af",900:"#1e3a8a",950:"#172554"}},cyan:{name:"Cyan",shades:{50:"#ecfeff",100:"#cffafe",200:"#a5f3fc",300:"#67e8f9",400:"#22d3ee",500:"#06b6d4",600:"#0891b2",700:"#0e7490",800:"#155e75",900:"#164e63",950:"#083344"}},teal:{name:"Teal",shades:{50:"#f0fdfa",100:"#ccfbf1",200:"#99f6e4",300:"#5eead4",400:"#2dd4bf",500:"#14b8a6",600:"#0d9488",700:"#0f766e",800:"#115e59",900:"#134e4a",950:"#042f2e"}},emerald:{name:"Émeraude",shades:{50:"#ecfdf5",100:"#d1fae5",200:"#a7f3d0",300:"#6ee7b7",400:"#34d399",500:"#10b981",600:"#059669",700:"#047857",800:"#065f46",900:"#064e3b",950:"#022c22"}},amber:{name:"Ambre",shades:{50:"#fffbeb",100:"#fef3c7",200:"#fde68a",300:"#fcd34d",400:"#fbbf24",500:"#f59e0b",600:"#d97706",700:"#b45309",800:"#92400e",900:"#78350f",950:"#451a03"}},orange:{name:"Orange",shades:{50:"#fff7ed",100:"#ffedd5",200:"#fed7aa",300:"#fdba74",400:"#fb923c",500:"#f97316",600:"#ea580c",700:"#c2410c",800:"#9a3412",900:"#7c2d12",950:"#431407"}},rose:{name:"Rose",shades:{50:"#fff1f2",100:"#ffe4e6",200:"#fecdd3",300:"#fda4af",400:"#fb7185",500:"#f43f5e",600:"#e11d48",700:"#be123c",800:"#9f1239",900:"#881337",950:"#4c0519"}},pink:{name:"Pink",shades:{50:"#fdf2f8",100:"#fce7f3",200:"#fbcfe8",300:"#f9a8d4",400:"#f472b6",500:"#ec4899",600:"#db2777",700:"#be185d",800:"#9d174d",900:"#831843",950:"#500724"}}},No={card:"large",button:"medium",badge:"medium",input:"medium",modal:"xlarge",menuItem:"medium"},_s={neutral:{name:"Neutre",icon:"⚪",colors:{light:{light:"#ffffff",medium:"#f4f4f5",dark:"#e4e4e7",border:"#d4d4d8"},dark:{light:"#1c1c1f",medium:"#27272a",dark:"#3f3f46",border:"#52525b"}}},ocean:{name:"Océan",icon:"🌊",colors:{light:{light:"#e0f2fe",medium:"#bae6fd",dark:"#7dd3fc",border:"#93c5fd"},dark:{light:"#141c24",medium:"#1a2836",dark:"#2a4a5e",border:"#3a5a70"}}},forest:{name:"Forêt",icon:"🌲",colors:{light:{light:"#d1fae5",medium:"#a7f3d0",dark:"#6ee7b7",border:"#86efac"},dark:{light:"#121d18",medium:"#182a22",dark:"#2a4a3a",border:"#3a5a4a"}}},sunset:{name:"Coucher de soleil",icon:"🌅",colors:{light:{light:"#fef3c7",medium:"#fde68a",dark:"#fbbf24",border:"#fcd34d"},dark:{light:"#1c1810",medium:"#2a2418",dark:"#4a3a24",border:"#5a4a34"}}},lavender:{name:"Lavande",icon:"💜",colors:{light:{light:"#ede9fe",medium:"#ddd6fe",dark:"#c4b5fd",border:"#c4b5fd"},dark:{light:"#1a1820",medium:"#24222e",dark:"#3a3650",border:"#4a4660"}}},rose:{name:"Rose",icon:"🌸",colors:{light:{light:"#fce7f3",medium:"#fbcfe8",dark:"#f9a8d4",border:"#f9a8d4"},dark:{light:"#1c1418",medium:"#2a1e24",dark:"#4a3040",border:"#5a4050"}}}},rr="neutral",Ws=s=>{const t=os[s]?.shades||os.indigo.shades;return{name:"Clair",primary:os.indigo.shades,accent:t,backgrounds:{app:"#fafafa",primary:"#ffffff",secondary:"#f4f4f5",tertiary:"#e4e4e7",card:"#ffffff",hover:"#f4f4f5",active:"#e4e4e7"},text:{primary:"#18181b",secondary:"#52525b",tertiary:"#71717a",muted:"#a1a1aa",inverse:"#fafafa"},border:{default:"#e4e4e7",subtle:"#f4f4f5",strong:"#d4d4d8"},status:{success:{bg:"#f0fdfa",text:"#0f766e",border:"#99f6e4",dot:"#14b8a6"},warning:{bg:"#fffbeb",text:"#b45309",border:"#fde68a",dot:"#f59e0b"},error:{bg:"#fff1f2",text:"#be123c",border:"#fecdd3",dot:"#f43f5e"},info:{bg:"#f0f9ff",text:"#0369a1",border:"#bae6fd",dot:"#0ea5e9"}},accentTransparent:{bg:`${t[50]}`,text:t[700],border:t[200]}}},Xs=s=>{const t=os[s]?.shades||os.indigo.shades;return{name:"Sombre",primary:os.indigo.shades,accent:t,backgrounds:{app:"#161618",primary:"#1c1c1f",secondary:"#232326",tertiary:"#2a2a2e",card:"#1c1c1f",hover:"#27272a",active:"#3f3f46"},text:{primary:"#fafafa",secondary:"#d4d4d8",tertiary:"#a1a1aa",muted:"#71717a",inverse:"#18181b"},border:{default:"#3f3f46",subtle:"#27272a",strong:"#52525b"},status:{success:{bg:"rgba(20, 184, 166, 0.15)",text:"#5eead4",border:"rgba(20, 184, 166, 0.3)",dot:"#14b8a6"},warning:{bg:"rgba(245, 158, 11, 0.15)",text:"#fbbf24",border:"rgba(245, 158, 11, 0.3)",dot:"#f59e0b"},error:{bg:"rgba(244, 63, 94, 0.15)",text:"#fb7185",border:"rgba(244, 63, 94, 0.3)",dot:"#f43f5e"},info:{bg:"rgba(14, 165, 233, 0.15)",text:"#7dd3fc",border:"rgba(14, 165, 233, 0.3)",dot:"#0ea5e9"}},accentTransparent:{bg:`rgba(${Tr(t[500])}, 0.15)`,text:t[300],border:`rgba(${Tr(t[500])}, 0.3)`}}};function Tr(s){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return t?`${parseInt(t[1],16)}, ${parseInt(t[2],16)}, ${parseInt(t[3],16)}`:"99, 102, 241"}const xt={mode:"dark",borderRadius:No,colors:{light:Ws("indigo"),dark:Xs("indigo")},accentColorKey:"indigo",itemPaletteKey:rr},wo=[{id:"default",name:"Par défaut",description:"Style SmartStack classique avec coins arrondis",icon:"✨",config:{borderRadius:{card:"large",button:"medium",badge:"medium",input:"medium",modal:"xlarge",menuItem:"medium"},accentColorKey:"indigo",itemPaletteKey:"neutral"}},{id:"minimal",name:"Minimal",description:"Style épuré et professionnel",icon:"⚪",config:{borderRadius:{card:"medium",button:"small",badge:"small",input:"small",modal:"medium",menuItem:"small"},accentColorKey:"slate",itemPaletteKey:"neutral"}},{id:"corporate",name:"Corporate",description:"Style sobre pour environnement professionnel",icon:"🏢",config:{borderRadius:{card:"small",button:"small",badge:"medium",input:"small",modal:"medium",menuItem:"small"},accentColorKey:"gray",itemPaletteKey:"neutral"}},{id:"ocean",name:"Océan",description:"Teintes bleues apaisantes",icon:"🌊",config:{borderRadius:{card:"large",button:"medium",badge:"medium",input:"medium",modal:"xlarge",menuItem:"medium"},accentColorKey:"cyan",itemPaletteKey:"ocean"}},{id:"forest",name:"Forêt",description:"Tons verts naturels",icon:"🌲",config:{borderRadius:{card:"medium",button:"medium",badge:"medium",input:"medium",modal:"large",menuItem:"medium"},accentColorKey:"emerald",itemPaletteKey:"forest"}},{id:"sunset",name:"Coucher de soleil",description:"Couleurs chaudes et accueillantes",icon:"🌅",config:{borderRadius:{card:"large",button:"large",badge:"xxlarge",input:"medium",modal:"xlarge",menuItem:"medium"},accentColorKey:"orange",itemPaletteKey:"sunset"}},{id:"lavender",name:"Lavande",description:"Tons violets élégants",icon:"💜",config:{borderRadius:{card:"xlarge",button:"large",badge:"xlarge",input:"large",modal:"xlarge",menuItem:"large"},accentColorKey:"violet",itemPaletteKey:"lavender"}},{id:"rose",name:"Rose",description:"Teintes roses douces",icon:"🌸",config:{borderRadius:{card:"xxlarge",button:"xlarge",badge:"xxlarge",input:"large",modal:"xxlarge",menuItem:"large"},accentColorKey:"pink",itemPaletteKey:"rose"}}],El="smartstack-theme-config";class jt extends Error{statusCode;details;constructor(t,r,n){super(t),this.name="AppError",this.statusCode=r,this.details=n}}class nr extends Error{constructor(t="Network error occurred"){super(t),this.name="NetworkError"}}class Dl extends Error{code;constructor(t="Authentication required",r){super(t),this.name="AuthenticationError",this.code=r}}class ko extends Error{constructor(t="Access denied"){super(t),this.name="ForbiddenError"}}const Co=10;class So{queue=[];recentErrors=[];isProcessing=!1;batchSize=10;batchDelay=2e3;async logError(t,r,n){const i=typeof t=="string"?t:t.message;let o=i;if(n?.url){const x=String(n.url),u=n.status?` [${n.status}]`:"";o=`${i}${u} - ${x}`}const c={message:o,stack:typeof t=="string"?void 0:t.stack,url:window.location.href,component:r,level:"Error",metadata:n};this.storeRecentError(c),this.queue.push({type:"error",data:c}),this.processQueue()}async logCritical(t,r,n){const i=typeof t=="string"?t:t.message;let o=i;if(n?.url){const u=String(n.url),d=n.status?` [${n.status}]`:"";o=`${i}${d} - ${u}`}const c={message:o,stack:typeof t=="string"?void 0:t.stack,url:window.location.href,component:r,level:"Critical",metadata:n};return this.storeRecentError(c),await this.sendErrorWithResponse(c)}getRecentErrors(){return[...this.recentErrors]}clearRecentErrors(){this.recentErrors=[]}storeRecentError(t){this.recentErrors.unshift({...t,timestamp:new Date}),this.recentErrors.length>Co&&this.recentErrors.pop()}async logEvent(t,r,n){const i={event:t,category:r,data:n};this.queue.push({type:"event",data:i}),this.processQueue()}async processQueue(){if(this.isProcessing||this.queue.length===0)return;this.isProcessing=!0,await new Promise(r=>setTimeout(r,this.batchDelay));const t=this.queue.splice(0,this.batchSize);for(const r of t)try{r.type==="error"?await this.sendError(r.data):await this.sendEvent(r.data)}catch{}this.isProcessing=!1,this.queue.length>0&&this.processQueue()}async sendError(t){const r=localStorage.getItem("token");await fetch("/api/logs/client-error",{method:"POST",headers:{"Content-Type":"application/json",...r&&{Authorization:`Bearer ${r}`}},body:JSON.stringify(t)})}async sendErrorWithResponse(t){const r=localStorage.getItem("token");try{const n=await fetch("/api/logs/client-error",{method:"POST",headers:{"Content-Type":"application/json",...r&&{Authorization:`Bearer ${r}`}},body:JSON.stringify(t)});return n.ok&&n.status===200&&(await n.json()).ticketNumber||null}catch{return null}}async sendEvent(t){const r=localStorage.getItem("token");await fetch("/api/logs/client-event",{method:"POST",headers:{"Content-Type":"application/json",...r&&{Authorization:`Bearer ${r}`}},body:JSON.stringify(t)})}}const qe=new So;window.onerror=(s,t,r,n,i)=>{qe.logError(i||String(s),"window.onerror",{source:t,lineno:r,colno:n})};window.onunhandledrejection=s=>{qe.logError(s.reason instanceof Error?s.reason:String(s.reason),"unhandledrejection")};const Be=ar.create({timeout:3e4,headers:{"Content-Type":"application/json"}});Be.interceptors.request.use(s=>{const t=localStorage.getItem("token");t&&s.headers&&(s.headers.Authorization=`Bearer ${t}`);const r=crypto.randomUUID();s.headers&&(s.headers["X-Correlation-ID"]=r);const n=localStorage.getItem("i18nextLng")||navigator.language||"fr";s.headers&&(s.headers["Accept-Language"]=n);const i=localStorage.getItem("currentTenantSlug");return i&&s.headers&&!s.headers["X-Tenant-Slug"]&&(s.headers["X-Tenant-Slug"]=i),s},s=>(qe.logError(s,"apiClient.request"),Promise.reject(s)));Be.interceptors.response.use(s=>s,async s=>{const t=s.config?.headers?.["X-Correlation-ID"];if(ar.isCancel(s)||s.code==="ERR_CANCELED")return Promise.reject(s);if(!s.response){const c=new nr("Impossible de se connecter au serveur. Vérifiez votre connexion internet.");return qe.logError(c,"apiClient.response",{correlationId:t}),Promise.reject(c)}const{status:r,data:n}=s.response,i=n?.message||s.message,o=n?.code;switch(r){case 401:{const c=new Dl(i,o);qe.logError(c,"apiClient.response",{correlationId:t,url:s.config?.url,code:o});const x=s.config?.url||"",d=["/api/user/preferences","/api/auth/session-info","/api/auth/refresh","/api/navigation/menu","/api/navigation/favorites","/api/navigation/contexts","/api/onboarding/status","/api/platform/administration/tenants/tenant-analytics/track/"].some(m=>x.startsWith(m));if(!window.location.pathname.includes("/login")&&!d){localStorage.removeItem("token"),localStorage.removeItem("refreshToken"),localStorage.removeItem("user");const p=o==="SESSION_EXPIRED"?"/login?reason=session_expired":"/login";window.location.href=p}return Promise.reject(c)}case 403:{const c=new ko(i),x=["/api/platform/administration/tenants/tenant-analytics/track/"],u=s.config?.url||"";return x.some(m=>u.startsWith(m))||qe.logCritical(c,"apiClient.response",{correlationId:t,url:s.config?.url,method:s.config?.method}),Promise.reject(c)}case 404:return Promise.reject(new jt(i||"Resource not found",r));case 400:return Promise.reject(new jt(i||"Invalid request",r,n?.details));case 500:case 502:case 503:case 504:{const c=new jt(i||"Server error",r);return qe.logError(c,"apiClient.response",{correlationId:t,url:s.config?.url,status:r}),Promise.reject(c)}default:{const c=new jt(i,r,n?.details);return qe.logError(c,"apiClient.response",{correlationId:t,status:r}),Promise.reject(c)}}});const oe={get:(s,t)=>Be.get(s,t).then(r=>r.data),post:(s,t,r)=>Be.post(s,t,r).then(n=>n.data),put:(s,t,r)=>Be.put(s,t,r).then(n=>n.data),patch:(s,t,r)=>Be.patch(s,t,r).then(n=>n.data),delete:(s,t)=>Be.delete(s,t).then(r=>r.data)},Is={preferences:{get:()=>oe.get("/api/user/preferences"),updateTheme:s=>oe.put("/api/user/preferences/theme",s),updateLanguage:s=>oe.put("/api/user/preferences/language",s),updateNotifications:s=>oe.put("/api/user/preferences/notifications",s)},dashboard:{getAll:(s=30,t=10)=>oe.get(`/api/platform/user/dashboard/all?period=${s}&errorLimit=${t}`),getSessionAnalytics:(s=30)=>oe.get(`/api/platform/user/dashboard/session-analytics?period=${s}`),getLoginErrors:(s=10)=>oe.get(`/api/platform/user/dashboard/login-errors?limit=${s}`),getCurrentSession:()=>oe.get("/api/platform/user/dashboard/current-session"),getDeviceStats:()=>oe.get("/api/platform/user/dashboard/device-stats"),getWeeklyStats:(s=30)=>oe.get(`/api/platform/user/dashboard/weekly-stats?period=${s}`),getHourlyStats:(s=30)=>oe.get(`/api/platform/user/dashboard/hourly-stats?period=${s}`),getApplicationUsage:(s=30)=>oe.get(`/api/platform/user/dashboard/application-usage?period=${s}`)}},To=s=>({get:(t,r)=>Be.get(t,{...r,headers:s?{...r?.headers,"X-Tenant-Slug":s}:r?.headers}).then(n=>n.data),post:(t,r,n)=>Be.post(t,r,{...n,headers:s?{...n?.headers,"X-Tenant-Slug":s}:n?.headers}).then(i=>i.data),put:(t,r,n)=>Be.put(t,r,{...n,headers:s?{...n?.headers,"X-Tenant-Slug":s}:n?.headers}).then(i=>i.data),patch:(t,r,n)=>Be.patch(t,r,{...n,headers:s?{...n?.headers,"X-Tenant-Slug":s}:n?.headers}).then(i=>i.data),delete:(t,r)=>Be.delete(t,{...r,headers:s?{...r?.headers,"X-Tenant-Slug":s}:r?.headers}).then(n=>n.data)}),lt={PasswordResetMalfunction:1,FalsePositive:2,UrgentBusinessNeed:3,TechnicalSystemError:4,SupportTicketVerified:5},lr=s=>{const t=s?To(s):oe;return{users:{getAll:r=>t.get("/api/platform/administration/users",{params:r}),getById:r=>t.get(`/api/platform/administration/users/${r}`),create:r=>t.post("/api/platform/administration/users",r),update:(r,n)=>t.put(`/api/platform/administration/users/${r}`,n),sendPasswordResetLink:r=>t.post(`/api/platform/administration/users/${r}/send-password-reset`),resetPasswordDirect:(r,n)=>t.post(`/api/platform/administration/users/${r}/reset-password-direct`,n?{temporaryPassword:n}:{}),activate:r=>t.patch(`/api/platform/administration/users/${r}/activate`),deactivate:r=>t.patch(`/api/platform/administration/users/${r}/deactivate`),unlock:(r,n)=>t.post(`/api/platform/administration/users/${r}/unlock`,n),clearFailedAttempts:r=>t.post(`/api/platform/administration/users/${r}/clear-failed-attempts`),delete:r=>t.delete(`/api/platform/administration/users/${r}`),getSessions:r=>t.get(`/api/platform/administration/users/${r}/sessions`),endAllSessions:r=>t.post(`/api/platform/administration/users/${r}/sessions/end-all`),endSession:(r,n)=>t.delete(`/api/platform/administration/users/${r}/sessions/${n}`),getActivity:r=>t.get(`/api/platform/administration/users/${r}/activity`),getCustomRole:r=>t.get(`/api/platform/administration/users/${r}/custom-role`),createCustomRole:r=>t.post(`/api/platform/administration/users/${r}/custom-role`),deleteCustomRole:r=>t.delete(`/api/platform/administration/users/${r}/custom-role`),getHistory:(r,n=50)=>t.get(`/api/platform/administration/users/${r}/history`,{params:{limit:n}}),restoreFromHistory:(r,n)=>t.post(`/api/platform/administration/users/${r}/history/${n}/restore`),getOrganizationReferences:()=>t.get("/api/platform/administration/users/organization-references"),references:{getCompanies:r=>t.get("/api/platform/administration/users/references/companies",{params:r}),getDepartments:r=>t.get("/api/platform/administration/users/references/departments",{params:r}),getJobTitles:r=>t.get("/api/platform/administration/users/references/job-titles",{params:r}),getOffices:r=>t.get("/api/platform/administration/users/references/offices",{params:r}),createCompany:(r,n)=>t.post(`/api/platform/administration/users/references/companies${n?`?tenantId=${n}`:""}`,r),createDepartment:(r,n)=>t.post(`/api/platform/administration/users/references/departments${n?`?tenantId=${n}`:""}`,r),createJobTitle:(r,n)=>t.post(`/api/platform/administration/users/references/job-titles${n?`?tenantId=${n}`:""}`,r),createOffice:(r,n)=>t.post(`/api/platform/administration/users/references/offices${n?`?tenantId=${n}`:""}`,r),updateCompany:(r,n)=>t.put(`/api/platform/administration/users/references/companies/${r}`,n),updateDepartment:(r,n)=>t.put(`/api/platform/administration/users/references/departments/${r}`,n),updateJobTitle:(r,n)=>t.put(`/api/platform/administration/users/references/job-titles/${r}`,n),updateOffice:(r,n)=>t.put(`/api/platform/administration/users/references/offices/${r}`,n),activateCompany:r=>t.patch(`/api/platform/administration/users/references/companies/${r}/activate`),activateDepartment:r=>t.patch(`/api/platform/administration/users/references/departments/${r}/activate`),activateJobTitle:r=>t.patch(`/api/platform/administration/users/references/job-titles/${r}/activate`),activateOffice:r=>t.patch(`/api/platform/administration/users/references/offices/${r}/activate`),deactivateCompany:r=>t.patch(`/api/platform/administration/users/references/companies/${r}/deactivate`),deactivateDepartment:r=>t.patch(`/api/platform/administration/users/references/departments/${r}/deactivate`),deactivateJobTitle:r=>t.patch(`/api/platform/administration/users/references/job-titles/${r}/deactivate`),deactivateOffice:r=>t.patch(`/api/platform/administration/users/references/offices/${r}/deactivate`),deleteCompany:r=>t.delete(`/api/platform/administration/users/references/companies/${r}`),deleteDepartment:r=>t.delete(`/api/platform/administration/users/references/departments/${r}`),deleteJobTitle:r=>t.delete(`/api/platform/administration/users/references/job-titles/${r}`),deleteOffice:r=>t.delete(`/api/platform/administration/users/references/offices/${r}`)},updateProfile:(r,n)=>t.put(`/api/platform/administration/users/${r}/profile`,n),updateOrganization:(r,n)=>t.put(`/api/platform/administration/users/${r}/organization`,n),updateJobInfo:(r,n)=>t.put(`/api/platform/administration/users/${r}/job-info`,n),updatePhones:(r,n)=>t.put(`/api/platform/administration/users/${r}/phones`,n),updateAddress:(r,n)=>t.put(`/api/platform/administration/users/${r}/address`,n),updateContact:(r,n)=>t.put(`/api/platform/administration/users/${r}/contact`,n),getTenants:r=>t.get(`/api/platform/administration/users/${r}/tenants`),getGroups:r=>t.get(`/api/platform/administration/users/${r}/groups`),getConsolidatedRoles:(r,n)=>{const i=n?`/api/platform/administration/users/${r}/consolidated-roles?tenantId=${n}`:`/api/platform/administration/users/${r}/consolidated-roles`;return t.get(i)},getApplicationAccess:(r,n)=>{const i=n?`/api/platform/administration/users/${r}/application-access?tenantId=${n}`:`/api/platform/administration/users/${r}/application-access`;return t.get(i)}},roles:{getAll:r=>t.get("/api/platform/administration/permissions/roles",{params:r}),getAssignable:()=>t.get("/api/platform/administration/permissions/roles",{params:{excludeCategories:"Custom",minPermissionsCount:1}}),getByApplication:r=>t.get("/api/platform/administration/permissions/roles",{params:{applicationId:r,excludeCategories:"Custom",minPermissionsCount:1}}),getById:r=>t.get(`/api/platform/administration/permissions/roles/${r}`),create:r=>t.post("/api/platform/administration/permissions/roles",r),update:(r,n)=>t.put(`/api/platform/administration/permissions/roles/${r}`,n),delete:r=>t.delete(`/api/platform/administration/permissions/roles/${r}`),assignUser:(r,n)=>t.post(`/api/platform/administration/permissions/roles/${r}/users/${n}`),removeUser:(r,n)=>t.delete(`/api/platform/administration/permissions/roles/${r}/users/${n}`),getGroups:r=>t.get(`/api/platform/administration/permissions/roles/${r}/groups`),assignGroup:(r,n)=>t.post(`/api/platform/administration/permissions/roles/${r}/groups/${n}`),removeGroup:(r,n)=>t.delete(`/api/platform/administration/permissions/roles/${r}/groups/${n}`),getTranslations:r=>t.get(`/api/platform/administration/permissions/roles/${r}/translations`),upsertTranslation:(r,n,i)=>t.put(`/api/platform/administration/permissions/roles/${r}/translations/${n}`,i),deleteTranslation:(r,n)=>t.delete(`/api/platform/administration/permissions/roles/${r}/translations/${n}`)},permissions:{getAll:r=>t.get("/api/platform/administration/permissions",{params:r}),getById:r=>t.get(`/api/platform/administration/permissions/${r}`),getTree:()=>t.get("/api/platform/administration/permissions/tree"),getMatrix:()=>t.get("/api/platform/administration/permissions/matrix"),delete:r=>t.delete(`/api/platform/administration/permissions/${r}`)},applications:{getAll:r=>t.get("/api/platform/administration/applications",{params:r}),getById:r=>t.get(`/api/platform/administration/applications/${r}`),getContexts:()=>t.get("/api/platform/administration/applications/contexts"),update:(r,n)=>t.put(`/api/platform/administration/applications/${r}`,n),activate:r=>t.patch(`/api/platform/administration/applications/${r}/activate`),deactivate:r=>t.patch(`/api/platform/administration/applications/${r}/deactivate`),getModules:r=>t.get(`/api/platform/administration/applications/${r}/modules`),updateModule:(r,n,i)=>t.put(`/api/platform/administration/applications/${r}/modules/${n}`,i),getModuleSections:(r,n)=>t.get(`/api/platform/administration/applications/${r}/modules/${n}/sections`),reorderModules:(r,n)=>t.put(`/api/platform/administration/applications/${r}/modules/reorder`,{items:n}),reorderSections:(r,n,i)=>t.put(`/api/platform/administration/applications/${r}/modules/${n}/sections/reorder`,{items:i}),getTenants:r=>t.get(`/api/platform/administration/applications/${r}/tenants`),getAvailableTenants:r=>t.get(`/api/platform/administration/applications/${r}/tenants/available`),assignToTenant:(r,n,i)=>t.post(`/api/platform/administration/applications/${r}/tenants/${n}`,i?{accessLevel:i}:{}),removeFromTenant:(r,n)=>t.delete(`/api/platform/administration/applications/${r}/tenants/${n}`),updateTenantAccessLevel:(r,n,i)=>t.patch(`/api/platform/administration/applications/${r}/tenants/${n}/access-level`,{accessLevel:i}),bulkAssignTenants:(r,n)=>t.post(`/api/platform/administration/applications/${r}/tenants/bulk`,n)},dashboard:{getOverview:(r=30,n)=>t.get("/api/platform/administration/users/dashboard/overview",{params:{days:r},signal:n?.signal}),getByStatus:r=>t.get("/api/platform/administration/users/dashboard/by-status",{signal:r?.signal}),getByRole:r=>t.get("/api/platform/administration/users/dashboard/by-role",{signal:r?.signal}),getByType:r=>t.get("/api/platform/administration/users/dashboard/by-type",{signal:r?.signal}),getLoginActivity:(r=30,n)=>t.get("/api/platform/administration/users/dashboard/login-activity",{params:{days:r},signal:n?.signal}),getTrends:(r=30,n)=>t.get("/api/platform/administration/users/dashboard/trends",{params:{days:r},signal:n?.signal}),getRecentUsers:(r=10,n)=>t.get("/api/platform/administration/users/dashboard/recent-users",{params:{limit:r},signal:n?.signal}),getSecurityAlerts:(r=3,n=24,i)=>t.get("/api/platform/administration/users/dashboard/security-alerts",{params:{threshold:r,hours:n},signal:i?.signal}),getActiveSessions:r=>t.get("/api/platform/administration/users/dashboard/active-sessions",{signal:r?.signal}),getLatestActiveSessions:(r=5,n)=>t.get("/api/platform/administration/users/dashboard/latest-active-sessions",{params:{limit:r},signal:n?.signal})},settings:{getAll:()=>t.get("/api/platform/administration/configuration/settings"),getByCategory:r=>t.get(`/api/platform/administration/configuration/settings/${r}`),get:(r,n)=>t.get(`/api/platform/administration/configuration/settings/${r}/${n}`),update:(r,n,i)=>t.put(`/api/platform/administration/configuration/settings/${r}/${n}`,{value:i}),reset:(r,n)=>t.post(`/api/platform/administration/configuration/settings/${r}/${n}/reset`),getHistory:(r,n)=>t.get(`/api/platform/administration/configuration/settings/${r}/${n}/history`),getCategories:()=>t.get("/api/platform/administration/configuration/settings/categories")},tenants:{getConfig:()=>t.get("/api/platform/administration/tenants/config"),getAll:async r=>(await t.get("/api/platform/administration/tenants",{params:r})).items,getById:r=>t.get(`/api/platform/administration/tenants/${r}`),createB2C:r=>t.post("/api/platform/administration/tenants/b2c",r),createB2B:r=>t.post("/api/platform/administration/tenants/b2b",r),update:(r,n)=>t.put(`/api/platform/administration/tenants/${r}`,n),delete:r=>t.delete(`/api/platform/administration/tenants/${r}`),activate:r=>t.post(`/api/platform/administration/tenants/${r}/activate`),suspend:r=>t.post(`/api/platform/administration/tenants/${r}/suspend`),archive:r=>t.delete(`/api/platform/administration/tenants/${r}`),checkSlugAvailable:r=>t.get(`/api/platform/administration/tenants/check-slug/${r}`),getMembers:r=>t.get(`/api/platform/administration/tenants/${r}/members`),getMember:(r,n)=>t.get(`/api/platform/administration/tenants/${r}/members/${n}`),addMember:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/members`,n),removeMember:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/members/${n}`),setMemberDefault:(r,n)=>t.patch(`/api/platform/administration/tenants/${r}/members/${n}/set-default`),transferOwnership:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/members/transfer-ownership`,{toUserId:n}),assignRole:(r,n,i)=>t.post(`/api/platform/administration/tenants/${r}/members/${n}/roles/${i}`),removeRole:(r,n,i)=>t.delete(`/api/platform/administration/tenants/${r}/members/${n}/roles/${i}`),assignMemberRoles:(r,n,i)=>t.put(`/api/platform/administration/tenants/${r}/members/${n}/roles`,{roleIds:i}),getMemberCustomRole:(r,n)=>t.get(`/api/platform/administration/tenants/${r}/members/${n}/custom-role`),createMemberCustomRole:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/members/${n}/custom-role`),deleteMemberCustomRole:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/members/${n}/custom-role`),getTenantRoles:r=>t.get(`/api/platform/administration/tenants/${r}/roles`),getGroups:r=>t.get(`/api/platform/administration/tenants/${r}/groups`),getAvailableGroups:r=>t.get(`/api/platform/administration/tenants/${r}/groups/available`),addGroupToTenant:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/groups`,{groupId:n}),removeGroupFromTenant:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/groups/${n}`),getApplications:r=>t.get(`/api/platform/administration/tenants/${r}/applications`),getAvailableApplications:r=>t.get(`/api/platform/administration/tenants/${r}/applications/available`),assignApplication:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/applications/${n}`),removeApplication:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/applications/${n}`),bulkAssignApplications:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/applications/bulk`,n),toggleApplication:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/applications/${n}/toggle`,{isActive:i}),updateApplicationAccessLevel:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/applications/${n}/access-level`,{accessLevel:i}),getModules:r=>t.get(`/api/platform/administration/tenants/${r}/modules`),getAvailableModules:r=>t.get(`/api/platform/administration/tenants/${r}/modules/available`),assignModule:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/modules/${n}`),removeModule:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/modules/${n}`),toggleModule:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/modules/${n}/toggle`,{isActive:i}),getSections:r=>t.get(`/api/platform/administration/tenants/${r}/sections`),getAvailableSections:r=>t.get(`/api/platform/administration/tenants/${r}/sections/available`),assignSection:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/sections/${n}`),removeSection:(r,n)=>t.delete(`/api/platform/administration/tenants/${r}/sections/${n}`),toggleSection:(r,n,i)=>t.patch(`/api/platform/administration/tenants/${r}/sections/${n}/toggle`,{isActive:i}),getModulesWithSections:(r,n)=>t.get(`/api/platform/administration/tenants/${r}/applications/${n}/modules-tree`),linkOrganisation:(r,n)=>t.post(`/api/platform/administration/tenants/${r}/organisation`,{organisationId:n}),unlinkOrganisation:r=>t.delete(`/api/platform/administration/tenants/${r}/organisation`)},templates:{getAll:()=>t.get("/api/platform/administration/tenants/templates"),getById:r=>t.get(`/api/platform/administration/tenants/templates/${r}`),create:r=>t.post("/api/platform/administration/tenants/templates",r),update:(r,n)=>t.put(`/api/platform/administration/tenants/templates/${r}`,n),delete:r=>t.delete(`/api/platform/administration/tenants/templates/${r}`),assignApplication:(r,n)=>t.post(`/api/platform/administration/tenants/templates/${r}/applications/${n}`),removeApplication:(r,n)=>t.delete(`/api/platform/administration/tenants/templates/${r}/applications/${n}`),bulkAssignApplications:(r,n)=>t.post(`/api/platform/administration/tenants/templates/${r}/applications/bulk`,n),getTenants:r=>t.get(`/api/platform/administration/tenants/templates/${r}/tenants`),getApplications:r=>t.get(`/api/platform/administration/tenants/templates/${r}/applications`),getAvailableApplications:r=>t.get(`/api/platform/administration/tenants/templates/${r}/applications/available`),updateApplicationAccessLevel:(r,n,i)=>t.patch(`/api/platform/administration/tenants/templates/${r}/applications/${n}/access-level`,{accessLevel:i}),getApplicationModules:(r,n)=>t.get(`/api/platform/administration/tenants/templates/${r}/applications/${n}/modules`),updateApplicationModules:(r,n,i)=>t.put(`/api/platform/administration/tenants/templates/${r}/applications/${n}/modules`,i)},organisations:{getAvailable:r=>t.get("/api/organisations/available",{params:r?{search:r}:void 0}),getById:r=>t.get(`/api/organisations/${r}`),create:r=>t.post("/api/organisations",r),lookup:(r,n)=>t.get("/api/organisations/lookup",{params:{countryCode:r,identifier:n}})},myTenants:{getAll:r=>t.get("/api/platform/administration/tenants/my",{params:r?{search:r}:void 0}),getDefault:()=>t.get("/api/platform/administration/tenants/my/default"),setDefault:r=>t.post(`/api/platform/administration/tenants/${r}/set-default`),clearDefault:()=>t.delete("/api/platform/administration/tenants/clear-default"),getFavorites:()=>t.get("/api/user/preferences/tenant-favorites"),addFavorite:r=>t.post(`/api/user/preferences/tenant-favorites/${r}`),removeFavorite:r=>t.delete(`/api/user/preferences/tenant-favorites/${r}`),recordRecent:r=>t.post(`/api/user/preferences/tenant-recent/${r}`)},preferences:{get:()=>t.get("/api/user/preferences"),getGlobal:()=>t.get("/api/user/preferences/global"),getForTenant:r=>t.get(`/api/user/preferences/for-tenant/${r}`),getThemeOverrides:()=>t.get("/api/user/preferences/theme-overrides"),deleteTenantOverride:()=>t.delete("/api/user/preferences/tenant-override"),applyToTenant:()=>t.post("/api/user/preferences/apply-to-tenant")}}},le=lr(),as=(s,t,r)=>{const n=s[t];return n?typeof n=="function"?n():Promise.resolve(n):new Promise((i,o)=>{(typeof queueMicrotask=="function"?queueMicrotask:setTimeout)(o.bind(null,new Error("Unknown variable dynamic import: "+t+(t.split("/").length!==r?". Note that variables only represent file names one level deep.":""))))})},Ll=async s=>{if(!s)return null;try{const[t,r,n,i,o,c,x,u,d,m,p,h,v]=await Promise.all([as(Object.assign({"./locales/de/common.json":()=>Promise.resolve().then(()=>require("./common-B6hOC7Z1.cjs")),"./locales/en/common.json":()=>Promise.resolve().then(()=>require("./common-WTcRPHwd.cjs")),"./locales/fr/common.json":()=>Promise.resolve().then(()=>require("./common-CrmmeiUS.cjs")),"./locales/it/common.json":()=>Promise.resolve().then(()=>require("./common-B7ae-mQA.cjs"))}),`./locales/${s}/common.json`,4),as(Object.assign({"./locales/de/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-BIfBA5zU.cjs")),"./locales/en/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-Djc1f5z5.cjs")),"./locales/fr/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-BVdU6a5A.cjs")),"./locales/it/navigation.json":()=>Promise.resolve().then(()=>require("./navigation-BgT6W7T7.cjs"))}),`./locales/${s}/navigation.json`,4),as(Object.assign({"./locales/de/auth.json":()=>Promise.resolve().then(()=>require("./auth-C5zpZ9k7.cjs")),"./locales/en/auth.json":()=>Promise.resolve().then(()=>require("./auth-DL47kvnl.cjs")),"./locales/fr/auth.json":()=>Promise.resolve().then(()=>require("./auth-B-hELPDB.cjs")),"./locales/it/auth.json":()=>Promise.resolve().then(()=>require("./auth-CyPkCta2.cjs"))}),`./locales/${s}/auth.json`,4),as(Object.assign({"./locales/de/admin.json":()=>Promise.resolve().then(()=>require("./admin-wwcGfjWu.cjs")),"./locales/en/admin.json":()=>Promise.resolve().then(()=>require("./admin-CylPg5D5.cjs")),"./locales/fr/admin.json":()=>Promise.resolve().then(()=>require("./admin-4VkTpwkH.cjs")),"./locales/it/admin.json":()=>Promise.resolve().then(()=>require("./admin-CxYCOIEX.cjs"))}),`./locales/${s}/admin.json`,4),as(Object.assign({"./locales/de/support.json":()=>Promise.resolve().then(()=>require("./support-CzyyqmKL.cjs")),"./locales/en/support.json":()=>Promise.resolve().then(()=>require("./support-uf0CffL4.cjs")),"./locales/fr/support.json":()=>Promise.resolve().then(()=>require("./support-BeGp6i4F.cjs")),"./locales/it/support.json":()=>Promise.resolve().then(()=>require("./support-B1RXel78.cjs"))}),`./locales/${s}/support.json`,4),as(Object.assign({"./locales/de/docs.json":()=>Promise.resolve().then(()=>require("./docs-CikbZEP3.cjs")),"./locales/en/docs.json":()=>Promise.resolve().then(()=>require("./docs-eIYCBYJf.cjs")),"./locales/fr/docs.json":()=>Promise.resolve().then(()=>require("./docs-dAIQDVc3.cjs")),"./locales/it/docs.json":()=>Promise.resolve().then(()=>require("./docs-DaN5xRMQ.cjs"))}),`./locales/${s}/docs.json`,4),as(Object.assign({"./locales/de/ai.json":()=>Promise.resolve().then(()=>require("./ai-BIrcm_pp.cjs")),"./locales/en/ai.json":()=>Promise.resolve().then(()=>require("./ai-B8deAoMx.cjs")),"./locales/fr/ai.json":()=>Promise.resolve().then(()=>require("./ai-DqrFlpsS.cjs")),"./locales/it/ai.json":()=>Promise.resolve().then(()=>require("./ai-CnpjG8DZ.cjs"))}),`./locales/${s}/ai.json`,4),as(Object.assign({"./locales/de/communications.json":()=>Promise.resolve().then(()=>require("./communications-DBbKXpf1.cjs")),"./locales/en/communications.json":()=>Promise.resolve().then(()=>require("./communications-BPsS3Vfm.cjs")),"./locales/fr/communications.json":()=>Promise.resolve().then(()=>require("./communications-DElJaoVw.cjs")),"./locales/it/communications.json":()=>Promise.resolve().then(()=>require("./communications-BKaku0MU.cjs"))}),`./locales/${s}/communications.json`,4),as(Object.assign({"./locales/de/entra.json":()=>Promise.resolve().then(()=>require("./entra-BadKCc7Y.cjs")),"./locales/en/entra.json":()=>Promise.resolve().then(()=>require("./entra-CfLYpxKq.cjs")),"./locales/fr/entra.json":()=>Promise.resolve().then(()=>require("./entra-Bc0Dwf7d.cjs")),"./locales/it/entra.json":()=>Promise.resolve().then(()=>require("./entra-DDgx1JoT.cjs"))}),`./locales/${s}/entra.json`,4),as(Object.assign({"./locales/en/structure.json":()=>Promise.resolve().then(()=>require("./structure-BL5cd83u.cjs")),"./locales/fr/structure.json":()=>Promise.resolve().then(()=>require("./structure-BblXL_QG.cjs"))}),`./locales/${s}/structure.json`,4).catch(()=>({default:{}})),as(Object.assign({"./locales/de/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-DLJ9mTYQ.cjs")),"./locales/en/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-pkUX3R0G.cjs")),"./locales/fr/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-Di_IL1wh.cjs")),"./locales/it/preferences.json":()=>Promise.resolve().then(()=>require("./preferences-B65OLntJ.cjs"))}),`./locales/${s}/preferences.json`,4).catch(()=>({default:{}})),as(Object.assign({"./locales/de/groups.json":()=>Promise.resolve().then(()=>require("./groups-BcmmnEo6.cjs")),"./locales/en/groups.json":()=>Promise.resolve().then(()=>require("./groups-BqOvsO0R.cjs")),"./locales/fr/groups.json":()=>Promise.resolve().then(()=>require("./groups-CzMRaBiO.cjs")),"./locales/it/groups.json":()=>Promise.resolve().then(()=>require("./groups-Blo6Xw1w.cjs"))}),`./locales/${s}/groups.json`,4).catch(()=>({default:{}})),as(Object.assign({"./locales/en/ba.json":()=>Promise.resolve().then(()=>require("./ba-9HglDm-t.cjs")),"./locales/fr/ba.json":()=>Promise.resolve().then(()=>require("./ba-CXlHUyjN.cjs"))}),`./locales/${s}/ba.json`,4).catch(()=>({default:{}}))]);return{common:t.default,navigation:r.default,auth:n.default,admin:i.default,support:o.default,docs:c.default,ai:x.default,communications:u.default,entra:d.default,structure:m.default||{},preferences:p.default||{},groups:h.default||{},ba:v.default||{}}}catch(t){return console.warn(`Failed to load language: ${s}`,t),null}},Ao={},Ro=()=>{const s=localStorage.getItem("i18nextLng");if(s&&["en","fr","de","it"].includes(s))return s;const t=navigator.language.split("-")[0];return["en","fr","de","it"].includes(t)?t:"en"},Ha=Ro();Ks.use(lo).use(ne.initReactI18next).init({resources:Ao,lng:Ha,fallbackLng:"en",defaultNS:"common",ns:["common","navigation","auth","admin","support","docs","ai","communications","entra","structure","preferences","groups","ba"],interpolation:{escapeValue:!1},detection:{order:["localStorage","navigator","htmlTag"],caches:["localStorage"]}});Ll(Ha).then(s=>{s&&Object.entries(s).forEach(([t,r])=>{Ks.addResourceBundle(Ha,t,r,!0,!0)})});const ir=async s=>{if(!Ks.hasResourceBundle(s,"common")){const t=await Ll(s);t&&Object.entries(t).forEach(([r,n])=>{Ks.addResourceBundle(s,r,n,!0,!0)})}return Ks.changeLanguage(s)},Pl=l.createContext(void 0);function Io(){if(typeof window>"u")return xt;try{const t=localStorage.getItem(El);if(t){const r=JSON.parse(t);return console.log("[ThemeContext] Loaded from localStorage:",{mode:r.mode,accentColorKey:r.accentColorKey,borderRadius:r.borderRadius,itemPaletteKey:r.itemPaletteKey}),{...xt,...r,borderRadius:{...xt.borderRadius,...r.borderRadius},itemPaletteKey:r.itemPaletteKey||rr,colors:{light:Ws(r.accentColorKey||"indigo"),dark:Xs(r.accentColorKey||"indigo")}}}}catch{console.warn("[ThemeContext] Failed to load theme config from localStorage")}const s=window.matchMedia("(prefers-color-scheme: dark)").matches;return console.log("[ThemeContext] No localStorage, using system preference:",s?"dark":"light"),{...xt,mode:s?"dark":"light"}}function yt(s){const t=s.accentColorKey||"indigo",r=s.borderRadius;return{mode:s.theme||"dark",accentColorKey:t,borderRadius:{card:r?.card||"large",button:r?.button||"medium",badge:r?.badge||"medium",input:r?.input||"medium",modal:r?.modal||"xlarge",menuItem:r?.menuItem||"medium"},itemPaletteKey:s.itemPaletteKey||rr,colors:{light:Ws(t),dark:Xs(t)}}}function Eo(s){const t=document.documentElement,r=s.mode==="dark"?s.colors.dark:s.colors.light,n=os[s.accentColorKey]?.shades||os.indigo.shades,i=_s[s.itemPaletteKey]||_s.neutral,o=s.mode==="dark"?i.colors.dark:i.colors.light;console.log("[applyThemeToDocument] Applying theme:",{accentColorKey:s.accentColorKey,itemPaletteKey:s.itemPaletteKey,mode:s.mode}),s.mode==="dark"?t.classList.add("dark"):t.classList.remove("dark"),t.style.setProperty("--radius-card",fs[s.borderRadius.card]),t.style.setProperty("--radius-button",fs[s.borderRadius.button]),t.style.setProperty("--radius-badge",fs[s.borderRadius.badge]),t.style.setProperty("--radius-input",fs[s.borderRadius.input]),t.style.setProperty("--radius-modal",fs[s.borderRadius.modal]),t.style.setProperty("--radius-menu-item",fs[s.borderRadius.menuItem]),Object.entries(n).forEach(([c,x])=>{t.style.setProperty(`--color-accent-${c}`,x)}),t.style.setProperty("--item-color-light",o.light),t.style.setProperty("--item-color-medium",o.medium),t.style.setProperty("--item-color-dark",o.dark),t.style.setProperty("--item-color-border",o.border),t.style.setProperty("--bg-app",r.backgrounds.app),t.style.setProperty("--bg-primary",r.backgrounds.primary),t.style.setProperty("--bg-secondary",r.backgrounds.secondary),t.style.setProperty("--bg-tertiary",r.backgrounds.tertiary),t.style.setProperty("--bg-card",r.backgrounds.card),t.style.setProperty("--bg-hover",r.backgrounds.hover),t.style.setProperty("--bg-active",r.backgrounds.active),t.style.setProperty("--text-primary",r.text.primary),t.style.setProperty("--text-secondary",r.text.secondary),t.style.setProperty("--text-tertiary",r.text.tertiary),t.style.setProperty("--text-muted",r.text.muted),t.style.setProperty("--text-inverse",r.text.inverse),t.style.setProperty("--border-color",r.border.default),t.style.setProperty("--border-subtle",r.border.subtle),t.style.setProperty("--border-strong",r.border.strong),t.style.setProperty("--success-bg",r.status.success.bg),t.style.setProperty("--success-text",r.status.success.text),t.style.setProperty("--success-border",r.status.success.border),t.style.setProperty("--success-dot",r.status.success.dot),t.style.setProperty("--warning-bg",r.status.warning.bg),t.style.setProperty("--warning-text",r.status.warning.text),t.style.setProperty("--warning-border",r.status.warning.border),t.style.setProperty("--warning-dot",r.status.warning.dot),t.style.setProperty("--error-bg",r.status.error.bg),t.style.setProperty("--error-text",r.status.error.text),t.style.setProperty("--error-border",r.status.error.border),t.style.setProperty("--error-dot",r.status.error.dot),t.style.setProperty("--info-bg",r.status.info.bg),t.style.setProperty("--info-text",r.status.info.text),t.style.setProperty("--info-border",r.status.info.border),t.style.setProperty("--info-dot",r.status.info.dot),t.style.setProperty("--accent-bg",r.accentTransparent.bg),t.style.setProperty("--accent-text",r.accentTransparent.text),t.style.setProperty("--accent-border",r.accentTransparent.border)}function $l({children:s}){const[t,r]=l.useState(Io),[n,i]=l.useState(!1),[o,c]=l.useState(null),[x,u]=l.useState(void 0),[d,m]=l.useState([]),{i18n:p}=ne.useTranslation(),h=l.useRef(null),v=l.useRef(!0),b=l.useRef(!1),g=l.useRef(!1),j=l.useCallback(async(X,O=void 0)=>{if(!localStorage.getItem("token")){console.log("[ThemeContext] Skipping server sync - no token");return}if(g.current){console.log("[ThemeContext] Skipping save - tenant switch in progress (in saveToServer)");return}let K=null;const $=localStorage.getItem("currentTenantId");if(O===void 0)$?(console.log("[ThemeContext] Scope not initialized, using current tenant:",$),K=$):(console.log("[ThemeContext] No tenant selected, saving to GLOBAL"),K=null);else{if(O!==null&&$&&O!==$){console.log("[ThemeContext] Aborting save - tenant mismatch (target: %s, current: %s)",O,$);return}K=O}try{i(!0),console.log("[ThemeContext] 🔄 SAVING theme to server:",{targetTenantId:K,mode:X.mode,accentColorKey:X.accentColorKey,itemPaletteKey:X.itemPaletteKey,borderRadius:X.borderRadius}),await Is.preferences.updateTheme({mode:X.mode,accentColorKey:X.accentColorKey,borderRadius:{card:X.borderRadius.card,button:X.borderRadius.button,badge:X.borderRadius.badge,input:X.borderRadius.input,modal:X.borderRadius.modal,menuItem:X.borderRadius.menuItem},itemPaletteKey:X.itemPaletteKey,targetTenantId:K}),console.log("[ThemeContext] ✅ Theme saved successfully to tenant:",K||"GLOBAL"),K&&!d.includes(K)&&m(E=>[...E,K])}catch(E){console.error("[ThemeContext] ❌ Failed to save theme to server:",{error:E,targetTenantId:K,mode:X.mode,accentColorKey:X.accentColorKey,localStorage_currentTenantId:localStorage.getItem("currentTenantId"),localStorage_currentTenantSlug:localStorage.getItem("currentTenantSlug")})}finally{i(!1)}},[d]),w=l.useCallback((X,O=void 0)=>{h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{j(X,O)},1e3)},[j]);l.useLayoutEffect(()=>{Eo(t)},[t]),l.useEffect(()=>{const X={mode:t.mode,borderRadius:t.borderRadius,accentColorKey:t.accentColorKey,itemPaletteKey:t.itemPaletteKey};localStorage.setItem(El,JSON.stringify(X)),console.log("[ThemeContext] Config changed:",{mode:t.mode,accentColorKey:t.accentColorKey,itemPaletteKey:t.itemPaletteKey,isInitialLoad:v.current,isSwitchingTenant:g.current,selectedThemeTenant:x,isThemeScopeInitialized:b.current,currentTenantIdInStorage:localStorage.getItem("currentTenantId")}),g.current?console.log("[ThemeContext] Skipping save - tenant switch in progress"):v.current?console.log("[ThemeContext] Skipping save - initial load"):(console.log("[ThemeContext] Triggering debounced save to tenant:",x),w(t,x)),v.current=!1},[t,w,x]),l.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const f=l.useCallback(async X=>{const O=localStorage.getItem("token"),U=localStorage.getItem("currentTenantSlug");if(!O){console.log("[ThemeContext] No token found, skipping server load");return}const K=X==="global";if(!K&&!U){console.log("[ThemeContext] No tenant slug found, skipping server load (not global scope)");return}try{i(!0),console.log("[ThemeContext] Loading preferences from server...",{forceScope:X,loadGlobalOnly:K,tenantSlug:U||"GLOBAL"});const $=K?await le.preferences.getGlobal():await le.preferences.get();console.log("[ThemeContext] Received preferences from server:",{theme:$.theme,accentColorKey:$.accentColorKey,borderRadius:$.borderRadius,itemPaletteKey:$.itemPaletteKey,scope:$.scope}),c($.scope);const E=yt($);console.log("[ThemeContext] Converted to config:",{mode:E.mode,accentColorKey:E.accentColorKey,borderRadius:E.borderRadius,itemPaletteKey:E.itemPaletteKey}),v.current=!0,r(E),b.current=!0,console.log("[ThemeContext] Theme applied from server successfully (scope: %s)",$.scope.effectiveScope),$.language&&$.language!==p.language&&(ir($.language),document.documentElement.lang=$.language)}catch($){console.error("[ThemeContext] Failed to load theme from server:",$),console.warn("Using localStorage theme as fallback")}finally{i(!1)}},[p]),N=l.useCallback(async()=>{const X=localStorage.getItem("token"),O=localStorage.getItem("currentTenantSlug");if(!X||!O){console.log("[ThemeContext] Cannot apply to tenant - no auth or tenant context");return}try{i(!0),console.log("[ThemeContext] Creating tenant-specific preferences...");const U=await le.preferences.applyToTenant();c(U.scope),console.log("[ThemeContext] Tenant-specific preferences created successfully")}catch(U){throw console.error("[ThemeContext] Failed to create tenant-specific preferences:",U),U}finally{i(!1)}},[]),k=l.useCallback(async()=>{const X=localStorage.getItem("token"),O=localStorage.getItem("currentTenantSlug");if(!X||!O){console.log("[ThemeContext] Cannot reset to global - no auth or tenant context");return}try{i(!0),console.log("[ThemeContext] Deleting tenant-specific preferences...");const U=await le.preferences.deleteTenantOverride();c(U.scope);const K=yt(U);v.current=!0,r(K),console.log("[ThemeContext] Reverted to global preferences successfully")}catch(U){throw console.error("[ThemeContext] Failed to delete tenant-specific preferences:",U),U}finally{i(!1)}},[]),C=l.useCallback(async()=>{if(localStorage.getItem("token"))try{const O=await le.preferences.getThemeOverrides();m(O),console.log("[ThemeContext] Loaded tenant overrides:",O.length)}catch(O){console.error("[ThemeContext] Failed to load tenant overrides:",O)}},[]),y=l.useCallback(async(X,O=!1)=>{if(h.current&&(console.log("[ThemeContext] Clearing pending save due to tenant switch"),clearTimeout(h.current),h.current=null),g.current=!0,b.current=!0,v.current=!0,u(X),O){console.log("[ThemeContext] Scope set to",X||"GLOBAL","(skipLoad=true, not loading from server)"),g.current=!1;return}if(!localStorage.getItem("token")){g.current=!1;return}try{if(i(!0),X===null){console.log("[ThemeContext] Loading global-only preferences...");const K=await le.preferences.getGlobal();c(K.scope);const $=yt(K);v.current=!0,r($)}else{console.log("[ThemeContext] Loading preferences for tenant:",X);const K=await le.preferences.getForTenant(X);c(K.scope);const $=yt(K);v.current=!0,r($)}}catch(K){console.error("[ThemeContext] Failed to load preferences for tenant:",K)}finally{i(!1),g.current=!1}},[]),A=l.useCallback(()=>{r(X=>({...X,mode:X.mode==="light"?"dark":"light",colors:{light:Ws(X.accentColorKey),dark:Xs(X.accentColorKey)}}))},[]),D=l.useCallback(X=>{console.log("[ThemeContext] setMode called with:",X),r(O=>({...O,mode:X}))},[]),R=l.useCallback((X,O)=>{r(U=>({...U,borderRadius:{...U.borderRadius,[X]:O}}))},[]),L=l.useCallback(X=>{console.log("[ThemeContext] setAccentColor called with:",X),os[X]&&r(O=>({...O,accentColorKey:X,colors:{light:Ws(X),dark:Xs(X)}}))},[]),S=l.useCallback(X=>{_s[X]&&r(O=>({...O,itemPaletteKey:X}))},[]),T=l.useCallback(X=>{r(O=>{const U=X.accentColorKey||O.accentColorKey;return{...O,...X,borderRadius:{...O.borderRadius,...X.borderRadius},accentColorKey:U,itemPaletteKey:X.itemPaletteKey||O.itemPaletteKey,colors:{light:Ws(U),dark:Xs(U)}}})},[]),I=l.useCallback(()=>{r(xt)},[]),M=l.useCallback(X=>fs[t.borderRadius[X]],[t.borderRadius]);return e.jsx(Pl.Provider,{value:{config:t,mode:t.mode,toggleMode:A,setMode:D,setBorderRadius:R,setAccentColor:L,setItemPalette:S,applyPreset:T,resetToDefault:I,getBorderRadius:M,loadFromServer:f,isSyncing:n,scopeInfo:o,applyToTenant:N,resetToGlobal:k,selectedThemeTenant:x,setSelectedThemeTenant:y,tenantOverrides:d,loadTenantOverrides:C},children:s})}function et(){const s=l.useContext(Pl);if(s===void 0)throw new Error("useTheme must be used within a ThemeProvider");return s}let it=null,Ds=null;const Do={async getFeatureConfig(s){return it||Ds||(Ds=(async()=>{try{return it=(await ar.get("/api/config/features",{timeout:1e4,signal:s,headers:{"Content-Type":"application/json"}})).data,it}finally{Ds=null}})(),Ds)},clearCache(){it=null,Ds=null}},Ml=l.createContext(void 0);function Lo({children:s}){const[t,r]=l.useState(null),[n,i]=l.useState(!0);l.useEffect(()=>{const c=new AbortController;return Do.getFeatureConfig(c.signal).then(x=>{c.signal.aborted||r(x)}).catch(x=>{x.name==="CanceledError"||c.signal.aborted||(console.error("Failed to load feature config:",x),r({multiTenantEnabled:!0,enableB2B:!0,enableB2C:!0,useUrlRouting:!0,systemTenantSlug:null,systemTenantName:null}))}).finally(()=>{c.signal.aborted||i(!1)}),()=>c.abort()},[]);const o={config:t,isLoading:n,isMultiTenant:t?.multiTenantEnabled??!0,isSingleTenant:t?!t.multiTenantEnabled:!1,isHybridMode:t?.multiTenantEnabled===!0&&t?.enableB2B===!1&&t?.enableB2C===!0,enableB2B:t?.enableB2B??!0,enableB2C:t?.enableB2C??!0,useUrlRouting:t?.useUrlRouting??!0,systemTenantSlug:t?.systemTenantSlug??null,systemTenantName:t?.systemTenantName??null};return e.jsx(Ml.Provider,{value:o,children:s})}function vt(){const s=l.useContext(Ml);if(!s)throw new Error("useFeatureConfig must be used within FeatureConfigProvider");return s}function Fl(s,t){const r=s.toLowerCase(),n=t.toLowerCase();if(r==="*"||r===n)return!0;if(r.endsWith(".*")){const i=r.slice(0,-2);return n.startsWith(i+".")||n===i}return!1}function Ul(s,t){return s.includes("*")||t.includes("Super Administrator")}const or=l.createContext(void 0),Ls="token",Ps="user";function Ar(s){const t=s.split("/").filter(Boolean);return t.length===0||["login","callback","logout","onboarding","system"].includes(t[0])?null:t[0]}function Bl({children:s}){const[t,r]=l.useState(()=>{if(typeof window<"u"){const v=localStorage.getItem(Ps);if(v)try{return JSON.parse(v)}catch{return null}}return null}),[n,i]=l.useState(!0),[o,c]=l.useState(()=>typeof window<"u"?Ar(window.location.pathname):null),x=[],u=l.useCallback((v,b)=>{localStorage.setItem(Ls,v),localStorage.setItem(Ps,JSON.stringify(b)),r(b)},[]),d=l.useCallback(async()=>{try{localStorage.getItem(Ls)&&await oe.post("/api/auth/logout")}catch{}localStorage.removeItem(Ls),localStorage.removeItem("refreshToken"),localStorage.removeItem(Ps),r(null),window.location.href="/login"},[]),m=l.useCallback(v=>{c(v)},[]),p=l.useCallback(v=>{if(!t)return!1;if(Ul(t.permissions,t.roles)||t.permissions.includes(v))return!0;for(const b of t.permissions)if(Fl(b,v))return!0;return!1},[t]),h=l.useCallback(async()=>{if(localStorage.getItem(Ls))try{const b=await oe.get("/api/auth/me");r(b),localStorage.setItem(Ps,JSON.stringify(b))}catch(b){console.error("Failed to refresh permissions:",b)}},[]);return l.useEffect(()=>{localStorage.getItem(Ls)&&!t?oe.get("/api/auth/me").then(b=>{r(b),localStorage.setItem(Ps,JSON.stringify(b))}).catch(()=>{localStorage.removeItem(Ls),localStorage.removeItem("refreshToken"),localStorage.removeItem(Ps)}).finally(()=>i(!1)):i(!1)},[t]),l.useEffect(()=>{const v=()=>{c(Ar(window.location.pathname))};return window.addEventListener("popstate",v),()=>window.removeEventListener("popstate",v)},[]),e.jsx(or.Provider,{value:{user:t,isAuthenticated:!!t,isLoading:n,availableContexts:x,currentContext:o,login:u,logout:d,setCurrentContext:m,hasPermission:p,refreshPermissions:h},children:s})}function Ke(){const s=l.useContext(or);if(s===void 0)throw new Error("useAuth must be used within an AuthProvider");return s}function Po(){return l.useContext(or)??null}const Ka={"business.support-client.my-tickets":{navRoute:"business.support-client.my-tickets",api:"/api/business/support-client/my-tickets",web:"/business/support-client/my-tickets",permissions:[],controller:"MyTickets",methods:["GET","POST"]},"platform.administration.ai.dashboard":{navRoute:"platform.administration.ai.dashboard",api:"/api/platform/administration/ai/dashboard",web:"/platform/administration/ai/dashboard",permissions:[],controller:"AiDashboard",methods:[]},"platform.administration.ai.instances":{navRoute:"platform.administration.ai.instances",api:"/api/platform/administration/ai/instances",web:"/platform/administration/ai/instances",permissions:[],controller:"AiProviderInstances",methods:["GET","POST"]},"platform.administration.ai.prompts":{navRoute:"platform.administration.ai.prompts",api:"/api/platform/administration/ai/prompts",web:"/platform/administration/ai/prompts",permissions:[],controller:"AiPrompts",methods:["GET","POST"]},"platform.administration.ai.schemas":{navRoute:"platform.administration.ai.schemas",api:"/api/platform/administration/ai/schemas",web:"/platform/administration/ai/schemas",permissions:[],controller:"AiSchemas",methods:["GET","POST"]},"platform.administration.ai.settings":{navRoute:"platform.administration.ai.settings",api:"/api/platform/administration/ai/settings",web:"/platform/administration/ai/settings",permissions:[],controller:"AiSettings",methods:[]},"platform.administration.applications":{navRoute:"platform.administration.applications",api:"/api/platform/administration/applications",web:"/platform/administration/applications",permissions:[],controller:"Applications",methods:["GET"]},"platform.administration.applications.application-analytics":{navRoute:"platform.administration.applications.application-analytics",api:"/api/platform/administration/applications/application-analytics",web:"/platform/administration/applications/application-analytics",permissions:[],controller:"ApplicationAnalytics",methods:[]},"platform.administration.communications.email-templates":{navRoute:"platform.administration.communications.email-templates",api:"/api/platform/administration/communications/email-templates",web:"/platform/administration/communications/email-templates",permissions:[],controller:"EmailTemplates",methods:["GET","POST"]},"platform.administration.communications.workflows":{navRoute:"platform.administration.communications.workflows",api:"/api/platform/administration/communications/workflows",web:"/platform/administration/communications/workflows",permissions:[],controller:"Workflows",methods:["GET","POST"]},"platform.administration.entra":{navRoute:"platform.administration.entra",api:"/api/platform/administration/entra",web:"/platform/administration/entra",permissions:[],controller:"Entra",methods:[]},"platform.administration.license":{navRoute:"platform.administration.license",api:"/api/platform/administration/license",web:"/platform/administration/license",permissions:[],controller:"License",methods:["GET"]},"platform.administration.permissions":{navRoute:"platform.administration.permissions",api:"/api/platform/administration/permissions",web:"/platform/administration/permissions",permissions:[],controller:"Permissions",methods:["GET","POST"]},"platform.administration.roles":{navRoute:"platform.administration.roles",api:"/api/platform/administration/roles",web:"/platform/administration/roles",permissions:[],controller:"Roles",methods:["GET","POST"]},"platform.administration.settings":{navRoute:"platform.administration.settings",api:"/api/platform/administration/settings",web:"/platform/administration/settings",permissions:[],controller:"Settings",methods:["GET"]},"platform.administration.users":{navRoute:"platform.administration.users",api:"/api/platform/administration/users",web:"/platform/administration/users",permissions:[],controller:"Users",methods:["GET","POST"]},"platform.administration.users.dashboard":{navRoute:"platform.administration.users.dashboard",api:"/api/platform/administration/users/dashboard",web:"/platform/administration/users/dashboard",permissions:[],controller:"UserDashboard",methods:[]},"platform.support.dashboard":{navRoute:"platform.support.dashboard",api:"/api/platform/support/dashboard",web:"/platform/support/dashboard",permissions:[],controller:"Dashboard",methods:[]},"platform.support.notifications":{navRoute:"platform.support.notifications",api:"/api/platform/support/notifications",web:"/platform/support/notifications",permissions:[],controller:"Notifications",methods:["GET"]},"platform.support.sla":{navRoute:"platform.support.sla",api:"/api/platform/support/sla",web:"/platform/support/sla",permissions:[],controller:"Sla",methods:[]},"platform.support.templates":{navRoute:"platform.support.templates",api:"/api/platform/support/templates",web:"/platform/support/templates",permissions:[],controller:"Templates",methods:["GET","POST"]},"platform.support.tickets":{navRoute:"platform.support.tickets",api:"/api/platform/support/tickets",web:"/platform/support/tickets",permissions:[],controller:"Tickets",methods:["GET","POST"]},"platform.user.application-tracking":{navRoute:"platform.user.application-tracking",api:"/api/platform/user/application-tracking",web:"/platform/user/application-tracking",permissions:[],controller:"ApplicationTracking",methods:[]},"platform.user.dashboard":{navRoute:"platform.user.dashboard",api:"/api/platform/user/dashboard",web:"/platform/user/dashboard",permissions:[],controller:"Dashboard",methods:[]},"platform.user.preferences":{navRoute:"platform.user.preferences",api:"/api/user/preferences",web:"/platform/user/preferences",permissions:[],controller:"Preferences",methods:["GET"]}},Ol=l.createContext(void 0);function ql({children:s}){const[t,r]=l.useState(null),[n,i]=l.useState(!0),[o,c]=l.useState(null),x=l.useRef(null),u=l.useCallback(async h=>{try{i(!0),c(null);const v=await oe.get(Ka["platform.administration.license"].api,{signal:h});h?.aborted||r(v)}catch(v){if(v instanceof Error&&v.name==="CanceledError"||h?.aborted)return;c(v instanceof Error?v.message:"Failed to load license info"),console.error("Failed to fetch license:",v)}finally{h?.aborted||i(!1)}},[]);l.useEffect(()=>{x.current?.abort();const h=new AbortController;return x.current=h,u(h.signal),()=>h.abort()},[u]);const d=l.useCallback(h=>t?t.enabledFeatures.includes("*")?!0:t.enabledFeatures.some(v=>v.toLowerCase()===h.toLowerCase()):!1,[t]),m=l.useCallback(async()=>{x.current?.abort();const h=new AbortController;x.current=h,await u(h.signal)},[u]),p=l.useCallback(async h=>{try{const v=await oe.post(`${Ka["platform.administration.license"].api}/activate`,{licenseKey:h});return v.success?(await m(),{success:!0}):{success:!1,error:v.errorMessage||"Activation failed"}}catch(v){return{success:!1,error:v instanceof Error?v.message:"Activation failed"}}},[m]);return e.jsx(Ol.Provider,{value:{license:t,isLoading:n,error:o,isFeatureEnabled:d,isReadOnlyMode:t?.isReadOnlyMode??!1,refreshLicense:m,activateLicense:p},children:s})}function _t(){const s=l.useContext(Ol);if(s===void 0)throw new Error("useLicense must be used within a LicenseProvider");return s}const Vl=l.createContext(void 0),xs="currentTenantId",hs="currentTenantSlug",bs="isGlobalView";function $o({children:s}){const{isAuthenticated:t,user:r,refreshPermissions:n}=Ke(),{isSingleTenant:i,isLoading:o}=vt(),[c,x]=l.useState(null),[u,d]=l.useState([]),[m,p]=l.useState(!0),[h,v]=l.useState(null),[b,g]=l.useState(()=>localStorage.getItem(bs)==="true"),j=l.useRef(!1),w=l.useRef(""),f=u.filter(I=>I.type==="Business"),N=u.find(I=>I.type==="Personal")||null,k=l.useCallback(I=>{if(d(I),I.length===0){x(null),g(!1),localStorage.removeItem(xs),localStorage.removeItem(hs),localStorage.removeItem(bs),p(!1);return}const M=localStorage.getItem(xs),X=M?I.find($=>$.id===M):null;if(X&&X.status==="Active"){x(X),g(!1),localStorage.setItem(xs,X.id),localStorage.setItem(hs,X.slug),localStorage.removeItem(bs),p(!1);return}if(localStorage.getItem(bs)==="true"){g(!0),x(null),p(!1);return}const U=I.find($=>$.isDefault&&$.status==="Active");if(U){x(U),g(!1),localStorage.setItem(xs,U.id),localStorage.setItem(hs,U.slug),localStorage.removeItem(bs),p(!1);return}const K=I.find($=>$.status==="Active");x(K||null),K&&(localStorage.setItem(xs,K.id),localStorage.setItem(hs,K.slug)),p(!1)},[]),C=l.useCallback(async I=>{const M=u.find(X=>X.id===I);if(!M)throw new Error("Tenant not found");if(M.status!=="Active")throw new Error("Cannot switch to inactive tenant");g(!1),localStorage.removeItem(bs),x(M),localStorage.setItem(xs,I),localStorage.setItem(hs,M.slug)},[u]),y=l.useCallback(()=>{g(!0),localStorage.setItem(bs,"true"),x(null),localStorage.removeItem(xs),localStorage.removeItem(hs)},[]),A=l.useCallback(()=>{g(!1),localStorage.removeItem(bs);const I=u.find(O=>O.isDefault&&O.status==="Active"),M=u.find(O=>O.status==="Active"),X=I||M||null;X&&(x(X),localStorage.setItem(xs,X.id),localStorage.setItem(hs,X.slug))},[u]),D=l.useCallback(async I=>{console.log("[TenantContext] setDefaultTenant called with:",I);try{await le.myTenants.setDefault(I),console.log("[TenantContext] setDefault API call succeeded"),d(M=>{const X=M.map(O=>({...O,isDefault:O.id===I}));return console.log("[TenantContext] Updated userTenants:",X.map(O=>({id:O.id,name:O.name,isDefault:O.isDefault}))),X}),await C(I)}catch(M){throw console.error("[TenantContext] Failed to set default tenant:",M),M}},[C]),R=l.useCallback(async()=>{try{await le.myTenants.clearDefault(),d(I=>I.map(M=>({...M,isDefault:!1}))),y()}catch(I){throw console.error("[TenantContext] Failed to clear default tenant:",I),I}},[y]),L=l.useCallback(async()=>{p(!0),v(null);try{await n()}catch(I){console.error("Failed to refresh tenants:",I),v("Failed to refresh tenants")}finally{p(!1)}},[n]);l.useEffect(()=>{if(!t||!r){j.current&&(d([]),x(null),p(!1),j.current=!1,w.current="");return}const I=r.tenants||[];console.log("[TenantContext] user.tenants from AuthContext:",{count:I.length,tenants:I.map(X=>({id:X.id,name:X.name,type:X.type,isDefault:X.isDefault}))});const M=I.map(X=>`${X.id}:${X.status}:${X.isDefault}`).sort((X,O)=>X.localeCompare(O)).join(",");(!j.current||M!==w.current)&&(j.current=!0,w.current=M,k(I))},[t,r,k]),l.useEffect(()=>{t||(x(null),d([]),localStorage.removeItem(xs),localStorage.removeItem(hs))},[t]);const S=r?Ul(r.permissions||[],r.roles||[]):!1,T={currentTenant:c,userTenants:u,b2bTenants:f,personalTenant:N,isLoading:m||o,error:h,switchTenant:C,setDefaultTenant:D,clearDefaultTenant:R,refreshTenants:L,hasMultipleTenants:!i&&u.filter(I=>I.status==="Active").length>1,isCurrentTenantOwner:c?.isOwner??!1,hasGlobalRoles:S,isGlobalView:b,enterGlobalView:y,exitGlobalView:A};return e.jsx(Vl.Provider,{value:T,children:s})}function ze(){const s=l.useContext(Vl);if(s===void 0)throw new Error("useTenant must be used within a TenantProvider");return s}const Nt=5,zl=l.createContext(null);function Gl({children:s}){const{i18n:t}=ne.useTranslation(),{isAuthenticated:r}=Ke(),{currentTenant:n,isLoading:i}=ze(),[o,c]=l.useState([]),[x,u]=l.useState(!1),[d,m]=l.useState(null),[p,h]=l.useState(!1),v=l.useCallback(()=>{h(!0)},[]),b=l.useCallback(()=>{h(!1)},[]),g=l.useCallback(async()=>{try{u(!0),m(null);const D=(await oe.get("/api/navigation/module-favorites")).map(R=>({id:R.id,code:R.code,label:R.label,icon:R.icon||"Star",route:R.route||"",applicationId:R.applicationId,applicationCode:R.applicationCode,applicationLabel:R.applicationLabel,displayOrder:R.displayOrder}));c(D)}catch(A){console.error("Failed to load favorite modules:",A),m("Erreur lors du chargement des favoris"),c([])}finally{u(!1)}},[]);l.useEffect(()=>{r&&!i?g():r||(c([]),m(null))},[r,i,n,g]),l.useEffect(()=>{const A=()=>{r&&!i&&g()};return t.on("languageChanged",A),()=>{t.off("languageChanged",A)}},[t,r,i,g]);const j=l.useCallback(async A=>{if(o.length>=Nt||o.some(D=>D.id===A.id))return!1;try{return m(null),await oe.post(`/api/navigation/module-favorites/${A.id}`),c(D=>[...D,{...A,displayOrder:D.length+1}]),!0}catch(D){return console.error("Failed to add favorite module:",D),await g(),!1}},[o,g]),w=l.useCallback(async A=>{try{return m(null),await oe.delete(`/api/navigation/module-favorites/${A}`),c(D=>D.filter(R=>R.id!==A)),!0}catch(D){return console.error("Failed to remove favorite module:",D),await g(),!1}},[g]),f=l.useCallback(A=>o.some(D=>D.id===A),[o]),N=l.useCallback(async A=>f(A.id)?await w(A.id):await j(A),[f,w,j]),k=l.useCallback(async A=>{const D=A.slice(0,Nt),R=D.map(S=>S.id),L=[...o];c(D.map((S,T)=>({...S,displayOrder:T+1})));try{return m(null),await oe.put("/api/navigation/module-favorites/reorder",R),!0}catch(S){return console.error("Failed to reorder favorite modules:",S),c(L),!1}},[o]),C=o.length<Nt;return e.jsx(zl.Provider,{value:{favorites:o,loading:x,error:d,addFavorite:j,removeFavorite:w,toggleFavorite:N,isFavorite:f,reorderFavorites:k,canAddMore:C,maxFavorites:Nt,reload:g,expandFavorites:p,triggerExpand:v,clearExpand:b,requiresTenant:!1},children:s})}function rs(){const s=l.useContext(zl);if(!s)throw new Error("useFavorites must be used within a FavoritesProvider");return s}const Hl="smartstack-sidebar-collapsed",Kl=l.createContext(void 0);function Mo(){if(typeof window>"u")return!1;try{return localStorage.getItem(Hl)==="true"}catch{return!1}}function _l({children:s}){const[t,r]=l.useState(Mo);l.useEffect(()=>{localStorage.setItem(Hl,String(t))},[t]);const n=l.useCallback(()=>{r(c=>!c)},[]),i=l.useCallback(c=>{r(c)},[]),o=t?64:256;return e.jsx(Kl.Provider,{value:{isCollapsed:t,toggleCollapsed:n,setCollapsed:i,sidebarWidth:o},children:s})}function st(){const s=l.useContext(Kl);if(s===void 0)throw new Error("useSidebar must be used within a SidebarProvider");return s}const Wl=l.createContext(void 0);function Fo(s){let t=s.split("/").filter(Boolean);return t.length>=2&&t[0]==="t"&&(t=t.slice(2)),t.length===0?{context:null,app:null,module:null}:["login","callback","logout","onboarding","system"].includes(t[0])?{context:null,app:null,module:null}:{context:t[0],app:t[1]||null,module:t[2]||null}}function cr({children:s}){const t=Q.useLocation(),{i18n:r}=ne.useTranslation(),{currentTenant:n,isLoading:i}=ze(),[o,c]=l.useState(null),[x,u]=l.useState([]),[d,m]=l.useState(!0),p=l.useRef(!1),h=l.useRef(void 0),v=l.useRef(!1),{context:b,app:g,module:j}=Fo(t.pathname),w=l.useCallback(async()=>{try{const T=await oe.get("/api/navigation/menu");c(T)}catch(T){console.error("Failed to fetch menu:",T)}},[]),f=l.useCallback(async()=>{try{const T=await oe.get("/api/navigation/favorites");u(T)}catch(T){console.error("Failed to fetch favorites:",T)}},[]),N=l.useCallback(async()=>{v.current||(v.current=!0,m(!0),await w(),n&&await f(),m(!1),v.current=!1)},[w,f,n]);l.useEffect(()=>{const T=localStorage.getItem("token"),I=n?.id;if(!(!T||i)&&!v.current){if(!p.current){p.current=!0,h.current=I,N();return}I!==h.current&&(h.current=I,N())}},[n?.id,i]),l.useEffect(()=>{const T=()=>{localStorage.getItem("token")&&N()};return r.on("languageChanged",T),()=>{r.off("languageChanged",T)}},[r,N]);const k=l.useCallback(T=>T.startsWith("core_")?T.slice(5):T.startsWith("ext_")?T.slice(4):T,[]),C=l.useCallback((T,I)=>T&&T.split("/").filter(Boolean)[I]||null,[]),y=l.useCallback(()=>o?.contexts.find(T=>k(T.code)===b),[o,b,k]),A=l.useCallback(()=>y()?.applications.find(I=>C(I.route,1)===g||k(I.code)===g),[y,g,C,k]),D=l.useCallback(()=>A()?.modules.find(I=>C(I.route,2)===j||k(I.code)===j),[A,j,C,k]),R=l.useCallback(T=>o?.contexts.find(M=>k(M.code)===T)?.applications||[],[o,k]),L=l.useCallback(T=>x.some(I=>I.id===T),[x]),S=l.useCallback(async T=>{try{L(T)?(await oe.delete(`/api/navigation/favorites/${T}`),u(I=>I.filter(M=>M.id!==T))):(await oe.post(`/api/navigation/favorites/${T}`,{}),await f())}catch(I){console.error("Failed to toggle favorite:",I)}},[L,f]);return e.jsx(Wl.Provider,{value:{menu:o,favorites:x,currentContextCode:b,currentAppCode:g,currentModuleCode:j,isLoading:d,getCurrentContext:y,getCurrentApplication:A,getCurrentModule:D,getApplicationsForContext:R,toggleFavorite:S,isFavorite:L,refreshMenu:N},children:s})}function Ze(){const s=l.useContext(Wl);if(s===void 0)throw new Error("useNavigation must be used within a NavigationProvider");return s}const Xl=l.createContext(null);function Ql({children:s}){const{isAuthenticated:t,refreshPermissions:r}=Ke(),{refreshMenu:n}=Ze(),i=l.useRef(null),[o,c]=l.useState(Me.HubConnectionState.Disconnected),x=l.useRef(new Set),u=l.useRef(new Set),d=l.useRef(!1),m=l.useCallback(async()=>{if(!d.current){d.current=!0;try{await Promise.all([r(),n()]),console.log("[SignalR] Permissions and menu refreshed")}catch(j){console.error("[SignalR] Failed to refresh permissions:",j)}finally{d.current=!1}}},[r,n]),p=l.useCallback(async()=>{const j=localStorage.getItem("token");if(!j){console.warn("[SignalR] No token available, skipping connection");return}if(!(i.current?.state===Me.HubConnectionState.Connected||i.current?.state===Me.HubConnectionState.Connecting))try{const w=new Me.HubConnectionBuilder().withUrl("/hubs/notifications",{accessTokenFactory:()=>j}).withAutomaticReconnect({nextRetryDelayInMilliseconds:f=>f.previousRetryCount===0?0:f.previousRetryCount===1?2e3:f.previousRetryCount===2?1e4:f.previousRetryCount<5?3e4:null}).configureLogging(Me.LogLevel.Warning).build();w.on("ReceiveNotification",f=>{x.current.forEach(N=>N(f))}),w.on("UnreadCountUpdate",f=>{u.current.forEach(N=>N(f))}),w.on("PermissionsChanged",m),w.onreconnecting(()=>{c(Me.HubConnectionState.Reconnecting)}),w.onreconnected(()=>{c(Me.HubConnectionState.Connected)}),w.onclose(()=>{c(Me.HubConnectionState.Disconnected)}),await w.start(),i.current=w,c(Me.HubConnectionState.Connected),console.log("[SignalR] Connected to notification hub")}catch(w){console.error("[SignalR] Failed to connect:",w),c(Me.HubConnectionState.Disconnected)}},[m]),h=l.useCallback(async()=>{if(i.current)try{await i.current.stop(),i.current=null,c(Me.HubConnectionState.Disconnected),console.log("[SignalR] Disconnected from notification hub")}catch(j){console.error("[SignalR] Failed to disconnect:",j)}},[]);l.useEffect(()=>(t?p():h(),()=>{h()}),[t,p,h]);const v=l.useCallback(j=>(x.current.add(j),()=>{x.current.delete(j)}),[]),b=l.useCallback(j=>(u.current.add(j),()=>{u.current.delete(j)}),[]),g={isConnected:o===Me.HubConnectionState.Connected,connectionState:o,onNotification:v,onUnreadCountUpdate:b};return e.jsx(Xl.Provider,{value:g,children:s})}function dr(){const s=l.useContext(Xl);if(!s)throw new Error("useSignalRContext must be used within a SignalRProvider");return s}const us={register:async s=>oe.post("/api/auth/register",s),confirmEmail:async s=>oe.post("/api/auth/confirm-email",{token:s}),resendConfirmation:async s=>oe.post("/api/auth/resend-confirmation",{email:s}),forgotPassword:async s=>oe.post("/api/auth/forgot-password",{email:s}),resetPassword:async(s,t)=>oe.post("/api/auth/reset-password",{token:s,newPassword:t}),login:async(s,t)=>{const r=await oe.post("/api/auth/login",{email:s,password:t});return r.token&&(localStorage.setItem("token",r.token),localStorage.setItem("refreshToken",r.refreshToken)),r},logout:async()=>{try{await oe.post("/api/auth/logout")}finally{localStorage.removeItem("token"),localStorage.removeItem("refreshToken"),localStorage.removeItem("user")}},changePassword:async(s,t)=>oe.post("/api/auth/change-password",{currentPassword:s,newPassword:t}),refreshSession:async()=>{const s=await oe.post("/api/auth/refresh");return s.token&&(localStorage.setItem("token",s.token),localStorage.setItem("refreshToken",s.refreshToken)),s},getSessionInfo:async s=>oe.get("/api/auth/session-info",{signal:s?.signal})};function Jl(s={}){const{checkIntervalMs:t=6e4,onSessionExpired:r,onWarningThreshold:n,enabled:i=!0}=s,[o,c]=l.useState({isActive:!0,timeRemainingSeconds:0,isWarning:!1,sessionInfo:null}),[x,u]=l.useState(!1),d=l.useRef(!1),m=l.useRef(null),p=l.useRef(null),h=l.useCallback(async b=>{if(!i)return;if(!localStorage.getItem("token")){c(j=>({...j,isActive:!1}));return}try{const j=await us.getSessionInfo({signal:b});if(b?.aborted)return;const w=Math.min(j.timeUntilIdleExpirySeconds,j.timeUntilAbsoluteExpirySeconds);c({isActive:!0,timeRemainingSeconds:w,isWarning:j.isWarningThreshold,sessionInfo:j}),j.isWarningThreshold&&!d.current&&(d.current=!0,n?.()),j.isWarningThreshold||(d.current=!1)}catch(j){if(j instanceof Error&&j.name==="CanceledError"||b?.aborted)return;c(w=>({...w,isActive:!1})),r?.()}},[i,r,n]),v=l.useCallback(async()=>{if(x)return!1;u(!0);try{return await us.refreshSession(),d.current=!1,await h(),!0}catch{return c(b=>({...b,isActive:!1})),!1}finally{u(!1)}},[x,h]);return l.useEffect(()=>{if(!i)return;p.current?.abort();const b=new AbortController;return p.current=b,h(b.signal),m.current=setInterval(()=>h(),t),()=>{b.abort(),m.current&&clearInterval(m.current)}},[i,t,h]),l.useEffect(()=>{if(!i)return;const b=()=>{o.isWarning&&h()},g=["mousedown","keydown","touchstart","scroll"];return g.forEach(j=>{window.addEventListener(j,b,{passive:!0})}),()=>{g.forEach(j=>{window.removeEventListener(j,b)})}},[i,o.isWarning,h]),{...o,isRefreshing:x,refreshSession:v,checkSession:h}}function Uo(s){if(s<=0)return"0:00";const t=Math.floor(s/60),r=s%60;if(t>=60){const n=Math.floor(t/60),i=t%60;return`${n}h ${i}min`}return`${t}:${r.toString().padStart(2,"0")}`}function Yl({isOpen:s,timeRemainingSeconds:t,onExtendSession:r,onLogout:n}){const{t:i}=ne.useTranslation("common"),[o,c]=l.useState(!1),[x,u]=l.useState(t);l.useEffect(()=>{u(t)},[t]),l.useEffect(()=>{if(!s||x<=0)return;const p=setInterval(()=>{u(h=>h<=1?(n(),0):h-1)},1e3);return()=>clearInterval(p)},[s,x,n]);const d=async()=>{c(!0);try{await r()||n()}finally{c(!1)}};if(!s)return null;const m=Math.max(0,Math.min(100,x/300*100));return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm",children:e.jsxs("div",{className:"relative w-full max-w-md bg-[var(--bg-card)] rounded-2xl shadow-2xl border border-amber-500/30 overflow-hidden animate-in fade-in zoom-in duration-200",children:[e.jsx("div",{className:"absolute top-0 left-0 h-1 bg-amber-500/30 w-full",children:e.jsx("div",{className:"h-full bg-gradient-to-r from-amber-500 to-orange-500 transition-all duration-1000 ease-linear",style:{width:`${m}%`}})}),e.jsxs("div",{className:"p-6 pt-8",children:[e.jsxs("div",{className:"flex flex-col items-center text-center mb-6",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-amber-500/20 flex items-center justify-center mb-4",children:e.jsx(a.Clock,{className:"w-8 h-8 text-amber-500"})}),e.jsx("h2",{className:"text-xl font-semibold text-[var(--text-primary)] mb-2",children:i("session.warningTitle","Session Expiring")}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:i("session.warningMessage","Your session will expire due to inactivity.")}),e.jsx("div",{className:"text-4xl font-mono font-bold text-amber-500 tabular-nums",children:Uo(x)}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] mt-2",children:i("session.remainingTime","remaining")})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs("button",{onClick:n,className:"flex-1 flex items-center justify-center gap-2 px-6 py-3 rounded-xl border border-[var(--border-color)] text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] transition-all font-medium",children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),i("session.logout","Logout")]}),e.jsxs("button",{onClick:d,disabled:o,className:"flex-1 flex items-center justify-center gap-2 px-6 py-3 rounded-xl font-medium transition-all bg-gradient-to-r from-amber-500 to-orange-500 text-white hover:from-amber-600 hover:to-orange-600 shadow-lg shadow-amber-500/30 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(a.RefreshCw,{className:`w-4 h-4 ${o?"animate-spin":""}`}),o?i("session.extending","Extending..."):i("session.extend","Continue Session")]})]})]})]})})}const Bo=l.createContext(void 0);function Zl({children:s}){const{isAuthenticated:t,logout:r}=Ke(),n=l.useCallback(()=>{localStorage.removeItem("token"),localStorage.removeItem("refreshToken"),localStorage.removeItem("user"),window.location.href="/login?reason=session_expired"},[]),{isActive:i,timeRemainingSeconds:o,isWarning:c,refreshSession:x}=Jl({enabled:t,checkIntervalMs:3e4,onSessionExpired:n}),u=l.useCallback(async()=>{try{await us.logout()}finally{r()}},[r]),d=l.useCallback(async()=>await x(),[x]);return e.jsxs(Bo.Provider,{value:{isSessionActive:i,timeRemainingSeconds:o,isWarning:c,refreshSession:x},children:[s,e.jsx(Yl,{isOpen:c&&t,timeRemainingSeconds:o,onExtendSession:d,onLogout:u})]})}const Oo=150;function qo({children:s}){const t=Po(),r=t?.isAuthenticated??!1,n=t?.isLoading??!0,{currentTenant:i,isLoading:o,isGlobalView:c}=ze(),{setSelectedThemeTenant:x,selectedThemeTenant:u,loadFromServer:d}=et(),m=l.useRef(null),p=l.useRef(!1),h=l.useRef(null),v=l.useRef(null),b=l.useCallback(()=>{h.current&&(clearTimeout(h.current),h.current=null)},[]),g=l.useCallback(()=>m.current==="global"?!1:(b(),console.log("[ThemeSync] Cancelling pending theme load - entering global view"),v.current=null,console.log("[ThemeSync] Entering global view, loading global preferences"),m.current="global",p.current=!0,d("global"),x(null,!0),!0),[b,d,x]),j=l.useCallback((N,k)=>{v.current=N,console.log("[ThemeSync] Tenant changed, waiting for stabilization:",k),h.current=setTimeout(()=>{v.current===N?(console.log("[ThemeSync] Tenant stabilized, loading preferences for:",k),m.current=N,p.current=!0,v.current=null,x(N,!1)):console.log("[ThemeSync] Tenant changed during stabilization, skipping load for:",k),h.current=null},Oo)},[x]),w=l.useCallback(()=>{if(!i)return;const N=i.id!==m.current,k=v.current!==null&&v.current!==i.id;!N&&!k||(b(),console.log("[ThemeSync] Cancelling pending theme load for:",v.current),N?j(i.id,i.slug):(console.log("[ThemeSync] User switched back to original tenant, cancelling pending load"),v.current=null))},[i,b,j]),f=l.useCallback(()=>{console.log("[ThemeSync] User logged out, resetting tenant tracking"),b(),m.current=null,v.current=null,p.current=!1},[b]);return l.useEffect(()=>{if(console.log("[ThemeSync] State changed:",{isAuthenticated:r,authLoading:n,tenantLoading:o,hasTenant:!!i,currentTenantId:i?.id,isGlobalView:c,lastTenantId:m.current,pendingTenantId:v.current,hasInitialLoad:p.current,selectedThemeTenant:u}),!r){f();return}if(!(n||o)){if(c&&!i){g();return}i&&w()}},[r,n,o,i,c,g,w,f]),l.useEffect(()=>()=>{b()},[b]),e.jsx(e.Fragment,{children:s})}function Vo(s){const t=s.message.toLowerCase(),r=s.name.toLowerCase();return t.includes("network")||t.includes("fetch")||t.includes("failed to fetch")||t.includes("econnrefused")||t.includes("timeout")?"network":t.includes("401")||t.includes("403")||t.includes("unauthorized")||t.includes("forbidden")||t.includes("permission")?"permission":t.includes("404")||t.includes("not found")?"notFound":r.includes("validation")||t.includes("validation")||t.includes("invalid")?"validation":"technical"}function zo(){const s=Date.now().toString(36),t=Math.random().toString(36).substring(2,6);return`ERR-${s}-${t}`.toUpperCase()}const Go={network:{icon:a.WifiOff,color:"text-orange-500",bgColor:"bg-orange-500/10"},permission:{icon:a.ShieldX,color:"text-red-500",bgColor:"bg-red-500/10"},notFound:{icon:a.FileWarning,color:"text-yellow-500",bgColor:"bg-yellow-500/10"},validation:{icon:a.AlertTriangle,color:"text-amber-500",bgColor:"bg-amber-500/10"},technical:{icon:a.Bug,color:"text-red-500",bgColor:"bg-red-500/10"}};function ei({error:s,resetErrorBoundary:t}){const{t:r}=ne.useTranslation("common"),[n,i]=l.useState(!1),[o]=l.useState(()=>zo()),c=Vo(s),x=Go[c],u=x.icon,d=()=>{window.history.length>2&&document.referrer?window.location.href=document.referrer:window.history.length>2?(window.history.back(),setTimeout(()=>window.location.reload(),50)):window.location.href="/"};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)] p-4",children:e.jsx("div",{className:"max-w-lg w-full p-8 bg-[var(--bg-card)] border border-[var(--border-color)] rounded-2xl shadow-xl",children:e.jsxs("div",{className:"flex flex-col items-center text-center",children:[e.jsx("div",{className:`w-16 h-16 rounded-full ${x.bgColor} flex items-center justify-center mb-6`,children:e.jsx(u,{className:`w-8 h-8 ${x.color}`})}),e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)] mb-2",children:r(`errors.${c}.title`,r("errors.technical.title"))}),e.jsx("p",{className:"text-[var(--text-secondary)] mb-4",children:r(`errors.${c}.description`,r("errors.technical.description"))}),e.jsxs("div",{className:"mb-6 px-3 py-1.5 bg-[var(--bg-tertiary)] rounded-lg border border-[var(--border-color)]",children:[e.jsxs("span",{className:"text-xs text-[var(--text-tertiary)]",children:[r("errors.errorId"),": "]}),e.jsx("span",{className:"text-xs font-mono text-[var(--text-secondary)]",children:o})]}),!1,e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 w-full",children:[e.jsxs("button",{onClick:t,className:"flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[var(--color-accent-600)] hover:bg-[var(--color-accent-700)] text-white font-medium transition-all",children:[e.jsx(a.RefreshCw,{className:"w-4 h-4"}),r("errors.retry")]}),e.jsxs("button",{onClick:d,className:"flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] border border-[var(--border-color)] text-[var(--text-primary)] font-medium transition-all",children:[e.jsx(a.ArrowLeft,{className:"w-4 h-4"}),r("errors.goBack")]}),e.jsxs("a",{href:"/",className:"flex-1 flex items-center justify-center gap-2 py-3 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-hover)] border border-[var(--border-color)] text-[var(--text-primary)] font-medium transition-all",children:[e.jsx(a.Home,{className:"w-4 h-4"}),r("errors.home")]})]}),e.jsxs("p",{className:"mt-6 text-sm text-[var(--text-tertiary)]",children:[r("errors.persistsHelp")," ",e.jsx("a",{href:"mailto:support@smartstack.app",className:"text-[var(--color-accent-500)] hover:underline",children:r("errors.contactSupport")})]})]})})})}function Ho(s,t){qe.logCritical(s,"GlobalErrorBoundary",{componentStack:t.componentStack})}function Ko(){window.location.reload()}function si({children:s}){return e.jsx(Rl.ErrorBoundary,{FallbackComponent:ei,onError:Ho,onReset:Ko,children:s})}const mr=Ka["platform.user.application-tracking"].api,_o="00000000-0000-0000-0000-000000000000",Rr=s=>!!s&&s!==_o,ti=s=>{const t=s.match(/^\/t\/[^/]+(\/.*)$/);return t?t[1]:s},Wo=s=>{const t=ti(s);return t.startsWith("/platform/")||t.startsWith("/personal/")||t.startsWith("/business/")},ai=(s,t)=>{if(!s||typeof s!="object"||!("status"in s))return!0;const r=s.status;return!t.includes(r??-1)},Xo=async(s,t)=>{const r=new Date,n=Math.floor((r.getTime()-t.getTime())/1e3);try{await oe.post(`${mr}/end`,{accessId:s,endedAt:r.toISOString(),durationSeconds:n})}catch(i){ai(i,[401,408])&&console.error("Failed to end page tracking:",i)}},Qo=async s=>{const t=new Date;try{return(await oe.post(`${mr}/start`,{route:s,accessedAt:t.toISOString()})).accessId}catch(r){return ai(r,[401])&&console.error("Failed to track page access:",r),null}},Jo=(s,t)=>{const r=localStorage.getItem("token");if(!r)return;const n=new Date,i=Math.floor((n.getTime()-t.getTime())/1e3);fetch(`${mr}/end`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r}`},body:JSON.stringify({accessId:s,endedAt:n.toISOString(),durationSeconds:i}),keepalive:!0}).catch(()=>{})};function ri(){const s=Q.useLocation(),t=l.useRef(new Date),r=l.useRef(null),n=l.useRef(!1);l.useEffect(()=>n.current?void 0:((async()=>{const o=ti(s.pathname);Wo(o)&&(n.current=!0,Rr(r.current)&&await Xo(r.current,t.current),t.current=new Date,r.current=await Qo(o),n.current=!1)})(),()=>{Rr(r.current)&&Jo(r.current,t.current)}),[s.pathname])}function Yo(){return ri(),null}function Zo(){return Q.useInRouterContext()?e.jsx(Yo,{}):null}const ot="/api/platform/administration/tenants/tenant-analytics",bt={getDashboardStats:async(s=30)=>await oe.get(`${ot}/dashboard`,{params:{period:s}}),getTopTenants:async(s=10,t=30,r="access")=>await oe.get(`${ot}/top-tenants`,{params:{limit:s,period:t,sortBy:r}}),getTrends:async(s=30)=>await oe.get(`${ot}/trends`,{params:{period:s}}),trackStart:async s=>await oe.post(`${ot}/track/start`,{tenantId:s}),trackEnd:async s=>{await oe.post(`${ot}/track/end`,{accessId:s})}},ec="/api/platform/administration/tenants/tenant-analytics";function sc(){const{currentTenant:s}=ze(),{isAuthenticated:t}=Ke(),r=l.useRef(null),n=l.useRef(null),i=l.useRef(!1);l.useEffect(()=>{if(!t)return;const o=window.location.pathname;if(o.startsWith("/auth/")||o.startsWith("/login"))return;const c=s?.id??null;return c===n.current||i.current?void 0:(i.current=!0,(async()=>{if(r.current){try{await bt.trackEnd(r.current)}catch{}r.current=null}if(n.current=c,c)try{const u=await bt.trackStart(c);r.current=u.accessId}catch{r.current=null}i.current=!1})(),()=>{if(r.current){const u=localStorage.getItem("token");if(!u)return;fetch(`${ec}/track/end`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify({accessId:r.current}),keepalive:!0}).catch(()=>{}),r.current=null,n.current=null}})},[s?.id,t])}function tc(){return sc(),null}const Wt=l.createContext(null);function ni(){const s=l.useContext(Wt);if(!s)throw new Error("useSlotFill must be used within a SlotFillProvider");return s}function li({children:s,initialFills:t}){const r=l.useMemo(()=>{const i=new Map;return t&&Object.entries(t).forEach(([o,c])=>{const x=i.get(o)||[];Array.isArray(c)?i.set(o,[...x,...c]):i.set(o,[...x,c])}),i},[t]),n=l.useMemo(()=>({fills:r,registerFill:(i,o)=>{const c=r.get(i)||[];r.set(i,[...c,o])},unregisterFill:(i,o)=>{const c=r.get(i)||[];r.set(i,c.filter(x=>x!==o))},getSlotContent:i=>r.get(i)||[]}),[r]);return e.jsx(Wt.Provider,{value:n,children:s})}function ls({name:s,context:t={},children:r,fallback:n,wrapper:i}){const c=l.useContext(Wt)?.getSlotContent(s)||[],x=l.useMemo(()=>({slotName:s,context:t}),[s,t]),u=l.useMemo(()=>c.length===0?n||null:c.map((m,p)=>{const h=`${s}-${p}`;return e.jsx(l.Fragment,{children:oi(m,x)},h)}),[c,s,x,n]),d=e.jsxs(e.Fragment,{children:[u,r]});return i?e.jsx(i,{children:d}):e.jsx(e.Fragment,{children:d})}function ii({slot:s,children:t}){const{registerFill:r,unregisterFill:n}=ni();return l.useMemo(()=>(r(s,t),()=>n(s,t)),[s,t,r,n]),null}function oi(s,t){if(s==null)return null;if(Array.isArray(s))return e.jsx(e.Fragment,{children:s.map((r,n)=>e.jsx(l.Fragment,{children:oi(r,t)},`slot-item-${n}`))});if(l.isValidElement(s))return s;if(typeof s=="function"){const r=s;return e.jsx(r,{...t})}return s}function ac(s){return(l.useContext(Wt)?.getSlotContent(s)?.length||0)>0}function rc(s){function t(n){return e.jsx(ls,{...n,name:s})}t.displayName=`Slot(${s})`;function r({children:n}){return e.jsx(ii,{slot:s,children:n})}return r.displayName=`Fill(${s})`,{Slot:t,Fill:r,slotName:s}}const ci=l.createContext(null);function gt(){const s=l.useContext(ci);return s||{config:{},getPage:()=>{},getSlotContent:()=>{},getTableColumns:()=>[],getFormFields:()=>[],hasExtension:()=>!1}}function Xt(s){const{getPage:t}=gt();return t(s)}function di(s){const{getTableColumns:t}=gt();return t(s)}function nc(s){const{getFormFields:t}=gt();return t(s)}function lc(s){const{hasExtension:t}=gt();return t(s)}function mi({config:s={},children:t}){const r=l.useMemo(()=>{const{pages:n={},slots:i={},tableColumns:o={},formFields:c={}}=s;return{config:s,getPage:x=>n[x],getSlotContent:x=>i[x],getTableColumns:x=>o[x]||[],getFormFields:x=>c[x]||[],hasExtension:x=>x in n||x in i||x in o||x in c}},[s]);return e.jsx(ci.Provider,{value:r,children:e.jsx(li,{initialFills:s.slots,children:t})})}const ic=l.createContext(null);function oc({config:s,children:t}){typeof window<"u"&&(window.__SMARTSTACK_CONFIG__=s);const r=l.useMemo(()=>({config:s}),[s]);return e.jsx(ic.Provider,{value:r,children:e.jsx(si,{children:e.jsx(mi,{config:s.extensions,children:e.jsx($l,{children:e.jsx(Lo,{children:e.jsx(Bl,{children:e.jsx(ql,{children:e.jsx($o,{children:e.jsx(cr,{children:e.jsx(Ql,{children:e.jsx(Gl,{children:e.jsx(_l,{children:e.jsx(Zl,{children:e.jsxs(qo,{children:[e.jsx(Zo,{}),e.jsx(tc,{}),t]})})})})})})})})})})})})})})}function da({to:s,replace:t=!0}){const{slug:r}=Q.useParams(),n=r?`/t/${r}${s}`:s;return e.jsx(Q.Navigate,{to:n,replace:t})}function ms(){const{mode:s,toggleMode:t}=et(),n=(s==="dark"?"dark":"light")==="light";return e.jsx("button",{onClick:t,className:"relative p-2 bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-all duration-300 group",style:{borderRadius:"var(--radius-button)"},"aria-label":`Basculer vers le mode ${n?"sombre":"clair"}`,children:e.jsxs("div",{className:"relative w-6 h-6",children:[e.jsx(a.Sun,{className:`absolute inset-0 w-6 h-6 text-amber-500 transition-all duration-300 ${n?"opacity-100 rotate-0 scale-100":"opacity-0 rotate-90 scale-0"}`}),e.jsx(a.Moon,{className:`absolute inset-0 w-6 h-6 text-[var(--color-accent-400)] transition-all duration-300 ${n?"opacity-0 -rotate-90 scale-0":"opacity-100 rotate-0 scale-100"}`})]})})}const ma=[{code:"en",label:"English",short:"EN"},{code:"fr",label:"Français",short:"FR"},{code:"de",label:"Deutsch",short:"DE"},{code:"it",label:"Italiano",short:"IT"}];function tt(){const{i18n:s}=ne.useTranslation(),{isAuthenticated:t}=Ke(),[r,n]=l.useState(!1),i=l.useRef(null),o=s.language?.split("-")[0]||"en",c=ma.find(u=>u.code===o)||ma[0],x=async u=>{if(await ir(u),document.documentElement.lang=u,n(!1),t)try{await Is.preferences.updateLanguage({language:u})}catch(d){console.warn("Failed to save language preference to server",d)}};return l.useEffect(()=>{const u=d=>{i.current&&!i.current.contains(d.target)&&n(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]),e.jsxs("div",{ref:i,className:"relative",children:[e.jsx("button",{onClick:()=>n(!r),className:"relative p-2 bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-all duration-300",style:{borderRadius:"var(--radius-button)"},"aria-label":"Change language",children:e.jsx("span",{className:"flex items-center justify-center w-6 h-6 text-xs font-bold text-[var(--text-secondary)]",children:c.short})}),r&&e.jsx("div",{className:"absolute right-0 mt-2 py-1 bg-[var(--bg-tertiary)] border border-[var(--border-color)] shadow-lg shadow-[var(--shadow-color)] z-50 overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:ma.map(u=>{const d=u.code===o;return e.jsxs("button",{onClick:()=>x(u.code),className:`w-full flex items-center gap-3 px-4 py-2.5 text-left transition-colors whitespace-nowrap ${d?"bg-primary-600/10 text-primary-500":"text-[var(--text-secondary)] hover:bg-[var(--bg-secondary)] hover:text-[var(--text-primary)]"}`,children:[e.jsx("span",{className:"text-xs font-bold w-6",children:u.short}),e.jsx("span",{className:"text-sm font-medium",children:u.label}),d&&e.jsx(a.Check,{className:"w-4 h-4 ml-auto text-primary-500"})]},u.code)})})]})}function xi(s,t){if(!t.useUrlRouting||!t.slug)return pt(s);if(s.startsWith(`/t/${t.slug}`))return s;const r=pt(s);return`/t/${t.slug}${r}`}function Ir(s){const t=s.match(/^\/t\/([^/]+)/);return t?t[1]:null}function pt(s){return s.replace(/^\/t\/[^/]+/,"")||"/"}function ws(){const{currentTenant:s}=ze(),{useUrlRouting:t}=vt();return l.useCallback(r=>xi(r,{slug:s?.slug,useUrlRouting:t}),[s?.slug,t])}const cc={personal:a.User,platform:a.Shield,business:a.Briefcase};function dc(s){return s.startsWith("core_")?s.slice(5):s.startsWith("ext_")?s.slice(4):s}function mc({name:s,className:t}){const n=es[s];return n?e.jsx(n,{className:t}):e.jsx(a.Star,{className:t})}const Er={background:"linear-gradient(to bottom right, var(--color-accent-500), var(--color-accent-600))"},xc={personal:{background:"linear-gradient(to bottom right, var(--color-accent-500), var(--color-accent-600))"},platform:{background:"linear-gradient(to bottom right, rgb(245, 158, 11), rgb(217, 119, 6))"},business:{background:"linear-gradient(to bottom right, rgb(16, 185, 129), rgb(5, 150, 105))"}},Dr={personal:{bg:{backgroundColor:"var(--accent-bg)",borderColor:"var(--accent-border)"},textClass:"text-[var(--color-accent-600)] border"},platform:{bg:{backgroundColor:"rgb(245 158 11 / 0.1)",borderColor:"rgb(245 158 11 / 0.2)"},textClass:"text-amber-500 border"},business:{bg:{backgroundColor:"rgb(16 185 129 / 0.1)",borderColor:"rgb(16 185 129 / 0.2)"},textClass:"text-emerald-500 border"}};function uc(s){let t=s;if(s.startsWith("/t/")){const r=s.split("/").filter(Boolean);r.length>=3&&(t="/"+r.slice(2).join("/"))}return t.startsWith("/platform")?"platform":t.startsWith("/business")?"business":"personal"}function Qt(){const{t:s}=ne.useTranslation("navigation"),{user:t,logout:r}=Ke(),{menu:n,refreshMenu:i,getApplicationsForContext:o}=Ze(),{refreshTenants:c}=ze(),x=Q.useLocation(),u=Q.useNavigate(),d=ws(),[m,p]=l.useState(!1),[h,v]=l.useState(!1),b=l.useRef(null),g=async()=>{v(!0);try{await oe.post("/api/navigation/invalidate-cache"),await Promise.all([i(),c()])}catch(A){console.error("Failed to refresh cache:",A)}finally{v(!1),p(!1)}},j=uc(x.pathname),w=(n?.contexts||[]).map(A=>{const D=dc(A.code);return{code:D,label:A.label,icon:A.icon||"",route:A.route||`/${D}`,color:D==="platform"?"amber":D==="business"?"emerald":"primary"}}),N=o("personal").flatMap(A=>A.modules);l.useEffect(()=>{function A(D){b.current&&!b.current.contains(D.target)&&p(!1)}return document.addEventListener("mousedown",A),()=>document.removeEventListener("mousedown",A)},[]),l.useEffect(()=>{function A(D){D.key==="Escape"&&p(!1)}return document.addEventListener("keydown",A),()=>document.removeEventListener("keydown",A)},[]);const k=()=>{if(!t)return"?";const A=t.firstName?.[0]||"",D=t.lastName?.[0]||"";return(A+D).toUpperCase()||t.email[0].toUpperCase()},C=()=>t?t.firstName||t.lastName?`${t.firstName||""} ${t.lastName||""}`.trim():t.email.split("@")[0]:"",y=(A,D)=>{p(!1),D!==j&&u(d(A))};return e.jsxs("div",{ref:b,className:"relative",children:[e.jsxs("button",{onClick:()=>p(!m),className:"flex items-center gap-2 p-1.5 pr-3 bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-all duration-200 group",style:{borderRadius:"var(--radius-button)"},"aria-expanded":m,"aria-haspopup":"true",children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-white text-sm font-medium shadow-sm",style:Er,children:k()}),e.jsx(a.ChevronDown,{className:`w-4 h-4 text-[var(--text-tertiary)] transition-transform duration-200 ${m?"rotate-180":""}`})]}),e.jsx("div",{className:`absolute right-0 mt-2 w-72 origin-top-right transition-all duration-200 ease-out ${m?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"p-4 bg-gradient-to-br from-[var(--bg-secondary)] to-[var(--bg-tertiary)]",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 rounded-full flex items-center justify-center text-white text-lg font-semibold shadow-lg",style:Er,children:k()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-[var(--text-primary)] truncate",children:C()}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] truncate",children:t?.email})]})]})}),w.length>1&&e.jsxs("div",{className:"p-2 border-b border-[var(--border-color)]",children:[e.jsx("p",{className:"px-3 py-1.5 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider",children:s("avatarMenu.switchContext")}),e.jsx("div",{className:"space-y-1 mt-1",children:w.map(A=>{const D=cc[A.code]||a.User,R=A.code===j;return e.jsxs("button",{onClick:()=>y(A.route,A.code),className:`w-full flex items-center gap-3 px-3 py-2.5 transition-all duration-150 ${R?Dr[A.code].textClass:"hover:bg-[var(--bg-tertiary)]"}`,style:{borderRadius:"var(--radius-menu-item)",...R?Dr[A.code].bg:{}},children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center ${R?"text-white shadow-sm":"bg-[var(--bg-tertiary)] text-[var(--text-secondary)]"}`,style:R?xc[A.code]:{},children:e.jsx(D,{className:"w-4 h-4"})}),e.jsx("span",{className:`flex-1 text-left font-medium ${R?"":"text-[var(--text-primary)]"}`,children:A.label}),R&&e.jsx(a.Check,{className:"w-4 h-4"})]},A.code)})})]}),e.jsxs("div",{className:"p-2",children:[N.map(A=>e.jsxs(Q.Link,{to:d(A.route||"#"),onClick:()=>p(!1),className:"flex items-center gap-3 px-3 py-2.5 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-tertiary)] flex items-center justify-center text-[var(--text-secondary)]",children:A.icon?e.jsx(mc,{name:A.icon,className:"w-4 h-4"}):e.jsx(a.Star,{className:"w-4 h-4"})}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:A.label})]},A.id)),e.jsxs("button",{onClick:g,disabled:h,className:"w-full flex items-center gap-3 px-3 py-2.5 hover:bg-[var(--bg-tertiary)] transition-colors disabled:opacity-50",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-tertiary)] flex items-center justify-center text-[var(--text-secondary)]",children:e.jsx(a.RefreshCw,{className:`w-4 h-4 ${h?"animate-spin":""}`})}),e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:s("avatarMenu.refreshCache")})]})]}),e.jsx("div",{className:"p-2 border-t border-[var(--border-color)]",children:e.jsxs("button",{onClick:()=>{p(!1),r()},className:"w-full flex items-center gap-3 px-3 py-2.5 hover:bg-red-500/10 transition-colors group",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-[var(--bg-tertiary)] group-hover:bg-red-500/20 flex items-center justify-center text-[var(--text-secondary)] group-hover:text-red-500 transition-colors",children:e.jsx(a.LogOut,{className:"w-4 h-4"})}),e.jsx("span",{className:"font-medium text-[var(--text-primary)] group-hover:text-red-500 transition-colors",children:s("avatarMenu.logout")})]})})]})})]})}function xr(){const{t:s}=ne.useTranslation("navigation"),{isAuthenticated:t}=Ke(),[r,n]=l.useState(!1);return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("a",{href:"/",className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 rounded-xl animated-gradient flex items-center justify-center",children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[!1,e.jsx(tt,{}),e.jsx(ms,{}),t?e.jsx(Qt,{}):e.jsx("a",{href:"/login",className:"hidden md:inline-flex px-4 py-2 rounded-xl bg-primary-600 hover:bg-primary-700 text-white font-medium transition-colors",children:s("header.login")}),e.jsx("button",{onClick:()=>n(!r),className:"md:hidden p-2 rounded-lg hover:bg-[var(--bg-tertiary)] transition-colors",children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"md:hidden py-4 border-t border-[var(--border-color)]",children:e.jsx("div",{className:"flex flex-col gap-4",children:!t&&e.jsx("a",{href:"/login",className:"px-4 py-2 rounded-xl bg-primary-600 hover:bg-primary-700 text-white font-medium transition-colors text-center",children:s("header.login")})})})]})})}function ur(){const s=new Date().getFullYear();return e.jsx("footer",{className:"bg-[var(--bg-secondary)] border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-8",children:[e.jsxs("div",{className:"md:col-span-1",children:[e.jsxs("a",{href:"/",className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl animated-gradient flex items-center justify-center",children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsx("p",{className:"text-[var(--text-tertiary)] text-sm",children:"Le socle moderne pour vos applications d'entreprise."})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] mb-4",children:"Produit"}),e.jsxs("ul",{className:"space-y-2",children:[e.jsx("li",{children:e.jsx("a",{href:"#features",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Fonctionnalités"})}),e.jsx("li",{children:e.jsx("a",{href:"#modules",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Modules"})}),e.jsx("li",{children:e.jsx("a",{href:"#pricing",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Tarifs"})})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] mb-4",children:"Entreprise"}),e.jsxs("ul",{className:"space-y-2",children:[e.jsx("li",{children:e.jsx("a",{href:"#about",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"À propos"})}),e.jsx("li",{children:e.jsx("a",{href:"#contact",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Contact"})}),e.jsx("li",{children:e.jsx("a",{href:"#careers",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Carrières"})})]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold text-[var(--text-primary)] mb-4",children:"Légal"}),e.jsxs("ul",{className:"space-y-2",children:[e.jsx("li",{children:e.jsx("a",{href:"#privacy",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Confidentialité"})}),e.jsx("li",{children:e.jsx("a",{href:"#terms",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Conditions"})}),e.jsx("li",{children:e.jsx("a",{href:"#security",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] text-sm transition-colors",children:"Sécurité"})})]})]})]}),e.jsxs("div",{className:"mt-12 pt-8 border-t border-[var(--border-color)] flex flex-col sm:flex-row items-center justify-between gap-4",children:[e.jsxs("p",{className:"text-[var(--text-tertiary)] text-sm",children:["© ",s," SmartStack. Tous droits réservés."]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("a",{href:"https://github.com",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(a.Github,{className:"w-5 h-5"})}),e.jsx("a",{href:"https://twitter.com",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(a.Twitter,{className:"w-5 h-5"})}),e.jsx("a",{href:"https://linkedin.com",target:"_blank",rel:"noopener noreferrer",className:"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:e.jsx(a.Linkedin,{className:"w-5 h-5"})})]})]})]})})}function ui(){return e.jsx(cr,{children:e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)] flex flex-col",children:[e.jsx(xr,{}),e.jsx("main",{className:"flex-1 pt-16",children:e.jsx(Q.Outlet,{})}),e.jsx(ur,{})]})})}const pc={settings:a.Settings,users:a.Users,key:a.Key,briefcase:a.Briefcase,folder:a.FolderOpen,file:a.FileText,box:a.Box};function hc(s){return s&&pc[s.toLowerCase()]||a.Box}function Lr({app:s,isFavorite:t,onToggleFavorite:r,onSelect:n}){const i=hc(s.icon);return e.jsxs("div",{className:"group relative",children:[e.jsxs("button",{onClick:n,className:"w-full flex flex-col items-center gap-2 p-3 hover:bg-[var(--bg-tertiary)] transition-all duration-200",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-[var(--color-accent-500)]/20 to-[var(--color-accent-600)]/20 flex items-center justify-center group-hover:from-[var(--color-accent-500)]/30 group-hover:to-[var(--color-accent-600)]/30 transition-all",style:{borderRadius:"var(--radius-card)"},children:e.jsx(i,{className:"w-6 h-6 text-[var(--color-accent-500)]"})}),e.jsx("span",{className:"text-xs font-medium text-[var(--text-primary)] text-center line-clamp-2",children:s.label})]}),e.jsx("button",{onClick:o=>{o.stopPropagation(),r()},className:`absolute top-1 right-1 p-1.5 transition-all duration-200 ${t?"text-amber-500 bg-amber-500/10":"text-[var(--text-tertiary)] opacity-0 group-hover:opacity-100 hover:bg-[var(--bg-secondary)]"}`,style:{borderRadius:"var(--radius-button)"},title:t?"Retirer des favoris":"Ajouter aux favoris",children:e.jsx(a.Star,{className:`w-4 h-4 ${t?"fill-current":""}`})})]})}function pr(){const{t:s}=ne.useTranslation("navigation"),{favorites:t,getApplicationsForContext:r,currentContextCode:n,toggleFavorite:i,isFavorite:o}=Ze(),[c,x]=l.useState(!1),u=l.useRef(null),d=Q.useNavigate(),m=ws(),p=n?r(n):[];l.useEffect(()=>{function v(b){u.current&&!u.current.contains(b.target)&&x(!1)}return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]),l.useEffect(()=>{function v(b){b.key==="Escape"&&x(!1)}return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[]);const h=v=>{x(!1),v.route&&d(m(v.route))};return e.jsxs("div",{ref:u,className:"relative",children:[e.jsx("button",{onClick:()=>x(!c),className:"p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},"aria-expanded":c,"aria-haspopup":"true",title:s("appSwitcher.title","Applications"),children:e.jsx(a.LayoutGrid,{className:"w-5 h-5 text-[var(--text-secondary)]"})}),e.jsx("div",{className:`absolute right-0 mt-2 w-80 origin-top-right transition-all duration-200 ease-out ${c?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[t.length>0&&e.jsxs("div",{className:"p-3 border-b border-[var(--border-color)]",children:[e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-2",children:[e.jsx(a.Star,{className:"w-3 h-3 text-amber-500 fill-amber-500"}),s("appSwitcher.favorites","Favoris")]}),e.jsx("div",{className:"grid grid-cols-3 gap-1 mt-2",children:t.slice(0,6).map(v=>e.jsx(Lr,{app:v,isFavorite:!0,onToggleFavorite:()=>i(v.id),onSelect:()=>{x(!1),v.route&&d(m(v.route))}},v.id))})]}),e.jsxs("div",{className:"p-3",children:[e.jsx("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider",children:s("appSwitcher.allApps","Toutes les applications")}),p.length>0?e.jsx("div",{className:"grid grid-cols-3 gap-1 mt-2 max-h-64 overflow-y-auto",children:p.map(v=>e.jsx(Lr,{app:v,isFavorite:o(v.id),onToggleFavorite:()=>i(v.id),onSelect:()=>h(v)},v.id))}):e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] text-center py-6",children:s("appSwitcher.noApps","Aucune application disponible")})]})]})})]})}const bc={Pending:"bg-blue-500",Active:"bg-emerald-500",Suspended:"bg-amber-500",Archived:"bg-gray-400"},vc={Pending:"En attente",Active:"Actif",Suspended:"Suspendu",Archived:"Archivé"};function xa({tenant:s,isSelected:t,isFavorite:r,hasThemeOverride:n,onSelect:i,onToggleFavorite:o,showStatus:c=!0}){const x=s.type==="Business",u=s.status==="Active",d=(m,p)=>m?"bg-[var(--color-accent-500)]/10 text-[var(--color-accent-600)]":p?"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]";return e.jsxs("div",{className:"flex items-center group",children:[e.jsxs("button",{onClick:i,disabled:!u,className:`flex-1 flex items-center gap-3 px-3 py-2.5 text-left transition-all duration-150 ${d(t,u)}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:`flex-shrink-0 w-8 h-8 flex items-center justify-center ${x?"bg-blue-500/10":"bg-violet-500/10"}`,style:{borderRadius:"var(--radius-card)"},children:x?e.jsx(a.Building2,{className:"w-4 h-4 text-blue-500"}):e.jsx(a.User,{className:"w-4 h-4 text-violet-500"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:s.name}),n&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-[var(--color-accent-500)]",title:"Thème personnalisé"})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("span",{className:"text-xs text-[var(--text-tertiary)] truncate",children:s.organisationName||s.slug}),c&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${bc[s.status]}`}),s.status!=="Active"&&e.jsx("span",{className:"text-xs text-[var(--text-tertiary)]",children:vc[s.status]})]})]})]}),t&&e.jsx(a.Check,{className:"w-4 h-4 text-[var(--color-accent-500)] flex-shrink-0"})]}),o&&u&&e.jsx("button",{onClick:m=>{m.stopPropagation(),o()},className:`p-2 transition-colors ${r?"text-amber-500":"text-[var(--text-tertiary)] opacity-0 group-hover:opacity-100 hover:text-amber-500"}`,title:r?"Retirer des favoris":"Ajouter aux favoris",children:e.jsx(a.Star,{className:`w-4 h-4 ${r?"fill-amber-500":""}`})})]})}const pi="tenant_recents",_a=5;function hi(){try{return JSON.parse(localStorage.getItem(pi)||"[]")}catch{return[]}}function gc(s){const t=hi().filter(r=>r!==s);t.unshift(s),localStorage.setItem(pi,JSON.stringify(t.slice(0,_a)))}const fc=(s,t,r,n)=>{if(n)return;const i=o=>{s.current&&!s.current.contains(o.target)&&(t(!1),r(""))};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},jc=(s,t,r)=>{if(r)return;const n=i=>{i.key==="Escape"&&(s(!1),t(""))};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)};function hr(){const{t:s}=ne.useTranslation("navigation"),{refreshMenu:t}=Ze(),{isSingleTenant:r}=vt(),{currentTenant:n,userTenants:i,switchTenant:o,isLoading:c,hasMultipleTenants:x,hasGlobalRoles:u,isGlobalView:d,enterGlobalView:m}=ze(),{tenantOverrides:p,loadTenantOverrides:h}=et(),[v,b]=l.useState(!1),[g,j]=l.useState(""),[w,f]=l.useState([]),[N]=l.useState(()=>hi()),k=l.useRef(null),C=l.useRef(null);l.useEffect(()=>{v&&!r&&(le.myTenants.getFavorites().then(f).catch(console.error),h())},[v,r,h]),l.useEffect(()=>{v&&C.current&&!r&&setTimeout(()=>C.current?.focus(),100)},[v,r]),l.useEffect(()=>fc(k,b,j,r),[r]),l.useEffect(()=>jc(b,j,r),[r]);const y=l.useCallback(async M=>{if(M===n?.id&&!d){b(!1);return}try{gc(M),le.myTenants.recordRecent(M).catch(console.error),await o(M),b(!1),j(""),await t()}catch(X){console.error("Failed to switch tenant:",X)}},[n?.id,d,o,t]),A=l.useCallback(async()=>{m(),b(!1),j(""),await t()},[m,t]),D=l.useCallback(async M=>{const X=w.includes(M);try{if(X){const O=await le.myTenants.removeFavorite(M);f(O)}else{const O=await le.myTenants.addFavorite(M);f(O)}}catch(O){console.error("Failed to toggle favorite:",O)}},[w]),R=l.useMemo(()=>{if(!g.trim())return i;const M=g.toLowerCase();return i.filter(X=>X.name.toLowerCase().includes(M)||X.slug.toLowerCase().includes(M)||X.organisationName&&X.organisationName.toLowerCase().includes(M))},[i,g]),L=l.useMemo(()=>R.filter(M=>w.includes(M.id)&&M.status==="Active"),[R,w]),S=l.useMemo(()=>g.trim()?[]:N.map(M=>i.find(X=>X.id===M)).filter(M=>!!M&&M.status==="Active"&&!w.includes(M.id)).slice(0,_a),[N,i,w,g]),T=l.useMemo(()=>{const M=new Set([...w,...N.slice(0,_a)]);return R.filter(X=>!M.has(X.id))},[R,w,N]);if(r||c)return null;if(!(x||u)&&n){const M=n.type==="Business";return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-[var(--bg-secondary)] border border-[var(--border-color)]",style:{borderRadius:"var(--radius-button)"},children:[M?e.jsx(a.Building2,{className:"w-4 h-4 text-blue-500"}):e.jsx(a.User,{className:"w-4 h-4 text-violet-500"}),e.jsx("span",{className:"text-sm font-medium text-[var(--text-primary)]",children:n.name})]})}return e.jsxs("div",{ref:k,className:"relative",children:[e.jsxs("button",{onClick:()=>b(!v),className:`flex items-center gap-2 px-3 py-1.5 border transition-colors ${d?"bg-emerald-500/10 border-emerald-500/30 hover:bg-emerald-500/20":"bg-[var(--bg-secondary)] border-[var(--border-color)] hover:bg-[var(--bg-tertiary)]"}`,style:{borderRadius:"var(--radius-button)"},"aria-expanded":v,"aria-haspopup":"true",children:[d?e.jsxs(e.Fragment,{children:[e.jsx(a.Globe,{className:"w-4 h-4 text-emerald-600"}),e.jsx("span",{className:"text-sm font-medium text-emerald-700",children:s("tenants.selector.global","Global")})]}):n?e.jsxs(e.Fragment,{children:[n.type==="Business"?e.jsx(a.Building2,{className:"w-4 h-4 text-blue-500"}):e.jsx(a.User,{className:"w-4 h-4 text-violet-500"}),e.jsx("span",{className:"text-sm font-medium text-[var(--text-primary)] max-w-[120px] truncate",children:n.name})]}):e.jsxs(e.Fragment,{children:[e.jsx(a.Building2,{className:"w-4 h-4 text-[var(--text-secondary)]"}),e.jsx("span",{className:"text-sm font-medium text-[var(--text-secondary)]",children:s("tenants.selector.select","Select")})]}),e.jsx(a.ChevronDown,{className:`w-4 h-4 text-[var(--text-tertiary)] transition-transform ${v?"rotate-180":""}`})]}),e.jsx("div",{className:`absolute left-0 mt-2 w-80 origin-top-left transition-all duration-200 ease-out z-50 ${v?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-2 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"p-2 border-b border-[var(--border-color)]",children:e.jsxs("div",{className:"relative",children:[e.jsx(a.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("input",{ref:C,type:"text",value:g,onChange:M=>j(M.target.value),placeholder:s("tenants.selector.search","Rechercher..."),className:"w-full pl-9 pr-3 py-2 text-sm bg-[var(--bg-secondary)] border border-[var(--border-color)] focus:border-[var(--color-accent-500)] focus:outline-none",style:{borderRadius:"var(--radius-input)"}})]})}),e.jsxs("div",{className:"max-h-80 overflow-y-auto",children:[u&&!g&&e.jsx("div",{className:"p-2 border-b border-[var(--border-color)]",children:e.jsxs("button",{onClick:A,className:`w-full flex items-center gap-3 px-3 py-2.5 text-left transition-all duration-150 ${d?"bg-emerald-500/10 text-emerald-700":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 bg-emerald-500/10 flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Globe,{className:"w-4 h-4 text-emerald-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium",children:s("tenants.selector.global","Global")}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] mt-0.5",children:s("tenants.selector.globalDesc","Voir tous les tenants")})]}),d&&e.jsx(a.Check,{className:"w-4 h-4 text-emerald-600 flex-shrink-0"})]})}),L.length>0&&e.jsxs("div",{className:"p-2",children:[e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(a.Star,{className:"w-3 h-3 text-amber-500"}),s("tenants.selector.favorites","Favoris")]}),e.jsx("div",{className:"mt-1",children:L.map(M=>e.jsx(xa,{tenant:M,isSelected:!d&&n?.id===M.id,isFavorite:!0,hasThemeOverride:p.includes(M.id),onSelect:()=>y(M.id),onToggleFavorite:()=>D(M.id)},M.id))})]}),S.length>0&&e.jsxs("div",{className:`p-2 ${L.length>0?"border-t border-[var(--border-color)]":""}`,children:[e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(a.Clock,{className:"w-3 h-3"}),s("tenants.selector.recent","Récents")]}),e.jsx("div",{className:"mt-1",children:S.map(M=>e.jsx(xa,{tenant:M,isSelected:!d&&n?.id===M.id,isFavorite:w.includes(M.id),hasThemeOverride:p.includes(M.id),onSelect:()=>y(M.id),onToggleFavorite:()=>D(M.id)},M.id))})]}),T.length>0&&e.jsxs("div",{className:`p-2 ${L.length>0||S.length>0?"border-t border-[var(--border-color)]":""}`,children:[!g&&e.jsxs("p",{className:"px-2 py-1 text-xs font-medium text-[var(--text-tertiary)] uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(a.Building2,{className:"w-3 h-3"}),s("tenants.selector.all","Tous")]}),e.jsx("div",{className:"mt-1 max-h-40 overflow-y-auto",children:T.map(M=>e.jsx(xa,{tenant:M,isSelected:!d&&n?.id===M.id,isFavorite:w.includes(M.id),hasThemeOverride:p.includes(M.id),onSelect:()=>y(M.id),onToggleFavorite:()=>D(M.id)},M.id))})]}),g&&R.length===0&&e.jsx("div",{className:"p-4 text-center text-sm text-[var(--text-tertiary)]",children:s("tenants.selector.noResults","Aucun résultat")})]}),e.jsx("div",{className:"p-2 border-t border-[var(--border-color)]",children:e.jsxs(Q.Link,{to:"/personal/myspace/tenants",className:"flex items-center justify-center gap-2 px-3 py-2 text-sm text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},onClick:()=>b(!1),children:[e.jsx(a.Eye,{className:"w-4 h-4"}),s("tenants.selector.viewAll","Voir tous mes espaces")," (",i.length,")"]})})]})})]})}const Ts={getOverview:(s=30)=>oe.get("/api/platform/support/dashboard/overview",{params:{days:s}}),getByStatus:()=>oe.get("/api/platform/support/dashboard/by-status"),getByPriority:()=>oe.get("/api/platform/support/dashboard/by-priority"),getByType:(s=30)=>oe.get("/api/platform/support/dashboard/by-type",{params:{days:s}}),getAgentWorkload:()=>oe.get("/api/platform/support/dashboard/agent-workload"),getTrends:(s=30)=>oe.get("/api/platform/support/dashboard/trends",{params:{days:s}}),getSatisfactionStats:(s=30)=>oe.get("/api/platform/support/dashboard/satisfaction",{params:{days:s}}),getSlaCompliance:(s=30)=>oe.get("/api/platform/support/dashboard/sla-compliance",{params:{days:s}})},js={getConfigurations:()=>oe.get("/api/platform/support/sla/configurations"),updateConfiguration:(s,t)=>oe.put(`/api/platform/support/sla/configurations/${s}`,t),getEscalationRules:()=>oe.get("/api/platform/support/sla/escalation-rules"),getBreachedTickets:(s=!0,t=!0)=>oe.get("/api/platform/support/sla/breached",{params:{responseBreached:s,resolutionBreached:t}}),getTicketsApproachingBreach:(s=60)=>oe.get("/api/platform/support/sla/approaching-breach",{params:{warningMinutes:s}}),getMetrics:(s,t)=>oe.get("/api/platform/support/sla/metrics",{params:{fromDate:s,toDate:t}}),escalateTicket:(s,t,r)=>oe.post(`/api/platform/support/sla/tickets/${s}/escalate`,{level:t,reason:r})},ns={getAll:(s=1,t=20,r,n)=>oe.get("/api/platform/support/notifications",{params:{page:s,pageSize:t,isRead:r,tenantId:n}}),getUnread:(s=10)=>oe.get("/api/platform/support/notifications/unread",{params:{limit:s}}),getUnreadCount:()=>oe.get("/api/platform/support/notifications/unread/count"),markAsRead:s=>oe.patch(`/api/platform/support/notifications/${s}/read`),markAllAsRead:()=>oe.patch("/api/platform/support/notifications/read-all"),delete:s=>oe.delete(`/api/platform/support/notifications/${s}`),deleteAll:()=>oe.delete("/api/platform/support/notifications/all"),getPreferences:()=>oe.get("/api/platform/support/notifications/preferences"),updatePreferences:s=>oe.put("/api/platform/support/notifications/preferences",s)},As={getAll:(s,t=!0)=>oe.get("/api/platform/support/templates",{params:{category:s,activeOnly:t}}),getById:s=>oe.get(`/api/platform/support/templates/${s}`),getCategories:()=>oe.get("/api/platform/support/templates/categories"),getByCategory:s=>oe.get(`/api/platform/support/templates/by-category/${s}`),create:s=>oe.post("/api/platform/support/templates",s),update:(s,t)=>oe.put(`/api/platform/support/templates/${s}`,t),activate:s=>oe.patch(`/api/platform/support/templates/${s}/activate`),deactivate:s=>oe.patch(`/api/platform/support/templates/${s}/deactivate`),delete:s=>oe.delete(`/api/platform/support/templates/${s}`),render:(s,t)=>oe.post(`/api/platform/support/templates/${s}/render`,{variables:t})};function bi(s,t){return s?t===s?"current":"other":"global"}const gs={STARTED:"EntraSyncStarted",COMPLETED:"EntraSyncCompleted",FAILED:"EntraSyncFailed"};function yc(s,t,r){if(r){const i=t.relatedEntityId,o=s.filter(c=>!(c.type===gs.STARTED&&c.relatedEntityId===i));return[t,...o].slice(0,10)}return s.some(i=>i.id===t.id)?s:[t,...s].slice(0,10)}function Jt(){const s=Q.useNavigate(),{currentTenant:t,hasMultipleTenants:r}=ze(),[n,i]=l.useState(!1),[o,c]=l.useState(0),[x,u]=l.useState([]),[d,m]=l.useState(!1),p=l.useRef(null),{isConnected:h,onNotification:v,onUnreadCountUpdate:b}=dr(),[,g]=l.useState(0);l.useEffect(()=>{if(!x.some(T=>T.type===gs.STARTED&&!T.isRead))return;const S=setInterval(()=>{g(T=>T+1)},1e3);return()=>clearInterval(S)},[x]),l.useEffect(()=>{const L=v(T=>{const I={id:T.id,type:T.type,title:T.title,message:T.message,relatedEntityType:T.relatedEntityType,relatedEntityId:T.relatedEntityId,actionUrl:T.actionUrl,isRead:T.isRead,readAt:T.readAt,createdAt:T.createdAt,tenantId:T.tenantId,tenantName:T.tenantName,tenantSlug:T.tenantSlug},M=T.type===gs.COMPLETED||T.type===gs.FAILED;u(X=>yc(X,I,M))}),S=b(T=>{c(T)});return()=>{L(),S()}},[v,b]);const j=l.useCallback(async()=>{try{const L=await ns.getUnreadCount();c(L.count)}catch(L){console.error("Failed to load unread count:",L)}},[]),w=l.useCallback(async()=>{try{m(!0);const L=await ns.getUnread(10);u(L)}catch(L){console.error("Failed to load notifications:",L)}finally{m(!1)}},[]);l.useEffect(()=>{j()},[j]),l.useEffect(()=>{n&&w()},[n,w]),l.useEffect(()=>{const L=S=>{p.current&&!p.current.contains(S.target)&&i(!1)};return document.addEventListener("mousedown",L),()=>document.removeEventListener("mousedown",L)},[]);const f=async(L,S)=>{S.stopPropagation();try{await ns.markAsRead(L),u(T=>T.map(I=>I.id===L?{...I,isRead:!0}:I)),c(T=>Math.max(0,T-1))}catch(T){console.error("Failed to mark as read:",T)}},N=async()=>{try{await ns.markAllAsRead(),u(L=>L.map(S=>({...S,isRead:!0}))),c(0)}catch(L){console.error("Failed to mark all as read:",L)}},k=async(L,S)=>{S.stopPropagation();try{await ns.delete(L);const T=x.find(I=>I.id===L);u(I=>I.filter(M=>M.id!==L)),T&&!T.isRead&&c(I=>Math.max(0,I-1))}catch(T){console.error("Failed to delete notification:",T)}},C=L=>{L.isRead||(ns.markAsRead(L.id),c(S=>Math.max(0,S-1))),i(!1),L.actionUrl&&s(L.actionUrl)},y=L=>{switch(L){case"TicketCreated":return"🎫";case"TicketAssigned":return"👤";case"TicketStatusChanged":case"StatusChanged":return"🔄";case"TicketCommented":case"CommentAdded":return"💬";case"TicketResolved":return"✅";case"TicketClosed":return"🔒";case"TicketUpdated":return"📝";case"SlaResponseBreached":case"SlaResolutionBreached":return"⚠️";case"SlaWarning":return"⏰";case"TicketEscalated":return"📈";case"SatisfactionRequested":return"⭐";case"GroupMemberAdded":return"👥";case"GroupMemberRemoved":return"🚪";case"RoleAssigned":return"🎭";case"RoleRemoved":return"🚫";case"RolePermissionsChanged":return"🔑";case"AccountUpdated":return"👤";case"SystemAnnouncement":return"📢";case gs.STARTED:return null;case gs.COMPLETED:return"✅";case gs.FAILED:return"❌";default:return"📌"}},A=L=>{const S=new Date(L).getTime(),T=Date.now(),I=Math.floor((T-S)/1e3),M=Math.floor(I/60),X=I%60;return`${M.toString().padStart(2,"0")}:${X.toString().padStart(2,"0")}`},D=L=>{const S=new Date(L),I=new Date().getTime()-S.getTime(),M=Math.floor(I/6e4),X=Math.floor(M/60),O=Math.floor(X/24);return M<1?"Just now":M<60?`${M}m ago`:X<24?`${X}h ago`:O<7?`${O}d ago`:S.toLocaleDateString()},R=L=>{if(!r)return null;const S=bi(L.tenantId,t?.id??null);return S==="global"?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300 border border-purple-200 dark:border-purple-700",children:"System"}):S==="current"?e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-[var(--bg-secondary)] text-[var(--text-secondary)] border border-[var(--border-color)] truncate max-w-[120px]",children:L.tenantName}):e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 border border-blue-200 dark:border-blue-700 font-medium truncate max-w-[120px]",children:L.tenantName})};return e.jsxs("div",{className:"relative",ref:p,children:[e.jsxs("button",{onClick:()=>i(!n),className:"relative p-2 rounded-lg hover:bg-[var(--bg-hover)] transition-colors","aria-label":"Notifications",children:[e.jsx(a.Bell,{className:"w-5 h-5"}),o>0&&e.jsx("span",{className:"absolute -top-1 -right-1 w-5 h-5 bg-red-500 text-white text-xs font-bold rounded-full flex items-center justify-center",children:o>9?"9+":o})]}),n&&e.jsxs("div",{className:"absolute right-0 mt-2 w-96 bg-[var(--bg-primary)] rounded-lg shadow-xl border border-[var(--border-color)] z-50 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-[var(--border-color)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"font-semibold",children:"Notifications"}),h?e.jsx("span",{title:"Real-time connected",children:e.jsx(a.Wifi,{className:"w-3 h-3 text-green-500"})}):e.jsx("span",{title:"Offline mode",children:e.jsx(a.WifiOff,{className:"w-3 h-3 text-gray-400"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o>0&&e.jsxs("button",{onClick:N,className:"text-sm text-[var(--color-primary-600)] hover:underline flex items-center gap-1",children:[e.jsx(a.CheckCheck,{className:"w-4 h-4"}),"Mark all read"]}),e.jsx("button",{onClick:()=>i(!1),className:"p-1 rounded hover:bg-[var(--bg-hover)]",children:e.jsx(a.X,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"max-h-96 overflow-y-auto",children:d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(a.Loader2,{className:"w-6 h-6 animate-spin text-[var(--color-primary-600)]"})}):x.length>0?x.map(L=>{const S=L.type===gs.STARTED&&!L.isRead,T=y(L.type);return e.jsx("div",{onClick:()=>C(L),onKeyDown:I=>{(I.key==="Enter"||I.key===" ")&&C(L)},role:"button",tabIndex:0,className:`p-4 border-b border-[var(--border-color)] cursor-pointer hover:bg-[var(--bg-hover)] transition-colors ${L.isRead?"":"bg-blue-50/50 dark:bg-blue-900/10"} ${S?"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20":""}`,children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("span",{className:"text-xl flex-shrink-0",children:S?e.jsx(a.RefreshCw,{className:"w-5 h-5 text-[var(--color-accent-600)] animate-spin"}):T}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:`text-sm ${L.isRead?"":"font-semibold"}`,children:L.title}),R(L)]}),S?e.jsxs("span",{className:"text-xs font-mono font-bold text-[var(--color-accent-600)] flex-shrink-0 bg-[var(--color-accent-100)] px-2 py-0.5 rounded",children:["⏱ ",A(L.createdAt)]}):e.jsx("span",{className:"text-xs text-[var(--text-secondary)] flex-shrink-0",children:D(L.createdAt)})]}),e.jsx("p",{className:"text-sm text-[var(--text-secondary)] line-clamp-2 mt-1",children:L.message})]}),e.jsxs("div",{className:"flex flex-col gap-1 flex-shrink-0",children:[!L.isRead&&!S&&e.jsx("button",{onClick:I=>f(L.id,I),className:"p-1 rounded hover:bg-[var(--bg-secondary)]",title:"Mark as read",children:e.jsx(a.Check,{className:"w-4 h-4 text-green-600"})}),!S&&e.jsx("button",{onClick:I=>k(L.id,I),className:"p-1 rounded hover:bg-[var(--bg-secondary)]",title:"Delete",children:e.jsx(a.Trash2,{className:"w-4 h-4 text-red-500"})})]})]})},L.id)}):e.jsxs("div",{className:"py-8 text-center text-[var(--text-secondary)]",children:[e.jsx(a.Bell,{className:"w-12 h-12 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No notifications"})]})}),e.jsx("div",{className:"p-3 border-t border-[var(--border-color)] text-center",children:e.jsx("button",{onClick:()=>{i(!1),s("/notifications")},className:"text-sm text-[var(--color-primary-600)] hover:underline",children:"View all notifications"})})]})]})}const wt="support_error_context";class Nc{async captureContext(){const t={url:window.location.href,timestamp:new Date,recentErrors:qe.getRecentErrors(),browserInfo:{userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,screenWidth:window.screen.width,screenHeight:window.screen.height}};try{const r=await this.captureScreenshot();t.screenshot=r}catch(r){console.warn("[ErrorContextService] Failed to capture screenshot:",r)}return t}async captureScreenshot(){try{console.log("[ErrorContextService] Capturing screenshot with modern-screenshot, scale:",1);const r=await Cr.domToJpeg(document.body,{scale:1,quality:.85,backgroundColor:"#1a1a2e",style:{transform:"none"},filter:n=>{if(n instanceof HTMLElement){const i=n.tagName?.toUpperCase();return i!=="IFRAME"&&i!=="VIDEO"}return!0}});return console.log("[ErrorContextService] Screenshot captured, size:",Math.round(r.length/1024),"KB"),r.length>4*1024*1024?(console.log("[ErrorContextService] Screenshot too large, recompressing..."),await this.recompressScreenshot(r,.7)):r}catch(t){console.error("[ErrorContextService] Screenshot capture failed:",t);try{console.log("[ErrorContextService] Trying fallback screenshot capture...");const r=await Cr.domToJpeg(document.body,{scale:.75,quality:.8,backgroundColor:"#1a1a2e"});return console.log("[ErrorContextService] Fallback screenshot captured, size:",Math.round(r.length/1024),"KB"),r}catch(r){console.error("[ErrorContextService] Fallback also failed:",r);return}}}async recompressScreenshot(t,r){return new Promise(n=>{const i=new Image;i.onload=()=>{const o=document.createElement("canvas");o.width=i.width,o.height=i.height;const c=o.getContext("2d");if(c){c.drawImage(i,0,0);const x=o.toDataURL("image/jpeg",r);console.log("[ErrorContextService] Recompressed to:",Math.round(x.length/1024),"KB"),n(x)}else n(t)},i.onerror=()=>n(t),i.src=t})}saveContext(t){try{const r=JSON.stringify(t);console.log("[ErrorContextService] Saving context, total size:",Math.round(r.length/1024),"KB");try{sessionStorage.setItem(wt,r),console.log("[ErrorContextService] Context saved successfully")}catch{console.warn("[ErrorContextService] SessionStorage quota exceeded, saving without screenshot");const i={...t,screenshot:void 0};sessionStorage.setItem(wt,JSON.stringify(i))}}catch(r){console.error("[ErrorContextService] Failed to save context:",r)}}loadContext(){try{const t=sessionStorage.getItem(wt);if(console.log("[ErrorContextService] Loading context, data exists:",!!t,"size:",t?Math.round(t.length/1024):0,"KB"),t){const r=JSON.parse(t);return r.timestamp=new Date(r.timestamp),r.recentErrors=r.recentErrors.map(n=>({...n,timestamp:new Date(n.timestamp)})),console.log("[ErrorContextService] Context loaded, screenshot exists:",!!r.screenshot,"screenshot size:",r.screenshot?Math.round(r.screenshot.length/1024):0,"KB"),r.screenshot&&!r.screenshot.startsWith("data:image/")&&(console.warn("[ErrorContextService] Invalid screenshot data URL, clearing it"),r.screenshot=void 0),r}}catch(t){console.warn("[ErrorContextService] Failed to load context:",t)}return null}clearContext(){sessionStorage.removeItem(wt)}formatErrorsForDescription(t){return t.length===0?"":t.slice(0,5).map((n,i)=>{const o=n.timestamp.toLocaleTimeString();return`${i+1}. [${o}] ${n.message}${n.component?` (${n.component})`:""}`}).join(`
2
+ `)}}const ys=new Nc,ua="ticket_drafts",Pr=5,$r=7;class wc{getDrafts(){try{const t=localStorage.getItem(ua);return t?JSON.parse(t).map(n=>({...n,createdAt:new Date(n.createdAt),updatedAt:new Date(n.updatedAt)})):[]}catch(t){return console.warn("[TicketDraftService] Failed to load drafts:",t),[]}}saveDrafts(t){try{const r=t.map(i=>({...i,createdAt:i.createdAt.toISOString(),updatedAt:i.updatedAt.toISOString()})),n=JSON.stringify(r);return console.log("[TicketDraftService] Saving drafts, total size:",Math.round(n.length/1024),"KB"),localStorage.setItem(ua,n),!0}catch(r){if(console.error("[TicketDraftService] Failed to save drafts:",r),r instanceof DOMException&&r.name==="QuotaExceededError"){console.warn("[TicketDraftService] Quota exceeded, trying without screenshots and attachments...");try{const n=t.map(i=>({...i,screenshot:void 0,attachments:void 0,createdAt:i.createdAt.toISOString(),updatedAt:i.updatedAt.toISOString()}));return localStorage.setItem(ua,JSON.stringify(n)),console.warn("[TicketDraftService] Saved without screenshots and attachments"),!0}catch(n){console.error("[TicketDraftService] Still failed without large data:",n)}}return!1}}cleanupExpiredDrafts(){const t=this.getDrafts(),r=new Date,n=$r*24*60*60*1e3,i=t.filter(o=>r.getTime()-o.updatedAt.getTime()<n);i.length!==t.length&&(console.log("[TicketDraftService] Cleaned up",t.length-i.length,"expired drafts"),this.saveDrafts(i))}getAllDrafts(){return this.cleanupExpiredDrafts(),this.getDrafts().sort((t,r)=>r.updatedAt.getTime()-t.updatedAt.getTime())}getDraft(t){return this.getAllDrafts().find(n=>n.id===t)||null}createDraft(){const t=this.getAllDrafts();if(t.length>=Pr){const o=t[t.length-1];this.deleteDraft(o.id)}const r=new Date,n={id:crypto.randomUUID(),type:null,title:"",description:"",priority:"Medium",includeScreenshot:!0,includeErrorLogs:!0,createdAt:r,updatedAt:r},i=[n,...this.getDrafts().slice(0,Pr-1)];return this.saveDrafts(i),console.log("[TicketDraftService] Created new draft:",n.id),n}updateDraft(t,r){const n=this.getDrafts(),i=n.findIndex(x=>x.id===t);if(i===-1)return console.warn("[TicketDraftService] Draft not found:",t),{success:!1,draft:null};const o={...n[i],...r,updatedAt:new Date};console.log("[TicketDraftService] Updating draft:",t,{type:o.type,title:o.title?.substring(0,30),descriptionLength:o.description?.length,priority:o.priority,hasScreenshot:!!o.screenshot,screenshotSize:o.screenshot?Math.round(o.screenshot.length/1024):0,hasErrorContext:!!o.errorContext,attachmentsCount:o.attachments?.length||0,attachmentsTotalSize:o.attachments?.reduce((x,u)=>x+u.size,0)||0}),n[i]=o;const c=this.saveDrafts(n);return{success:c,draft:c?o:null}}deleteDraft(t){const r=this.getDrafts(),n=r.filter(i=>i.id!==t);return n.length===r.length?!1:(this.saveDrafts(n),console.log("[TicketDraftService] Deleted draft:",t),!0)}getDraftCount(){return this.getAllDrafts().length}hasDrafts(){return this.getDraftCount()>0}getTimeUntilExpiration(t){const r=$r*24*60*60*1e3,n=t.updatedAt.getTime()+r,i=Math.max(0,n-Date.now()),o=Math.floor(i/(1440*60*1e3)),c=Math.floor(i%(1440*60*1e3)/(3600*1e3));return{days:o,hours:c}}}const Ye=new wc;function Yt({variant:s="icon",className:t=""}){const{t:r}=ne.useTranslation(["common","support"]),n=Q.useNavigate(),[i,o]=l.useState(!1),[c,x]=l.useState(!1),[u,d]=l.useState([]),m=l.useRef(null);l.useEffect(()=>{c&&d(Ye.getAllDrafts())},[c]),l.useEffect(()=>{const w=f=>{m.current&&!m.current.contains(f.target)&&x(!1)};return c&&document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[c]);const p=async w=>{o(!0),x(!1);const N=(w?Ye.getDraft(w):null)?.screenshot;let k=null;if(N)console.log("[CreateTicketButton] Resuming draft with existing screenshot, skipping capture"),ys.clearContext();else try{console.log("[CreateTicketButton] Starting context capture..."),k=await ys.captureContext(),console.log("[CreateTicketButton] Context captured, screenshot:",!!k.screenshot,"size:",k.screenshot?Math.round(k.screenshot.length/1024):0,"KB"),ys.saveContext(k),console.log("[CreateTicketButton] Context saved to sessionStorage")}catch(C){console.warn("[CreateTicketButton] Failed to capture error context:",C)}if(o(!1),w)n(`/platform/support/tickets/new?draft=${w}`);else{const C=Ye.createDraft();k&&(console.log("[CreateTicketButton] Saving captured context directly to draft:",C.id),Ye.updateDraft(C.id,{screenshot:k.screenshot,errorContext:{url:k.url,timestamp:k.timestamp.toISOString(),recentErrors:k.recentErrors.map(y=>({...y,timestamp:y.timestamp.toISOString()})),browserInfo:k.browserInfo}})),n(`/platform/support/tickets/new?draft=${C.id}`)}},h=async()=>{const w=Ye.getAllDrafts();w.length>0?(d(w),x(!0)):await p()},v=(w,f)=>{w.stopPropagation(),Ye.deleteDraft(f);const N=Ye.getAllDrafts();d(N),N.length===0&&x(!1)},b=w=>w.title?w.title.length>30?w.title.substring(0,30)+"...":w.title:w.type?r(`support:tickets.types.${w.type}`):r("common:drafts.untitled"),g=w=>{const N=new Date().getTime()-w.getTime(),k=Math.floor(N/6e4),C=Math.floor(N/36e5),y=Math.floor(N/864e5);return k<1?r("common:drafts.justNow"):k<60?r("common:drafts.minutesAgo",{count:k}):C<24?r("common:drafts.hoursAgo",{count:C}):r("common:drafts.daysAgo",{count:y})},j=()=>e.jsxs("div",{ref:m,className:"absolute right-0 top-full mt-2 w-80 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-xl z-50",children:[e.jsxs("div",{className:"p-3 border-b border-[var(--border-color)]",children:[e.jsx("h3",{className:"font-medium text-sm",children:r("common:drafts.existingDrafts")}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)] mt-1",children:r("common:drafts.selectOrCreate")})]}),e.jsx("div",{className:"max-h-64 overflow-y-auto",children:u.map(w=>{const f=Ye.getTimeUntilExpiration(w);return e.jsxs("div",{onClick:()=>p(w.id),role:"button",tabIndex:0,onKeyDown:N=>N.key==="Enter"&&p(w.id),className:"w-full p-3 flex items-start gap-3 hover:bg-[var(--bg-hover)] transition-colors text-left border-b border-[var(--border-color)] last:border-b-0 cursor-pointer",children:[e.jsx(a.FileEdit,{className:"w-4 h-4 text-[var(--text-secondary)] mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:b(w)}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-[var(--text-secondary)] mt-1",children:[e.jsx(a.Clock,{className:"w-3 h-3"}),e.jsx("span",{children:g(w.updatedAt)}),e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"•"}),e.jsx("span",{className:"text-[var(--warning-text)]",children:f.days>0?r("common:drafts.expiresInDays",{count:f.days}):r("common:drafts.expiresInHours",{count:f.hours})})]})]}),e.jsx("button",{onClick:N=>v(N,w.id),className:"p-1.5 rounded hover:bg-[var(--error-bg)] text-[var(--text-secondary)] hover:text-[var(--error-text)] transition-colors",title:r("common:actions.delete"),children:e.jsx(a.Trash2,{className:"w-4 h-4"})})]},w.id)})}),e.jsx("div",{className:"p-2 border-t border-[var(--border-color)]",children:e.jsxs("button",{onClick:()=>p(),className:"w-full flex items-center justify-center gap-2 px-4 py-2 bg-[var(--color-primary-600)] text-white rounded-lg hover:bg-[var(--color-primary-700)] transition-colors text-sm",children:[e.jsx(a.Plus,{className:"w-4 h-4"}),r("common:drafts.createNew")]})})]});return s==="icon"?e.jsxs("div",{className:"relative",children:[e.jsx("button",{onClick:h,disabled:i,className:`p-2 rounded-lg hover:bg-[var(--bg-hover)] transition-colors disabled:opacity-50 ${t}`,title:r("common:actions.createTicket"),children:i?e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}):e.jsx(a.Headset,{className:"w-5 h-5"})}),c&&j()]}):e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:h,disabled:i,className:`flex items-center gap-2 px-4 py-2 bg-[var(--color-primary-600)] text-white rounded-lg hover:bg-[var(--color-primary-700)] transition-colors disabled:opacity-50 ${t}`,children:[i?e.jsx(a.Loader2,{className:"w-4 h-4 animate-spin"}):e.jsx(a.Headset,{className:"w-4 h-4"}),r("common:actions.createTicket")]}),c&&j()]})}function vi({onMenuToggle:s}){const{t}=ne.useTranslation(["admin","navigation"]),[r,n]=l.useState(!1),i=ws(),{getApplicationsForContext:o}=Ze(),{logout:c}=Ke(),u=o("platform").flatMap(d=>d.modules);return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[s&&e.jsx("button",{onClick:s,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.Menu,{className:"w-5 h-5"})}),e.jsxs(Q.Link,{to:i("/platform"),className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 animated-gradient flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 ml-4 px-2.5 py-1 border border-emerald-500/30 bg-emerald-500/10",style:{borderRadius:"var(--radius-badge)"},children:[e.jsx(a.Shield,{className:"w-3.5 h-3.5 text-emerald-500"}),e.jsx("span",{className:"text-xs font-medium text-emerald-500",children:t("admin:header.indicator")})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(pr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(tt,{}),e.jsx(ms,{}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 pl-3 border-l border-[var(--border-color)]",children:[!1,e.jsx(Yt,{}),e.jsx(Jt,{}),e.jsx(Qt,{})]}),e.jsx("button",{onClick:()=>n(!r),className:"sm:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"sm:hidden py-4 border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[u.map(d=>e.jsx(Q.Link,{to:i(d.route||"#"),className:"px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:d.label},d.id)),e.jsx("hr",{className:"my-2 border-[var(--border-color)]"}),e.jsxs("button",{onClick:()=>{n(!1),c()},className:"flex items-center gap-2 px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors text-red-500",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),t("navigation:header.logout")]})]})})]})})}function Wa({name:s,className:t}){const n=es[s];return n?e.jsx(n,{className:t}):e.jsx(a.Star,{className:t})}function Xa(s){if(!s)return a.Box;const t=es;if(t[s])return t[s];const r=s.toLowerCase(),n=Object.keys(t).find(i=>i.toLowerCase()===r);return n?t[n]:a.Box}function kc({module:s,isActive:t,isCollapsed:r,onClose:n,buildUrl:i}){const[o,c]=l.useState(!1),[x,u]=l.useState({top:0,left:0}),d=l.useRef(null),m=l.useRef(null),p=()=>{if(r){if(d.current&&(clearTimeout(d.current),d.current=null),m.current){const v=m.current.getBoundingClientRect();u({top:v.top,left:v.right+8})}c(!0)}},h=()=>{r&&(d.current=setTimeout(()=>{c(!1)},150))};return l.useEffect(()=>()=>{d.current&&clearTimeout(d.current)},[]),e.jsxs("div",{ref:m,className:"relative",onMouseEnter:p,onMouseLeave:h,children:[e.jsxs(Q.Link,{to:i(s.route),onClick:n,className:`flex items-center transition-colors ${r?"justify-center px-2 py-2":"gap-3 px-3 py-2"} ${t?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},title:r?`${s.label} (${s.applicationLabel})`:void 0,children:[e.jsx(Wa,{name:s.icon,className:"w-4 h-4 flex-shrink-0"}),!r&&e.jsx("span",{className:"text-sm font-medium truncate",children:s.label})]}),r&&o&&Zs.createPortal(e.jsx("div",{className:"fixed z-[9999] pointer-events-auto",style:{top:x.top,left:x.left},onMouseEnter:p,onMouseLeave:h,children:e.jsx("div",{className:"px-3 py-2 bg-[var(--bg-secondary)] border border-[var(--border-color)] shadow-lg whitespace-nowrap",style:{borderRadius:"var(--radius-menu-item)"},children:e.jsx("span",{className:"text-sm font-medium text-[var(--text-primary)]",children:s.label})})}),document.body)]})}function Cc({module:s,isExpanded:t,onToggle:r,onNavigate:n,currentPath:i,isCollapsed:o}){const[c,x]=l.useState(!1),[u,d]=l.useState({top:0,left:0}),[m,p]=l.useState(new Set),h=l.useRef(null),v=l.useRef(null),b=Xa(s.icon),g=s.route?i===s.route:i.includes(`/${s.code}`),j=(s.sections?.length??0)>0,w=s.label;l.useEffect(()=>{if(!s.sections)return;const y=s.sections.find(A=>A.resources?.some(D=>D.route&&i.startsWith(D.route)));y&&!m.has(y.id)&&p(A=>new Set([...A,y.id]))},[i,s.sections,m]);const f=y=>{p(A=>{const D=new Set(A);return D.has(y)?D.delete(y):D.add(y),D})},N=()=>{if(o){if(h.current&&(clearTimeout(h.current),h.current=null),v.current){const y=v.current.getBoundingClientRect();d({top:y.top,left:y.right+8})}x(!0)}},k=()=>{o&&(h.current=setTimeout(()=>{x(!1)},150))};l.useEffect(()=>()=>{h.current&&clearTimeout(h.current)},[]);const C=()=>{j&&!o?r():s.route&&n(s.route)};return e.jsxs("div",{ref:v,className:"relative",onMouseEnter:N,onMouseLeave:k,children:[e.jsxs("button",{onClick:C,className:`w-full flex items-center transition-all duration-200 ${o?"justify-center px-2 py-2.5":"gap-3 px-3 py-2.5"} ${g?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},title:o&&!j?w:void 0,children:[e.jsx(b,{className:"w-5 h-5 flex-shrink-0"}),!o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-left font-medium text-sm truncate",children:w}),j&&(t?e.jsx(a.ChevronDown,{className:"w-4 h-4 text-[var(--text-tertiary)] flex-shrink-0"}):e.jsx(a.ChevronRight,{className:"w-4 h-4 text-[var(--text-tertiary)] flex-shrink-0"}))]})]}),o&&c&&Zs.createPortal(e.jsx("div",{className:"fixed z-[9999] pointer-events-auto",style:{top:u.top,left:u.left},onMouseEnter:N,onMouseLeave:k,children:e.jsxs("div",{className:"min-w-[200px] bg-[var(--bg-secondary)] border border-[var(--border-color)] shadow-lg",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"px-3 py-2 border-b border-[var(--border-color)]",children:e.jsx("span",{className:"text-sm font-semibold text-[var(--text-primary)]",children:w})}),e.jsx("div",{className:"p-1.5",children:j?s.sections.map(y=>{const A=Xa(y.icon),D=y.route&&i===y.route;return e.jsxs("button",{onClick:()=>y.route&&n(y.route),className:`w-full flex items-center gap-2.5 px-2.5 py-2 transition-colors ${D?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(A,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{className:"text-sm",children:y.label})]},y.id)}):s.route&&e.jsxs("button",{onClick:()=>n(s.route),className:"w-full flex items-center gap-2.5 px-2.5 py-2 hover:bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(b,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{className:"text-sm",children:"Ouvrir"})]})})]})}),document.body),!o&&t&&j&&e.jsx("div",{className:"ml-4 pl-4 border-l border-[var(--border-color)] mt-1 space-y-1",children:s.sections.map(y=>e.jsx(Sc,{section:y,currentPath:i,onNavigate:n,isCollapsed:o,isExpanded:m.has(y.id),onToggle:()=>f(y.id)},y.id))})]})}function Sc({section:s,currentPath:t,onNavigate:r,isCollapsed:n,isExpanded:i,onToggle:o}){const c=Xa(s.icon),x=s.route&&(t===s.route||t.startsWith(s.route+"/")),u=(s.resources?.length??0)>0,d=s.label,m=p=>{p.preventDefault(),s.route&&r(s.route),u&&o()};return n?null:e.jsxs("div",{children:[e.jsxs("button",{onClick:m,className:`w-full flex items-center gap-3 px-3 py-2 transition-all duration-200 ${x?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-secondary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(c,{className:"w-4 h-4 flex-shrink-0"}),e.jsx("span",{className:"flex-1 text-sm text-left",children:d}),u&&(i?e.jsx(a.ChevronDown,{className:"w-3.5 h-3.5 text-[var(--text-tertiary)] flex-shrink-0"}):e.jsx(a.ChevronRight,{className:"w-3.5 h-3.5 text-[var(--text-tertiary)] flex-shrink-0"}))]}),i&&u&&e.jsx("div",{className:"ml-4 pl-3 border-l border-[var(--border-color)] mt-1 space-y-0.5",children:s.resources.map(p=>e.jsx(Tc,{resource:p,currentPath:t,onNavigate:r},p.id))})]})}function Tc({resource:s,currentPath:t,onNavigate:r}){const n=s.route&&t.startsWith(s.route),i=o=>{o.preventDefault(),s.route&&r(s.route)};return e.jsxs("button",{onClick:i,className:`w-full flex items-center gap-2.5 px-2.5 py-1.5 transition-all duration-200 ${n?"bg-[var(--accent-bg)] text-[var(--color-accent-500)]":"hover:bg-[var(--bg-tertiary)] text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"}`,style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-current flex-shrink-0"}),e.jsx("span",{className:"text-xs text-left",children:s.label})]})}const Ac=(s,t)=>s?s.modules.find(n=>n.sections?.length?n.sections.some(i=>i.route&&t.pathname===i.route):!1)||s.modules.find(n=>n.route&&t.pathname.startsWith(n.route)&&(n.sections?.length??0)>0):null;function Zt({isOpen:s,onClose:t}){const{t:r}=ne.useTranslation(["navigation","common"]),n=Q.useLocation(),i=Q.useNavigate(),{getCurrentApplication:o,isLoading:c,currentContextCode:x}=Ze(),{favorites:u,loading:d}=rs(),{expandFavorites:m,clearExpand:p}=rs(),{isCollapsed:h,toggleCollapsed:v}=st(),b=ws(),[g,j]=l.useState(new Set),[w,f]=l.useState(!1);l.useEffect(()=>{m&&(queueMicrotask(()=>{f(!1)}),p())},[m,p]);const N=o();l.useEffect(()=>{if(!N)return;const A=Ac(N,n);A&&!g.has(A.id)&&queueMicrotask(()=>{j(D=>new Set([...D,A.id]))})},[n.pathname,N,g]);const k=A=>{j(D=>{const R=new Set(D);return R.has(A)?R.delete(A):R.add(A),R})},C=A=>{i(b(A)),t()},y=N?.label??"";return N?e.jsxs(e.Fragment,{children:[s&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 lg:hidden",onClick:t}),e.jsxs("aside",{className:`group/sidebar fixed top-16 bottom-0 left-0 bg-[var(--bg-primary)] border-r border-[var(--border-color)] transform transition-all duration-300 z-50 overflow-visible ${h?"w-16":"w-64"} ${s?"translate-x-0":"-translate-x-full lg:translate-x-0"}`,children:[e.jsxs("button",{onClick:v,className:"hidden lg:flex absolute top-1/2 -translate-y-1/2 w-3 h-16 items-center justify-center group/toggle transition-all duration-200 z-[9999]",style:{right:"-12px"},title:h?r("sidebar.expand","Agrandir le menu"):r("sidebar.collapse","Réduire le menu"),children:[e.jsx("div",{className:"absolute left-0 w-[3px] h-full bg-[var(--border-color)] group-hover/toggle:bg-[var(--color-accent-500)] transition-colors duration-200 rounded-full"}),e.jsx("div",{className:"absolute right-0 w-4 h-4 flex items-center justify-center bg-[var(--bg-secondary)] border border-[var(--border-color)] group-hover/toggle:border-[var(--color-accent-500)] group-hover/toggle:text-[var(--color-accent-500)] text-[var(--text-muted)] rounded-full shadow-sm transition-all duration-200",children:h?e.jsx(a.ChevronRight,{className:"w-3 h-3"}):e.jsx(a.ChevronLeft,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:`${h?"p-2":"p-4"}`,children:[e.jsxs("div",{className:"flex items-center justify-between group/header",children:[h?e.jsx("div",{className:"w-full flex justify-center",children:e.jsx("div",{className:"w-10 h-10 flex items-center justify-center bg-gradient-to-br from-[var(--color-accent-500)] to-[var(--color-accent-700)] text-white shadow-sm",style:{borderRadius:"var(--radius-button)"},title:y,children:e.jsx(Wa,{name:N.icon||"LayoutGrid",className:"w-5 h-5"})})}):e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:"w-10 h-10 flex-shrink-0 flex items-center justify-center bg-gradient-to-br from-[var(--color-accent-500)] to-[var(--color-accent-700)] text-white shadow-sm",style:{borderRadius:"var(--radius-button)"},children:e.jsx(Wa,{name:N.icon||"LayoutGrid",className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"font-semibold text-[var(--text-primary)] truncate",children:y}),e.jsx("div",{className:"flex items-center gap-1.5 mt-0.5",children:e.jsxs("span",{className:"inline-flex items-center px-1.5 py-0.5 text-[10px] font-medium bg-[var(--bg-tertiary)] text-[var(--text-secondary)]",style:{borderRadius:"4px"},children:[N.modules.length," ",N.modules.length===1?"module":"modules"]})})]})]}),e.jsx("button",{onClick:t,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.X,{className:"w-5 h-5"})})]}),e.jsx("div",{className:`mt-3 h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent ${h?"mx-1":""}`})]}),e.jsxs("nav",{className:`flex-1 overflow-y-auto overflow-x-hidden space-y-1 ${h?"p-2 pt-3":"p-3"}`,children:[!d&&u.length>0&&e.jsxs("div",{className:"mb-4",children:[!h&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 mb-1",children:[e.jsxs("button",{onClick:()=>f(!w),className:"flex items-center gap-2 text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider hover:text-[var(--text-primary)] transition-colors",children:[e.jsx("div",{className:`transition-transform duration-200 ${w?"":"rotate-90"}`,children:e.jsx(a.ChevronRight,{className:"w-3.5 h-3.5"})}),e.jsx(a.Star,{className:"w-3.5 h-3.5 text-amber-500"}),r("common:favorites.quickAccess")]}),e.jsx(Q.Link,{to:b("/personal/myspace/preferences?tab=favorites"),onClick:t,className:"p-1.5 text-[var(--text-muted)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},title:r("common:favorites.manage"),children:e.jsx(a.Settings,{className:"w-3.5 h-3.5"})})]}),(h||!w)&&e.jsx("div",{className:"space-y-0.5",children:u.map(A=>e.jsx(kc,{module:A,isActive:n.pathname===A.route,isCollapsed:h,onClose:t,buildUrl:b},A.id))}),!h&&e.jsxs("div",{className:"mt-4 pt-4",children:[e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent mb-3"}),e.jsxs("div",{className:"flex items-center gap-2 px-3",children:[e.jsx("div",{className:"w-1 h-3.5 bg-gradient-to-b from-[var(--color-accent-500)] to-[var(--color-accent-300)] rounded-full"}),e.jsx("span",{className:"text-xs font-semibold text-[var(--text-muted)] uppercase tracking-wider",children:r("sidebar.navigation","Navigation")})]})]}),h&&e.jsx("div",{className:"my-3 mx-1",children:e.jsx("div",{className:"h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent"})})]}),c?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"w-6 h-6 border-2 border-[var(--color-accent-500)] border-t-transparent rounded-full animate-spin"})}):N.modules.length>0?N.modules.map(A=>e.jsx(Cc,{module:A,isExpanded:g.has(A.id),onToggle:()=>k(A.id),onNavigate:C,currentPath:n.pathname,isCollapsed:h},A.id)):!h&&e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] text-center py-8",children:r("sidebar.noModules","Aucun module disponible")})]}),!h&&e.jsxs("div",{className:"p-3",children:[e.jsx("div",{className:"mb-3 h-px bg-gradient-to-r from-transparent via-[var(--border-color)] to-transparent"}),e.jsxs("button",{onClick:()=>C(`/${x||"platform"}`),className:"w-full flex items-center gap-2 px-3 py-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] transition-all",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.ChevronLeft,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:r("sidebar.backToApps","Retour aux applications")})]})]})]})]})]}):null}const gi="smartstack-doc-panel-size",fi=l.createContext(void 0);function Rc(){if(typeof window>"u")return 33;try{const s=localStorage.getItem(gi);if(s){const t=parseFloat(s);if(t>=20&&t<=60)return t}}catch{}return 33}const kt={users:"/system/docs/user/modules","users/dashboard":"/system/docs/user/modules","users/list":"/system/docs/user/modules","users/create":"/system/docs/user/modules",permissions:"/system/docs/user/modules","permissions/roles":"/system/docs/user/modules","permissions/permissions":"/system/docs/user/modules",applications:"/system/docs/user/architecture",workflows:"/system/docs/user/support-templates","workflows/list":"/system/docs/user/support-templates","workflows/create":"/system/docs/user/support-templates","workflows/triggers":"/system/docs/user/support-templates","workflows/history":"/system/docs/user/support-templates","workflows/email-templates":"/system/docs/user/support-templates","workflows/email-templates/email":"/system/docs/user/support-templates","workflows/email-templates/sms":"/system/docs/user/support-templates","workflows/email-templates/create":"/system/docs/user/support-templates",ai:"/system/docs/user/ai","ai/providers":"/system/docs/user/ai","ai/models":"/system/docs/user/ai","ai/prompts":"/system/docs/user/ai","entra-id":"/system/docs/user/modules","entra-id/configuration":"/system/docs/user/modules","entra-id/sync":"/system/docs/user/modules",settings:"/system/docs/user/settings",dashboard:"/system/docs/user/support-dashboard",tickets:"/system/docs/user/support-tickets","my-tickets":"/system/docs/user/support-my-tickets","sla-config":"/system/docs/user/support-sla","escalation-config":"/system/docs/user/support-escalation",profile:"/system/docs/user/modules",preferences:"/system/docs/user/modules"},Mr={administration:"/system/docs/user/modules",support:"/system/docs/user/support-dashboard",ai:"/system/docs/user/ai",myspace:"/system/docs/user/modules","support-client":"/system/docs/user/support"};function Fr(s){const t=s.split("/").filter(Boolean);if(t.length>=3){const r=t.slice(2);for(let n=r.length;n>0;n--){const i=r.slice(0,n).join("/");if(kt[i])return kt[i]}if(t[1]==="support"){const n=`support/${r[0]}`;if(kt[n])return kt[n]}}if(t.length>=2){const r=t[1];if(Mr[r])return Mr[r]}return"/system/docs/user"}function br({children:s}){const[t,r]=l.useState(!1),[n,i]=l.useState(Rc),[o,c]=l.useState(null),x=Q.useLocation(),u=l.useRef(x.pathname);l.useEffect(()=>{u.current!==x.pathname&&(u.current=x.pathname,r(!1))},[x.pathname]),l.useEffect(()=>{n>=20&&n<=60&&localStorage.setItem(gi,String(n))},[n]);const d=l.useCallback(v=>{const b=v||Fr(x.pathname);c(b),r(!0)},[x.pathname]),m=l.useCallback(()=>{r(!1)},[]),p=l.useCallback(()=>{if(t)r(!1);else{const v=Fr(x.pathname);c(v),r(!0)}},[t,x.pathname]),h=l.useCallback(v=>{v>=20&&v<=60&&i(v)},[]);return e.jsx(fi.Provider,{value:{isOpen:t,panelSize:n,docUrl:o,openDocPanel:d,closeDocPanel:m,toggleDocPanel:p,setPanelSize:h},children:s})}function ea(){const s=l.useContext(fi);if(s===void 0)throw new Error("useDocPanel must be used within a DocPanelProvider");return s}const Ur=60,Ic=33;function Ec(){const{t:s}=ne.useTranslation("common"),{isOpen:t,docUrl:r,closeDocPanel:n,panelSize:i,setPanelSize:o}=ea();if(!t||!r)return null;const c=r.startsWith("http")?r:window.location.origin+r,x=c.includes("?")?"&":"?",u=`${c}${x}embedded=true`,d=i>=Ur-1,m=()=>{o(d?Ic:Ur)};return e.jsxs("div",{className:"h-full flex flex-col bg-[var(--bg-primary)] border-l border-[var(--border-color)]",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[var(--border-color)] bg-[var(--bg-secondary)]",children:[e.jsx("h3",{className:"font-semibold text-sm flex items-center gap-2",children:s("docPanel.title")}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{onClick:m,className:"p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",title:s(d?"docPanel.minimize":"docPanel.maximize"),children:d?e.jsx(a.Minimize2,{className:"w-4 h-4"}):e.jsx(a.Maximize2,{className:"w-4 h-4"})}),e.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",title:s("docPanel.openInNewTab"),children:e.jsx(a.ExternalLink,{className:"w-4 h-4"})}),e.jsx("button",{onClick:n,className:"p-1.5 rounded hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",title:s("docPanel.close"),children:e.jsx(a.X,{className:"w-4 h-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-hidden",children:e.jsx("iframe",{src:u,title:s("docPanel.title"),className:"w-full h-full border-0"})})]})}function ji({children:s}){const{isOpen:t,panelSize:r,setPanelSize:n}=ea(),[i,o]=nt.useGroupCallbackRef(),c=l.useRef(r),[x,u]=l.useState(!1);if(l.useEffect(()=>{u(!!i)},[i]),l.useEffect(()=>{i&&x&&c.current!==r&&(i.setLayout({"main-content":100-r,"doc-panel":r}),c.current=r)},[r,i,x]),!t)return e.jsx(e.Fragment,{children:s});const d=p=>{c.current=p.asPercentage,n(p.asPercentage)},m={"main-content":100-r,"doc-panel":r};return e.jsxs(nt.Group,{orientation:"horizontal",className:"h-full",defaultLayout:m,groupRef:o,children:[e.jsx(nt.Panel,{id:"main-content",minSize:40,maxSize:80,children:e.jsx("div",{className:"w-full h-full overflow-auto",children:s})}),e.jsx(nt.Separator,{className:"w-1 bg-[var(--border-color)] hover:bg-[var(--color-primary-400)] transition-colors cursor-col-resize group/separator relative",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover/separator:bg-[var(--color-primary-100)]/20"})}),e.jsx(nt.Panel,{id:"doc-panel",minSize:20,maxSize:60,onResize:d,children:e.jsx(Ec,{})})]})}function yi(){const{t:s}=ne.useTranslation("common"),{isOpen:t,openDocPanel:r}=ea();return t?null:e.jsxs("button",{onClick:()=>r(),className:"hidden lg:flex fixed right-0 top-1/2 -translate-y-1/2 w-3 h-16 items-center justify-center group/toggle transition-all duration-200 z-[100]",title:s("docPanel.open"),"aria-label":s("docPanel.open"),children:[e.jsx("div",{className:"absolute right-0 w-[3px] h-full bg-[var(--border-color)] group-hover/toggle:bg-[var(--color-primary-500)] transition-colors duration-200 rounded-full"}),e.jsx("div",{className:"absolute left-0 -translate-x-full w-6 h-6 flex items-center justify-center bg-[var(--bg-secondary)] border border-[var(--border-color)] group-hover/toggle:border-[var(--color-primary-500)] group-hover/toggle:text-[var(--color-primary-500)] text-[var(--text-muted)] rounded-full shadow-sm transition-all duration-200",children:e.jsx(a.BookOpen,{className:"w-3 h-3"})}),e.jsx("div",{className:"absolute right-6 top-1/2 -translate-y-1/2 px-2 py-1 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-md shadow-lg opacity-0 group-hover/toggle:opacity-100 transition-opacity duration-200 pointer-events-none whitespace-nowrap text-xs font-medium text-[var(--text-primary)]",children:s("docPanel.title")})]})}function Dc(){const[s,t]=l.useState(!1),{currentAppCode:r}=Ze(),{isCollapsed:n}=st(),i=!!r;return e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:[e.jsx(vi,{onMenuToggle:()=>t(!s)}),i&&e.jsx(Zt,{isOpen:s,onClose:()=>t(!1)}),e.jsx("main",{className:`pt-16 transition-all duration-300 h-[calc(100vh-4rem)] ${i?n?"lg:pl-16":"lg:pl-64":""}`,children:e.jsx(ji,{children:e.jsx("div",{className:"p-4 sm:p-6 lg:px-10 h-full overflow-auto",children:e.jsx(Q.Outlet,{})})})}),e.jsx(yi,{})]})}function ut(){return e.jsx(br,{children:e.jsx(Dc,{})})}function Ni({onMenuToggle:s}){const{t}=ne.useTranslation(["business","navigation"]),[r,n]=l.useState(!1),{getApplicationsForContext:i}=Ze(),o=ws(),{logout:c}=Ke(),x=i("business");return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[s&&e.jsx("button",{onClick:s,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.Menu,{className:"w-5 h-5"})}),e.jsxs(Q.Link,{to:o("/business"),className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 animated-gradient flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]}),e.jsxs("div",{className:"hidden sm:flex items-center gap-2 ml-4 px-2.5 py-1 bg-teal-500/10 border border-teal-500/30",style:{borderRadius:"var(--radius-badge)"},children:[e.jsx(a.Briefcase,{className:"w-3.5 h-3.5 text-teal-500"}),e.jsx("span",{className:"text-xs font-medium text-teal-500",children:"Business"})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(pr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(tt,{}),e.jsx(ms,{}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 pl-3 border-l border-[var(--border-color)]",children:[!1,e.jsx(Yt,{}),e.jsx(Jt,{}),e.jsx(Qt,{})]}),e.jsx("button",{onClick:()=>n(!r),className:"sm:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"sm:hidden py-4 border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[x.map(u=>e.jsx(Q.Link,{to:o(u.route||"#"),className:"px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:u.label},u.id)),e.jsx("hr",{className:"my-2 border-[var(--border-color)]"}),e.jsxs("button",{onClick:()=>{n(!1),c()},className:"flex items-center gap-2 px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors text-red-500",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),t("navigation:header.logout")]})]})})]})})}function Lc(){const[s,t]=l.useState(!1),{currentAppCode:r}=Ze(),{isCollapsed:n}=st(),i=!!r;return e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:[e.jsx(Ni,{onMenuToggle:()=>t(!s)}),i&&e.jsx(Zt,{isOpen:s,onClose:()=>t(!1)}),e.jsx("main",{className:`pt-16 transition-all duration-300 ${i?n?"lg:pl-16":"lg:pl-64":""}`,children:e.jsx("div",{className:"p-4 sm:p-6 lg:px-10 h-full overflow-auto",children:e.jsx(Q.Outlet,{})})})]})}function Qa(){return e.jsx(Lc,{})}function wi({onMenuToggle:s}){const{t}=ne.useTranslation("navigation"),[r,n]=l.useState(!1),{getApplicationsForContext:i}=Ze(),{logout:o}=Ke(),c=ws(),x=i("personal").flatMap(u=>u.modules);return e.jsx("header",{className:"fixed top-0 left-0 right-0 z-50 bg-[var(--bg-primary)]/80 backdrop-blur-lg border-b border-[var(--border-color)]",children:e.jsxs("nav",{className:"px-4 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"flex items-center justify-between h-16",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[s&&e.jsx("button",{onClick:s,className:"lg:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:e.jsx(a.Menu,{className:"w-5 h-5"})}),e.jsxs(Q.Link,{to:c("/personal/myspace"),className:"flex items-center gap-3 group",children:[e.jsx("div",{className:"relative",children:e.jsx("div",{className:"w-10 h-10 animated-gradient flex items-center justify-center",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Layers,{className:"w-5 h-5 text-white"})})}),e.jsx("span",{className:"text-xl font-bold gradient-text",children:"SmartStack"})]})]}),e.jsx("div",{className:"hidden md:flex items-center gap-6",children:e.jsxs(Q.Link,{to:c("/personal/myspace"),className:"flex items-center gap-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(a.Home,{className:"w-4 h-4"}),t("breadcrumb.myspace")]})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hr,{}),e.jsx("div",{className:"h-6 w-px bg-[var(--border-color)]"}),e.jsx(tt,{}),e.jsx(ms,{}),e.jsxs("div",{className:"hidden sm:flex items-center gap-1 pl-3 border-l border-[var(--border-color)]",children:[!1,e.jsx(Yt,{}),e.jsx(Jt,{}),e.jsx(Qt,{})]}),e.jsx("button",{onClick:()=>n(!r),className:"sm:hidden p-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-button)"},children:r?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})})]})]}),r&&e.jsx("div",{className:"sm:hidden py-4 border-t border-[var(--border-color)]",children:e.jsxs("div",{className:"flex flex-col gap-2",children:[x.map(u=>e.jsx(Q.Link,{to:c(u.route||"#"),className:"px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors",style:{borderRadius:"var(--radius-menu-item)"},children:u.label},u.id)),e.jsx("hr",{className:"my-2 border-[var(--border-color)]"}),e.jsxs("button",{onClick:()=>{n(!1),o()},className:"flex items-center gap-2 px-3 py-2 hover:bg-[var(--bg-tertiary)] transition-colors text-red-500",style:{borderRadius:"var(--radius-menu-item)"},children:[e.jsx(a.LogOut,{className:"w-4 h-4"}),t("header.logout")]})]})})]})})}function Pc(){const[s,t]=l.useState(!1),{currentAppCode:r}=Ze(),{isCollapsed:n}=st(),i=!!r;return e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:[e.jsx(wi,{onMenuToggle:()=>t(!s)}),i&&e.jsx(Zt,{isOpen:s,onClose:()=>t(!1)}),e.jsx("main",{className:`pt-16 transition-all duration-300 h-[calc(100vh-4rem)] ${i?n?"lg:pl-16":"lg:pl-64":""}`,children:e.jsx(ji,{children:e.jsx("div",{className:"p-4 sm:p-6 lg:px-10 h-full overflow-auto",children:e.jsx(Q.Outlet,{})})})}),e.jsx(yi,{})]})}function Ja(){return e.jsx(br,{children:e.jsx(Pc,{})})}const $c=[{title:"Infrastructure",description:"Architecture technique, structure du projet et technologies utilisees",href:"/system/docs/developer/infrastructure",category:"developer",tags:[".NET 10","React 19","EF Core","SQL Server","architecture"],icon:a.Server},{title:"Installation",description:"Guide complet pour installer et configurer l'environnement de developpement",href:"/system/docs/developer/installation",category:"developer",tags:["setup","configuration","prerequisites","npm","dotnet","CLI","MCP"],icon:a.Download},{title:"Base de donnees",description:"Modele conceptuel de donnees avec schemas, tables et relations",href:"/system/docs/developer/database",category:"developer",tags:["MCD","Schemas","Relations","SQL","EF Core","migrations","ERD","diagramme","nav","auth","usr","support","ten","ai","wkf","cfg","entra","ref","loc","lic","Contexts","Applications","Modules","Sections","Resources","ContextMaintenance","Users","Roles","UserRoles","Permissions","RolePermissions","RefreshTokens","Sessions","Profiles","Preferences","Tickets","TicketComments","TicketAttachments","TicketTemplates","Notifications","Tenants","TenantApplications","TenantUsers","Providers","Models","Prompts","PromptVersions","PromptExecutions","Workflows","WorkflowSteps","WorkflowExecutions","EmailTemplates","Settings","SettingCategories","Groups","GroupMembers","SyncStates","Companies","Departments","Positions","Languages","Translations","Licenses","LicenseFeatures","Status","Type","Priority","TenantId","UserId","RoleId","PermissionId","CreatedAt","UpdatedAt","CreatedBy","UpdatedBy","IsDeleted","DeletedAt","TenantStatus","TicketStatus","TicketPriority","TicketType","UserType","Theme","Pending","Active","Suspended","Archived","Open","InProgress","Resolved","Closed","Low","Medium","High","Critical","Bug","FeatureRequest","Support","Question"],icon:a.Database},{title:"Architecture Dual-DbContext",description:"Separation Core/Extensions pour la distribution NuGet et les projets client",href:"/system/docs/developer/dual-dbcontext",category:"developer",tags:["CoreDbContext","ExtensionsDbContext","NuGet","Migrations","schema"],icon:a.Layers},{title:"FK Cross-Schema",description:"Comment referencer les entites Core depuis vos entites Extensions",href:"/system/docs/developer/cross-schema-fk",category:"developer",tags:["ICoreDataService","GUID FK","No Navigation","foreign key"],icon:a.Link2},{title:"Mode Multi-Tenant",description:"Configuration Single-Tenant vs Multi-Tenant et migration entre les modes",href:"/system/docs/developer/multi-tenant-mode",category:"developer",tags:["Single-Tenant","Multi-Tenant","Configuration","tenant","workspace"],icon:a.Building2},{title:"Integration Microsoft Teams",description:"Embarquer SmartStack dans Teams via Website Tab sans developpement",href:"/system/docs/developer/teams-integration",category:"developer",tags:["Microsoft Teams","Teams","Website Tab","iframe","SSO","embedding"],icon:a.Monitor},{title:"Architecture",description:"Vue d'ensemble de l'architecture fonctionnelle de SmartStack",href:"/system/docs/user/architecture",category:"user",tags:["architecture","modules","navigation","contextes"],icon:a.Layers},{title:"Modules",description:"Liste des modules disponibles et leur configuration",href:"/system/docs/user/modules",category:"user",tags:["modules","fonctionnalites","features"],icon:a.FileText},{title:"Module Support",description:"Documentation complete du module de ticketing et support client",href:"/system/docs/user/support",category:"user",tags:["tickets","support","SLA","escalation","templates"],icon:a.Headphones},{title:"Intelligence Artificielle",description:"Configuration des providers IA, prompts et integrations",href:"/system/docs/user/ai",category:"user",tags:["IA","AI","prompts","OpenAI","Claude","providers"],icon:a.Bot},{title:"Parametres Systeme",description:"Configuration globale et parametres de la plateforme",href:"/system/docs/user/settings",category:"user",tags:["settings","configuration","parametres","systeme"],icon:a.Settings},{title:"Presentation SmartStack",description:"Presentation interactive de la plateforme SmartStack",href:"/system/docs/presentation",category:"user",tags:["presentation","slides","demo","overview"],icon:a.Presentation}];function Mc({className:s="",placeholder:t="Rechercher...",onResultClick:r}){const[n,i]=l.useState(""),[o,c]=l.useState(!1),[x,u]=l.useState(0),d=l.useRef(null),m=l.useRef(null),p=Q.useNavigate(),h=l.useMemo(()=>{if(!n.trim())return[];const w=n.toLowerCase().split(" ").filter(Boolean);return $c.filter(f=>{const N=[f.title,f.description,...f.tags,f.category].join(" ").toLowerCase();return w.every(k=>N.includes(k))})},[n]);l.useEffect(()=>{u(0)},[h]);const v=w=>{if(!(!o||h.length===0))switch(w.key){case"ArrowDown":w.preventDefault(),u(f=>(f+1)%h.length);break;case"ArrowUp":w.preventDefault(),u(f=>(f-1+h.length)%h.length);break;case"Enter":w.preventDefault(),h[x]&&b(h[x]);break;case"Escape":c(!1),i(""),d.current?.blur();break}},b=w=>{p(w.href),i(""),c(!1),r?.()};l.useEffect(()=>{const w=f=>{m.current&&!m.current.contains(f.target)&&d.current&&!d.current.contains(f.target)&&c(!1)};return document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[]);const g=w=>w==="developer"?"Developpeur":"Utilisateur",j=w=>w==="developer"?"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-400";return e.jsxs("div",{className:`relative ${s}`,children:[e.jsxs("div",{className:"relative",children:[e.jsx(a.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("input",{ref:d,type:"text",value:n,onChange:w=>{i(w.target.value),c(!0)},onFocus:()=>c(!0),onKeyDown:v,placeholder:t,className:"w-full pl-9 pr-8 py-2 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg focus:outline-none focus:ring-2 focus:ring-[var(--color-primary-400)] focus:border-transparent"}),n&&e.jsx("button",{onClick:()=>{i(""),d.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-[var(--bg-hover)]",children:e.jsx(a.X,{className:"w-3 h-3 text-[var(--text-tertiary)]"})})]}),o&&n.trim()&&e.jsxs("div",{ref:m,className:"absolute top-full left-0 right-0 mt-1 bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-lg shadow-lg overflow-hidden z-50 max-h-80 overflow-y-auto",children:[h.length===0?e.jsxs("div",{className:"p-4 text-center text-[var(--text-secondary)] text-sm",children:['Aucun resultat pour "',n,'"']}):e.jsx("div",{className:"py-1",children:h.map((w,f)=>{const N=w.icon;return e.jsxs("button",{onClick:()=>b(w),onMouseEnter:()=>u(f),className:`w-full flex items-start gap-3 px-3 py-2 text-left transition-colors ${f===x?"bg-[var(--color-primary-600)]/10":"hover:bg-[var(--bg-hover)]"}`,children:[e.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0 ${f===x?"bg-[var(--color-primary-600)] text-white":"bg-[var(--bg-secondary)]"}`,children:e.jsx(N,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm truncate",children:w.title}),e.jsx("span",{className:`px-1.5 py-0.5 text-xs rounded ${j(w.category)}`,children:g(w.category)})]}),e.jsx("p",{className:"text-xs text-[var(--text-secondary)] truncate mt-0.5",children:w.description})]}),e.jsx(a.ArrowRight,{className:`w-4 h-4 flex-shrink-0 mt-2 ${f===x?"text-[var(--color-primary-600)]":"text-[var(--text-tertiary)]"}`})]},w.href)})}),e.jsxs("div",{className:"px-3 py-2 border-t border-[var(--border-color)] bg-[var(--bg-secondary)] text-xs text-[var(--text-tertiary)] flex items-center gap-4",children:[e.jsxs("span",{children:[e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-[var(--bg-primary)] border border-[var(--border-color)]",children:"↑↓"})," naviguer"]}),e.jsxs("span",{children:[e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-[var(--bg-primary)] border border-[var(--border-color)]",children:"↵"})," ouvrir"]}),e.jsxs("span",{children:[e.jsx("kbd",{className:"px-1 py-0.5 rounded bg-[var(--bg-primary)] border border-[var(--border-color)]",children:"esc"})," fermer"]})]})]})]})}const Fc=[{title:"Accueil",href:"/system/docs",icon:a.Book},{title:"Developpeur",href:"/system/docs/developer",icon:a.Code,children:[{title:"Infrastructure",href:"/system/docs/developer/infrastructure"},{title:"Installation",href:"/system/docs/developer/installation"},{title:"Base de donnees",href:"/system/docs/developer/database"},{title:"Dual-DbContext",href:"/system/docs/developer/dual-dbcontext"},{title:"FK Cross-Schema",href:"/system/docs/developer/cross-schema-fk"},{title:"Tenant",href:"/system/docs/developer/tenants",children:[{title:"Mode Multi-Tenant",href:"/system/docs/developer/tenants/multi-tenant-mode"},{title:"Tenant B2C",href:"/system/docs/developer/tenants/b2c"}]},{title:"Integration Teams",href:"/system/docs/developer/teams-integration"},{title:"Tests de Securite",href:"/system/docs/developer/testing/security"}]},{title:"Utilisateur",href:"/system/docs/user",icon:a.Users,children:[{title:"Architecture",href:"/system/docs/user/architecture"},{title:"Modules",href:"/system/docs/user/modules"}]},{title:"Analyse metier",href:"/system/docs/ba",icon:a.BarChart3}];function pa({item:s,isChild:t=!1,depth:r=0}){const i=Q.useLocation().pathname===s.href,o="icon"in s?s.icon:null;return e.jsxs(Q.NavLink,{to:s.href,className:`flex items-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${i?"bg-[var(--color-primary-600)] text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] hover:text-[var(--text-primary)]"} ${t?"ml-6":""} ${r>1?"ml-12":""}`,children:[o&&e.jsx(o,{className:"w-4 h-4"}),!o&&t&&e.jsx(a.ChevronRight,{className:"w-3 h-3"}),s.title]})}function ki(){const[s,t]=l.useState(!1),r=Q.useLocation(),[n]=Q.useSearchParams(),i=n.get("embedded")==="true",o=m=>r.pathname===m.href?!0:"children"in m&&Array.isArray(m.children)?m.children.some(p=>r.pathname===p.href?!0:"children"in p&&Array.isArray(p.children)?p.children.some(h=>r.pathname===h.href):!1):!1,c=m=>r.pathname===m.href?!0:m.children?m.children.some(p=>r.pathname===p.href):!1,x=m=>m.children&&c(m)?e.jsx("div",{className:"mt-1 space-y-1",children:m.children.map(p=>e.jsx(pa,{item:p,isChild:!0,depth:2},p.href))}):null,u=m=>m.children&&o(m)?e.jsx("div",{className:"mt-1 space-y-1",children:m.children.map(p=>e.jsxs("div",{children:[e.jsx(pa,{item:p,isChild:!0}),x(p)]},p.href))}):null,d=()=>e.jsx("nav",{className:"space-y-1",children:Fc.map(m=>e.jsxs("div",{children:[e.jsx(pa,{item:m}),u(m)]},m.href))});return i?e.jsx("div",{className:"min-h-screen bg-[var(--bg-primary)]",children:e.jsx("main",{className:"p-4 lg:p-6",children:e.jsx("div",{className:"max-w-4xl mx-auto",children:e.jsx(Q.Outlet,{})})})}):e.jsx(cr,{children:e.jsxs("div",{className:"min-h-screen bg-[var(--bg-primary)] flex flex-col",children:[e.jsx(xr,{}),e.jsxs("div",{className:"flex-1 flex pt-16",children:[e.jsx("button",{className:"lg:hidden fixed bottom-4 right-4 z-50 p-3 rounded-full bg-[var(--color-primary-600)] text-white shadow-lg",onClick:()=>t(!s),children:s?e.jsx(a.X,{className:"w-6 h-6"}):e.jsx(a.Menu,{className:"w-6 h-6"})}),s&&e.jsx("div",{className:"lg:hidden fixed inset-0 z-40 bg-black/50",onClick:()=>t(!1)}),e.jsx("aside",{className:`fixed lg:sticky top-16 z-40 lg:z-0 h-[calc(100vh-4rem)] w-64 bg-[var(--bg-secondary)] border-r border-[var(--border-color)] overflow-y-auto transition-transform lg:translate-x-0 ${s?"translate-x-0":"-translate-x-full"}`,children:e.jsxs("div",{className:"p-4",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx(a.Book,{className:"w-5 h-5 text-[var(--color-primary-600)]"}),"Documentation"]}),e.jsx(Mc,{className:"mb-4",placeholder:"Rechercher dans la doc...",onResultClick:()=>t(!1)}),e.jsx(d,{})]})}),e.jsx("main",{className:"flex-1 min-w-0 p-6 lg:p-8",children:e.jsx("div",{className:"max-w-4xl mx-auto",children:e.jsx(Q.Outlet,{})})})]}),e.jsx(ur,{})]})})}function Br(){const{slug:s}=Q.useParams(),t=Q.useNavigate(),r=Q.useLocation(),{currentTenant:n,userTenants:i,switchTenant:o,isLoading:c}=ze(),{useUrlRouting:x,isLoading:u}=vt(),d=l.useRef(!1),m=l.useRef(null),p=l.useRef(null);return l.useEffect(()=>{if(c||u||!x)return;const h=s||Ir(r.pathname),v=h!==p.current;if(p.current=h,!!v&&h&&h!==n?.slug){const b=i.find(g=>g.slug===h&&g.status==="Active");if(b)console.log("[TenantRouteWrapper] URL slug changed, switching to:",h),m.current=h,o(b.id).then(()=>{m.current=null}).catch(g=>{m.current=null,console.error("[TenantRouteWrapper] Failed to switch tenant:",g)});else if(console.warn("[TenantRouteWrapper] Invalid tenant slug in URL:",h),n){const g=pt(r.pathname);t(`/t/${n.slug}${g}`,{replace:!0})}else t("/",{replace:!0})}},[s,r.pathname,n?.slug,i,x,c,u,o,t]),l.useEffect(()=>{if(c||u||d.current)return;const h=r.pathname,v=Ir(h);if(!x&&v){console.log("[TenantRouteWrapper] No URL routing, stripping slug from URL"),d.current=!0;const b=pt(h);t(b,{replace:!0}),setTimeout(()=>{d.current=!1},100);return}if(x&&n&&!v&&h!=="/"&&!h.startsWith("/login")&&!h.startsWith("/auth")&&!h.startsWith("/public")){console.log("[TenantRouteWrapper] URL routing mode, adding slug to URL"),d.current=!0;const g=xi(h,{slug:n.slug,useUrlRouting:!0});t(g,{replace:!0}),setTimeout(()=>{d.current=!1},100);return}if(x&&n&&v&&v!==n.slug&&v!==m.current){console.log("[TenantRouteWrapper] URL slug mismatch, updating to:",n.slug),d.current=!0;const b=pt(h);t(`/t/${n.slug}${b}`,{replace:!0}),setTimeout(()=>{d.current=!1},100);return}},[r.pathname,n?.slug,x,c,u,t]),e.jsx(Q.Outlet,{})}const Uc=(s,t)=>{const r=t.exec(s);return r?r[1]:""},Bc=[{detect:s=>s.includes("edg/")||s.includes("edge/"),name:"Edge",pattern:/Edg(?:e)?\/(\d+)/i},{detect:s=>s.includes("opr/")||s.includes("opera"),name:"Opera",pattern:/(?:OPR|Opera)\/(\d+)/i},{detect:s=>s.includes("chrome")&&!s.includes("edg"),name:"Chrome",pattern:/Chrome\/(\d+)/i},{detect:s=>s.includes("safari")&&!s.includes("chrome"),name:"Safari",pattern:/Version\/(\d+)/i},{detect:s=>s.includes("firefox"),name:"Firefox",pattern:/Firefox\/(\d+)/i},{detect:s=>s.includes("msie")||s.includes("trident"),name:"Internet Explorer",pattern:/(?:MSIE |rv:)(\d+)/i}],Oc=(s,t)=>{const r=Bc.find(n=>n.detect(s));return r?{browser:r.name,version:Uc(t,r.pattern)}:{browser:"Unknown",version:""}},qc={"windows nt 10":"10/11","windows nt 6.3":"8.1","windows nt 6.2":"8","windows nt 6.1":"7"},Vc=s=>{for(const[t,r]of Object.entries(qc))if(s.includes(t))return r;return""},zc=[{detect:s=>s.includes("windows nt"),name:"Windows",getVersion:s=>Vc(s)},{detect:s=>s.includes("windows"),name:"Windows",getVersion:()=>""},{detect:s=>s.includes("iphone"),name:"iOS",getVersion:(s,t)=>{const r=t.match(/OS (\d+)_/i);return r?r[1]:""}},{detect:s=>s.includes("ipad"),name:"iPadOS",getVersion:(s,t)=>{const r=t.match(/OS (\d+)_/i);return r?r[1]:""}},{detect:s=>s.includes("mac os x"),name:"macOS",getVersion:(s,t)=>{const r=t.match(/Mac OS X (\d+)[._](\d+)/i);return r?`${r[1]}.${r[2]}`:""}},{detect:s=>s.includes("android"),name:"Android",getVersion:(s,t)=>{const r=t.match(/Android (\d+)/i);return r?r[1]:""}},{detect:s=>s.includes("linux"),name:"Linux",getVersion:()=>""},{detect:s=>s.includes("cros"),name:"Chrome OS",getVersion:()=>""}],Gc=(s,t)=>{const r=zc.find(n=>n.detect(s));if(r){const n=r.getVersion(s,t);return{os:r.name,version:n}}return{os:"Unknown",version:""}},Hc=s=>/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk)/i.test(s)?"Tablet":/(android|webos|iphone|ipod|blackberry|iemobile|opera mini|mobile|phone)/i.test(s)?"Mobile":"Desktop";function Ci(s){if(!s)return{browser:"Unknown",browserVersion:"",os:"Unknown",osVersion:"",device:"Unknown",formatted:"Unknown"};const t=s.toLowerCase(),{browser:r,version:n}=Oc(t,s),{os:i,version:o}=Gc(t,s),c=Hc(t),x=i!=="Unknown"?`${r} ${n?n+" ":""}sur ${i}${o?" "+o:""}`:r;return{browser:r,browserVersion:n,os:i,osVersion:o,device:c,formatted:x}}function Si(){const s=navigator.userAgent.toLowerCase();return/(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(s)?"tablet":/(android|webos|iphone|ipod|blackberry|iemobile|opera mini|mobile|phone)/.test(s)?"mobile":/(windows|macintosh|linux|x11)/.test(s)?"desktop":"unknown"}async function Ti(){try{const s=await fetch("https://api.ipify.org?format=json",{method:"GET",signal:AbortSignal.timeout(5e3)});return s.ok?(await s.json()).ip||null:(console.warn("Failed to fetch IP address from ipify.org"),null)}catch(s){return console.warn("Unable to fetch client IP address:",s),null}}const Kc=[{icon:a.Shield,title:"Sécurité avancée",description:"Authentification multi-facteurs et contrôle d'accès granulaire"},{icon:a.Zap,title:"Performance optimale",description:"Interface rapide et réactive pour une productivité maximale"},{icon:a.Users,title:"Collaboration",description:"Gestion des équipes et permissions centralisée"},{icon:a.BarChart3,title:"Analytics",description:"Tableaux de bord et rapports en temps réel"}],_c=s=>{switch(s){case"ACCOUNT_DISABLED":return e.jsx(a.UserX,{className:"w-5 h-5 flex-shrink-0"});case"ACCOUNT_LOCKED":return e.jsx(a.Clock,{className:"w-5 h-5 flex-shrink-0"});case"EXTERNAL_AUTH_REQUIRED":return e.jsx(a.KeyRound,{className:"w-5 h-5 flex-shrink-0"});case"NETWORK_ERROR":return e.jsx(a.WifiOff,{className:"w-5 h-5 flex-shrink-0"});default:return e.jsx(a.AlertCircle,{className:"w-5 h-5 flex-shrink-0"})}},Wc=s=>{switch(s){case"ACCOUNT_DISABLED":return"bg-orange-500/10 border-orange-500/20 text-orange-600 dark:text-orange-400";case"ACCOUNT_LOCKED":return"bg-amber-500/10 border-amber-500/20 text-amber-600 dark:text-amber-400";case"EXTERNAL_AUTH_REQUIRED":return"bg-blue-500/10 border-blue-500/20 text-blue-600 dark:text-blue-400";case"NETWORK_ERROR":return"bg-gray-500/10 border-gray-500/20 text-gray-600 dark:text-gray-400";default:return"bg-red-500/10 border-red-500/20 text-red-500"}};function Xc(){const[s,t]=l.useState(""),[r,n]=l.useState(""),[i,o]=l.useState(!1),[c,x]=l.useState(!1),[u,d]=l.useState("auth"),[m,p]=l.useState(null),h=async v=>{v.preventDefault(),p(null),d("auth"),x(!0);try{qe.logEvent("login_attempt","auth",{email:s});const b=Si(),g=await Ti(),j=await oe.post("/api/auth/login",{email:s,password:r,deviceType:b,clientIp:g});localStorage.setItem("token",j.token),localStorage.setItem("refreshToken",j.refreshToken),localStorage.setItem("user",JSON.stringify(j.user)),qe.logEvent("login_success","auth",{email:s}),d("prefs");try{if(!(await oe.get("/api/onboarding/status")).hasCompletedOnboarding){window.location.href="/auth/onboarding";return}}catch{}try{const w=await Is.preferences.get(),f={mode:w.theme||"dark",accentColorKey:w.accentColorKey||"indigo",borderRadius:w.borderRadius||{},itemPaletteKey:w.itemPaletteKey||"neutral"};localStorage.setItem("smartstack-theme-config",JSON.stringify(f)),w.language&&localStorage.setItem("i18nextLng",w.language)}catch{}window.location.href="/personal/myspace"}catch(b){if(b instanceof nr)p({message:b.message,code:"NETWORK_ERROR"});else if(b instanceof Dl)p({message:b.message,code:b.code});else{const g=b instanceof Error?b.message:"Une erreur inattendue est survenue";p({message:g})}qe.logError(b instanceof Error?b:new Error(String(b)),"LoginPage.handleSubmit",{email:s})}finally{x(!1)}};return e.jsxs("div",{className:"min-h-screen flex",children:[e.jsxs("div",{className:"hidden lg:flex lg:w-1/2 xl:w-[55%] relative overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 animated-gradient"}),e.jsx("div",{className:"absolute inset-0 opacity-10",style:{backgroundImage:"radial-gradient(circle at 1px 1px, white 1px, transparent 0)",backgroundSize:"40px 40px"}}),e.jsx("div",{className:"absolute top-20 left-20 w-72 h-72 bg-white/10 rounded-full blur-3xl animate-pulse"}),e.jsx("div",{className:"absolute bottom-20 right-20 w-96 h-96 bg-white/10 rounded-full blur-3xl animate-pulse",style:{animationDelay:"1s"}}),e.jsx("div",{className:"absolute top-1/2 left-1/3 w-64 h-64 bg-white/5 rounded-full blur-2xl animate-pulse",style:{animationDelay:"2s"}}),e.jsxs("div",{className:"relative z-10 flex flex-col justify-between p-12 xl:p-16 text-white w-full",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-12 h-12 bg-white/20 backdrop-blur-sm rounded-xl flex items-center justify-center",children:e.jsx(a.Layers,{className:"w-7 h-7 text-white"})}),e.jsx("span",{className:"text-2xl font-bold",children:"SmartStack"})]}),e.jsxs("div",{className:"max-w-lg",children:[e.jsx("h1",{className:"text-4xl xl:text-5xl font-bold leading-tight mb-6",children:"Votre plateforme de gestion unifiée"}),e.jsx("p",{className:"text-xl text-white/80 mb-12",children:"Simplifiez vos processus, centralisez vos données et boostez la productivité de votre équipe."}),e.jsx("div",{className:"grid grid-cols-2 gap-6",children:Kc.map(v=>e.jsxs("div",{className:"bg-white/10 backdrop-blur-sm rounded-2xl p-5 hover:bg-white/15 transition-colors",children:[e.jsx(v.icon,{className:"w-8 h-8 mb-3 text-white/90"}),e.jsx("h3",{className:"font-semibold mb-1",children:v.title}),e.jsx("p",{className:"text-sm text-white/70",children:v.description})]},v.title))})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex -space-x-3",children:[1,2,3,4].map(v=>e.jsx("div",{className:"w-10 h-10 rounded-full bg-white/20 border-2 border-white/30 flex items-center justify-center text-sm font-medium",children:String.fromCharCode(64+v)},v))}),e.jsxs("p",{className:"text-white/80",children:[e.jsx("span",{className:"font-semibold text-white",children:"+500"})," entreprises nous font confiance"]})]})]})]}),e.jsxs("div",{className:"w-full lg:w-1/2 xl:w-[45%] flex flex-col relative bg-[var(--bg-primary)]",children:[e.jsx("div",{className:"lg:hidden absolute inset-0",children:e.jsxs("div",{className:"absolute inset-0 overflow-hidden",children:[e.jsx("div",{className:"absolute -top-40 -right-40 w-96 h-96 rounded-full bg-primary-500/20 blur-3xl animate-pulse"}),e.jsx("div",{className:"absolute -bottom-40 -left-40 w-96 h-96 rounded-full bg-accent-500/20 blur-3xl animate-pulse",style:{animationDelay:"1s"}})]})}),e.jsxs("div",{className:"absolute top-6 right-6 z-10 flex items-center gap-2",children:[e.jsx("a",{href:"/",className:"p-2 rounded-lg bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] transition-colors",title:"Retour à l'accueil",children:e.jsx(a.Home,{className:"w-5 h-5 text-[var(--text-secondary)]"})}),e.jsx(ms,{})]}),e.jsx("div",{className:"flex-1 flex items-center justify-center p-6 sm:p-8 lg:p-12",children:e.jsxs("div",{className:"w-full max-w-md relative",children:[e.jsxs("div",{className:"lg:hidden flex flex-col items-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl animated-gradient flex items-center justify-center mb-4 shadow-lg",children:e.jsx(a.Layers,{className:"w-8 h-8 text-white"})}),e.jsx("h1",{className:"text-2xl font-bold",children:"SmartStack"})]}),e.jsxs("div",{className:"hidden lg:block mb-8",children:[e.jsx("h2",{className:"text-3xl font-bold mb-2",children:"Bienvenue"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:"Connectez-vous à votre compte pour continuer"})]}),m&&e.jsxs("div",{className:`mb-6 p-4 rounded-xl border text-sm flex items-start gap-3 ${Wc(m.code)}`,children:[_c(m.code),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:m.message}),m.code==="ACCOUNT_DISABLED"&&e.jsx("p",{className:"text-xs mt-1 opacity-80",children:"Contactez le support si vous pensez qu'il s'agit d'une erreur."}),m.code==="EXTERNAL_AUTH_REQUIRED"&&e.jsx("p",{className:"text-xs mt-1 opacity-80",children:"Utilisez les boutons Microsoft ou Google ci-dessous."})]})]}),e.jsxs("form",{onSubmit:h,className:"space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium mb-2",children:"Adresse email"}),e.jsxs("div",{className:"relative",children:[e.jsx(a.Mail,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-[var(--text-tertiary)]"}),e.jsx("input",{id:"email",type:"email",value:s,onChange:v=>t(v.target.value),placeholder:"vous@exemple.com",required:!0,className:"w-full pl-12 pr-4 py-3.5 rounded-xl bg-[var(--bg-tertiary)] border border-[var(--border-color)] focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 outline-none transition-all placeholder:text-[var(--text-tertiary)]"})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium mb-2",children:"Mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx(a.Lock,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-[var(--text-tertiary)]"}),e.jsx("input",{id:"password",type:i?"text":"password",value:r,onChange:v=>n(v.target.value),placeholder:"••••••••",required:!0,className:"w-full pl-12 pr-12 py-3.5 rounded-xl bg-[var(--bg-tertiary)] border border-[var(--border-color)] focus:border-primary-500 focus:ring-2 focus:ring-primary-500/20 outline-none transition-all placeholder:text-[var(--text-tertiary)]"}),e.jsx("button",{type:"button",onClick:()=>o(!i),className:"absolute right-4 top-1/2 -translate-y-1/2 text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors",children:i?e.jsx(a.EyeOff,{className:"w-5 h-5"}):e.jsx(a.Eye,{className:"w-5 h-5"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)] bg-[var(--bg-tertiary)] text-primary-600 focus:ring-primary-500/20"}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:"Se souvenir de moi"})]}),e.jsx("a",{href:"/forgot-password",className:"text-primary-500 hover:text-primary-600 font-medium transition-colors",children:"Mot de passe oublié ?"})]}),e.jsx("button",{type:"submit",disabled:c,className:"w-full py-3.5 px-4 rounded-xl bg-primary-600 hover:bg-primary-700 disabled:bg-primary-600/50 text-white font-semibold transition-all shadow-lg shadow-primary-500/25 hover:shadow-primary-500/40 disabled:shadow-none flex items-center justify-center gap-2",children:c?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}),u==="auth"?"Connexion en cours...":"Chargement des préférences..."]}):"Se connecter"})]}),e.jsxs("div",{className:"relative my-8",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-[var(--border-color)]"})}),e.jsx("div",{className:"relative flex justify-center text-sm",children:e.jsx("span",{className:"px-4 bg-[var(--bg-primary)] text-[var(--text-tertiary)]",children:"Ou continuer avec"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("button",{type:"button",onClick:()=>window.location.href="/api/auth/microsoft",className:"flex items-center justify-center gap-3 py-3.5 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] font-medium transition-all",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 21 21",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("rect",{x:"1",y:"1",width:"9",height:"9",fill:"#F25022"}),e.jsx("rect",{x:"11",y:"1",width:"9",height:"9",fill:"#7FBA00"}),e.jsx("rect",{x:"1",y:"11",width:"9",height:"9",fill:"#00A4EF"}),e.jsx("rect",{x:"11",y:"11",width:"9",height:"9",fill:"#FFB900"})]}),"Microsoft"]}),e.jsxs("button",{type:"button",onClick:()=>window.location.href="/api/auth/google",className:"flex items-center justify-center gap-3 py-3.5 px-4 rounded-xl bg-[var(--bg-tertiary)] hover:bg-[var(--bg-secondary)] border border-[var(--border-color)] font-medium transition-all",children:[e.jsxs("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[e.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),e.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),e.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),e.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),"Google"]})]}),e.jsxs("p",{className:"text-center text-[var(--text-secondary)] mt-8",children:["Nouveau sur SmartStack ?"," ",e.jsx("a",{href:"/register",className:"text-primary-500 hover:text-primary-600 font-semibold transition-colors",children:"Créer un compte"})]})]})}),e.jsx("div",{className:"p-6 text-center",children:e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)]",children:["© ",new Date().getFullYear()," SmartStack. Tous droits réservés."]})})]})]})}function Qc(){const[s,t]=l.useState(""),[r,n]=l.useState(""),[i,o]=l.useState(""),[c,x]=l.useState(""),[u,d]=l.useState(""),[m,p]=l.useState(!1),[h,v]=l.useState(!1),[b,g]=l.useState(!1),[j,w]=l.useState(null),[f,N]=l.useState(null),k=()=>!s||!r||!i||!c||!u?(w("Tous les champs sont requis"),!1):r!==i?(w("Les mots de passe ne correspondent pas"),!1):r.length<8?(w("Le mot de passe doit contenir au moins 8 caractères"),!1):!0,C=async y=>{if(y.preventDefault(),w(null),N(null),!!k()){g(!0);try{qe.logEvent("register_attempt","auth",{email:s});const A=await us.register({email:s,password:r,firstName:c,lastName:u});qe.logEvent("register_success","auth",{email:s}),N(A.message),t(""),n(""),o(""),x(""),d("")}catch(A){if(A instanceof nr)w(A.message);else{const D=A instanceof Error?A.message:"Une erreur inattendue est survenue";w(D)}qe.logError(A instanceof Error?A:new Error(String(A)),"RegisterPage.handleSubmit",{email:s})}finally{g(!1)}}};return e.jsxs("div",{className:"min-h-screen flex",children:[e.jsxs("div",{className:"hidden lg:flex lg:w-1/2 bg-gradient-to-br from-blue-600 via-purple-600 to-indigo-600 p-12 text-white flex-col justify-between relative overflow-hidden",children:[e.jsx("div",{className:"absolute inset-0 opacity-10",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 2px 2px, white 1px, transparent 0)",backgroundSize:"40px 40px"}})}),e.jsxs("div",{className:"relative z-10",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-12",children:[e.jsx("div",{className:"p-2 bg-white/20 backdrop-blur-sm rounded-lg",children:e.jsx("div",{className:"w-8 h-8 flex items-center justify-center",children:e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",className:"w-6 h-6",children:e.jsx("path",{d:"M12 2L2 7V17L12 22L22 17V7L12 2ZM12 4.5L19 8.27V15.73L12 19.5L5 15.73V8.27L12 4.5Z"})})})}),e.jsx("div",{className:"text-2xl font-bold tracking-tight",children:"SmartStack"})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("h1",{className:"text-4xl font-bold leading-tight",children:["Créez votre compte",e.jsx("br",{}),e.jsx("span",{className:"text-white/80",children:"et rejoignez-nous"})]}),e.jsx("p",{className:"text-white/80 text-lg max-w-md",children:"Accédez à une plateforme complète de gestion avec authentification sécurisée et tableau de bord personnalisé."})]})]}),e.jsxs("div",{className:"relative z-10 text-sm text-white/60",children:["© ",new Date().getFullYear()," SmartStack. Tous droits réservés."]})]}),e.jsx("div",{className:"w-full lg:w-1/2 flex items-center justify-center p-8 bg-white dark:bg-gray-900",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900 dark:text-white mb-2",children:"Créer un compte"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Remplissez vos informations pour commencer"})]}),f&&e.jsxs("div",{className:"mb-6 p-4 bg-green-500/10 border border-green-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.CheckCircle2,{className:"w-5 h-5 text-green-600 dark:text-green-400 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-green-600 dark:text-green-400",children:f}),e.jsx("p",{className:"text-xs text-green-600/80 dark:text-green-400/80 mt-1",children:"Consultez vos emails pour confirmer votre adresse."})]})]}),j&&e.jsxs("div",{className:"mb-6 p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-500 flex-1",children:j})]}),e.jsxs("form",{onSubmit:C,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"firstName",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Prénom"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.User,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"firstName",type:"text",value:c,onChange:y=>x(y.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"Jean",required:!0,autoComplete:"given-name",disabled:b})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"lastName",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Nom"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.User,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"lastName",type:"text",value:u,onChange:y=>d(y.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"Dupont",required:!0,autoComplete:"family-name",disabled:b})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Adresse email"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Mail,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"email",type:"email",value:s,onChange:y=>t(y.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"vous@exemple.com",required:!0,autoComplete:"email",disabled:b})]})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"password",type:m?"text":"password",value:r,onChange:y=>n(y.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:b}),e.jsx("button",{type:"button",onClick:()=>p(!m),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",tabIndex:-1,children:m?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Minimum 8 caractères"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmPassword",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Confirmer le mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"confirmPassword",type:h?"text":"password",value:i,onChange:y=>o(y.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-800 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-colors",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:b}),e.jsx("button",{type:"button",onClick:()=>v(!h),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600 dark:hover:text-gray-300",tabIndex:-1,children:h?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]})]}),e.jsx("button",{type:"submit",disabled:b,className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:b?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"h-5 w-5 animate-spin"}),"Création en cours..."]}):e.jsx(e.Fragment,{children:"Créer mon compte"})})]}),e.jsx("div",{className:"mt-6 text-center space-y-2",children:e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Vous avez déjà un compte ?"," ",e.jsx(Q.Link,{to:"/login",className:"text-blue-600 dark:text-blue-400 hover:underline font-medium",children:"Se connecter"})]})})]})})]})}function Jc(){const[s]=Q.useSearchParams(),t=s.get("token"),[r,n]=l.useState("loading"),[i,o]=l.useState(""),[c,x]=l.useState(""),[u,d]=l.useState(""),[m,p]=l.useState(!1),[h,v]=l.useState("");l.useEffect(()=>{if(!t){n("error"),o("Lien de confirmation invalide. Aucun token fourni.");return}(async()=>{try{const j=await us.confirmEmail(t);n("success"),o(j.message),x(j.email)}catch(j){const w=j,f=j?.code;n(f==="TOKEN_EXPIRED"?"expired":f==="TOKEN_ALREADY_USED"?"already_used":"error"),o(w?.message||"Une erreur est survenue lors de la confirmation.")}})()},[t]);const b=async g=>{if(g.preventDefault(),!!u){p(!0),v("");try{const j=await us.resendConfirmation(u);v(j.message)}catch(j){v(j?.message||"Erreur lors de l'envoi.")}finally{p(!1)}}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-8",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[r==="loading"&&e.jsxs("div",{className:"text-center",children:[e.jsx(a.Loader2,{className:"w-16 h-16 text-blue-500 animate-spin mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Confirmation en cours..."}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Veuillez patienter pendant que nous vérifions votre email."})]}),r==="success"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Email confirmé !"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:i}),c&&e.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-6",children:["Compte : ",e.jsx("strong",{children:c})]}),e.jsx(Q.Link,{to:"/login",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 transition-all",children:"Se connecter"})]}),(r==="error"||r==="expired"||r==="already_used")&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:`w-16 h-16 rounded-full flex items-center justify-center mx-auto mb-4 ${r==="already_used"?"bg-amber-100 dark:bg-amber-900/30":"bg-red-100 dark:bg-red-900/30"}`,children:r==="already_used"?e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-amber-600 dark:text-amber-400"}):e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsxs("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:[r==="expired"&&"Lien expiré",r==="already_used"&&"Lien déjà utilisé",r==="error"&&"Erreur de confirmation"]}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:i}),(r==="expired"||r==="error")&&e.jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 pt-6 mt-6",children:[e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mb-4",children:"Demander un nouveau lien de confirmation :"}),e.jsxs("form",{onSubmit:b,className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Mail,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{type:"email",value:u,onChange:g=>d(g.target.value),placeholder:"Votre email",className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",required:!0})]}),e.jsxs("button",{type:"submit",disabled:m,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 disabled:opacity-50 transition-colors",children:[m?e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}):e.jsx(a.RefreshCw,{className:"w-5 h-5"}),"Renvoyer le lien"]})]}),h&&e.jsx("p",{className:"mt-3 text-sm text-green-600 dark:text-green-400",children:h})]}),r==="already_used"&&e.jsx(Q.Link,{to:"/login",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 transition-all",children:"Se connecter"})]})]}),e.jsx("p",{className:"text-center text-sm text-gray-500 dark:text-gray-400 mt-6",children:e.jsx(Q.Link,{to:"/login",className:"hover:underline",children:"Retour à la connexion"})})]})})}function Yc(){const[s,t]=l.useState(""),[r,n]=l.useState(!1),[i,o]=l.useState(null),[c,x]=l.useState(!1),u=async d=>{d.preventDefault(),o(null),n(!0);try{await us.forgotPassword(s),x(!0)}catch(m){o(m?.message||"Une erreur est survenue")}finally{n(!1)}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-8",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[c?e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Email envoyé !"}),e.jsxs("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:["Si un compte existe avec l'adresse ",e.jsx("strong",{children:s}),", vous recevrez un lien de réinitialisation."]}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"N'oubliez pas de vérifier vos spams."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.Mail,{className:"w-8 h-8 text-blue-600 dark:text-blue-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Mot de passe oublié ?"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Entrez votre email et nous vous enverrons un lien pour réinitialiser votre mot de passe."})]}),i&&e.jsxs("div",{className:"mb-6 p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-500",children:i})]}),e.jsxs("form",{onSubmit:u,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Adresse email"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Mail,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"email",type:"email",value:s,onChange:d=>t(d.target.value),className:"block w-full pl-10 pr-3 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"vous@exemple.com",required:!0,autoComplete:"email",disabled:r})]})]}),e.jsx("button",{type:"submit",disabled:r,className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 disabled:opacity-50 transition-all",children:r?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"h-5 w-5 animate-spin"}),"Envoi en cours..."]}):"Envoyer le lien"})]})]}),e.jsx("div",{className:"mt-6 pt-6 border-t border-gray-200 dark:border-gray-700",children:e.jsxs(Q.Link,{to:"/login",className:"flex items-center justify-center gap-2 text-sm text-gray-600 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-400 transition-colors",children:[e.jsx(a.ArrowLeft,{className:"w-4 h-4"}),"Retour à la connexion"]})})]})]})})}function Zc(){const[s]=Q.useSearchParams(),t=Q.useNavigate(),r=s.get("token"),[n,i]=l.useState(""),[o,c]=l.useState(""),[x,u]=l.useState(!1),[d,m]=l.useState(!1),[p,h]=l.useState(!1),[v,b]=l.useState("form"),[g,j]=l.useState(null);l.useEffect(()=>{r||(b("invalid_token"),j("Lien de réinitialisation invalide. Aucun token fourni."))},[r]);const w=()=>n.length<8?(j("Le mot de passe doit contenir au moins 8 caractères"),!1):n!==o?(j("Les mots de passe ne correspondent pas"),!1):!0,f=async N=>{if(N.preventDefault(),j(null),!(!w()||!r)){h(!0);try{await us.resetPassword(r,n),b("success")}catch(k){const C=k,y=k?.code;y==="TOKEN_EXPIRED"||y==="TOKEN_ALREADY_USED"||y==="INVALID_TOKEN"?(b("error"),j(C?.message||"Le lien de réinitialisation est invalide ou a expiré.")):j(C?.message||"Une erreur est survenue")}finally{h(!1)}}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900 p-8",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"flex justify-end mb-8",children:e.jsx(ms,{})}),e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[v==="invalid_token"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Lien invalide"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:g}),e.jsx(Q.Link,{to:"/forgot-password",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",children:"Demander un nouveau lien"})]}),v==="error"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Lien expiré"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:g}),e.jsx(Q.Link,{to:"/forgot-password",className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg font-medium hover:bg-blue-700 transition-colors",children:"Demander un nouveau lien"})]}),v==="success"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle2,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Mot de passe réinitialisé !"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:"Votre mot de passe a été modifié avec succès. Vous pouvez maintenant vous connecter."}),e.jsx("button",{onClick:()=>t("/login"),className:"inline-flex items-center justify-center gap-2 px-6 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 transition-all",children:"Se connecter"})]}),v==="form"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 bg-blue-100 dark:bg-blue-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.Lock,{className:"w-8 h-8 text-blue-600 dark:text-blue-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Nouveau mot de passe"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Choisissez un nouveau mot de passe sécurisé."})]}),g&&e.jsxs("div",{className:"mb-6 p-4 bg-red-500/10 border border-red-500/20 rounded-lg flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-500",children:g})]}),e.jsxs("form",{onSubmit:f,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Nouveau mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"password",type:x?"text":"password",value:n,onChange:N=>i(N.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:p}),e.jsx("button",{type:"button",onClick:()=>u(!x),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",tabIndex:-1,children:x?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Minimum 8 caractères"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"confirmPassword",className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Confirmer le mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none",children:e.jsx(a.Lock,{className:"h-5 w-5 text-gray-400"})}),e.jsx("input",{id:"confirmPassword",type:d?"text":"password",value:o,onChange:N=>c(N.target.value),className:"block w-full pl-10 pr-10 py-2.5 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"••••••••",required:!0,autoComplete:"new-password",disabled:p}),e.jsx("button",{type:"button",onClick:()=>m(!d),className:"absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600",tabIndex:-1,children:d?e.jsx(a.EyeOff,{className:"h-5 w-5"}):e.jsx(a.Eye,{className:"h-5 w-5"})})]})]}),e.jsx("button",{type:"submit",disabled:p,className:"w-full flex items-center justify-center gap-2 px-4 py-3 bg-gradient-to-r from-blue-600 to-purple-600 text-white rounded-lg font-medium hover:from-blue-700 hover:to-purple-700 disabled:opacity-50 transition-all",children:p?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"h-5 w-5 animate-spin"}),"Réinitialisation..."]}):"Réinitialiser le mot de passe"})]})]}),e.jsx("div",{className:"mt-6 pt-6 border-t border-gray-200 dark:border-gray-700",children:e.jsx(Q.Link,{to:"/login",className:"flex items-center justify-center text-sm text-gray-600 dark:text-gray-400 hover:text-blue-600 dark:hover:text-blue-400 transition-colors",children:"Retour à la connexion"})})]})]})})}function ed(){const{t:s}=ne.useTranslation(),t=Q.useNavigate(),[r,n]=l.useState(""),[i,o]=l.useState(""),[c,x]=l.useState(""),[u,d]=l.useState(!1),[m,p]=l.useState(!1),[h,v]=l.useState(!1),[b,g]=l.useState(null),[j,w]=l.useState(!1),N=(y=>{const A=[];return y.length<8&&A.push("Au moins 8 caractères"),/[A-Z]/.test(y)||A.push("Au moins une majuscule"),/[a-z]/.test(y)||A.push("Au moins une minuscule"),/[0-9]/.test(y)||A.push("Au moins un chiffre"),A})(i),k=i===c&&N.length===0&&r.length>0,C=async y=>{if(y.preventDefault(),!!k){v(!0),g(null);try{await us.changePassword(r,i),w(!0),setTimeout(()=>{t("/")},2e3)}catch(A){A instanceof Error?g(A.message):g("Une erreur est survenue")}finally{v(!1)}}};return j?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 p-4",children:e.jsxs("div",{className:"w-full max-w-md bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8 text-center",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.CheckCircle,{className:"w-8 h-8 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-2",children:"Mot de passe modifié"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Vous allez être redirigé vers l'accueil..."})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 p-4",children:e.jsx("div",{className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl shadow-xl p-8",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"w-16 h-16 bg-amber-100 dark:bg-amber-900/30 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(a.Lock,{className:"w-8 h-8 text-amber-600 dark:text-amber-400"})}),e.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:s("auth.forceChangePassword.title","Changement de mot de passe requis")}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mt-2",children:s("auth.forceChangePassword.description","Pour des raisons de sécurité, vous devez définir un nouveau mot de passe.")})]}),b&&e.jsxs("div",{className:"mb-6 p-4 rounded-xl bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300 flex items-center gap-2",children:[e.jsx(a.AlertTriangle,{className:"w-5 h-5 flex-shrink-0"}),e.jsx("span",{children:b})]}),e.jsxs("form",{onSubmit:C,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:s("auth.forceChangePassword.currentPassword","Mot de passe actuel (temporaire)")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:u?"text":"password",required:!0,value:r,onChange:y=>n(y.target.value),className:"w-full px-4 py-3 rounded-xl border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Entrez le mot de passe fourni par l'administrateur"}),e.jsx("button",{type:"button",onClick:()=>d(!u),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:u?e.jsx(a.EyeOff,{className:"w-5 h-5"}):e.jsx(a.Eye,{className:"w-5 h-5"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:s("auth.forceChangePassword.newPassword","Nouveau mot de passe")}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:m?"text":"password",required:!0,value:i,onChange:y=>o(y.target.value),className:"w-full px-4 py-3 rounded-xl border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"Choisissez un nouveau mot de passe"}),e.jsx("button",{type:"button",onClick:()=>p(!m),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300",children:m?e.jsx(a.EyeOff,{className:"w-5 h-5"}):e.jsx(a.Eye,{className:"w-5 h-5"})})]}),i&&e.jsx("div",{className:"mt-2 space-y-1",children:["Au moins 8 caractères","Au moins une majuscule","Au moins une minuscule","Au moins un chiffre"].map((y,A)=>{const D=[i.length>=8,/[A-Z]/.test(i),/[a-z]/.test(i),/[0-9]/.test(i)];return e.jsxs("div",{className:`flex items-center gap-2 text-sm ${D[A]?"text-green-600":"text-gray-500"}`,children:[D[A]?e.jsx(a.CheckCircle,{className:"w-4 h-4"}):e.jsx("div",{className:"w-4 h-4 rounded-full border border-current"}),y]},`pwd-req-${A}`)})})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:s("auth.forceChangePassword.confirmPassword","Confirmer le nouveau mot de passe")}),e.jsx("input",{type:"password",required:!0,value:c,onChange:y=>x(y.target.value),className:`w-full px-4 py-3 rounded-xl border ${c&&c!==i?"border-red-500 focus:ring-red-500":"border-gray-300 dark:border-gray-600 focus:ring-blue-500"} bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2`,placeholder:"Confirmez votre nouveau mot de passe"}),c&&c!==i&&e.jsx("p",{className:"mt-1 text-sm text-red-600",children:"Les mots de passe ne correspondent pas"})]}),e.jsx("button",{type:"submit",disabled:!k||h,className:"w-full py-3 px-4 rounded-xl bg-blue-600 hover:bg-blue-700 text-white font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:h?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Modification en cours..."})]}):e.jsx("span",{children:s("auth.forceChangePassword.submit","Définir mon nouveau mot de passe")})})]})]})})})}const sd={auth_failed:"L'authentification a échoué. Veuillez réessayer.",no_email:"Impossible de récupérer votre adresse email depuis le fournisseur.",account_disabled:"Votre compte est désactivé. Contactez l'administrateur.",account_locked:"Votre compte est verrouillé. Contactez l'administrateur.",internal_error:"Une erreur interne est survenue. Veuillez réessayer."};function td(){const[s]=Q.useSearchParams(),t=Q.useNavigate(),[r,n]=l.useState("processing"),[i,o]=l.useState("");l.useEffect(()=>{const u=s.get("token"),d=s.get("refreshToken"),m=s.get("error");if(m){n("error"),o(sd[m]||"Une erreur est survenue lors de l'authentification.");return}u&&d?c(u,d):(n("error"),o("Paramètres d'authentification manquants."))},[s]);const c=async(u,d)=>{try{localStorage.setItem("token",u),localStorage.setItem("refreshToken",d);try{const h=await Ti(),v=Si();(h||v)&&await fetch("/api/auth/update-session-client-info",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${u}`},body:JSON.stringify({clientIp:h,deviceType:v})})}catch(h){console.warn("Failed to update session client info:",h)}const m=await fetch("/api/auth/me",{headers:{Authorization:`Bearer ${u}`}});if(!m.ok)throw new Error("Failed to fetch user info");const p=await m.json();localStorage.setItem("user",JSON.stringify(p));try{const h=await fetch("/api/onboarding/status",{headers:{Authorization:`Bearer ${u}`}});if(h.ok&&!(await h.json()).hasCompletedOnboarding){n("success"),setTimeout(()=>{window.location.href="/auth/onboarding"},1500);return}}catch{}try{const h=await Is.preferences.get(),v={mode:h.theme||"dark",accentColorKey:h.accentColorKey||"indigo",borderRadius:h.borderRadius||{},itemPaletteKey:h.itemPaletteKey||"neutral"};localStorage.setItem("smartstack-theme-config",JSON.stringify(v)),h.language&&localStorage.setItem("i18nextLng",h.language)}catch{}n("success"),setTimeout(()=>{window.location.href="/personal/myspace"},1500)}catch(m){console.error("Auth callback error:",m),n("error"),o("Erreur lors de la finalisation de l'authentification.")}},x=()=>{t("/login")};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)]",children:e.jsx("div",{className:"max-w-md w-full mx-4",children:e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-2xl p-8 shadow-lg border border-[var(--border-color)]",children:[r==="processing"&&e.jsxs("div",{className:"text-center",children:[e.jsx(a.Loader2,{className:"w-16 h-16 mx-auto text-[var(--color-accent-500)] animate-spin mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Authentification en cours..."}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:"Veuillez patienter pendant que nous finalisons votre connexion."})]}),r==="success"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mb-4",children:e.jsx(a.CheckCircle,{className:"w-10 h-10 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Connexion réussie !"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:"Vous allez être redirigé vers votre espace personnel..."})]}),r==="error"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-16 h-16 mx-auto bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mb-4",children:e.jsx(a.XCircle,{className:"w-10 h-10 text-red-600 dark:text-red-400"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Échec de l'authentification"}),e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 rounded-lg p-4 mb-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(a.AlertCircle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-700 dark:text-red-300",children:i})]})}),e.jsx("button",{onClick:x,className:"btn btn-primary w-full",children:"Retourner à la connexion"})]})]})})})}const Or=[{code:"fr",name:"Francais",flag:"🇫🇷"},{code:"en",name:"English",flag:"🇬🇧"},{code:"de",name:"Deutsch",flag:"🇩🇪"},{code:"it",name:"Italiano",flag:"🇮🇹"}],ha=[{value:"light",labelKey:"themeLight",icon:"☀️"},{value:"dark",labelKey:"themeDark",icon:"🌙"},{value:"system",labelKey:"themeSystem",icon:"💻"}],ba=[{key:"indigo",color:"#6366f1",name:"Indigo"},{key:"blue",color:"#3b82f6",name:"Blue"},{key:"emerald",color:"#10b981",name:"Emerald"},{key:"amber",color:"#f59e0b",name:"Amber"},{key:"rose",color:"#f43f5e",name:"Rose"},{key:"purple",color:"#a855f7",name:"Purple"}];function ad(){const{t:s,i18n:t}=ne.useTranslation("auth"),r=Q.useNavigate(),[n,i]=l.useState("language"),[o,c]=l.useState(t.language?.substring(0,2)||"fr"),[x,u]=l.useState("dark"),[d,m]=l.useState("indigo"),[p,h]=l.useState(!1),[v,b]=l.useState(null),[g,j]=l.useState(!1);l.useEffect(()=>{(async()=>{try{(await oe.get("/api/onboarding/status")).hasCompletedOnboarding&&r("/personal/myspace",{replace:!0})}catch{}})()},[r]),l.useEffect(()=>{o&&o!==t.language?.substring(0,2)&&ir(o)},[o,t]);const w=[{key:"language",labelKey:"stepLanguage",icon:e.jsx(a.Globe,{className:"w-5 h-5"})},{key:"theme",labelKey:"stepTheme",icon:e.jsx(a.Palette,{className:"w-5 h-5"})},{key:"complete",labelKey:"stepComplete",icon:e.jsx(a.Sparkles,{className:"w-5 h-5"})}],f=w.findIndex(y=>y.key===n),N=()=>{const y=f+1;y<w.length&&i(w[y].key)},k=()=>{const y=f-1;y>=0&&i(w[y].key)},C=async()=>{h(!0),b(null);try{await oe.post("/api/onboarding/complete",{language:o,theme:x,accentColorKey:d}),localStorage.setItem("i18nextLng",o),localStorage.setItem("smartstack-theme-config",JSON.stringify({mode:x,accentColorKey:d,borderRadius:{},itemPaletteKey:"neutral"})),j(!0),setTimeout(()=>{window.location.href="/personal/myspace"},2e3)}catch(y){console.error("Onboarding error:",y),b(s("onboarding.errorMessage"))}finally{h(!1)}};return g?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)]",children:e.jsx("div",{className:"max-w-md w-full mx-4",children:e.jsx("div",{className:"bg-[var(--bg-secondary)] rounded-2xl p-8 shadow-lg border border-[var(--border-color)]",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-20 h-20 mx-auto bg-green-100 dark:bg-green-900/30 rounded-full flex items-center justify-center mb-6",children:e.jsx(a.CheckCircle,{className:"w-12 h-12 text-green-600 dark:text-green-400"})}),e.jsx("h2",{className:"text-2xl font-bold mb-3",children:s("onboarding.successTitle")}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("onboarding.successMessage")}),e.jsx("div",{className:"mt-6",children:e.jsx(a.Loader2,{className:"w-6 h-6 mx-auto text-[var(--color-accent-500)] animate-spin"})})]})})})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-[var(--bg-primary)] p-4",children:e.jsxs("div",{className:"max-w-lg w-full",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("div",{className:"flex items-center justify-center gap-2 mb-4",children:e.jsx("div",{className:"w-12 h-12 bg-gradient-to-br from-blue-500 to-purple-600 rounded-xl flex items-center justify-center",children:e.jsx("span",{className:"text-white text-xl font-bold",children:"S"})})}),e.jsx("h1",{className:"text-3xl font-bold mb-2",children:s("onboarding.title")}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("onboarding.subtitle")})]}),e.jsx("div",{className:"flex justify-center mb-8",children:e.jsx("div",{className:"flex items-center gap-2",children:w.map((y,A)=>e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center transition-all ${A<=f?"bg-[var(--color-accent-500)] text-white":"bg-[var(--bg-tertiary)] text-[var(--text-secondary)]"}`,children:y.icon}),A<w.length-1&&e.jsx("div",{className:`w-12 h-1 mx-1 rounded transition-all ${A<f?"bg-[var(--color-accent-500)]":"bg-[var(--bg-tertiary)]"}`})]},y.key))})}),e.jsxs("div",{className:"bg-[var(--bg-secondary)] rounded-2xl p-8 shadow-lg border border-[var(--border-color)]",children:[n==="language"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold mb-6 text-center",children:s("onboarding.languageLabel")}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:Or.map(y=>e.jsxs("button",{onClick:()=>c(y.code),className:`p-4 rounded-xl border-2 transition-all ${o===y.code?"border-[var(--color-accent-500)] bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20":"border-[var(--border-color)] hover:border-[var(--color-accent-300)]"}`,children:[e.jsx("span",{className:"text-3xl mb-2 block",children:y.flag}),e.jsx("span",{className:"font-medium",children:y.name})]},y.code))})]}),n==="theme"&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold mb-6 text-center",children:s("onboarding.themeLabel")}),e.jsx("div",{className:"grid grid-cols-3 gap-3 mb-8",children:ha.map(y=>e.jsxs("button",{onClick:()=>u(y.value),className:`p-4 rounded-xl border-2 transition-all ${x===y.value?"border-[var(--color-accent-500)] bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20":"border-[var(--border-color)] hover:border-[var(--color-accent-300)]"}`,children:[e.jsx("span",{className:"text-2xl mb-2 block",children:y.icon}),e.jsx("span",{className:"text-sm font-medium",children:s(`onboarding.${y.labelKey}`)})]},y.value))}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3 text-[var(--text-secondary)]",children:s("onboarding.accentColorLabel")}),e.jsx("div",{className:"flex justify-center gap-3",children:ba.map(y=>e.jsx("button",{onClick:()=>m(y.key),className:`w-10 h-10 rounded-full transition-all ${d===y.key?"ring-2 ring-offset-2 ring-[var(--color-accent-500)] ring-offset-[var(--bg-secondary)]":"hover:scale-110"}`,style:{backgroundColor:y.color},title:y.name},y.key))})]})]}),n==="complete"&&e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-20 h-20 mx-auto bg-[var(--color-accent-100)] dark:bg-[var(--color-accent-900)]/30 rounded-full flex items-center justify-center mb-6",children:e.jsx(a.Sparkles,{className:"w-10 h-10 text-[var(--color-accent-500)]"})}),e.jsx("h2",{className:"text-xl font-semibold mb-4",children:s("onboarding.stepComplete")}),e.jsxs("div",{className:"text-[var(--text-secondary)] mb-6 space-y-2",children:[e.jsx("p",{children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(a.Globe,{className:"w-4 h-4"}),Or.find(y=>y.code===o)?.name]})}),e.jsx("p",{children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(a.Palette,{className:"w-4 h-4"}),ha.find(y=>y.value===x)?.icon," ",s(`onboarding.${ha.find(y=>y.value===x)?.labelKey}`)]})}),e.jsx("p",{children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx("span",{className:"w-4 h-4 rounded-full",style:{backgroundColor:ba.find(y=>y.key===d)?.color}}),ba.find(y=>y.key===d)?.name]})})]}),v&&e.jsx("div",{className:"bg-red-50 dark:bg-red-900/20 text-red-700 dark:text-red-300 rounded-lg p-3 mb-4 text-sm",children:v})]}),e.jsxs("div",{className:"flex justify-between mt-8",children:[f>0?e.jsxs("button",{onClick:k,className:"flex items-center gap-2 px-4 py-2 text-[var(--text-secondary)] hover:text-[var(--text-primary)] transition-colors",children:[e.jsx(a.ArrowLeft,{className:"w-4 h-4"}),s("onboarding.back")]}):e.jsx("div",{}),n==="complete"?e.jsx("button",{onClick:C,disabled:p,className:"flex items-center gap-2 px-6 py-2 bg-[var(--color-accent-500)] hover:bg-[var(--color-accent-600)] text-white rounded-lg font-medium transition-colors disabled:opacity-50",children:p?e.jsxs(e.Fragment,{children:[e.jsx(a.Loader2,{className:"w-4 h-4 animate-spin"}),s("onboarding.completing")]}):e.jsxs(e.Fragment,{children:[s("onboarding.complete"),e.jsx(a.CheckCircle,{className:"w-4 h-4"})]})}):e.jsxs("button",{onClick:N,className:"flex items-center gap-2 px-6 py-2 bg-[var(--color-accent-500)] hover:bg-[var(--color-accent-600)] text-white rounded-lg font-medium transition-colors",children:[s("onboarding.continue"),e.jsx(a.ArrowRight,{className:"w-4 h-4"})]})]})]})]})})}function De({items:s,className:t=""}){return e.jsx("nav",{"aria-label":"Breadcrumb",className:`flex items-center gap-1 text-sm ${t}`,children:s.map((r,n)=>{const i=n===s.length-1,o=n===0;return e.jsxs("div",{className:"flex items-center gap-1",children:[n>0&&e.jsx(a.ChevronRight,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),i?e.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--text-primary)] font-medium",children:[r.icon,r.label]}):r.href?e.jsxs(Q.Link,{to:r.href,className:"flex items-center gap-1.5 text-[var(--text-secondary)] hover:text-[var(--color-accent-600)] transition-colors",children:[o&&!r.icon&&e.jsx(a.Home,{className:"w-4 h-4"}),r.icon,r.label]}):e.jsxs("span",{className:"flex items-center gap-1.5 text-[var(--text-secondary)]",children:[r.icon,r.label]})]},`${n}-${r.label}`)})})}const rd={settings:a.Settings,users:a.Users,key:a.Key,briefcase:a.Briefcase,folder:a.FolderOpen,file:a.FileText,box:a.Box};function nd(s){return s&&rd[s.toLowerCase()]||a.Box}function qr({app:s,isFavorite:t,onToggleFavorite:r,buildUrl:n}){const i=nd(s.icon);return e.jsx("div",{className:"group relative bg-[var(--bg-card)] rounded-2xl border border-[var(--border-color)] overflow-hidden hover:border-primary-500/50 transition-all duration-300 hover:shadow-lg hover:shadow-primary-500/10",children:e.jsxs(Q.Link,{to:s.route?n(s.route):"#",className:"block p-6",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-gradient-to-br from-primary-500/20 to-primary-600/20 flex items-center justify-center group-hover:from-primary-500/30 group-hover:to-primary-600/30 transition-all",children:e.jsx(i,{className:"w-7 h-7 text-primary-500"})}),e.jsx("button",{onClick:o=>{o.preventDefault(),o.stopPropagation(),r()},className:`p-2 rounded-lg transition-all duration-200 ${t?"text-amber-500 bg-amber-500/10":"text-[var(--text-tertiary)] opacity-0 group-hover:opacity-100 hover:bg-[var(--bg-tertiary)]"}`,title:t?"Retirer des favoris":"Ajouter aux favoris",children:e.jsx(a.Star,{className:`w-5 h-5 ${t?"fill-current":""}`})})]}),e.jsx("h3",{className:"text-lg font-semibold text-[var(--text-primary)] mb-2",children:s.label}),e.jsxs("p",{className:"text-sm text-[var(--text-secondary)] mb-4",children:[s.modules.length," ",s.modules.length===1?"module":"modules"]}),e.jsxs("div",{className:"flex items-center gap-2 text-primary-500 text-sm font-medium opacity-0 group-hover:opacity-100 transition-opacity",children:["Ouvrir",e.jsx(a.ArrowRight,{className:"w-4 h-4"})]})]})})}function ld(){const{t:s}=ne.useTranslation("admin"),{favorites:t,getApplicationsForContext:r,toggleFavorite:n,isFavorite:i,isLoading:o}=Ze(),c=ws(),x=r("platform");return o?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("div",{className:"w-8 h-8 border-2 border-primary-500 border-t-transparent rounded-full animate-spin"})}):e.jsxs("div",{className:"space-y-8",children:[e.jsx(De,{items:[{label:s("applications.title","Applications")}]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s("applications.title","Applications")}),e.jsx("p",{className:"text-[var(--text-secondary)] mt-1",children:s("applications.subtitle","Sélectionnez une application pour commencer")})]}),t.length>0&&e.jsxs("section",{children:[e.jsxs("h2",{className:"text-lg font-semibold text-[var(--text-primary)] mb-4 flex items-center gap-2",children:[e.jsx(a.Star,{className:"w-5 h-5 text-amber-500 fill-amber-500"}),s("applications.favorites","Favoris")]}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:t.map(u=>{const d=x.find(m=>m.id===u.id);return d?e.jsx(qr,{app:d,isFavorite:!0,onToggleFavorite:()=>n(d.id),buildUrl:c},d.id):null})})]}),e.jsxs("section",{children:[e.jsx("h2",{className:"text-lg font-semibold text-[var(--text-primary)] mb-4",children:s("applications.all","Toutes les applications")}),x.length>0?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:x.map(u=>e.jsx(qr,{app:u,isFavorite:i(u.id),onToggleFavorite:()=>n(u.id),buildUrl:c},u.id))}):e.jsxs("div",{className:"text-center py-12 bg-[var(--bg-card)] rounded-2xl border border-[var(--border-color)]",children:[e.jsx(a.Box,{className:"w-12 h-12 text-[var(--text-tertiary)] mx-auto mb-4"}),e.jsx("p",{className:"text-[var(--text-secondary)]",children:s("applications.noApps","Aucune application disponible")})]})]})]})}const Js={getDashboardStats:async()=>await oe.get("/api/platform/administration/applications/application-analytics/dashboard"),getApplicationAnalytics:async s=>await oe.get(`/api/platform/administration/applications/application-analytics/${s}/analytics`),getApplicationActivity:async(s,t=1,r=20)=>await oe.get(`/api/platform/administration/applications/application-analytics/${s}/recent-activity`,{params:{page:t,pageSize:r}}),getDeviceStats:async(s=30,t)=>await oe.get("/api/platform/administration/applications/application-analytics/device-stats",{params:{period:s},signal:t?.signal}),getEngagementMetrics:async(s=30,t)=>await oe.get("/api/platform/administration/applications/application-analytics/engagement",{params:{period:s},signal:t?.signal}),getTopModules:async(s=10,t=30)=>await oe.get("/api/platform/administration/applications/application-analytics/modules/top",{params:{limit:s,period:t}}),getHierarchyData:async(s=0,t,r,n=30)=>{const i={level:s,period:n};return t&&(i.contextId=t),r&&(i.applicationId=r),await oe.get("/api/platform/administration/applications/application-analytics/hierarchy",{params:i})},getTrendsByApplication:async(s=30)=>await oe.get("/api/platform/administration/applications/application-analytics/trends-by-application",{params:{period:s}})},Vr={Desktop:e.jsx(a.Monitor,{className:"w-4 h-4"}),Mobile:e.jsx(a.Smartphone,{className:"w-4 h-4"}),Tablet:e.jsx(a.Tablet,{className:"w-4 h-4"}),Unknown:e.jsx(a.Monitor,{className:"w-4 h-4 opacity-50"})},zr=["#3b82f6","#22c55e","#f59e0b","#6b7280"],Gr=["#3b82f6","#8b5cf6","#22c55e","#f59e0b","#ef4444"],id=({data:s})=>!s||!s.byDeviceType?.length&&!s.byBrowser?.length?e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"No device data available"}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"By Device Type"}),e.jsx("div",{className:"space-y-3",children:s.byDeviceType.map((t,r)=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 w-28",children:[Vr[t.deviceType]||Vr.Unknown,e.jsx("span",{className:"text-sm",children:t.deviceType})]}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${t.percentage}%`,backgroundColor:zr[r%zr.length]}})}),e.jsxs("div",{className:"w-20 text-right",children:[e.jsx("span",{className:"font-medium",children:t.count}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] ml-1",children:["(",t.percentage.toFixed(1),"%)"]})]})]},t.deviceType))})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"By Browser"}),e.jsx("div",{className:"space-y-3",children:s.byBrowser.map((t,r)=>{const n=Math.max(...s.byBrowser.map(o=>o.count),1),i=t.count/n*100;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-24 text-sm",children:t.browser}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${i}%`,backgroundColor:Gr[r%Gr.length]}})}),e.jsx("div",{className:"w-12 text-right font-medium",children:t.count})]},t.browser)})})]})]}),Hr=["#ef4444","#f59e0b","#22c55e","#3b82f6"],od=({data:s})=>{if(!s)return e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"No engagement data available"});const t=Math.max(...s.sessionDistribution.map(n=>n.count),1),r=Math.max(...s.peakUsageHours.map(n=>n.accessCount),1);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"Session Duration Distribution"}),e.jsx("div",{className:"space-y-3",children:s.sessionDistribution.map((n,i)=>{const o=n.count/t*100;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-20 text-sm",children:n.label}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${o}%`,backgroundColor:Hr[i%Hr.length]}})}),e.jsxs("div",{className:"w-16 text-right",children:[e.jsx("span",{className:"font-medium",children:n.count}),e.jsx("span",{className:"text-xs text-[var(--text-secondary)] ml-1",children:"sessions"})]})]},n.bucket)})})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-3",children:"Peak Usage Hours"}),e.jsx("div",{className:"flex items-end gap-1 h-32 overflow-x-auto pb-2",children:s.peakUsageHours.map(n=>{const i=n.accessCount/r*100;return e.jsxs("div",{className:"flex-1 min-w-[20px] flex flex-col items-center gap-1",children:[e.jsx("div",{className:"w-full bg-gradient-to-t from-blue-500 to-cyan-500 rounded-t transition-all duration-300 hover:opacity-80",style:{height:`${i}%`,minHeight:n.accessCount>0?"4px":"0"},title:`${n.hour}h: ${n.accessCount} accesses`}),n.hour%3===0&&e.jsxs("span",{className:"text-xs text-[var(--text-secondary)]",children:[n.hour,"h"]})]},n.hour)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 pt-4 border-t border-[var(--border-color)]",children:[e.jsxs("div",{className:"text-center p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:s.dailyActiveUsers}),e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mt-1",children:"Daily Active Users"})]}),e.jsxs("div",{className:"text-center p-3 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsxs("div",{className:"text-2xl font-bold text-green-600",children:[(s.retentionRate*100).toFixed(1),"%"]}),e.jsx("div",{className:"text-xs text-[var(--text-secondary)] mt-1",children:"Retention Rate"})]})]})]})},cd={Active:"#22c55e",Inactive:"#ef4444"};function Kr(){const{t:s}=ne.useTranslation(["admin","navigation"]),t=Q.useNavigate(),{currentTenant:r,isGlobalView:n}=ze(),[i,o]=l.useState(!0),[c,x]=l.useState(!1),[u,d]=l.useState(30),[m,p]=l.useState(null),[h,v]=l.useState([]),[b,g]=l.useState([]),[j,w]=l.useState([]),[f,N]=l.useState([]),[k,C]=l.useState([]),[y,A]=l.useState(null),[D,R]=l.useState(null),[L,S]=l.useState(null),[T,I]=l.useState(null),M=l.useRef(null),X=l.useCallback(async U=>{try{I(null);const[K,$,E,q,F,V,P,B,J]=await Promise.all([le.dashboard.getOverview(u,{signal:U}),le.dashboard.getByStatus({signal:U}),le.dashboard.getByRole({signal:U}),le.dashboard.getTrends(u,{signal:U}),le.dashboard.getLatestActiveSessions(5,{signal:U}),le.dashboard.getSecurityAlerts(3,24,{signal:U}),le.dashboard.getActiveSessions({signal:U}),Js.getDeviceStats(u,{signal:U}),Js.getEngagementMetrics(u,{signal:U})]);U?.aborted||(p(K??null),v($??[]),g(E??[]),w(q??[]),N(F??[]),C(V??[]),A(P??null),R(B??null),S(J??null))}catch(K){if(K instanceof Error&&K.name==="CanceledError")return;console.error("Failed to load dashboard data:",K);const $=K;$.response?.status===401?I("Session expirée. Veuillez vous reconnecter."):$.response?.status===403?I("Vous n'avez pas les permissions nécessaires pour accéder au dashboard."):I("Erreur lors du chargement des données. Vérifiez que l'API est accessible.")}finally{U?.aborted||(o(!1),x(!1))}},[u,r?.id,n]);l.useEffect(()=>{M.current?.abort();const U=new AbortController;return M.current=U,X(U.signal),()=>{U.abort()}},[X]);const O=()=>{M.current?.abort();const U=new AbortController;M.current=U,x(!0),X(U.signal)};return i?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-600)]"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(De,{items:[{label:s("header.title")},{label:s("dashboard.title")}]}),T&&e.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg p-4 flex items-center gap-3",children:[e.jsx(a.AlertTriangle,{className:"w-5 h-5 text-red-600 dark:text-red-400 flex-shrink-0"}),e.jsx("div",{className:"flex-1",children:e.jsx("p",{className:"text-red-800 dark:text-red-200 font-medium",children:T})}),e.jsx("button",{onClick:O,className:"text-red-600 dark:text-red-400 hover:text-red-800 dark:hover:text-red-200",children:e.jsx(a.RefreshCw,{className:"w-5 h-5"})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-[var(--text-primary)] flex items-center gap-2",children:[e.jsx(a.Users,{className:"w-6 h-6"}),s("admin:header.title")]}),e.jsx("p",{className:"text-[var(--text-secondary)] mt-1",children:"Vue d'ensemble de la gestion des utilisateurs"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("select",{value:u,onChange:U=>d(Number(U.target.value)),className:"input",children:[e.jsx("option",{value:7,children:"7 derniers jours"}),e.jsx("option",{value:30,children:"30 derniers jours"}),e.jsx("option",{value:90,children:"90 derniers jours"})]}),e.jsxs("button",{onClick:O,disabled:c,className:"btn btn-secondary flex items-center gap-2",children:[e.jsx(a.RefreshCw,{className:`w-4 h-4 ${c?"animate-spin":""}`}),"Actualiser"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:[e.jsx($s,{title:"Total Utilisateurs",value:m?.totalUsers??0,icon:e.jsx(a.Users,{className:"w-5 h-5"}),color:"blue"}),e.jsx($s,{title:"Actifs",value:m?.activeUsers??0,icon:e.jsx(a.UserCheck,{className:"w-5 h-5"}),color:"green"}),e.jsx($s,{title:"Inactifs",value:m?.inactiveUsers??0,icon:e.jsx(a.UserX,{className:"w-5 h-5"}),color:"red"}),e.jsx($s,{title:"Nouveaux",value:m?.newUsers??0,icon:e.jsx(a.UserPlus,{className:"w-5 h-5"}),color:"blue",subtitle:`${u} derniers jours`}),e.jsx($s,{title:"Sessions",value:m?.totalSessions??0,icon:e.jsx(a.Activity,{className:"w-5 h-5"}),color:"green",subtitle:`${u} derniers jours`}),e.jsx($s,{title:"Connexions Echouées",value:m?.failedLogins??0,icon:e.jsx(a.AlertTriangle,{className:"w-5 h-5"}),color:m&&m.failedLogins>10?"red":"yellow",subtitle:`${u} derniers jours`})]}),(k?.length??0)>0&&e.jsxs("div",{className:"card p-4 border-l-4 border-red-500",children:[e.jsxs("h3",{className:"font-semibold text-red-600 flex items-center gap-2 mb-3",children:[e.jsx(a.AlertTriangle,{className:"w-5 h-5"}),"Alertes Sécurité (",k?.length??0,")"]}),e.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto",children:(k??[]).slice(0,5).map(U=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-red-50 dark:bg-red-900/20 rounded cursor-pointer hover:bg-red-100 dark:hover:bg-red-900/30",onClick:()=>t(`/platform/administration/users/${U.userId}`),children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:U.fullName}),e.jsx("span",{className:"ml-2 text-sm text-[var(--text-secondary)]",children:U.email})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-red-600 font-medium",children:[U.failedAttempts," échecs"]}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)]",children:[U.ipAddresses?.length??0," IP(s)"]})]})]},U.userId))})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.UserCheck,{className:"w-5 h-5"}),"Utilisateurs par Statut"]}),e.jsx("div",{className:"space-y-3",children:(h??[]).map(U=>{const K=(h??[]).reduce((E,q)=>E+q.count,0),$=K>0?U.count/K*100:0;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-24 text-sm",children:U.status==="Active"?"Actifs":"Inactifs"}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${$}%`,backgroundColor:cd[U.status]||"#6b7280"}})}),e.jsxs("div",{className:"w-20 text-right",children:[e.jsx("span",{className:"font-medium",children:U.count}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] ml-1",children:["(",$.toFixed(0),"%)"]})]})]},U.status)})})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Key,{className:"w-5 h-5"}),"Utilisateurs par Rôle"]}),e.jsx("div",{className:"space-y-3",children:(b?.length??0)>0?(b??[]).map((U,K)=>{const $=Math.max(...(b??[]).map(F=>F.count),1),E=U.count/$*100,q=["#3b82f6","#8b5cf6","#22c55e","#f59e0b","#ef4444"];return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-32 text-sm truncate",title:U.roleName,children:U.roleName}),e.jsx("div",{className:"flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${E}%`,backgroundColor:q[K%q.length]}})}),e.jsx("div",{className:"w-12 text-right font-medium",children:U.count})]},U.roleName)}):e.jsx("div",{className:"text-center py-4 text-[var(--text-secondary)]",children:"Aucun rôle configuré"})})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Shield,{className:"w-5 h-5"}),"Configuration Système"]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-purple-600",children:m?.totalRoles??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Rôles"})]}),e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-green-600",children:m?.totalPermissions??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Permissions"})]}),e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-blue-600",children:m?.usersLoggedInRecently??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Connectés récemment"})]}),e.jsxs("div",{className:"text-center p-4 bg-[var(--bg-secondary)] rounded-lg",children:[e.jsx("div",{className:"text-3xl font-bold text-orange-600",children:y?.totalActiveSessions??0}),e.jsx("div",{className:"text-sm text-[var(--text-secondary)]",children:"Sessions actives"})]})]})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Monitor,{className:"w-5 h-5"}),"Sessions Actives"]}),y&&((y.byBrowser?.length??0)>0||(y.byCountry?.length??0)>0)?e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2",children:"Par Navigateur"}),e.jsx("div",{className:"space-y-2",children:(y.byBrowser??[]).map(U=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{children:U.browser}),e.jsx("span",{className:"font-medium",children:U.count})]},U.browser))})]}),e.jsxs("div",{children:[e.jsxs("h4",{className:"text-sm font-medium text-[var(--text-secondary)] mb-2 flex items-center gap-1",children:[e.jsx(a.Globe,{className:"w-4 h-4"})," Par Pays"]}),e.jsx("div",{className:"space-y-2",children:(y.byCountry?.length??0)>0?(y.byCountry??[]).map(U=>e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{children:U.country}),e.jsx("span",{className:"font-medium",children:U.count})]},U.country)):e.jsx("span",{className:"text-[var(--text-secondary)] text-sm",children:"Non disponible"})})]})]}):e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"Aucune session active"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Monitor,{className:"w-5 h-5"}),"Appareils & Navigateurs"]}),e.jsx(id,{data:D})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Activity,{className:"w-5 h-5"}),"Engagement Utilisateurs"]}),e.jsx(od,{data:L})]})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.TrendingUp,{className:"w-5 h-5"}),"Tendances (",u," derniers jours)"]}),e.jsx("div",{className:"h-64",children:e.jsx(dd,{data:j??[]})})]}),e.jsxs("div",{className:"card p-4",children:[e.jsxs("h3",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(a.Clock,{className:"w-5 h-5"}),"Dernières Sessions Actives"]}),(f?.length??0)>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-[var(--border-color)]",children:[e.jsx("th",{className:"text-left p-3 font-medium",children:"Utilisateur"}),e.jsx("th",{className:"text-right p-3 font-medium",children:"Durée"})]})}),e.jsx("tbody",{children:(f??[]).map(U=>e.jsxs("tr",{className:"border-b border-[var(--border-color)] hover:bg-[var(--bg-secondary)] cursor-pointer",onClick:()=>t(`/platform/administration/users/${U.userId}`),children:[e.jsx("td",{className:"p-3 font-medium",children:U.fullName}),e.jsx("td",{className:"p-3 text-right",children:e.jsx("span",{className:"px-2 py-1 rounded text-xs font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400",children:U.duration})})]},U.userId+U.loginAt))})]})}):e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)]",children:"Aucune session active"})]})]})}function $s({title:s,value:t,icon:r,color:n,subtitle:i}){const o={blue:"bg-blue-50 text-blue-600 border-blue-200 dark:bg-blue-900/20 dark:border-blue-800",green:"bg-green-50 text-green-600 border-green-200 dark:bg-green-900/20 dark:border-green-800",yellow:"bg-yellow-50 text-yellow-600 border-yellow-200 dark:bg-yellow-900/20 dark:border-yellow-800",red:"bg-red-50 text-red-600 border-red-200 dark:bg-red-900/20 dark:border-red-800"};return e.jsxs("div",{className:`card p-4 border ${o[n]}`,children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-sm font-medium opacity-80",children:s}),r]}),e.jsx("div",{className:"text-2xl font-bold",children:t}),i&&e.jsx("div",{className:"text-xs opacity-70 mt-1",children:i})]})}function dd({data:s}){if(s.length===0)return e.jsx("div",{className:"flex items-center justify-center h-full text-[var(--text-secondary)]",children:"Aucune donnée de tendance disponible"});const t=Math.max(...s.flatMap(r=>[r.newUsers,r.logins]),1);return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-blue-500"}),e.jsx("span",{className:"text-sm",children:"Nouveaux utilisateurs"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-3 h-3 rounded bg-green-500"}),e.jsx("span",{className:"text-sm",children:"Connexions"})]})]}),e.jsx("div",{className:"flex-1 flex items-end gap-1 overflow-x-auto pb-4",children:s.map(r=>e.jsxs("div",{className:"flex-1 min-w-[20px] flex gap-0.5",children:[e.jsx("div",{className:"flex-1 bg-blue-500 rounded-t transition-all duration-300 hover:opacity-80",style:{height:`${r.newUsers/t*100}%`,minHeight:r.newUsers>0?"4px":"0"},title:`Nouveaux: ${r.newUsers}`}),e.jsx("div",{className:"flex-1 bg-green-500 rounded-t transition-all duration-300 hover:opacity-80",style:{height:`${r.logins/t*100}%`,minHeight:r.logins>0?"4px":"0"},title:`Connexions: ${r.logins}`})]},`${r.date}`))}),e.jsxs("div",{className:"flex justify-between text-xs text-[var(--text-secondary)] mt-2",children:[e.jsx("span",{children:s[0]&&new Date(s[0].date).toLocaleDateString("fr-FR")}),e.jsx("span",{children:s[s.length-1]&&new Date(s[s.length-1].date).toLocaleDateString("fr-FR")})]})]})}function md({data:s,viewMode:t,onViewModeChange:r,renderTable:n,renderCards:i,renderKanban:o,showTableView:c=!0,showCardsView:x=!0,showKanbanView:u=!0,tableLabel:d="Table",cardsLabel:m="Cards",kanbanLabel:p="Kanban"}){const[h,v]=l.useState("table"),b=t??h,g=r??v,j=[{mode:"table",label:d,icon:a.LayoutList,show:c},{mode:"cards",label:m,icon:a.LayoutGrid,show:x},{mode:"kanban",label:p,icon:a.Columns3,show:u}].filter(w=>w.show);return e.jsxs("div",{className:"space-y-4",children:[j.length>1&&e.jsx("div",{className:"flex items-center gap-1 p-1 rounded-[var(--radius-button)] bg-[var(--bg-secondary)] w-fit",children:j.map(({mode:w,label:f,icon:N})=>e.jsxs("button",{onClick:()=>g(w),className:`px-3 py-1.5 rounded-[var(--radius-button)] text-sm font-medium flex items-center gap-2 transition-all ${b===w?"bg-[var(--color-accent-600)] text-white shadow-sm":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"}`,children:[e.jsx(N,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:f})]},w))}),e.jsxs("div",{children:[b==="table"&&n&&n(s),b==="cards"&&i&&i(s),b==="kanban"&&o&&o(s)]})]})}function Es({viewMode:s,onChange:t,showTable:r=!0,showCards:n=!0,showKanban:i=!0,tableLabel:o="Table",cardsLabel:c="Cards",kanbanLabel:x="Kanban"}){const u=[{mode:"table",label:o,icon:a.LayoutList,show:r},{mode:"cards",label:c,icon:a.LayoutGrid,show:n},{mode:"kanban",label:x,icon:a.Columns3,show:i}].filter(d=>d.show);return u.length<=1?null:e.jsx("div",{className:"flex items-center gap-1 p-1 rounded-[var(--radius-button)] bg-[var(--bg-secondary)] border border-[var(--border-color)]",children:u.map(({mode:d,label:m,icon:p})=>e.jsxs("button",{onClick:()=>t(d),className:`px-3 py-1.5 rounded-[var(--radius-button)] text-sm font-medium flex items-center gap-2 transition-all ${s===d?"bg-[var(--color-accent-600)] text-white shadow-sm":"text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"}`,children:[e.jsx(p,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:m})]},d))})}const _r=["from-violet-500 to-purple-500","from-blue-500 to-cyan-500","from-emerald-500 to-teal-500","from-orange-500 to-amber-500","from-pink-500 to-rose-500","from-indigo-500 to-blue-500","from-fuchsia-500 to-pink-500","from-cyan-500 to-blue-500"];function xd(s){let t=0;for(let r=0;r<s.length;r++)t=s.charCodeAt(r)+((t<<5)-t);return _r[Math.abs(t)%_r.length]}function ud(s){return s.split(" ").map(t=>t[0]).join("").toUpperCase().slice(0,2)}function Ct({name:s,size:t="md",className:r=""}){const n={xs:"w-6 h-6 text-xs",sm:"w-8 h-8 text-xs",md:"w-10 h-10 text-sm",lg:"w-12 h-12 text-base",xl:"w-16 h-16 text-lg"},i={xs:"",sm:"shadow-md",md:"shadow-lg shadow-primary-500/20",lg:"shadow-lg shadow-primary-500/20",xl:"shadow-xl shadow-primary-500/25"};return e.jsx("div",{className:`${n[t]} ${i[t]} rounded-full bg-gradient-to-br ${xd(s)} flex items-center justify-center text-white font-semibold ${r}`,children:ud(s)})}function cs({status:s,label:t,showDot:r=!0,size:n="md"}){const i={active:"bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",inactive:"bg-[var(--bg-tertiary)] text-[var(--text-tertiary)] border-[var(--border-color)]",pending:"bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",warning:"bg-[var(--warning-bg)] text-[var(--warning-text)] border-[var(--warning-border)]",error:"bg-[var(--error-bg)] text-[var(--error-text)] border-[var(--error-border)]"},o={active:"bg-[var(--success-dot)]",inactive:"bg-[var(--text-muted)]",pending:"bg-[var(--warning-dot)]",warning:"bg-[var(--warning-dot)]",error:"bg-[var(--error-dot)]"},c={sm:"px-2 py-0.5 text-xs",md:"px-2.5 py-1 text-xs"};return e.jsxs("span",{className:`inline-flex items-center gap-1.5 ${c[n]} rounded-[var(--radius-badge)] font-medium border ${i[s]}`,children:[r&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${o[s]}`}),t]})}function St({role:s,variant:t="default",icon:r}){const n={accent:"bg-[var(--accent-bg)] text-[var(--accent-text)] border-[var(--accent-border)]",default:"bg-[var(--bg-secondary)] text-[var(--text-secondary)] border-[var(--border-color)]"};return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-[var(--radius-badge)] text-xs font-medium border ${n[t]}`,children:[r,s]})}function Ya({title:s,count:t,color:r,children:n,isDragOver:i,onDragOver:o,onDragLeave:c,onDrop:x}){const u={success:"bg-[var(--success-dot)]",warning:"bg-[var(--warning-dot)]",error:"bg-[var(--error-dot)]",default:"bg-[var(--text-muted)]"};return e.jsxs("div",{className:`min-w-[280px] flex-1 rounded-lg p-2 transition-colors ${i?"bg-[var(--color-accent-500)]/10 ring-2 ring-[var(--color-accent-500)]/50":""}`,onDragOver:o,onDragLeave:c,onDrop:x,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${u[r]}`}),e.jsx("h3",{className:"font-semibold text-[var(--text-primary)]",children:s}),e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-[var(--bg-secondary)] text-[var(--text-secondary)]",children:t})]}),e.jsx("div",{className:"space-y-3 min-h-[100px]",children:n})]})}function Za({children:s,onClick:t,draggable:r=!0,isDragging:n,onDragStart:i,onDragEnd:o}){return e.jsx("div",{draggable:r,onClick:t,onDragStart:i,onDragEnd:o,className:`bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)] p-4 transition-all hover:shadow-md hover:border-[var(--color-accent-500)]/30 cursor-grab active:cursor-grabbing ${n?"opacity-50 scale-95":""}`,children:s})}function ks({page:s,totalPages:t,totalCount:r,pageSize:n=20,onPageChange:i,itemLabel:o="éléments",showInfo:c=!0,showFirstLast:x=!0}){const u=(s-1)*n+1,d=Math.min(s*n,r),m=()=>{const p=[];if(t<=7)for(let h=1;h<=t;h++)p.push(h);else{p.push(1),s>3&&p.push("ellipsis");const h=Math.max(2,s-1),v=Math.min(t-1,s+1);for(let b=h;b<=v;b++)p.includes(b)||p.push(b);s<t-2&&p.push("ellipsis"),p.includes(t)||p.push(t)}return p};return e.jsx("div",{className:"card p-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4",children:[c&&e.jsxs("div",{className:"text-sm text-[var(--text-secondary)]",children:["Affichage de"," ",e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:u})," ","à"," ",e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:d})," ","sur"," ",e.jsx("span",{className:"font-medium text-[var(--text-primary)]",children:r})," ",o]}),t>1&&e.jsxs("div",{className:"flex items-center gap-1",children:[x&&e.jsx("button",{onClick:()=>i(1),disabled:s===1,className:"hidden sm:flex btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Première page",children:e.jsx(a.ChevronsLeft,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>i(Math.max(1,s-1)),disabled:s===1,className:"btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Page précédente",children:e.jsx(a.ChevronLeft,{className:"w-5 h-5"})}),e.jsx("div",{className:"flex items-center gap-1",children:m().map((p,h)=>p==="ellipsis"?e.jsx("span",{className:"px-2 text-[var(--text-muted)]",children:"..."},`ellipsis-${h}`):e.jsx("button",{onClick:()=>i(p),className:`w-10 h-10 rounded-[var(--radius-button)] text-sm font-medium transition-all ${s===p?"bg-[var(--color-accent-600)] text-white shadow-lg shadow-[var(--color-accent-500)]/30":"btn btn-secondary hover:bg-[var(--bg-hover)]"}`,children:p},`page-${p}`))}),e.jsx("button",{onClick:()=>i(Math.min(t,s+1)),disabled:s===t,className:"btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Page suivante",children:e.jsx(a.ChevronRight,{className:"w-5 h-5"})}),x&&e.jsx("button",{onClick:()=>i(t),disabled:s===t,className:"hidden sm:flex btn btn-secondary p-2 disabled:opacity-40 disabled:cursor-not-allowed",title:"Dernière page",children:e.jsx(a.ChevronsRight,{className:"w-4 h-4"})})]})]})})}class pd{pages=new Map;register(t,r,n=[]){this.pages.set(t,{key:t,defaultComponent:r,slots:n})}get(t){return this.pages.get(t)}getAll(){return Array.from(this.pages.values())}has(t){return this.pages.has(t)}getSlots(t){return this.pages.get(t)?.slots||[]}}const Ai=new pd;function hd(s,t){function r(n){const i=Xt(s);return i?e.jsx(i,{...n}):e.jsx(t,{...n})}return r.displayName=`Overridable(${s})`,r}function bd(s){const t=Xt(s),r=Ai.get(s);return t||r?.defaultComponent}function vd({pageKey:s,defaultComponent:t,params:r}){const n=Xt(s),i={pageKey:s,params:r};return n?e.jsx(n,{...i}):e.jsx(t,{...i})}const gd={USERS_LIST:"platform.administration.users",USERS_DETAIL:"platform.administration.users.detail",ROLES_LIST:"platform.administration.permissions.roles",ROLES_DETAIL:"platform.administration.permissions.roles.detail",PERMISSIONS_LIST:"platform.administration.permissions.permissions",PERMISSIONS_DETAIL:"platform.administration.permissions.permissions.detail",ASSIGNMENTS:"platform.administration.permissions.assignments",AI_DASHBOARD:"platform.administration.ai.dashboard",AI_PROMPTS_LIST:"platform.administration.ai.prompts",AI_PROMPTS_DETAIL:"platform.administration.ai.prompts.detail",WORKFLOWS_LIST:"platform.administration.workflows.list",WORKFLOWS_DETAIL:"platform.administration.workflows.detail",EMAIL_TEMPLATES_LIST:"platform.administration.workflows.email-templates",EMAIL_TEMPLATES_DETAIL:"platform.administration.workflows.email-templates.detail",TICKETS_LIST:"platform.support.tickets",TICKETS_DETAIL:"platform.support.tickets.detail",SUPPORT_DASHBOARD:"platform.support.dashboard",USER_PROFILE:"personal.myspace.profile",USER_PREFERENCES:"personal.myspace.preferences",USER_DASHBOARD:"personal.myspace.dashboard",MY_TICKETS_LIST:"business.support-client.my-tickets",MY_TICKETS_DETAIL:"business.support-client.my-tickets.detail"};function fd(){const{currentTenant:s,hasGlobalRoles:t,isGlobalView:r}=ze(),{currentModuleCode:n,getCurrentModule:i,isLoading:o,menu:c}=Ze();return t&&!r&&s&&n&&!o&&c?{isRestrictedModule:!i(),tenantName:s?.name||null}:{isRestrictedModule:!1,tenantName:null}}function jd(){const{t:s}=ne.useTranslation("admin"),{isRestrictedModule:t,tenantName:r}=fd();return t?e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 border bg-amber-500/10 border-amber-500/20",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 flex items-center justify-center bg-amber-500/10",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.AlertTriangle,{className:"w-4 h-4 text-amber-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium text-amber-700",children:s("scope.banner.restrictedModule","Module restreint")}),e.jsx("p",{className:"text-xs text-amber-600/70 mt-0.5",children:s("scope.banner.restrictedModuleDesc",`Le tenant "{{tenantName}}" n'a pas accès à ce module. Données affichées grâce à vos privilèges administrateur.`,{tenantName:r})})]})]}):null}function yd(s,t){const[r,n]=l.useState(s);return l.useEffect(()=>{const i=setTimeout(()=>n(s),t);return()=>clearTimeout(i)},[s,t]),r}const Nd={search:"",status:"all",roleId:"",source:"all",userType:"",sortBy:"lastname",sortDesc:!1};function Wr(){const{t:s}=ne.useTranslation("admin"),t=Q.useNavigate(),[r,n]=Q.useSearchParams(),i=di("users"),{currentTenant:o,isGlobalView:c}=ze(),{hasPermission:x}=Ke(),u=x("platform.administration.users.create"),d=x("platform.administration.users.update"),m=x("platform.administration.users.delete"),p=l.useMemo(()=>({search:r.get("search")||"",status:r.get("status")||"all",roleId:r.get("roleId")||"",source:r.get("source")||"all",userType:r.get("userType")||"",sortBy:r.get("sortBy")||"lastname",sortDesc:r.get("sortDesc")==="true"}),[]),[h,v]=l.useState([]),[b,g]=l.useState([]),[j,w]=l.useState(!0),[f,N]=l.useState(p),[k,C]=l.useState(!1),[y,A]=l.useState(parseInt(r.get("page")||"1")),[D,R]=l.useState(1),[L,S]=l.useState(0),[T,I]=l.useState(!1),[M,X]=l.useState(null),[O,U]=l.useState({email:"",password:"",firstName:"",lastName:"",roleIds:[]}),[K,$]=l.useState(!1),[E,q]=l.useState(null),[F,V]=l.useState("table");l.useEffect(()=>{const ee={search:r.get("search")||"",status:r.get("status")||"all",roleId:r.get("roleId")||"",source:r.get("source")||"all",userType:r.get("userType")||"",sortBy:r.get("sortBy")||"lastname",sortDesc:r.get("sortDesc")==="true"};JSON.stringify(ee)!==JSON.stringify(f)&&N(ee);const ge=parseInt(r.get("page")||"1");ge!==y&&A(ge)},[r]);const P=yd(f.search,300),B=l.useMemo(()=>{let ee=0;return f.status!=="all"&&ee++,f.roleId&&ee++,f.source!=="all"&&ee++,f.userType&&ee++,ee},[f]),J=l.useCallback(async()=>{try{w(!0);const ee=await le.users.getAll({page:y,pageSize:20,search:P||void 0,isActive:f.status==="all"?void 0:f.status==="active",entraOnly:f.source==="entra"?!0:void 0,roleId:f.roleId||void 0,userType:f.userType||void 0,sortBy:f.sortBy||void 0,sortDesc:f.sortDesc});v(ee.items),R(ee.totalPages),S(ee.totalCount)}catch(ee){console.error("Failed to load users:",ee)}finally{w(!1)}},[y,P,f.status,f.source,f.roleId,f.userType,f.sortBy,f.sortDesc,o?.id,c]);l.useEffect(()=>{const ee=new URLSearchParams;f.search&&ee.set("search",f.search),f.status!=="all"&&ee.set("status",f.status),f.roleId&&ee.set("roleId",f.roleId),f.source!=="all"&&ee.set("source",f.source),f.userType&&ee.set("userType",f.userType),f.sortBy!=="lastname"&&ee.set("sortBy",f.sortBy),f.sortDesc&&ee.set("sortDesc","true"),y>1&&ee.set("page",y.toString()),n(ee,{replace:!0})},[f,y,n]);const W=async()=>{try{const ee=await le.roles.getAll();g(ee)}catch(ee){console.error("Failed to load roles:",ee)}};l.useEffect(()=>{J()},[J]),l.useEffect(()=>{W()},[]);const re=()=>{N(Nd),A(1)},te=(ee,ge)=>{N(Re=>({...Re,[ee]:ge})),A(1)},ce=()=>{X(null),U({email:"",password:"",firstName:"",lastName:"",roleIds:[]}),q(null),I(!0)},he=async ee=>{try{const ge=await le.users.getById(ee.id);X(ee),U({email:ge.email,password:"",firstName:ge.firstName,lastName:ge.lastName,roleIds:ge.roles.map(Re=>Re.id)}),q(null),I(!0)}catch(ge){console.error("Failed to load user details:",ge)}},z=async ee=>{ee.preventDefault(),$(!0),q(null);try{if(M){const ge={email:O.email!==M.email?O.email:void 0,firstName:O.firstName,lastName:O.lastName,roleIds:O.roleIds};await le.users.update(M.id,ge)}else await le.users.create(O);I(!1),J()}catch(ge){const Re=ge instanceof Error?ge.message:"An error occurred";q(Re)}finally{$(!1)}},H=async(ee,ge)=>{ge?.stopPropagation();try{ee.isActive?await le.users.deactivate(ee.id):await le.users.activate(ee.id),J()}catch(Re){console.error("Failed to toggle user status:",Re)}},je=async(ee,ge)=>{if(ge?.stopPropagation(),!!confirm(s("users.confirmDelete",{name:ee.fullName})))try{await le.users.delete(ee.id),J()}catch(Re){console.error("Failed to delete user:",Re)}},xe=ee=>{U(ge=>({...ge,roleIds:ge.roleIds?.includes(ee)?ge.roleIds.filter(Re=>Re!==ee):[...ge.roleIds||[],ee]}))},we=h.filter(ee=>ee.isActive),Ne=h.filter(ee=>!ee.isActive),fe=Math.floor(we.length*.3),de=(ee,ge)=>ee?ge?"text-[var(--text-tertiary)] hover:text-[var(--warning-text)] hover:bg-[var(--warning-bg)]":"text-[var(--text-tertiary)] hover:text-[var(--success-text)] hover:bg-[var(--success-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]",se=(ee,ge,Re)=>ee?Re(ge?"users.deactivate":"users.activate"):Re("common.noPermission","Permission insuffisante"),ie=ee=>ee?"text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]",be=(ee,ge)=>ee?ge("common.edit"):ge("common.noPermission","Permission insuffisante"),_=ee=>ee?"text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]",ae=(ee,ge)=>ee?ge("common.delete"):ge("common.noPermission","Permission insuffisante"),ve=ee=>{const ge={Direct:"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300",Group:"bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300",Both:"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300"},Re={Direct:s("users.membershipDirect","Direct"),Group:s("users.membershipGroup","Via groupe"),Both:s("users.membershipBoth","Mixte")};return{color:ge[ee]||"",label:Re[ee]||""}},pe=()=>e.jsx("div",{className:"card overflow-hidden",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-[var(--bg-secondary)]",children:[e.jsx("th",{className:"w-12 px-4 py-3",children:e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)]"})}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider",children:s("users.columns.name")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden md:table-cell",children:s("users.columns.email")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden lg:table-cell",children:s("users.columns.role")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider",children:s("users.columns.status")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden xl:table-cell",children:s("users.columns.source","Source")}),e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden xl:table-cell",children:s("users.columns.group","Groupe")}),i.map(ee=>e.jsx("th",{className:"text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden xl:table-cell",style:ee.width?{width:ee.width}:void 0,children:ee.label},ee.key)),e.jsx("th",{className:"w-32 px-4 py-3"})]})}),e.jsx("tbody",{className:"divide-y divide-[var(--border-color)]",children:j?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"px-6 py-16 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-primary-500"}),e.jsx("span",{className:"text-sm text-[var(--text-secondary)]",children:"Chargement..."})]})})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"px-6 py-16 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-[var(--bg-secondary)] flex items-center justify-center",children:e.jsx(a.Search,{className:"w-8 h-8 text-[var(--text-tertiary)]"})}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s("users.noUsers")})]})})}):h.map(ee=>e.jsxs("tr",{className:"group hover:bg-[var(--bg-hover)] transition-all cursor-pointer",onClick:()=>t(`/platform/administration/users/${ee.id}`),children:[e.jsx("td",{className:"px-4 py-3",onClick:ge=>ge.stopPropagation(),children:e.jsx("input",{type:"checkbox",className:"w-4 h-4 rounded border-[var(--border-color)]"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-4 h-4 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-2.5 h-2.5 text-white"})})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-medium text-[var(--text-primary)] group-hover:text-primary-600 transition-colors truncate",children:ee.fullName}),ee.entraObjectId&&e.jsxs("span",{className:"hidden sm:inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400",children:[e.jsx(a.Cloud,{className:"w-2.5 h-2.5"}),"AAD"]})]}),e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)] truncate md:hidden flex items-center gap-1",children:[e.jsx(a.Mail,{className:"w-3 h-3"}),ee.email]})]})]})}),e.jsx("td",{className:"px-4 py-3 hidden md:table-cell",children:e.jsxs("div",{className:"flex items-center gap-2 text-[var(--text-secondary)]",children:[e.jsx(a.Mail,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("span",{className:"truncate",children:ee.email})]})}),e.jsx("td",{className:"px-4 py-3 hidden lg:table-cell",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ee.roles.length>0?ee.roles.map((ge,Re)=>e.jsx(St,{role:ge,variant:ge.toLowerCase().includes("admin")?"accent":"default",icon:e.jsx(a.Shield,{className:"w-3 h-3"})},`${ge}-${Re}`)):e.jsx("span",{className:"text-sm text-[var(--text-tertiary)] italic",children:"Aucun rôle"})})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(cs,{status:ee.isActive?"active":"inactive",label:ee.isActive?s("users.status.active"):s("users.status.inactive")})}),e.jsx("td",{className:"px-4 py-3 hidden xl:table-cell",children:(()=>{const{color:ge,label:Re}=ve(ee.membershipSource);return e.jsx("span",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium ${ge}`,children:Re})})()}),e.jsx("td",{className:"px-4 py-3 hidden xl:table-cell",children:ee.primaryGroupId?e.jsxs("button",{onClick:ge=>{ge.stopPropagation(),t(`/platform/administration/groups/${ee.primaryGroupId}`)},className:"inline-flex items-center gap-1.5 px-2 py-1 rounded-md text-xs font-medium bg-[var(--bg-secondary)] hover:bg-[var(--bg-hover)] text-[var(--text-secondary)] hover:text-primary-600 transition-colors",children:[e.jsx(a.Users,{className:"w-3 h-3"}),ee.primaryGroupName]}):e.jsx("span",{className:"text-[var(--text-tertiary)]",children:"—"})}),i.map(ge=>e.jsx("td",{className:"px-4 py-3 hidden xl:table-cell text-[var(--text-secondary)]",children:ge.render(ee,{tableId:"users",rowIndex:h.indexOf(ee)})},ge.key)),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:ge=>ge.stopPropagation(),children:[e.jsx("button",{onClick:()=>t(`/platform/administration/users/${ee.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("users.view"),children:e.jsx(a.Eye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>{ge.stopPropagation(),he(ee)},disabled:!d,className:`p-2 rounded-lg transition-all ${d?"text-[var(--text-tertiary)] hover:text-[var(--info-text)] hover:bg-[var(--info-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]"}`,title:d?s("common.edit"):s("common.noPermission","Permission insuffisante"),children:e.jsx(a.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>H(ee,ge),disabled:!d,className:`p-2 rounded-lg transition-all ${de(d,ee.isActive)}`,title:se(d,ee.isActive,s),children:ee.isActive?e.jsx(a.UserX,{className:"w-4 h-4"}):e.jsx(a.UserCheck,{className:"w-4 h-4"})}),ee.userType!=="System"&&ee.userType!=="LocalAdmin"&&e.jsx("button",{onClick:ge=>je(ee,ge),disabled:!m,className:`p-2 rounded-lg transition-all ${m?"text-[var(--text-tertiary)] hover:text-[var(--error-text)] hover:bg-[var(--error-bg)]":"opacity-50 cursor-not-allowed text-[var(--text-tertiary)]"}`,title:m?s("common.delete"):s("common.noPermission","Permission insuffisante"),children:e.jsx(a.Trash2,{className:"w-4 h-4"})}),e.jsx(ls,{name:"users.table.row.actions",context:{user:ee,reload:J}})]})})]},ee.id))})]})}),Se=()=>e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:j?e.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-16",children:[e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-primary-500"}),e.jsx("span",{className:"mt-3 text-sm text-[var(--text-secondary)]",children:"Chargement..."})]}):h.length===0?e.jsxs("div",{className:"col-span-full flex flex-col items-center justify-center py-16",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg bg-[var(--bg-secondary)] flex items-center justify-center mb-3",children:e.jsx(a.Search,{className:"w-8 h-8 text-[var(--text-tertiary)]"})}),e.jsx("span",{className:"text-[var(--text-secondary)]",children:s("users.noUsers")})]}):h.map(ee=>e.jsxs("div",{onClick:()=>t(`/platform/administration/users/${ee.id}`),className:"bg-[var(--bg-card)] border-2 border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)] rounded-[var(--radius-card)] overflow-hidden transition-all hover:shadow-lg hover:border-[var(--color-accent-400)] cursor-pointer flex flex-col",children:[e.jsx("div",{className:"bg-[var(--color-accent-50)] dark:bg-[var(--color-accent-900)]/20 p-4 border-b border-[var(--color-accent-200)] dark:border-[var(--color-accent-800)]",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName,size:"lg",className:"rounded-lg"}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-5 h-5 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-3 h-3 text-white"})})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-[var(--text-primary)] truncate",children:ee.fullName}),e.jsxs("p",{className:"text-xs text-[var(--text-tertiary)] truncate flex items-center gap-1",children:[e.jsx(a.Mail,{className:"w-3 h-3"}),ee.email]})]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 text-xs rounded-full font-medium ${ee.isActive?"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400":"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400"}`,children:ee.isActive?s("users.status.active"):s("users.status.inactive")}),ee.entraObjectId&&e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-blue-100 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400",children:[e.jsx(a.Cloud,{className:"w-2.5 h-2.5"}),"AAD"]})]})]})}),e.jsxs("div",{className:"p-4 flex flex-col flex-1",children:[e.jsxs("div",{className:"flex flex-wrap gap-1 mb-3",children:[ee.roles.length>0?ee.roles.slice(0,2).map(ge=>e.jsx(St,{role:ge,variant:ge.toLowerCase().includes("admin")?"accent":"default",icon:e.jsx(a.Shield,{className:"w-3 h-3"})},ge)):e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"Aucun rôle"}),ee.roles.length>2&&e.jsxs("span",{className:"text-xs px-2 py-0.5 rounded-md bg-[var(--bg-secondary)] text-[var(--text-muted)]",children:["+",ee.roles.length-2]})]}),e.jsx(ls,{name:"users.card.content",context:{user:ee}}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"flex items-center justify-end gap-1 pt-3 border-t border-[var(--border-color)]",onClick:ge=>ge.stopPropagation(),children:[e.jsx("button",{onClick:()=>t(`/platform/administration/users/${ee.id}`),className:"p-2 rounded-lg text-[var(--text-tertiary)] hover:text-primary-600 hover:bg-[var(--accent-bg)] transition-all",title:s("users.view"),children:e.jsx(a.Eye,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>{ge.stopPropagation(),he(ee)},disabled:!d,className:`p-2 rounded-lg transition-all ${ie(d)}`,title:be(d,s),children:e.jsx(a.Edit2,{className:"w-4 h-4"})}),e.jsx("button",{onClick:ge=>H(ee,ge),disabled:!d,className:`p-2 rounded-lg transition-all ${de(d,ee.isActive)}`,title:se(d,ee.isActive,s),children:ee.isActive?e.jsx(a.UserX,{className:"w-4 h-4"}):e.jsx(a.UserCheck,{className:"w-4 h-4"})}),ee.userType!=="System"&&ee.userType!=="LocalAdmin"&&e.jsx("button",{onClick:ge=>je(ee,ge),disabled:!m,className:`p-2 rounded-lg transition-all ${_(m)}`,title:ae(m,s),children:e.jsx(a.Trash2,{className:"w-4 h-4"})})]})]})]},ee.id))}),ke=()=>e.jsx("div",{className:"flex gap-6 overflow-x-auto pb-4",children:j?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center py-16",children:[e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-primary-500"}),e.jsx("span",{className:"mt-3 text-sm text-[var(--text-secondary)]",children:"Chargement..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ya,{title:"Actifs",count:we.length,color:"success",children:we.map(ee=>e.jsxs(Za,{onClick:()=>t(`/platform/administration/users/${ee.id}`),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName,size:"sm"}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-3.5 h-3.5 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-2 h-2 text-white"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:ee.fullName}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] truncate",children:ee.email})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[ee.roles.length>0?e.jsx(St,{role:ee.roles[0],variant:ee.roles[0].toLowerCase().includes("admin")?"accent":"default"}):e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"-"}),e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"En ligne"})]})]},ee.id))}),e.jsxs(Ya,{title:"Inactifs",count:Ne.length,color:"error",children:[Ne.map(ee=>e.jsxs(Za,{onClick:()=>t(`/platform/administration/users/${ee.id}`),children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ct,{name:ee.fullName,size:"sm"}),ee.entraObjectId&&e.jsx("div",{className:"absolute -bottom-0.5 -right-0.5 w-3.5 h-3.5 rounded-full bg-blue-500 flex items-center justify-center ring-2 ring-[var(--bg-card)]",title:s("users.syncedWithAad"),children:e.jsx(a.Cloud,{className:"w-2 h-2 text-white"})})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:ee.fullName}),e.jsx("p",{className:"text-xs text-[var(--text-tertiary)] truncate",children:ee.email})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[ee.roles.length>0?e.jsx(St,{role:ee.roles[0]}):e.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"-"}),e.jsx("button",{onClick:ge=>H(ee,ge),disabled:!d,className:`text-xs px-2 py-1 rounded transition-opacity ${d?"bg-[var(--success-bg)] text-[var(--success-text)] hover:opacity-80":"opacity-50 cursor-not-allowed bg-[var(--bg-secondary)] text-[var(--text-tertiary)]"}`,title:d?void 0:s("common.noPermission","Permission insuffisante"),children:"Réactiver"})]})]},ee.id)),Ne.length===0&&e.jsxs("div",{className:"border border-dashed border-[var(--border-color)] rounded-lg p-6 text-center",children:[e.jsx(a.UserCheck,{className:"w-6 h-6 mx-auto mb-2 text-[var(--text-muted)]"}),e.jsx("p",{className:"text-xs text-[var(--text-muted)]",children:"Aucun utilisateur inactif"})]})]})]})});return e.jsxs("div",{className:"space-y-6",children:[e.jsx(De,{items:[{label:s("header.title"),href:"/platform/administration"},{label:s("users.title")}]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-[var(--text-primary)]",children:s("users.title")}),e.jsxs("p",{className:"text-sm text-[var(--text-tertiary)] mt-1",children:[L," utilisateurs • ",fe," en ligne"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ls,{name:"users.header.actions",context:{users:h,totalCount:L,reload:J}}),e.jsxs("button",{onClick:ce,disabled:!u,className:`btn btn-primary ${u?"":"opacity-50 cursor-not-allowed"}`,title:u?void 0:s("common.noPermission","Permission insuffisante"),children:[e.jsx(a.Plus,{className:"w-4 h-4"}),s("users.create")]})]})]}),e.jsx(jd,{}),e.jsx("div",{className:"card p-4",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[e.jsxs("div",{className:"relative flex-1 max-w-md",children:[!f.search&&e.jsx(a.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-muted)] pointer-events-none"}),e.jsx("input",{type:"text",value:f.search,onChange:ee=>te("search",ee.target.value),placeholder:s("users.filters.searchPlaceholder"),className:"input w-full",style:f.search?void 0:{paddingLeft:"2.5rem"}}),f.search&&e.jsx("button",{onClick:()=>te("search",""),className:"absolute right-3 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-[var(--bg-secondary)]",children:e.jsx(a.X,{className:"w-3 h-3 text-[var(--text-tertiary)]"})})]}),e.jsxs("button",{onClick:()=>C(!k),className:`btn ${k?"btn-primary":"btn-secondary"} relative`,children:[e.jsx(a.Filter,{className:"w-4 h-4"}),e.jsx("span",{className:"hidden sm:inline",children:s("users.filters.title")}),B>0&&e.jsx("span",{className:"absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-[var(--color-accent-500)] text-white text-xs flex items-center justify-center",children:B})]}),B>0&&e.jsx("button",{onClick:re,className:"btn btn-ghost text-[var(--text-tertiary)] hover:text-[var(--text-primary)]",title:s("users.filters.reset"),children:e.jsx(a.RotateCcw,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"hidden md:block",children:e.jsx(Es,{viewMode:F,onChange:V,tableLabel:"Table",cardsLabel:"Cards",kanbanLabel:"Kanban"})})]}),k&&e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-4 pt-4 border-t border-[var(--border-color)]",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.status")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.status,onChange:ee=>te("status",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"all",children:s("users.filters.allStatuses")}),e.jsx("option",{value:"active",children:s("users.filters.activeOnly")}),e.jsx("option",{value:"inactive",children:s("users.filters.inactiveOnly")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.role")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.roleId,onChange:ee=>te("roleId",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"",children:s("users.filters.allRoles")}),b.map(ee=>e.jsx("option",{value:ee.id,children:ee.name},ee.id))]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.source")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.source,onChange:ee=>te("source",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"all",children:s("users.filters.allSources")}),e.jsx("option",{value:"entra",children:s("users.filters.entraOnly")}),e.jsx("option",{value:"local",children:s("users.filters.localOnly")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.userType")}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:f.userType,onChange:ee=>te("userType",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"",children:s("users.filters.allTypes")}),e.jsx("option",{value:"User",children:s("users.filters.typeUser")}),e.jsx("option",{value:"System",children:s("users.filters.typeSystem")}),e.jsx("option",{value:"LocalAdmin",children:s("users.filters.typeLocalAdmin")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[var(--text-tertiary)] mb-1.5",children:s("users.filters.sortBy")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsxs("select",{value:f.sortBy,onChange:ee=>te("sortBy",ee.target.value),className:"input w-full appearance-none pr-8",children:[e.jsx("option",{value:"lastname",children:s("users.filters.sortName")}),e.jsx("option",{value:"email",children:s("users.filters.sortEmail")}),e.jsx("option",{value:"lastlogin",children:s("users.filters.sortLastLogin")}),e.jsx("option",{value:"createdat",children:s("users.filters.sortCreatedAt")}),e.jsx("option",{value:"status",children:s("users.filters.sortStatus")})]}),e.jsx(a.ChevronDown,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-tertiary)] pointer-events-none"})]}),e.jsx("button",{onClick:()=>te("sortDesc",!f.sortDesc),className:`btn ${f.sortDesc?"btn-primary":"btn-secondary"} px-2.5`,title:f.sortDesc?s("users.filters.sortDesc"):s("users.filters.sortAsc"),children:e.jsx(a.ArrowUpDown,{className:"w-4 h-4"})})]})]})]}),B>0&&!k&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-[var(--text-tertiary)]",children:[e.jsx(a.Filter,{className:"w-4 h-4"}),e.jsx("span",{children:s("users.filters.activeFilters",{count:B})}),e.jsx("button",{onClick:()=>C(!0),className:"text-[var(--color-accent-600)] hover:underline",children:s("users.filters.title")})]})]})}),e.jsx("div",{className:"md:hidden",children:Se()}),e.jsxs("div",{className:"hidden md:block",children:[F==="table"&&pe(),F==="cards"&&Se(),F==="kanban"&&ke()]}),F!=="kanban"&&e.jsx(ks,{page:y,totalPages:D,totalCount:L,pageSize:20,onPageChange:A,itemLabel:"utilisateurs"}),T&&e.jsx("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm flex items-center justify-center z-50",children:e.jsxs("div",{className:"card w-full max-w-lg p-6 m-4 max-h-[90vh] overflow-y-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("h2",{className:"text-xl font-bold text-[var(--text-primary)]",children:s(M?"users.edit":"users.create")}),e.jsx("button",{onClick:()=>I(!1),className:"btn btn-ghost p-2",children:e.jsx(a.X,{className:"w-5 h-5"})})]}),E&&e.jsx("div",{className:"mb-4 p-3 rounded-lg bg-[var(--error-bg)] text-[var(--error-text)] text-sm border border-[var(--error-border)]",children:E}),e.jsxs("form",{onSubmit:z,className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.form.firstName")}),e.jsx("input",{type:"text",required:!0,value:O.firstName,onChange:ee=>U(ge=>({...ge,firstName:ee.target.value})),className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.form.lastName")}),e.jsx("input",{type:"text",required:!0,value:O.lastName,onChange:ee=>U(ge=>({...ge,lastName:ee.target.value})),className:"input w-full"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.columns.email")}),e.jsx("input",{type:"email",required:!0,value:O.email,onChange:ee=>U(ge=>({...ge,email:ee.target.value})),className:"input w-full"})]}),!M&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-1",children:s("users.form.password")}),e.jsx("input",{type:"password",required:!M,value:O.password,onChange:ee=>U(ge=>({...ge,password:ee.target.value})),autoComplete:"new-password",className:"input w-full"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-[var(--text-secondary)] mb-2",children:s("users.form.roles")}),e.jsx("div",{className:"space-y-2 max-h-48 overflow-y-auto p-3 border border-[var(--border-color)] rounded-lg bg-[var(--bg-secondary)]",children:b.map(ee=>e.jsxs("label",{className:"flex items-center gap-3 cursor-pointer p-2 rounded-lg hover:bg-[var(--bg-hover)] transition-colors",children:[e.jsx("input",{type:"checkbox",checked:O.roleIds?.includes(ee.id)||!1,onChange:()=>xe(ee.id),className:"w-4 h-4 rounded border-[var(--border-color)] text-primary-600 focus:ring-primary-500"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[var(--text-primary)] font-medium",children:ee.name}),ee.description&&e.jsx("p",{className:"text-xs text-[var(--text-tertiary)]",children:ee.description})]})]},ee.id))})]}),e.jsx(ls,{name:"users.form.fields.after",context:{formData:O,onChange:(ee,ge)=>{if(ee.startsWith("ext.")){const Re=ee.substring(4);U(Fe=>({...Fe,ext:{...Fe.ext||{},[Re]:ge}}))}else U(Re=>({...Re,[ee]:ge}))},disabled:K,isEditing:!!M,user:M}}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx("button",{type:"button",onClick:()=>I(!1),className:"btn btn-secondary",children:s("common.cancel")}),e.jsxs("button",{type:"submit",disabled:K,className:"btn btn-primary disabled:opacity-50",children:[K&&e.jsx(a.Loader2,{className:"w-4 h-4 animate-spin"}),s(M?"common.save":"common.create")]})]})]})]})})]})}function vr({value:s,onChange:t,adminTenants:r,userTenantMemberships:n=[],disabled:i=!1,showNotMemberWarning:o=!1}){const{t:c}=ne.useTranslation("admin"),[x,u]=l.useState(!1),[d,m]=l.useState(""),[p,h]=l.useState("all"),v=l.useRef(null),b=l.useRef(null);l.useEffect(()=>{function D(R){v.current&&!v.current.contains(R.target)&&u(!1)}return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[]),l.useEffect(()=>{function D(R){R.key==="Escape"&&u(!1)}return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[]),l.useEffect(()=>{x&&b.current&&setTimeout(()=>b.current?.focus(),50)},[x]);const g=l.useMemo(()=>{const D=new Map;return n.forEach(R=>D.set(R.tenantId,R)),D},[n]),{b2bTenants:j,b2cTenants:w,filteredTenants:f}=l.useMemo(()=>{const D=r.filter(S=>S.tenantType==="Business"),R=r.filter(S=>S.tenantType==="Personal");let L=r;if(p==="b2b"?L=D:p==="b2c"&&(L=R),d.trim()){const S=d.toLowerCase().trim();L=L.filter(T=>T.tenantName.toLowerCase().includes(S))}return{b2bTenants:D,b2cTenants:R,filteredTenants:L}},[r,p,d]),N=s==="global",k=N?null:s,C=()=>{t("global"),u(!1),m("")},y=D=>{const R=g.get(D.tenantId);t({tenantId:D.tenantId,tenantSlug:D.tenantSlug,tenantUserId:R?.tenantUserId||"",tenantName:D.tenantName}),u(!1),m("")};if(r.length===0)return null;const A=D=>{const R=!N&&k?.tenantId===D.tenantId,L=D.tenantType==="Business",S=g.has(D.tenantId);return e.jsxs("button",{type:"button",onClick:()=>y(D),className:`w-full flex items-center gap-3 px-3 py-2.5 text-left transition-colors ${R?"bg-blue-500/10 text-blue-700":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,role:"option","aria-selected":R,children:[e.jsx("div",{className:`flex-shrink-0 w-8 h-8 flex items-center justify-center ${L?"bg-blue-500/10":"bg-violet-500/10"}`,style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Building2,{className:`w-4 h-4 ${L?"text-blue-500":"text-violet-500"}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium truncate",children:D.tenantName}),S&&e.jsxs("span",{className:"flex-shrink-0 text-xs px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-600",children:[e.jsx(a.User,{className:"w-3 h-3 inline mr-0.5"}),c("userRoles.scope.selector.member","Membre")]})]}),e.jsx("span",{className:"text-xs text-[var(--text-tertiary)]",children:L?c("userRoles.scope.selector.b2b","Business"):c("userRoles.scope.selector.b2c","Personnel")})]}),R&&e.jsx(a.Check,{className:"w-4 h-4 text-blue-600 flex-shrink-0"})]},D.tenantId)};return e.jsxs("div",{ref:v,className:"relative inline-block",children:[e.jsxs("button",{type:"button",onClick:()=>!i&&u(!x),disabled:i,className:`flex items-center gap-2 px-3 py-2 text-sm font-medium border transition-colors ${N?"bg-emerald-500/10 border-emerald-500/30 text-emerald-700 hover:bg-emerald-500/20":"bg-blue-500/10 border-blue-500/30 text-blue-700 hover:bg-blue-500/20"} ${i?"opacity-50 cursor-not-allowed":""}`,style:{borderRadius:"var(--radius-button)"},"aria-expanded":x,"aria-haspopup":"listbox",children:[N?e.jsxs(e.Fragment,{children:[e.jsx(a.Globe,{className:"w-4 h-4"}),e.jsx("span",{children:c("userRoles.scope.selector.global","Global (plateforme)")})]}):e.jsxs(e.Fragment,{children:[e.jsx(a.Building2,{className:"w-4 h-4"}),e.jsx("span",{className:"max-w-[150px] truncate",children:k?.tenantName})]}),e.jsx(a.ChevronDown,{className:`w-4 h-4 transition-transform ${x?"rotate-180":""}`})]}),e.jsx("div",{className:`absolute left-0 mt-1 w-80 z-50 transition-all duration-150 ease-out ${x?"opacity-100 scale-100 translate-y-0":"opacity-0 scale-95 -translate-y-1 pointer-events-none"}`,children:e.jsxs("div",{className:"bg-[var(--bg-card)] border border-[var(--border-color)] shadow-xl overflow-hidden",style:{borderRadius:"var(--radius-card)"},children:[e.jsx("div",{className:"px-3 py-2 border-b border-[var(--border-color)] bg-[var(--bg-secondary)]",children:e.jsxs("div",{className:"relative",children:[e.jsx(a.Search,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-[var(--text-muted)]"}),e.jsx("input",{ref:b,type:"text",value:d,onChange:D=>m(D.target.value),placeholder:c("userRoles.scope.selector.search","Rechercher un tenant..."),className:"w-full pl-8 pr-3 py-1.5 text-sm bg-[var(--bg-primary)] border border-[var(--border-color)] rounded-md text-[var(--text-primary)] placeholder-[var(--text-muted)] focus:outline-none focus:ring-1 focus:ring-[var(--color-accent-500)]"})]})}),e.jsxs("div",{className:"flex items-center gap-1 px-3 py-2 border-b border-[var(--border-color)] bg-[var(--bg-tertiary)]",role:"tablist",children:[e.jsxs("button",{type:"button",onClick:()=>h("all"),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${p==="all"?"bg-[var(--color-accent-600)] text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,role:"tab","aria-selected":p==="all",children:[c("userRoles.scope.selector.filterAll","Tous")," (",r.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>h("b2b"),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${p==="b2b"?"bg-blue-600 text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,role:"tab","aria-selected":p==="b2b",children:[c("userRoles.scope.selector.filterB2B","B2B")," (",j.length,")"]}),e.jsxs("button",{type:"button",onClick:()=>h("b2c"),className:`px-2.5 py-1 text-xs font-medium rounded-md transition-colors ${p==="b2c"?"bg-violet-600 text-white":"text-[var(--text-secondary)] hover:bg-[var(--bg-hover)]"}`,role:"tab","aria-selected":p==="b2c",children:[c("userRoles.scope.selector.filterB2C","B2C")," (",w.length,")"]})]}),e.jsxs("div",{className:"py-1 max-h-72 overflow-y-auto",role:"listbox",children:[e.jsxs("button",{type:"button",onClick:C,className:`w-full flex items-center gap-3 px-3 py-2.5 text-left transition-colors ${N?"bg-emerald-500/10 text-emerald-700":"hover:bg-[var(--bg-tertiary)] text-[var(--text-primary)]"}`,role:"option","aria-selected":N,children:[e.jsx("div",{className:"flex-shrink-0 w-8 h-8 flex items-center justify-center bg-emerald-500/10",style:{borderRadius:"var(--radius-card)"},children:e.jsx(a.Globe,{className:"w-4 h-4 text-emerald-600"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium block",children:c("userRoles.scope.selector.global","Global (plateforme)")}),e.jsx("span",{className:"text-xs text-[var(--text-tertiary)]",children:c("userRoles.scope.selector.globalDesc","Rôles applicables sur toute la plateforme")})]}),N&&e.jsx(a.Check,{className:"w-4 h-4 text-emerald-600 flex-shrink-0"})]}),f.length>0&&e.jsx("div",{className:"border-t border-[var(--border-color)] my-1"}),f.length>0?f.map(A):e.jsx("div",{className:"px-3 py-4 text-center text-sm text-[var(--text-muted)]",children:c("userRoles.scope.selector.noResults","Aucun tenant trouvé")})]})]})}),o&&!N&&e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-sm text-amber-600",children:[e.jsx(a.AlertTriangle,{className:"w-4 h-4"}),e.jsx("span",{children:c("userRoles.scope.notMember","L'utilisateur n'est pas membre de ce tenant")})]})]})}function gr({columns:s,items:t,getItemId:r,getItemColumn:n,onMoveItem:i,renderCard:o,loading:c=!1,onAddItem:x,onCardClick:u,cardActions:d,emptyColumnMessage:m="Aucun élément",className:p="",columnMinWidth:h="280px",disabled:v=!1}){const[b,g]=l.useState(null),[j,w]=l.useState(null),[f,N]=l.useState(null),k=l.useCallback(T=>{T.onClick(),N(null)},[]),C=l.useCallback((T,I)=>e.jsxs("button",{onClick:M=>{M.stopPropagation(),k(T)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-left hover:bg-[var(--bg-tertiary)]",children:[T.icon,T.label]},I),[k]),y=l.useCallback(T=>t.filter(I=>n(I)===T),[t,n]),A=(T,I)=>{v||(g(I),T.dataTransfer.effectAllowed="move",T.dataTransfer.setData("text/plain",I))},D=(T,I)=>{v||!b||(T.preventDefault(),T.dataTransfer.dropEffect="move",w(I))},R=()=>{w(null)},L=(T,I)=>{if(v)return;T.preventDefault();const M=T.dataTransfer.getData("text/plain");M&&i(M,I),g(null),w(null)},S=()=>{g(null),w(null)};return c?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(a.Loader2,{className:"w-8 h-8 animate-spin text-[var(--color-primary-500)]"})}):e.jsx("div",{className:`flex gap-4 overflow-x-auto pb-4 ${p}`,children:s.map(T=>{const I=y(T.id),M=j===T.id,X=T.maxItems!==void 0&&I.length>=T.maxItems;return e.jsxs("div",{className:`flex-shrink-0 flex flex-col rounded-lg bg-[var(--bg-secondary)] border border-[var(--border-color)] ${M?"ring-2 ring-[var(--color-primary-500)]":""}`,style:{minWidth:h,maxWidth:h},onDragOver:O=>D(O,T.id),onDragLeave:R,onDrop:O=>L(O,T.id),children:[e.jsxs("div",{className:"flex items-center justify-between p-3 border-b border-[var(--border-color)]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[T.color&&e.jsx("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:T.color}}),e.jsx("h3",{className:"font-semibold text-sm text-[var(--text-primary)]",children:T.title}),e.jsxs("span",{className:"text-xs text-[var(--text-secondary)] px-1.5 py-0.5 rounded-full bg-[var(--bg-tertiary)]",children:[I.length,T.maxItems!==void 0&&` / ${T.maxItems}`]})]}),x&&T.canAddItem!==!1&&!X&&e.jsx("button",{onClick:()=>x(T.id),className:"btn btn-ghost p-1 hover:bg-[var(--bg-tertiary)]",title:"Ajouter","aria-label":`Ajouter à ${T.title}`,children:e.jsx(a.Plus,{className:"w-4 h-4"})})]}),e.jsxs("div",{className:"flex-1 p-2 space-y-2 overflow-y-auto max-h-[calc(100vh-300px)]",children:[I.length===0?e.jsx("div",{className:"text-center py-8 text-[var(--text-secondary)] text-sm",children:m}):I.map((O,U)=>{const K=r(O),$=b===K,E=d?.(O);return e.jsxs("div",{draggable:!v,onDragStart:q=>A(q,K),onDragEnd:S,onClick:()=>u?.(O),className:`
3
3
  relative group
4
4
  bg-[var(--bg-card)] border border-[var(--border-color)] rounded-lg
5
5
  ${v?"":"cursor-grab active:cursor-grabbing"}