import{j as e}from"./query-PJ0ZdjbV.js";import{a as u}from"./vendor-CWhr2lg4.js";import{D as y,E as b,F as _,B as k,d as R,e as B,f as H,g as P,h as E,M as L,G as O,H as M,J as C,K as a,O as $,Q as g,V as v,W as p,X as f,Y as A,Z as N,_ as S,$ as w,a0 as T,a1 as n}from"./index-BSPIaiZU.js";import{B as z}from"./badge-C34iUAiA.js";import{S as l}from"./skeleton-CfUgaIb_.js";import{P as F}from"./page-header-D8tSLbK0.js";import{E as I}from"./empty-state-lAjp7uO1.js";import"./ui-aO-W1bxx.js";function Y({session:s,onRevoke:c,isRevoking:r}){return e.jsxs(C,{children:[e.jsx(n,{children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.device_info||"Unknown Device"}),s.is_current&&e.jsx(z,{variant:"default",className:"text-xs",children:"Current"})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:s.ip_address??"—"})]})}),e.jsx(n,{children:e.jsx("p",{className:"text-xs text-muted-foreground max-w-xs truncate",title:s.user_agent,children:s.user_agent||"—"})}),e.jsx(n,{className:"text-sm text-muted-foreground",children:new Date(s.created_at).toLocaleDateString()}),e.jsx(n,{className:"text-sm text-muted-foreground",children:new Date(s.last_active).toLocaleString()}),e.jsx(n,{children:!s.is_current&&e.jsx(k,{variant:"outline",size:"sm",onClick:()=>c(s.id),disabled:r,className:"text-destructive hover:text-destructive",children:"Revoke"})})]})}function Z(){var j;const{data:s=[],isLoading:c}=y(),r=b(),i=_(),[D,o]=u.useState(!1),[d,x]=u.useState(null),h=s.filter(t=>!t.is_current);return e.jsxs("div",{className:"space-y-6",children:[e.jsx(F,{title:"Active Sessions",description:"Manage all devices where your account is currently signed in.",actions:h.length>0?e.jsx(k,{variant:"destructive",size:"sm",onClick:()=>o(!0),disabled:i.isPending,children:i.isPending?"Terminating…":"Terminate All Other Sessions"}):void 0}),e.jsxs(R,{children:[e.jsxs(B,{children:[e.jsx(H,{className:"text-base",children:s.length===0?"No Active Sessions":`${s.length} Active Session${s.length!==1?"s":""}`}),e.jsx(P,{children:"Sessions are created when you sign in and expire after the refresh token lifetime."})]}),e.jsx(E,{className:"p-0",children:c?e.jsx("div",{className:"p-5 space-y-4",children:Array.from({length:3}).map((t,m)=>e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(l,{className:"h-4 w-32"}),e.jsx(l,{className:"h-4 w-48"}),e.jsx(l,{className:"h-4 w-24"}),e.jsx(l,{className:"h-4 w-28"})]},m))}):s.length===0?e.jsx(I,{icon:L,title:"No active sessions",description:"Sessions appear here when you sign in from different devices.",className:"py-12"}):e.jsxs(O,{children:[e.jsx(M,{children:e.jsxs(C,{children:[e.jsx(a,{children:"Device"}),e.jsx(a,{children:"Browser / App"}),e.jsx(a,{children:"Signed In"}),e.jsx(a,{children:"Last Active"}),e.jsx(a,{})]})}),e.jsx($,{children:s.map(t=>e.jsx(Y,{session:t,onRevoke:m=>x(m),isRevoking:r.isPending},t.id))})]})})]}),i.isSuccess&&e.jsxs("p",{className:"text-[13px] text-green-600 font-medium",children:[((j=i.data)==null?void 0:j.revoked)??0," session(s) terminated successfully."]}),e.jsx(g,{open:D,onOpenChange:o,children:e.jsxs(v,{children:[e.jsx(p,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(f,{variant:"warning"}),e.jsxs("div",{children:[e.jsx(A,{children:"Terminate All Sessions"}),e.jsxs(N,{children:["This will sign out all other devices (",h.length," session",h.length!==1?"s":"","). Your current session will not be affected."]})]})]})}),e.jsxs(S,{children:[e.jsx(w,{children:"Cancel"}),e.jsx(T,{variant:"destructive",onClick:()=>{i.mutate(),o(!1)},children:"Terminate All"})]})]})}),e.jsx(g,{open:!!d,onOpenChange:t=>!t&&x(null),children:e.jsxs(v,{children:[e.jsx(p,{children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(f,{variant:"destructive"}),e.jsxs("div",{children:[e.jsx(A,{children:"Revoke Session"}),e.jsx(N,{children:"Are you sure you want to revoke this session? The device will be signed out immediately."})]})]})}),e.jsxs(S,{children:[e.jsx(w,{children:"Cancel"}),e.jsx(T,{variant:"destructive",onClick:()=>{d&&r.mutate(d),x(null)},children:"Revoke"})]})]})})]})}export{Z as SessionsPage};
