import{a as j,r as d,j as e,d as f}from"./index-D4ZMoJFe.js";import{M as N}from"./MgxAdminSubnav-C8dRaLnZ.js";const y=r=>{if(!r)return"—";const t=new Date(r);return Number.isNaN(t.getTime())?String(r):new Intl.DateTimeFormat("fr-DZ",{dateStyle:"short",timeStyle:"short"}).format(t)};function S(){var h;const{selectedCompanyId:r,user:t}=j(),o=r||(t==null?void 0:t.companyId)||((h=t==null?void 0:t.company)==null?void 0:h.id)||"",[c,b]=d.useState([]),[g,i]=d.useState(!0),[x,m]=d.useState(""),[n,p]=d.useState({from:"",to:""}),u=async()=>{var s,a;if(o){i(!0),m("");try{const l=await f.get("/mgx/logins",{params:{company_id:o,from:n.from||void 0,to:n.to||void 0}});b(l.data.items||[])}catch(l){m(((a=(s=l==null?void 0:l.response)==null?void 0:s.data)==null?void 0:a.message)||"Impossible de charger l'historique des connexions.")}finally{i(!1)}}};return d.useEffect(()=>{u()},[o]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"rounded-[2rem] border border-slate-200 bg-white p-6 shadow-xl shadow-slate-200/70 sm:p-8",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-amber-600",children:"Administration MGX"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-slate-950",children:"Historique des Connexions"}),e.jsx("p",{className:"mt-3 max-w-4xl text-sm leading-7 text-slate-600",children:"Consultez les accès à la plateforme avec l’adresse IP, le navigateur et le module utilisé lorsque disponible."}),e.jsx("div",{className:"mt-6",children:e.jsx(N,{})})]}),e.jsx("section",{className:"rounded-[2rem] border border-slate-200 bg-white p-6 shadow-xl shadow-slate-200/70",children:e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:[e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700",children:"Du"}),e.jsx("input",{type:"date",className:"input-dark",value:n.from,onChange:s=>p(a=>({...a,from:s.target.value}))})]}),e.jsxs("label",{className:"space-y-2",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700",children:"Au"}),e.jsx("input",{type:"date",className:"input-dark",value:n.to,onChange:s=>p(a=>({...a,to:s.target.value}))})]}),e.jsx("button",{type:"button",className:"btn-primary self-end",onClick:u,children:"Actualiser"})]})}),x?e.jsx("div",{className:"rounded-2xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:x}):null,e.jsx("section",{className:"overflow-hidden rounded-[2rem] border border-slate-200 bg-white shadow-xl shadow-slate-200/70",children:e.jsx("div",{className:"table-shell overflow-x-auto",children:e.jsxs("table",{className:"min-w-[1120px] w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-100 text-left text-xs uppercase tracking-[0.16em] text-slate-500",children:e.jsx("tr",{children:["Date","Utilisateur","IP","Module accédé","Navigateur","Résultat"].map(s=>e.jsx("th",{className:"px-4 py-3",children:s},s))})}),e.jsx("tbody",{children:g?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-8 text-center text-slate-500",children:"Chargement..."})}):c.length?c.map(s=>e.jsxs("tr",{className:`border-t ${s.result==="failure"?"bg-red-50/70":"hover:bg-slate-50"}`,children:[e.jsx("td",{className:"px-4 py-4 text-slate-600",children:y(s.attempted_at)}),e.jsx("td",{className:"px-4 py-4 text-slate-900",children:s.user_name}),e.jsx("td",{className:"px-4 py-4 font-mono text-xs text-slate-500",children:s.ip_address||"—"}),e.jsx("td",{className:"px-4 py-4",children:e.jsx("span",{className:`rounded-full border px-3 py-1 text-xs font-semibold ${s.module_accessed==="MGX"?"border-amber-200 bg-amber-50 text-amber-700":s.module_accessed==="SCF"?"border-blue-200 bg-blue-50 text-blue-700":"border-slate-200 bg-slate-100 text-slate-600"}`,children:s.module_accessed||"—"})}),e.jsx("td",{className:"px-4 py-4 text-slate-700",children:s.browser||"Inconnu"}),e.jsx("td",{className:"px-4 py-4",children:e.jsx("span",{className:`rounded-full border px-3 py-1 text-xs font-semibold ${s.result==="success"?"border-emerald-200 bg-emerald-50 text-emerald-700":"border-red-200 bg-red-50 text-red-700"}`,children:s.result==="success"?"Succès":"Échec"})})]},s.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-8 text-center text-slate-500",children:"Aucune connexion trouvée."})})})]})})})]})}export{S as default};
