Files
claude-relay-service/assets/UserManagementView-CctYOWS4.js
2026-01-22 07:08:39 +00:00

2 lines
32 KiB
JavaScript

import{r as f,o as G,x as i,L as b,y as n,z as e,P as r,K as U,aV as P,Q as W,ac as Y,C as z,Y as J,an as E,O as H,c as X,q as Z,R as N,aq as ee,u as Q}from"./vue-vendor-R8HMg95E.js";import{_ as q,c as A,s as M}from"./index-S7cfD3ib.js";import{C as te}from"./ConfirmModal-Vihre-Rx.js";import{d as se}from"./vendor-Dr8jvgFu.js";import"./element-plus-BUfCkBQO.js";const oe={key:0,class:"fixed inset-0 z-50 h-full w-full overflow-y-auto bg-gray-600 bg-opacity-50"},le={class:"relative top-10 mx-auto w-4/5 max-w-4xl rounded-md border bg-white p-5 shadow-lg"},re={class:"mt-3"},ae={class:"mb-6 flex items-center justify-between"},ie={class:"text-lg font-medium text-gray-900"},ne={class:"text-sm text-gray-500"},de={class:"mb-6"},ue={key:0,class:"py-12 text-center"},ce={key:1,class:"space-y-6"},me={class:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4"},ve={class:"overflow-hidden rounded-lg bg-blue-50 shadow"},xe={class:"p-5"},ge={class:"flex items-center"},pe={class:"ml-5 w-0 flex-1"},fe={class:"text-lg font-medium text-blue-900"},he={class:"overflow-hidden rounded-lg bg-green-50 shadow"},ye={class:"p-5"},we={class:"flex items-center"},be={class:"ml-5 w-0 flex-1"},ke={class:"text-lg font-medium text-green-900"},_e={class:"overflow-hidden rounded-lg bg-purple-50 shadow"},$e={class:"p-5"},Ce={class:"flex items-center"},Ae={class:"ml-5 w-0 flex-1"},Me={class:"text-lg font-medium text-purple-900"},Ue={class:"overflow-hidden rounded-lg bg-yellow-50 shadow"},je={class:"p-5"},ze={class:"flex items-center"},Ve={class:"ml-5 w-0 flex-1"},Be={class:"text-lg font-medium text-yellow-900"},Le={key:0,class:"rounded-lg border border-gray-200 bg-white"},Re={class:"overflow-hidden"},Se={class:"min-w-full divide-y divide-gray-200"},De={class:"divide-y divide-gray-200 bg-white"},Te={class:"whitespace-nowrap px-6 py-4"},Ie={class:"text-sm font-medium text-gray-900"},Fe={class:"text-sm text-gray-500"},Ne={class:"whitespace-nowrap px-6 py-4"},Pe={class:"whitespace-nowrap px-6 py-4 text-sm text-gray-900"},He={class:"whitespace-nowrap px-6 py-4 text-sm text-gray-900"},qe={class:"whitespace-nowrap px-6 py-4 text-sm text-gray-900"},Ke={class:"whitespace-nowrap px-6 py-4 text-sm text-gray-500"},Oe={class:"rounded-lg border border-gray-200 bg-white"},Ee={class:"p-6"},Qe={class:"flex h-64 items-center justify-center rounded-lg border-2 border-dashed border-gray-300"},Ge={class:"text-center"},We={class:"mt-1 text-sm text-gray-500"},Ye={key:1,class:"py-12 text-center"},Je={class:"mt-6 flex justify-end"},Xe={__name:"UserUsageStatsModal",props:{show:{type:Boolean,default:!1},user:{type:Object,default:null}},emits:["close"],setup(g,{emit:k}){const h=g,_=k,p=f(!1),x=f("week"),d=f(null),$=f(null),m=c=>c>=1e6?(c/1e6).toFixed(1)+"M":c>=1e3?(c/1e3).toFixed(1)+"K":c.toString(),l=c=>c?new Date(c).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):null,u=async()=>{if(h.user){p.value=!0;try{const[c,o]=await Promise.all([A.get(`/users/${h.user.id}/usage-stats`,{params:{period:x.value}}),A.get(`/users/${h.user.id}`)]);c.success&&(d.value=c.stats),o.success&&($.value=o.user)}catch(c){console.error("Failed to load user usage stats:",c),M("Failed to load usage statistics","error")}finally{p.value=!1}}};return G([()=>h.show,()=>h.user],([c,o])=>{c&&o&&u()}),(c,o)=>{var V,B,C,j,L,R,S,D,T,I;return g.show?(n(),i("div",oe,[e("div",le,[e("div",re,[e("div",ae,[e("div",null,[e("h3",ie," Usage Statistics - "+r(((V=g.user)==null?void 0:V.displayName)||((B=g.user)==null?void 0:B.username)),1),e("p",ne,"@"+r((C=g.user)==null?void 0:C.username)+" • "+r((j=g.user)==null?void 0:j.role),1)]),e("button",{class:"text-gray-400 hover:text-gray-600",onClick:o[0]||(o[0]=s=>_("close"))},o[3]||(o[3]=[e("svg",{class:"h-6 w-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M6 18L18 6M6 6l12 12","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)]))]),e("div",de,[U(e("select",{"onUpdate:modelValue":o[1]||(o[1]=s=>x.value=s),class:"block w-32 rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm",onChange:u},o[4]||(o[4]=[e("option",{value:"day"},"Last 24 Hours",-1),e("option",{value:"week"},"Last 7 Days",-1),e("option",{value:"month"},"Last 30 Days",-1),e("option",{value:"quarter"},"Last 90 Days",-1)]),544),[[P,x.value]])]),p.value?(n(),i("div",ue,o[5]||(o[5]=[e("svg",{class:"mx-auto h-8 w-8 animate-spin text-blue-600",fill:"none",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",fill:"currentColor"})],-1),e("p",{class:"mt-2 text-sm text-gray-500"},"Loading usage statistics...",-1)]))):(n(),i("div",ce,[e("div",me,[e("div",ve,[e("div",xe,[e("div",ge,[o[7]||(o[7]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-blue-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M13 10V3L4 14h7v7l9-11h-7z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",pe,[e("dl",null,[o[6]||(o[6]=e("dt",{class:"truncate text-sm font-medium text-blue-600"},"Requests",-1)),e("dd",fe,r(m(((L=d.value)==null?void 0:L.totalRequests)||0)),1)])])])])]),e("div",he,[e("div",ye,[e("div",we,[o[9]||(o[9]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-green-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",be,[e("dl",null,[o[8]||(o[8]=e("dt",{class:"truncate text-sm font-medium text-green-600"},"Input Tokens",-1)),e("dd",ke,r(m(((R=d.value)==null?void 0:R.totalInputTokens)||0)),1)])])])])]),e("div",_e,[e("div",$e,[e("div",Ce,[o[11]||(o[11]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-purple-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",Ae,[e("dl",null,[o[10]||(o[10]=e("dt",{class:"truncate text-sm font-medium text-purple-600"},"Output Tokens",-1)),e("dd",Me,r(m(((S=d.value)==null?void 0:S.totalOutputTokens)||0)),1)])])])])]),e("div",Ue,[e("div",je,[e("div",ze,[o[13]||(o[13]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-yellow-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",Ve,[e("dl",null,[o[12]||(o[12]=e("dt",{class:"truncate text-sm font-medium text-yellow-600"},"Total Cost",-1)),e("dd",Be," $"+r((((D=d.value)==null?void 0:D.totalCost)||0).toFixed(4)),1)])])])])])]),((I=(T=$.value)==null?void 0:T.apiKeys)==null?void 0:I.length)>0?(n(),i("div",Le,[o[15]||(o[15]=e("div",{class:"border-b border-gray-200 px-4 py-5 sm:px-6"},[e("h4",{class:"text-lg font-medium leading-6 text-gray-900"},"API Keys Usage")],-1)),e("div",Re,[e("table",Se,[o[14]||(o[14]=e("thead",{class:"bg-gray-50"},[e("tr",null,[e("th",{class:"px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500",scope:"col"}," API Key "),e("th",{class:"px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500",scope:"col"}," Status "),e("th",{class:"px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500",scope:"col"}," Requests "),e("th",{class:"px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500",scope:"col"}," Tokens "),e("th",{class:"px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500",scope:"col"}," Cost "),e("th",{class:"px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500",scope:"col"}," Last Used ")])],-1)),e("tbody",De,[(n(!0),i(W,null,Y($.value.apiKeys,s=>{var t,v,y,w;return n(),i("tr",{key:s.id},[e("td",Te,[e("div",Ie,r(s.name),1),e("div",Fe,r(s.keyPreview),1)]),e("td",Ne,[e("span",{class:z(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",s.isActive?"bg-green-100 text-green-800":"bg-red-100 text-red-800"])},r(s.isActive?"Active":"Disabled"),3)]),e("td",Pe,r(m(((t=s.usage)==null?void 0:t.requests)||0)),1),e("td",He,[e("div",null,"In: "+r(m(((v=s.usage)==null?void 0:v.inputTokens)||0)),1),e("div",null,"Out: "+r(m(((y=s.usage)==null?void 0:y.outputTokens)||0)),1)]),e("td",qe," $"+r((((w=s.usage)==null?void 0:w.totalCost)||0).toFixed(4)),1),e("td",Ke,r(s.lastUsedAt?l(s.lastUsedAt):"Never"),1)])}),128))])])])])):b("",!0),e("div",Oe,[o[19]||(o[19]=e("div",{class:"border-b border-gray-200 px-4 py-5 sm:px-6"},[e("h4",{class:"text-lg font-medium leading-6 text-gray-900"},"Usage Trend")],-1)),e("div",Ee,[e("div",Qe,[e("div",Ge,[o[16]||(o[16]=e("svg",{class:"mx-auto h-12 w-12 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)),o[17]||(o[17]=e("h3",{class:"mt-2 text-sm font-medium text-gray-900"},"Usage Chart",-1)),e("p",We," Daily usage trends for "+r(x.value)+" period ",1),o[18]||(o[18]=e("p",{class:"mt-2 text-xs text-gray-400"}," (Chart integration can be added with Chart.js, D3.js, or similar library) ",-1))])])])]),d.value&&d.value.totalRequests===0?(n(),i("div",Ye,o[20]||(o[20]=[e("svg",{class:"mx-auto h-12 w-12 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1),e("h3",{class:"mt-2 text-sm font-medium text-gray-900"},"No usage data",-1),e("p",{class:"mt-1 text-sm text-gray-500"}," This user hasn't made any API requests in the selected period. ",-1)]))):b("",!0)])),e("div",Je,[e("button",{class:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2",onClick:o[2]||(o[2]=s=>c.$emit("close"))}," Close ")])])])])):b("",!0)}}},Ze=q(Xe,[["__scopeId","data-v-3ed8ad13"]]),et={key:0,class:"fixed inset-0 z-50 h-full w-full overflow-y-auto bg-gray-600 bg-opacity-50"},tt={class:"relative top-20 mx-auto w-96 rounded-md border bg-white p-5 shadow-lg"},st={class:"mt-3"},ot={class:"mb-4 flex items-center justify-between"},lt={key:0,class:"space-y-4"},rt={class:"rounded-md bg-gray-50 p-4"},at={class:"flex items-center"},it={class:"ml-4"},nt={class:"text-sm font-medium text-gray-900"},dt={class:"text-sm text-gray-500"},ut={class:"mt-1"},ct={class:"space-y-2"},mt={class:"flex items-center"},vt=["disabled"],xt={class:"flex items-center"},gt=["disabled"],pt={key:0,class:"rounded-md border border-yellow-200 bg-yellow-50 p-4"},ft={class:"flex"},ht={class:"ml-3"},yt={class:"mt-2 text-sm text-yellow-700"},wt={key:0},bt={key:1},kt={key:1,class:"rounded-md border border-red-200 bg-red-50 p-4"},_t={class:"flex"},$t={class:"ml-3"},Ct={class:"text-sm text-red-700"},At={class:"flex justify-end space-x-3 pt-4"},Mt=["disabled"],Ut=["disabled"],jt={key:0,class:"flex items-center"},zt={key:1},Vt={__name:"ChangeRoleModal",props:{show:{type:Boolean,default:!1},user:{type:Object,default:null}},emits:["close","updated"],setup(g,{emit:k}){const h=g,_=k,p=f(!1),x=f(""),d=f(""),$=async()=>{var m,l;if(!(!h.user||d.value===h.user.role)){p.value=!0,x.value="";try{const u=await A.patch(`/users/${h.user.id}/role`,{role:d.value});u.success?(M(`User role updated to ${d.value}`,"success"),_("updated")):x.value=u.message||"Failed to update user role"}catch(u){console.error("Update user role error:",u),x.value=((l=(m=u.response)==null?void 0:m.data)==null?void 0:l.message)||u.message||"Failed to update user role"}finally{p.value=!1}}};return G([()=>h.show,()=>h.user],([m,l])=>{m&&l&&(d.value=l.role,x.value="",p.value=!1)}),(m,l)=>g.show?(n(),i("div",et,[e("div",tt,[e("div",st,[e("div",ot,[l[5]||(l[5]=e("h3",{class:"text-lg font-medium text-gray-900"},"Change User Role",-1)),e("button",{class:"text-gray-400 hover:text-gray-600",onClick:l[0]||(l[0]=u=>m.$emit("close"))},l[4]||(l[4]=[e("svg",{class:"h-6 w-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M6 18L18 6M6 6l12 12","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)]))]),g.user?(n(),i("div",lt,[e("div",rt,[e("div",at,[l[6]||(l[6]=e("div",{class:"flex-shrink-0"},[e("div",{class:"flex h-10 w-10 items-center justify-center rounded-full bg-gray-300"},[e("svg",{class:"h-6 w-6 text-gray-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])])],-1)),e("div",it,[e("p",nt,r(g.user.displayName||g.user.username),1),e("p",dt,"@"+r(g.user.username),1),e("div",ut,[e("span",{class:z(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",g.user.role==="admin"?"bg-purple-100 text-purple-800":"bg-blue-100 text-blue-800"])}," Current: "+r(g.user.role),3)])])])]),e("form",{class:"space-y-4",onSubmit:J($,["prevent"])},[e("div",null,[l[9]||(l[9]=e("label",{class:"mb-2 block text-sm font-medium text-gray-700"}," New Role ",-1)),e("div",ct,[e("label",mt,[U(e("input",{"onUpdate:modelValue":l[1]||(l[1]=u=>d.value=u),class:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500",disabled:p.value,type:"radio",value:"user"},null,8,vt),[[E,d.value]]),l[7]||(l[7]=e("div",{class:"ml-3"},[e("div",{class:"text-sm font-medium text-gray-900"},"User"),e("div",{class:"text-xs text-gray-500"},"Regular user with basic permissions")],-1))]),e("label",xt,[U(e("input",{"onUpdate:modelValue":l[2]||(l[2]=u=>d.value=u),class:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500",disabled:p.value,type:"radio",value:"admin"},null,8,gt),[[E,d.value]]),l[8]||(l[8]=e("div",{class:"ml-3"},[e("div",{class:"text-sm font-medium text-gray-900"},"Administrator"),e("div",{class:"text-xs text-gray-500"},"Full access to manage users and system")],-1))])])]),d.value!==g.user.role?(n(),i("div",pt,[e("div",ft,[l[11]||(l[11]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-5 w-5 text-yellow-400",fill:"currentColor",viewBox:"0 0 20 20"},[e("path",{"clip-rule":"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z","fill-rule":"evenodd"})])],-1)),e("div",ht,[l[10]||(l[10]=e("h3",{class:"text-sm font-medium text-yellow-800"},"Role Change Warning",-1)),e("div",yt,[d.value==="admin"?(n(),i("p",wt," Granting admin privileges will give this user full access to the system, including the ability to manage other users and their API keys. ")):(n(),i("p",bt," Removing admin privileges will restrict this user to only managing their own API keys and viewing their own usage statistics. "))])])])])):b("",!0),x.value?(n(),i("div",kt,[e("div",_t,[l[12]||(l[12]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-5 w-5 text-red-400",fill:"currentColor",viewBox:"0 0 20 20"},[e("path",{"clip-rule":"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z","fill-rule":"evenodd"})])],-1)),e("div",$t,[e("p",Ct,r(x.value),1)])])])):b("",!0),e("div",At,[e("button",{class:"rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50",disabled:p.value,type:"button",onClick:l[3]||(l[3]=u=>m.$emit("close"))}," Cancel ",8,Mt),e("button",{class:"rounded-md border border-transparent bg-blue-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",disabled:p.value||d.value===g.user.role,type:"submit"},[p.value?(n(),i("span",jt,l[13]||(l[13]=[e("svg",{class:"-ml-1 mr-2 h-4 w-4 animate-spin text-white",fill:"none",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",fill:"currentColor"})],-1),H(" Updating... ",-1)]))):(n(),i("span",zt,"Update Role"))],8,Ut)])],32)])):b("",!0)])])])):b("",!0)}},Bt=q(Vt,[["__scopeId","data-v-642cc3e3"]]),Lt={class:"space-y-6"},Rt={class:"sm:flex sm:items-center"},St={class:"mt-4 sm:ml-16 sm:mt-0 sm:flex-none"},Dt=["disabled"],Tt={class:"grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-4"},It={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},Ft={class:"p-5"},Nt={class:"flex items-center"},Pt={class:"ml-5 w-0 flex-1"},Ht={class:"text-lg font-medium text-gray-900 dark:text-white"},qt={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},Kt={class:"p-5"},Ot={class:"flex items-center"},Et={class:"ml-5 w-0 flex-1"},Qt={class:"text-lg font-medium text-gray-900 dark:text-white"},Gt={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},Wt={class:"p-5"},Yt={class:"flex items-center"},Jt={class:"ml-5 w-0 flex-1"},Xt={class:"text-lg font-medium text-gray-900 dark:text-white"},Zt={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},es={class:"p-5"},ts={class:"flex items-center"},ss={class:"ml-5 w-0 flex-1"},os={class:"text-lg font-medium text-gray-900 dark:text-white"},ls={class:"rounded-lg bg-white shadow dark:bg-gray-800"},rs={class:"px-4 py-5 sm:p-6"},as={class:"sm:flex sm:items-center sm:justify-between"},is={class:"space-y-4 sm:flex sm:items-center sm:space-x-4 sm:space-y-0"},ns={class:"min-w-0 flex-1"},ds={class:"relative rounded-md shadow-sm"},us={class:"overflow-hidden bg-white shadow dark:bg-gray-800 sm:rounded-md"},cs={class:"border-b border-gray-200 px-4 py-5 dark:border-gray-700 sm:px-6"},ms={class:"text-lg font-medium leading-6 text-gray-900 dark:text-white"},vs={key:0,class:"text-sm text-gray-500 dark:text-gray-400"},xs={key:0,class:"py-12 text-center"},gs={key:1,class:"divide-y divide-gray-200 dark:divide-gray-700",role:"list"},ps={class:"flex items-center justify-between"},fs={class:"flex min-w-0 flex-1 items-center"},hs={class:"ml-4 min-w-0 flex-1"},ys={class:"flex items-center"},ws={class:"truncate text-sm font-medium text-gray-900 dark:text-white"},bs={class:"ml-2 flex items-center space-x-2"},ks={class:"mt-1 flex items-center space-x-4 text-sm text-gray-500 dark:text-gray-400"},_s={key:0},$s={key:1},Cs={key:2},As={key:0,class:"mt-1 flex items-center space-x-4 text-xs text-gray-400 dark:text-gray-500"},Ms={class:"flex items-center space-x-2"},Us=["onClick"],js=["disabled","onClick"],zs=["title","onClick"],Vs={key:0,class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Bs={key:1,class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Ls=["onClick"],Rs={key:2,class:"py-12 text-center"},Ss={class:"mt-1 text-sm text-gray-500 dark:text-gray-400"},Ds={__name:"UserManagementView",setup(g){const k=f(!0),h=f([]),_=f(null),p=f(""),x=f(""),d=f(""),$=f(!1),m=f(!1),l=f(!1),u=f(null),c=f({title:"",message:"",confirmText:"",confirmClass:"",action:null}),o=X(()=>{let s=h.value;if(p.value){const t=p.value.toLowerCase();s=s.filter(v=>{var y,w;return v.username.toLowerCase().includes(t)||((y=v.displayName)==null?void 0:y.toLowerCase().includes(t))||((w=v.email)==null?void 0:w.toLowerCase().includes(t))})}if(x.value&&(s=s.filter(t=>t.role===x.value)),d.value!==""){const t=d.value==="true";s=s.filter(v=>v.isActive===t)}return s}),V=s=>s>=1e6?(s/1e6).toFixed(1)+"M":s>=1e3?(s/1e3).toFixed(1)+"K":s.toString(),B=s=>s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):null,C=async()=>{k.value=!0;try{const s={};x.value&&x.value.trim()!==""&&(s.role=x.value),d.value!==""&&(s.isActive=d.value);const[t,v]=await Promise.all([A.get("/users",{params:s}),A.get("/users/stats/overview")]);t.success&&(h.value=t.users),v.success&&(_.value=v.stats)}catch(s){console.error("Failed to load users:",s),M("Failed to load users","error")}finally{k.value=!1}},j=se(()=>{},300),L=s=>{u.value=s,$.value=!0},R=s=>{u.value=s,c.value={title:s.isActive?"Disable User":"Enable User",message:s.isActive?`Are you sure you want to disable user "${s.username}"? This will prevent them from logging in.`:`Are you sure you want to enable user "${s.username}"?`,confirmText:s.isActive?"Disable":"Enable",confirmClass:s.isActive?"bg-red-600 hover:bg-red-700":"bg-green-600 hover:bg-green-700",action:"toggleStatus"},m.value=!0},S=s=>{s.apiKeyCount!==0&&(u.value=s,c.value={title:"Disable All API Keys",message:`Are you sure you want to disable all ${s.apiKeyCount} API keys for user "${s.username}"? This will prevent them from using the service.`,confirmText:"Disable Keys",confirmClass:"bg-red-600 hover:bg-red-700",action:"disableKeys"},m.value=!0)},D=s=>{u.value=s,l.value=!0},T=async()=>{const s=u.value,t=c.value.action;try{if(t==="toggleStatus"){if((await A.patch(`/users/${s.id}/status`,{isActive:!s.isActive})).success){const y=h.value.findIndex(w=>w.id===s.id);y!==-1&&(h.value[y].isActive=!s.isActive),M(`User ${s.isActive?"disabled":"enabled"} successfully`,"success")}}else if(t==="disableKeys"){const v=await A.post(`/users/${s.id}/disable-keys`);v.success&&(M(`Disabled ${v.disabledCount} API keys`,"success"),await C())}}catch(v){console.error(`Failed to ${t}:`,v),M(`Failed to ${t}`,"error")}finally{m.value=!1,u.value=null}},I=()=>{l.value=!1,u.value=null,C()};return Z(()=>{C()}),(s,t)=>{var v,y,w,K,O;return n(),i("div",Lt,[e("div",Rt,[t[8]||(t[8]=e("div",{class:"sm:flex-auto"},[e("h1",{class:"text-2xl font-semibold text-gray-900 dark:text-white"},"User Management"),e("p",{class:"mt-2 text-sm text-gray-700 dark:text-gray-300"}," Manage users, their API keys, and view usage statistics ")],-1)),e("div",St,[e("button",{class:"inline-flex items-center justify-center rounded-md border border-transparent bg-blue-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50 sm:w-auto",disabled:k.value,onClick:C},t[7]||(t[7]=[e("svg",{class:"-ml-1 mr-2 h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1),H(" Refresh ",-1)]),8,Dt)])]),e("div",Tt,[e("div",It,[e("div",Ft,[e("div",Nt,[t[10]||(t[10]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-blue-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197m13.5-9a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",Pt,[e("dl",null,[t[9]||(t[9]=e("dt",{class:"truncate text-sm font-medium text-gray-500 dark:text-gray-400"}," Total Users ",-1)),e("dd",Ht,r(((v=_.value)==null?void 0:v.totalUsers)||0),1)])])])])]),e("div",qt,[e("div",Kt,[e("div",Ot,[t[12]||(t[12]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-green-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",Et,[e("dl",null,[t[11]||(t[11]=e("dt",{class:"truncate text-sm font-medium text-gray-500 dark:text-gray-400"}," Active Users ",-1)),e("dd",Qt,r(((y=_.value)==null?void 0:y.activeUsers)||0),1)])])])])]),e("div",Gt,[e("div",Wt,[e("div",Yt,[t[14]||(t[14]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-purple-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M15 7a2 2 0 012 2m0 0a2 2 0 012 2m-2-2h-6m6 0v6a2 2 0 01-2 2H9a2 2 0 01-2-2V9a2 2 0 012-2h6z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",Jt,[e("dl",null,[t[13]||(t[13]=e("dt",{class:"truncate text-sm font-medium text-gray-500 dark:text-gray-400"}," Total API Keys ",-1)),e("dd",Xt,r(((w=_.value)==null?void 0:w.totalApiKeys)||0),1)])])])])]),e("div",Zt,[e("div",es,[e("div",ts,[t[16]||(t[16]=e("div",{class:"flex-shrink-0"},[e("svg",{class:"h-6 w-6 text-yellow-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),e("div",ss,[e("dl",null,[t[15]||(t[15]=e("dt",{class:"truncate text-sm font-medium text-gray-500 dark:text-gray-400"}," Total Cost ",-1)),e("dd",os," $"+r((((O=(K=_.value)==null?void 0:K.totalUsage)==null?void 0:O.totalCost)||0).toFixed(4)),1)])])])])])]),e("div",ls,[e("div",rs,[e("div",as,[e("div",is,[e("div",ns,[e("div",ds,[t[17]||(t[17]=e("div",{class:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3"},[e("svg",{class:"h-5 w-5 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])],-1)),U(e("input",{"onUpdate:modelValue":t[0]||(t[0]=a=>p.value=a),class:"block w-full rounded-md border-gray-300 pl-10 focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white sm:text-sm",placeholder:"Search users...",type:"search",onInput:t[1]||(t[1]=(...a)=>Q(j)&&Q(j)(...a))},null,544),[[ee,p.value]])])]),e("div",null,[U(e("select",{"onUpdate:modelValue":t[2]||(t[2]=a=>x.value=a),class:"block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white sm:text-sm",onChange:C},t[18]||(t[18]=[e("option",{value:""},"All Roles",-1),e("option",{value:"user"},"User",-1),e("option",{value:"admin"},"Admin",-1)]),544),[[P,x.value]])]),e("div",null,[U(e("select",{"onUpdate:modelValue":t[3]||(t[3]=a=>d.value=a),class:"block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 dark:border-gray-600 dark:bg-gray-700 dark:text-white sm:text-sm",onChange:C},t[19]||(t[19]=[e("option",{value:""},"All Status",-1),e("option",{value:"true"},"Active",-1),e("option",{value:"false"},"Disabled",-1)]),544),[[P,d.value]])])])])])]),e("div",us,[e("div",cs,[e("h3",ms,[t[20]||(t[20]=H(" Users ",-1)),k.value?b("",!0):(n(),i("span",vs,"("+r(o.value.length)+" of "+r(h.value.length)+")",1))])]),k.value?(n(),i("div",xs,t[21]||(t[21]=[e("svg",{class:"mx-auto h-8 w-8 animate-spin text-blue-600",fill:"none",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z",fill:"currentColor"})],-1),e("p",{class:"mt-2 text-sm text-gray-500 dark:text-gray-400"},"Loading users...",-1)]))):o.value.length>0?(n(),i("ul",gs,[(n(!0),i(W,null,Y(o.value,a=>(n(),i("li",{key:a.id,class:"px-6 py-4"},[e("div",ps,[e("div",fs,[t[22]||(t[22]=e("div",{class:"flex-shrink-0"},[e("div",{class:"flex h-10 w-10 items-center justify-center rounded-full bg-gray-300 dark:bg-gray-600"},[e("svg",{class:"h-6 w-6 text-gray-600 dark:text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})])])],-1)),e("div",hs,[e("div",ys,[e("p",ws,r(a.displayName||a.username),1),e("div",bs,[e("span",{class:z(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",a.isActive?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"])},r(a.isActive?"Active":"Disabled"),3),e("span",{class:z(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",a.role==="admin"?"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200":"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200"])},r(a.role),3)])]),e("div",ks,[e("span",null,"@"+r(a.username),1),a.email?(n(),i("span",_s,r(a.email),1)):b("",!0),e("span",null,r(a.apiKeyCount||0)+" API keys",1),a.lastLoginAt?(n(),i("span",$s,"Last login: "+r(B(a.lastLoginAt)),1)):(n(),i("span",Cs,"Never logged in"))]),a.totalUsage?(n(),i("div",As,[e("span",null,r(V(a.totalUsage.requests||0))+" requests",1),e("span",null,"$"+r((a.totalUsage.totalCost||0).toFixed(4))+" total cost",1)])):b("",!0)])]),e("div",Ms,[e("button",{class:"inline-flex items-center rounded border border-transparent p-1 text-gray-400 hover:text-blue-600",title:"View Usage Stats",onClick:F=>L(a)},t[23]||(t[23]=[e("svg",{class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)]),8,Us),e("button",{class:"inline-flex items-center rounded border border-transparent p-1 text-gray-400 hover:text-red-600 disabled:cursor-not-allowed disabled:opacity-50",disabled:a.apiKeyCount===0,title:"Disable All API Keys",onClick:F=>S(a)},t[24]||(t[24]=[e("svg",{class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728L5.636 5.636m12.728 12.728L18 12M6 6l12 12","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)]),8,js),e("button",{class:z(["inline-flex items-center rounded border border-transparent p-1",a.isActive?"text-gray-400 hover:text-red-600":"text-gray-400 hover:text-green-600"]),title:a.isActive?"Disable User":"Enable User",onClick:F=>R(a)},[a.isActive?(n(),i("svg",Vs,t[25]||(t[25]=[e("path",{d:"M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728L5.636 5.636m12.728 12.728L18 12M6 6l12 12","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},null,-1)]))):(n(),i("svg",Bs,t[26]||(t[26]=[e("path",{d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"},null,-1)])))],10,zs),e("button",{class:"inline-flex items-center rounded border border-transparent p-1 text-gray-400 hover:text-purple-600",title:"Change Role",onClick:F=>D(a)},t[27]||(t[27]=[e("svg",{class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M12 6V4m0 2a2 2 0 100 4m0-4a2 2 0 110 4m-6 8a2 2 0 100-4m0 4a2 2 0 100 4m0-4v2m0-6V4m6 6v10m6-2a2 2 0 100-4m0 4a2 2 0 100 4m0-4v2m0-6V4","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)]),8,Ls)])])]))),128))])):(n(),i("div",Rs,[t[28]||(t[28]=e("svg",{class:"mx-auto h-12 w-12 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197m13.5-9a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)),t[29]||(t[29]=e("h3",{class:"mt-2 text-sm font-medium text-gray-900 dark:text-white"},"No users found",-1)),e("p",Ss,r(p.value?"No users match your search criteria.":"No users have been created yet."),1)]))]),N(Ze,{show:$.value,user:u.value,onClose:t[4]||(t[4]=a=>$.value=!1)},null,8,["show","user"]),N(te,{"confirm-class":c.value.confirmClass,"confirm-text":c.value.confirmText,message:c.value.message,show:m.value,title:c.value.title,onCancel:t[5]||(t[5]=a=>m.value=!1),onConfirm:T},null,8,["confirm-class","confirm-text","message","show","title"]),N(Bt,{show:l.value,user:u.value,onClose:t[6]||(t[6]=a=>l.value=!1),onUpdated:I},null,8,["show","user"])])}}},Hs=q(Ds,[["__scopeId","data-v-9cc35dda"]]);export{Hs as default};