import{e as g,r as l,fq as z,fr as U,ep as X,j as e,B as j,a6 as M,a4 as Y,dA as J,bF as C,S as T,bX as Q,c as N,bY as V,eR as Z,cX as W,cH as ee,cw as se,c4 as ae}from"./index-C4inJ1rU.js";import{C as te}from"./ConfirmModal-Dr1cpMpw.js";import{P as le,a as ie,B as ne,C as E}from"./PageLayout-CdGXajgM.js";import{R as $,C as y}from"./Grid-rJkrpDAP.js";import{S as ce}from"./shield-rLi3RwxU.js";import{A as de}from"./antenna-BFrGO3fo.js";import{T as F}from"./trash-2-1fU70LRT.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 re=[["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"}]],oe=g("badge-check",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=[["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"}]],xe=g("layout-grid",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=[["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"}]],ue=g("lock-keyhole",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 pe=[["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"}]],fe=g("user-check",pe),ye=[{id:"overview",label:"Overview",icon:xe},{id:"clients",label:"Authenticated Clients",icon:fe},{id:"identities",label:"By Identity",icon:oe}];function B(s){return s?new Date(s*1e3).toLocaleString():"Never"}function be(s){if(!s)return"Never";const t=Date.now()-s*1e3,i=Math.floor(t/6e4),x=Math.floor(t/36e5),d=Math.floor(t/864e5);return i<1?"Just now":i<60?`${i}m ago`:x<24?`${x}h ago`:d<365?`${d}d ago`:`${Math.floor(d/365)}y ago`}function b({label:s,value:t,icon:i}){return e.jsxs(E,{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(W,{centered:!0,children:e.jsx("span",{className:"type-data-xl text-fg-primary font-mono font-normal tabular-nums",children:t})})]})}const P={repeater:{icon:de,color:"var(--sys-blue)"},room_server:{icon:se,color:"var(--sys-pink)"},companion:{icon:ee,color:"var(--sys-cyan)"}};function je({identity:s}){const t=P[s.type]??P.repeater,i=t.icon;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:e.jsx(i,{className:"w-4 h-4"})}),e.jsx("span",{className:"type-micro",children:s.name}),e.jsx(ae,{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.color},children:s.type})]}),s.type==="companion"?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:"Bridge Registered"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",style:{"--data-box-color":s.registered?"var(--sys-green)":"var(--sys-red)"},children:s.registered?"✓ Running":"✗ Not Running"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Frame Client"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",style:{"--data-box-color":s.active?"var(--sys-green)":"var(--sys-amber)"},children:s.active?"Connected":"Idle"})]}),e.jsxs("div",{className:"flex-1 min-w-0 col-span-2",children:[e.jsx("div",{className:"data-box-label",children:"Client IP"}),e.jsx("div",{className:"data-box data-box-fill data-box-left font-mono",children:s.client_ip??"—"})]})]}):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 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 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:be(s.last_activity)})]})]}),e.jsxs(j,{color:"danger",outline:!0,onClick:t,className:"flex-shrink-0",children:[e.jsx(F,{"data-slot":"icon"}),"Remove"]})]})})}function Ne({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(j,{color:"danger",outline:!0,onClick:t,className:"flex-shrink-0",children:e.jsx(F,{"data-slot":"icon"})})]})})}function Re(){const[s,t]=l.useState("overview"),[i,x]=l.useState(!0),[d,S]=l.useState(!1),[h,v]=l.useState("idle"),[A,u]=l.useState(null),[w,D]=l.useState(null),[c,K]=l.useState([]),[r,H]=l.useState(null),[o,q]=l.useState(null),[n,p]=l.useState(null),[G,R]=l.useState(!1),k=(w==null?void 0:w.acls)??[],I=l.useMemo(()=>o?c.filter(a=>a.identity_name===o):c,[c,o]),f=l.useCallback(async()=>{u(null);try{const[a,m,_]=await Promise.all([z(),U(),X()]);a.success&&a.data&&D(a.data),m.success&&m.data&&K(m.data.clients||[]),_.success&&_.data&&H(_.data)}catch(a){u(a instanceof Error?a.message:"Failed to load session data")}},[]);l.useEffect(()=>{f().finally(()=>x(!1))},[f]);const L=async()=>{S(!0),v("loading"),await f(),S(!1),v("success"),setTimeout(()=>v("idle"),1500)},O=async()=>{if(n){R(!0);try{const a=await Z({public_key:n.publicKey,identity_hash:n.identityHash});a.success?await f():u(`Failed to remove client: ${a.error}`)}catch(a){u(a instanceof Error?a.message:"Failed to remove client")}finally{R(!1),p(null)}}};return e.jsxs(le,{children:[e.jsx(ie,{title:"Sessions",icon:e.jsx(C,{}),controls:e.jsxs(j,{color:h==="success"?"success":"primary",outline:!0,onClick:L,disabled:d,children:[h==="loading"?e.jsx(M,{"data-slot":"icon",className:"animate-spin"}):h==="success"?e.jsx(Y,{"data-slot":"icon"}):e.jsx(J,{"data-slot":"icon"}),h==="success"?"Done":"Refresh"]}),subtitle:e.jsx("p",{className:"type-body-sm text-fg-muted",children:"Manage authenticated clients and access control lists"})}),e.jsxs(ne,{children:[r&&e.jsxs($,{template:"widget",children:[e.jsx(y,{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(y,{span:6,md:3,children:e.jsx(b,{label:"Authenticated",value:r.total_clients,icon:e.jsx(ue,{className:"w-4 h-4"})})}),e.jsx(y,{span:6,md:3,children:e.jsx(b,{label:"Admin",value:r.admin_clients,icon:e.jsx(T,{className:"w-4 h-4"})})}),e.jsx(y,{span:6,md:3,children:e.jsx(b,{label:"Guest",value:r.guest_clients,icon:e.jsx(Q,{className:"w-4 h-4"})})})]}),e.jsx($,{template:"auto",children:e.jsxs(E,{neomorphic:!0,children:[e.jsx("div",{className:"flex flex-wrap gap-1 mb-5",children:e.jsx("div",{className:"toggle-group",children:ye.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(V,{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(j,{color:"primary",outline:!0,onClick:L,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(T,{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(ge,{client:a,onRemove:()=>p({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=>q(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.type==="companion"?`(${a.active?"active":"idle"})`:`(${a.authenticated_clients} clients)`]},a.name))]})]}),I.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(ce,{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:I.map(a=>e.jsx(Ne,{client:a,onRemove:()=>p({publicKey:a.public_key_full,identityHash:a.identity_hash,displayKey:a.public_key})},a.public_key_full))})]})]})})]})})]}),e.jsx(te,{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:G?"Removing...":"Remove",cancelLabel:"Cancel",variant:"danger",onConfirm:O,onCancel:()=>p(null)})]})}export{Re as default};
