import{d as x,r as l,eI as G,eJ as O,dF as J,j as e,B as g,L as M,D as U,bf as C,c as N,e2 as V,cp as Q,bY as Y}from"./index-CeMilrX4.js";import{C as Z}from"./ConfirmModal-BF449Kzb.js";import{D as W}from"./DataBox-Da-5DbUW.js";import{P as X,a as ee,B as se,C as D}from"./PageLayout-Cw_MXmcE.js";import{R as ae}from"./refresh-cw-DqhcBXAw.js";import{R as T,C as j}from"./Grid-BuDgMX1I.js";import{C as te}from"./circle-question-mark-Bqc_DPUo.js";import{T as le}from"./triangle-alert-DiFold9L.js";import{S as ie}from"./shield-D-fYOAoy.js";import{A as ne}from"./antenna-DhdWQ_ro.js";import{T as P}from"./trash-2-Bu7BoH4P.js";/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ce=[["path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",key:"3c2336"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],de=x("badge-check",ce);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const re=[["rect",{width:"7",height:"7",x:"3",y:"3",rx:"1",key:"1g98yp"}],["rect",{width:"7",height:"7",x:"14",y:"3",rx:"1",key:"6d4xhi"}],["rect",{width:"7",height:"7",x:"14",y:"14",rx:"1",key:"nxv5o0"}],["rect",{width:"7",height:"7",x:"3",y:"14",rx:"1",key:"1bb6yr"}]],oe=x("layout-grid",re);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const me=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],xe=x("lock-keyhole",me);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const he=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],$=x("shield-check",he);/**
 * @license lucide-react v0.559.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ue=[["path",{d:"m16 11 2 2 4-4",key:"9rsbq5"}],["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],pe=x("user-check",ue),fe=[{id:"overview",label:"Overview",icon:oe},{id:"clients",label:"Authenticated Clients",icon:pe},{id:"identities",label:"By Identity",icon:de}];function B(s){return s?new Date(s*1e3).toLocaleString():"Never"}function ye(s){if(!s)return"Never";const t=Date.now()-s*1e3,i=Math.floor(t/6e4),h=Math.floor(t/36e5),d=Math.floor(t/864e5);return i<1?"Just now":i<60?`${i}m ago`:h<24?`${h}h ago`:d<365?`${d}d ago`:`${Math.floor(d/365)}y ago`}function b({label:s,value:t,icon:i}){return e.jsxs(D,{neomorphic:!0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 mb-2 sm:mb-3",children:[i&&e.jsx("span",{className:"icon-sm text-icon-card-title",children:i}),e.jsx("span",{className:"type-micro",children:s})]}),e.jsx(Q,{centered:!0,children:e.jsx("span",{className:"type-data-xl text-fg-primary font-mono font-normal tabular-nums",children:t})})]})}function je({identity:s}){const t=s.type==="repeater";return e.jsxs("div",{className:"bg-subtle-fill/80 radius-inner depth-stroke-raised p-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5 sm:gap-2 mb-3",children:[e.jsx("span",{className:"icon-sm text-icon-card-title",children:t?e.jsx(ne,{className:"w-4 h-4"}):e.jsx(Y,{className:"w-4 h-4"})}),e.jsx("span",{className:"type-micro",children:s.name}),e.jsx(W,{copy:!0,size:"compact",truncate:[8,6],color:"text-fg-muted",children:s.hash}),e.jsx("span",{className:"data-box data-box-compact data-box-outlined ml-auto",style:{"--data-box-accent":t?"var(--sys-blue)":"var(--sys-pink)"},children:s.type})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Max Clients"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:s.max_clients})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Authenticated"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:s.authenticated_clients})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Admin Password"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",style:{"--data-box-color":s.has_admin_password?"var(--sys-green)":"var(--sys-red)"},children:s.has_admin_password?"✓ Set":"✗ Not Set"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Guest Password"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",style:{"--data-box-color":s.has_guest_password?"var(--sys-green)":"var(--sys-red)"},children:s.has_guest_password?"✓ Set":"✗ Not Set"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Read-Only Access"}),e.jsx("div",{className:N("data-box data-box-fill data-box-left",s.allow_read_only?"text-sys-green":"text-sys-red"),children:s.allow_read_only?"Allowed":"Disabled"})]})]})]})}function be({client:s,onRemove:t}){return e.jsx("div",{className:"bg-subtle-fill/80 radius-inner depth-stroke-raised p-4 transition-base hover:bg-subtle-fill-strong",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0 grid grid-cols-1 sm:grid-cols-5 gap-2 sm:gap-4 items-center",children:[e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("span",{className:"type-data-xs text-fg-muted block sm:hidden mb-0.5",children:"Client"}),e.jsx("span",{className:"type-data-sm text-fg-primary font-mono truncate block",children:s.public_key})]}),e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("span",{className:"type-data-xs text-fg-muted block sm:hidden mb-0.5",children:"Address"}),e.jsx("span",{className:"type-data-xs text-fg-muted font-mono truncate block",children:s.address})]}),e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("span",{className:"type-data-xs text-fg-muted block sm:hidden mb-0.5",children:"Identity"}),e.jsx("span",{className:"type-data-sm text-fg-primary block truncate",children:s.identity_name}),e.jsx("span",{className:"type-data-xs text-fg-muted block truncate",children:s.identity_hash})]}),e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("span",{className:"type-data-xs text-fg-muted block sm:hidden mb-0.5",children:"Permissions"}),e.jsx("span",{className:N("type-data-xs px-2 py-0.5 rounded-full font-medium inline-block",s.permissions==="admin"?"bg-sys-green/15 text-sys-green":"bg-sys-amber/15 text-sys-amber"),children:s.permissions})]}),e.jsxs("div",{className:"sm:col-span-1",children:[e.jsx("span",{className:"type-data-xs text-fg-muted block sm:hidden mb-0.5",children:"Last Activity"}),e.jsx("span",{className:"type-data-xs text-fg-muted",children:ye(s.last_activity)})]})]}),e.jsxs(g,{color:"danger",outline:!0,onClick:t,className:"flex-shrink-0",children:[e.jsx(P,{"data-slot":"icon"}),"Remove"]})]})})}function ge({client:s,onRemove:t}){return e.jsx("div",{className:"bg-subtle-fill/80 radius-inner depth-stroke-raised p-4 transition-base hover:bg-subtle-fill-strong",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:N("type-data-xs px-2 py-0.5 rounded-full font-medium",s.permissions==="admin"?"bg-sys-green/15 text-sys-green":"bg-sys-amber/15 text-sys-amber"),children:s.permissions}),e.jsx("span",{className:"type-data-sm text-fg-primary font-mono truncate",children:s.public_key})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-muted",children:"Address: "}),e.jsx("span",{className:"text-fg-primary/90 font-mono",children:s.address})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-muted",children:"Identity: "}),e.jsxs("span",{className:"text-fg-primary/90",children:[s.identity_name," (",s.identity_hash,")"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-muted",children:"Last Activity: "}),e.jsx("span",{className:"text-fg-primary/90",children:B(s.last_activity)})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-fg-muted",children:"Last Login: "}),e.jsx("span",{className:"text-fg-primary/90",children:B(s.last_login_success)})]})]})]}),e.jsx(g,{color:"danger",outline:!0,onClick:t,className:"flex-shrink-0",children:e.jsx(P,{"data-slot":"icon"})})]})})}function Me(){const[s,t]=l.useState("overview"),[i,h]=l.useState(!0),[d,S]=l.useState(!1),[u,v]=l.useState("idle"),[A,p]=l.useState(null),[w,F]=l.useState(null),[c,K]=l.useState([]),[r,E]=l.useState(null),[o,H]=l.useState(null),[n,f]=l.useState(null),[q,R]=l.useState(!1),k=(w==null?void 0:w.acls)??[],L=l.useMemo(()=>o?c.filter(a=>a.identity_name===o):c,[c,o]),y=l.useCallback(async()=>{p(null);try{const[a,m,_]=await Promise.all([G(),O(),J()]);a.success&&a.data&&F(a.data),m.success&&m.data&&K(m.data.clients||[]),_.success&&_.data&&E(_.data)}catch(a){p(a instanceof Error?a.message:"Failed to load session data")}},[]);l.useEffect(()=>{y().finally(()=>h(!1))},[y]);const I=async()=>{S(!0),v("loading"),await y(),S(!1),v("success"),setTimeout(()=>v("idle"),1500)},z=async()=>{if(n){R(!0);try{const a=await V({public_key:n.publicKey,identity_hash:n.identityHash});a.success?await y():p(`Failed to remove client: ${a.error}`)}catch(a){p(a instanceof Error?a.message:"Failed to remove client")}finally{R(!1),f(null)}}};return e.jsxs(X,{children:[e.jsx(ee,{title:"Sessions",icon:e.jsx(C,{}),controls:e.jsxs(g,{color:u==="success"?"success":"primary",outline:!0,onClick:I,disabled:d,children:[u==="loading"?e.jsx(M,{"data-slot":"icon",className:"animate-spin"}):u==="success"?e.jsx(U,{"data-slot":"icon"}):e.jsx(ae,{"data-slot":"icon"}),u==="success"?"Done":"Refresh"]}),subtitle:e.jsx("p",{className:"type-body-sm text-fg-muted",children:"Manage authenticated clients and access control lists"})}),e.jsxs(se,{children:[r&&e.jsxs(T,{template:"widget",children:[e.jsx(j,{span:6,md:3,children:e.jsx(b,{label:"Identities",value:r.total_identities,icon:e.jsx(C,{className:"w-4 h-4"})})}),e.jsx(j,{span:6,md:3,children:e.jsx(b,{label:"Authenticated",value:r.total_clients,icon:e.jsx(xe,{className:"w-4 h-4"})})}),e.jsx(j,{span:6,md:3,children:e.jsx(b,{label:"Admin",value:r.admin_clients,icon:e.jsx($,{className:"w-4 h-4"})})}),e.jsx(j,{span:6,md:3,children:e.jsx(b,{label:"Guest",value:r.guest_clients,icon:e.jsx(te,{className:"w-4 h-4"})})})]}),e.jsx(T,{template:"auto",children:e.jsxs(D,{neomorphic:!0,children:[e.jsx("div",{className:"flex flex-wrap gap-1 mb-5",children:e.jsx("div",{className:"toggle-group",children:fe.map(a=>{const m=s===a.id;return e.jsxs("button",{onClick:()=>t(a.id),className:N("toggle-group-item flex items-center gap-1.5",m&&"active"),children:[e.jsx(a.icon,{className:"w-3.5 h-3.5"}),a.label]},a.id)})})}),e.jsx("div",{className:"min-h-[300px]",children:i?e.jsxs("div",{className:"flex items-center justify-center py-12",children:[e.jsx(M,{className:"w-6 h-6 animate-spin text-sys-blue mr-3"}),e.jsx("span",{className:"type-body text-fg-muted",children:"Loading session data..."})]}):A?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-12 h-12 rounded-full bg-sys-red/10 mx-auto mb-3 flex items-center justify-center",children:e.jsx(le,{className:"w-6 h-6 text-sys-red"})}),e.jsx("p",{className:"type-body text-sys-red mb-2",children:"Failed to load session data"}),e.jsx("p",{className:"type-body-sm text-fg-muted mb-4",children:A}),e.jsx(g,{color:"primary",outline:!0,onClick:I,children:"Retry"})]}):e.jsxs(e.Fragment,{children:[s==="overview"&&e.jsx("div",{className:"space-y-4",children:k.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-subtle-fill mx-auto mb-4 flex items-center justify-center",children:e.jsx($,{className:"w-7 h-7 text-fg-muted/50"})}),e.jsx("p",{className:"type-body text-fg-muted",children:"No identities configured"})]}):k.map(a=>e.jsx(je,{identity:a},a.hash))}),s==="clients"&&e.jsxs("div",{className:"space-y-3",children:[c.length>0&&e.jsxs("div",{className:"hidden sm:grid grid-cols-5 gap-4 px-4 pb-2 border-b border-edge-subtle",children:[e.jsx("span",{className:"type-data-xs text-fg-muted font-medium",children:"Client"}),e.jsx("span",{className:"type-data-xs text-fg-muted font-medium",children:"Address"}),e.jsx("span",{className:"type-data-xs text-fg-muted font-medium",children:"Identity"}),e.jsx("span",{className:"type-data-xs text-fg-muted font-medium",children:"Permissions"}),e.jsx("span",{className:"type-data-xs text-fg-muted font-medium",children:"Last Activity"})]}),c.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-subtle-fill mx-auto mb-4 flex items-center justify-center",children:e.jsx(C,{className:"w-7 h-7 text-fg-muted/50"})}),e.jsx("p",{className:"type-body text-fg-muted",children:"No authenticated clients"})]}):c.map(a=>e.jsx(be,{client:a,onRemove:()=>f({publicKey:a.public_key_full,identityHash:a.identity_hash,displayKey:a.public_key})},a.public_key_full))]}),s==="identities"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"type-label text-fg-muted block mb-2",children:"Filter by Identity"}),e.jsxs("select",{value:o??"",onChange:a=>H(a.target.value||null),className:"w-full sm:w-auto bg-subtle-fill border border-edge-subtle radius-inner px-4 py-2 type-data text-fg-primary focus:outline-none focus:border-sys-blue/50 transition-colors",children:[e.jsx("option",{value:"",children:"All Identities"}),k.map(a=>e.jsxs("option",{value:a.name,children:[a.name," (",a.authenticated_clients," clients)"]},a.name))]})]}),L.length===0?e.jsxs("div",{className:"text-center py-12",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-subtle-fill mx-auto mb-4 flex items-center justify-center",children:e.jsx(ie,{className:"w-7 h-7 text-fg-muted/50"})}),e.jsx("p",{className:"type-body text-fg-muted",children:o?"No clients for selected identity":"No clients found"})]}):e.jsx("div",{className:"space-y-3",children:L.map(a=>e.jsx(ge,{client:a,onRemove:()=>f({publicKey:a.public_key_full,identityHash:a.identity_hash,displayKey:a.public_key})},a.public_key_full))})]})]})})]})})]}),e.jsx(Z,{isOpen:!!n,title:"Remove Client",message:`Are you sure you want to remove client '${n==null?void 0:n.displayKey}' from the ACL? This will disconnect the client.`,confirmLabel:q?"Removing...":"Remove",cancelLabel:"Cancel",variant:"danger",onConfirm:z,onCancel:()=>f(null)})]})}export{Me as default};
