import{a as j,r,j as e,d as N}from"./index-D4ZMoJFe.js";import{A as g}from"./AdminSubnav-B96tphNW.js";import{f as y,d as b}from"./adminUtils-Qmlne9KJ.js";function S(){var i;const{selectedCompanyId:m,user:t}=j(),c=m||(t==null?void 0:t.companyId)||((i=t==null?void 0:t.company)==null?void 0:i.id)||"",[p,n]=r.useState(!0),[d,l]=r.useState(""),[x,h]=r.useState([]),u=async()=>{var s,o;n(!0),l("");try{const a=await N.get("/login-history",{params:{company_id:c||void 0}});h(a.data.items||[])}catch(a){l(((o=(s=a==null?void 0:a.response)==null?void 0:s.data)==null?void 0:o.message)||"Impossible de charger l'historique des connexions.")}finally{n(!1)}};return r.useEffect(()=>{u()},[c]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"card-panel p-6 sm:p-8",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs uppercase tracking-[0.2em] text-accent",children:"Administration"}),e.jsx("h1",{className:"mt-3 text-3xl font-semibold text-text",children:"Historique des connexions"}),e.jsx("p",{className:"mt-3 max-w-3xl text-sm leading-7 text-textMuted",children:"Suivez les succès et échecs d'authentification, avec IP source et navigateur."})]}),e.jsx("div",{className:"mt-6",children:e.jsx(g,{})})]}),d?e.jsx("section",{className:"rounded-2xl border border-danger/20 bg-danger/5 px-5 py-4 text-sm text-danger",children:d}):null,e.jsx("section",{className:"table-shell overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-surface2 text-left text-xs uppercase tracking-[0.16em] text-textMuted",children:[e.jsx("th",{className:"px-4 py-3",children:"Date"}),e.jsx("th",{className:"px-4 py-3",children:"Utilisateur"}),e.jsx("th",{className:"px-4 py-3",children:"IP"}),e.jsx("th",{className:"px-4 py-3",children:"Navigateur"}),e.jsx("th",{className:"px-4 py-3",children:"Résultat"})]})}),e.jsx("tbody",{children:p?e.jsx("tr",{className:"border-t border-border/70",children:e.jsx("td",{colSpan:5,className:"px-4 py-10 text-center text-textMuted",children:"Chargement de l'historique..."})}):x.length?x.map(s=>e.jsxs("tr",{className:`border-t border-border/70 text-text ${s.result==="failure"?"bg-danger/5":""}`,children:[e.jsx("td",{className:"px-4 py-4 text-textMuted",children:y(s.attempted_at)}),e.jsxs("td",{className:"px-4 py-4",children:[e.jsx("div",{className:"font-medium",children:s.user_name}),e.jsx("div",{className:"mt-1 text-xs text-textMuted",children:s.email})]}),e.jsx("td",{className:"px-4 py-4 font-mono text-xs text-textMuted",children:s.ip_address||"—"}),e.jsx("td",{className:"px-4 py-4 text-textMuted",children:s.browser}),e.jsxs("td",{className:"px-4 py-4",children:[e.jsx("span",{className:`status-pill ${b(s.result)}`,children:s.result==="failure"?"Échec":"Succès"}),s.reason?e.jsx("div",{className:"mt-1 text-xs text-textMuted",children:s.reason}):null]})]},s.id)):e.jsx("tr",{className:"border-t border-border/70",children:e.jsx("td",{colSpan:5,className:"px-4 py-10 text-center text-textMuted",children:"Aucun événement de connexion trouvé."})})})]})})]})}export{S as default};
