mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
2 lines
32 KiB
JavaScript
2 lines
32 KiB
JavaScript
import{r as x,o as O,x as i,L as b,y as n,z as e,P as a,K as j,aV as P,u as h,Q as E,ac as Q,C as B,Y as W,an as K,O as N,c as Y,q as J,R as I,aq as X}from"./vue-vendor-DV7DYXbz.js";import{f as A,c as G,g as Z,d as ee,s as M,e as te,h as se,i as oe,j as le,k as ae}from"./index-BahP9Xx9.js";import{C as re}from"./ConfirmModal-C2rCOkXI.js";import{d as ie}from"./vendor-Dr8jvgFu.js";import"./element-plus-BSjV1f9S.js";const ne={key:0,class:"fixed inset-0 z-50 h-full w-full overflow-y-auto bg-gray-600 bg-opacity-50"},de={class:"relative top-10 mx-auto w-4/5 max-w-4xl rounded-md border bg-white p-5 shadow-lg"},ue={class:"mt-3"},ce={class:"mb-6 flex items-center justify-between"},me={class:"text-lg font-medium text-gray-900"},ve={class:"text-sm text-gray-500"},xe={class:"mb-6"},ge={key:0,class:"py-12 text-center"},pe={key:1,class:"space-y-6"},fe={class:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4"},he={class:"overflow-hidden rounded-lg bg-blue-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-blue-900"},_e={class:"overflow-hidden rounded-lg bg-green-50 shadow"},$e={class:"p-5"},Ce={class:"flex items-center"},Ae={class:"ml-5 w-0 flex-1"},Ue={class:"text-lg font-medium text-green-900"},Me={class:"overflow-hidden rounded-lg bg-purple-50 shadow"},je={class:"p-5"},ze={class:"flex items-center"},Be={class:"ml-5 w-0 flex-1"},Ve={class:"text-lg font-medium text-purple-900"},Le={class:"overflow-hidden rounded-lg bg-yellow-50 shadow"},Re={class:"p-5"},Se={class:"flex items-center"},Te={class:"ml-5 w-0 flex-1"},Fe={class:"text-lg font-medium text-yellow-900"},De={key:0,class:"rounded-lg border border-gray-200 bg-white"},Ie={class:"overflow-hidden"},Pe={class:"min-w-full divide-y divide-gray-200"},Ne={class:"divide-y divide-gray-200 bg-white"},He={class:"whitespace-nowrap px-6 py-4"},qe={class:"text-sm font-medium text-gray-900"},Ke={class:"text-sm text-gray-500"},Oe={class:"whitespace-nowrap px-6 py-4"},Ee={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"},Ge={class:"whitespace-nowrap px-6 py-4 text-sm text-gray-900"},We={class:"whitespace-nowrap px-6 py-4 text-sm text-gray-500"},Ye={class:"rounded-lg border border-gray-200 bg-white"},Je={class:"p-6"},Xe={class:"flex h-64 items-center justify-center rounded-lg border-2 border-dashed border-gray-300"},Ze={class:"text-center"},et={class:"mt-1 text-sm text-gray-500"},tt={key:1,class:"py-12 text-center"},st={class:"mt-6 flex justify-end"},ot={__name:"UserUsageStatsModal",props:{show:{type:Boolean,default:!1},user:{type:Object,default:null}},emits:["close"],setup(m,{emit:k}){const g=m,_=k,v=x(!1),c=x("week"),d=x(null),$=x(null),p=async()=>{if(g.user){v.value=!0;try{const[l,s]=await Promise.all([Z(g.user.id,{period:c.value}),ee(g.user.id)]);l.success&&(d.value=l.stats),s.success&&($.value=s.user)}catch(l){console.error("Failed to load user usage stats:",l),M("Failed to load usage statistics","error")}finally{v.value=!1}}};return O([()=>g.show,()=>g.user],([l,s])=>{l&&s&&p()}),(l,s)=>{var y,U,C,z,V,L,R,S,T,F;return m.show?(n(),i("div",ne,[e("div",de,[e("div",ue,[e("div",ce,[e("div",null,[e("h3",me," Usage Statistics - "+a(((y=m.user)==null?void 0:y.displayName)||((U=m.user)==null?void 0:U.username)),1),e("p",ve,"@"+a((C=m.user)==null?void 0:C.username)+" • "+a((z=m.user)==null?void 0:z.role),1)]),e("button",{class:"text-gray-400 hover:text-gray-600",onClick:s[0]||(s[0]=o=>_("close"))},s[3]||(s[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",xe,[j(e("select",{"onUpdate:modelValue":s[1]||(s[1]=o=>c.value=o),class:"block w-32 rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 sm:text-sm",onChange:p},s[4]||(s[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,c.value]])]),v.value?(n(),i("div",ge,s[5]||(s[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",pe,[e("div",fe,[e("div",he,[e("div",ye,[e("div",we,[s[7]||(s[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",be,[e("dl",null,[s[6]||(s[6]=e("dt",{class:"truncate text-sm font-medium text-blue-600"},"Requests",-1)),e("dd",ke,a(h(A)(((V=d.value)==null?void 0:V.totalRequests)||0)),1)])])])])]),e("div",_e,[e("div",$e,[e("div",Ce,[s[9]||(s[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",Ae,[e("dl",null,[s[8]||(s[8]=e("dt",{class:"truncate text-sm font-medium text-green-600"},"Input Tokens",-1)),e("dd",Ue,a(h(A)(((L=d.value)==null?void 0:L.totalInputTokens)||0)),1)])])])])]),e("div",Me,[e("div",je,[e("div",ze,[s[11]||(s[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",Be,[e("dl",null,[s[10]||(s[10]=e("dt",{class:"truncate text-sm font-medium text-purple-600"},"Output Tokens",-1)),e("dd",Ve,a(h(A)(((R=d.value)==null?void 0:R.totalOutputTokens)||0)),1)])])])])]),e("div",Le,[e("div",Re,[e("div",Se,[s[13]||(s[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",Te,[e("dl",null,[s[12]||(s[12]=e("dt",{class:"truncate text-sm font-medium text-yellow-600"},"Total Cost",-1)),e("dd",Fe," $"+a((((S=d.value)==null?void 0:S.totalCost)||0).toFixed(4)),1)])])])])])]),((F=(T=$.value)==null?void 0:T.apiKeys)==null?void 0:F.length)>0?(n(),i("div",De,[s[15]||(s[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",Ie,[e("table",Pe,[s[14]||(s[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",Ne,[(n(!0),i(E,null,Q($.value.apiKeys,o=>{var t,u,f,w;return n(),i("tr",{key:o.id},[e("td",He,[e("div",qe,a(o.name),1),e("div",Ke,a(o.keyPreview),1)]),e("td",Oe,[e("span",{class:B(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",o.isActive?"bg-green-100 text-green-800":"bg-red-100 text-red-800"])},a(o.isActive?"Active":"Disabled"),3)]),e("td",Ee,a(h(A)(((t=o.usage)==null?void 0:t.requests)||0)),1),e("td",Qe,[e("div",null,"In: "+a(h(A)(((u=o.usage)==null?void 0:u.inputTokens)||0)),1),e("div",null,"Out: "+a(h(A)(((f=o.usage)==null?void 0:f.outputTokens)||0)),1)]),e("td",Ge," $"+a((((w=o.usage)==null?void 0:w.totalCost)||0).toFixed(4)),1),e("td",We,a(o.lastUsedAt?h(G)(o.lastUsedAt):"Never"),1)])}),128))])])])])):b("",!0),e("div",Ye,[s[19]||(s[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",Je,[e("div",Xe,[e("div",Ze,[s[16]||(s[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)),s[17]||(s[17]=e("h3",{class:"mt-2 text-sm font-medium text-gray-900"},"Usage Chart",-1)),e("p",et," Daily usage trends for "+a(c.value)+" period ",1),s[18]||(s[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",tt,s[20]||(s[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",st,[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:s[2]||(s[2]=o=>l.$emit("close"))}," Close ")])])])])):b("",!0)}}},lt={key:0,class:"fixed inset-0 z-50 h-full w-full overflow-y-auto bg-gray-600 bg-opacity-50"},at={class:"relative top-20 mx-auto w-96 rounded-md border bg-white p-5 shadow-lg"},rt={class:"mt-3"},it={class:"mb-4 flex items-center justify-between"},nt={key:0,class:"space-y-4"},dt={class:"rounded-md bg-gray-50 p-4"},ut={class:"flex items-center"},ct={class:"ml-4"},mt={class:"text-sm font-medium text-gray-900"},vt={class:"text-sm text-gray-500"},xt={class:"mt-1"},gt={class:"space-y-2"},pt={class:"flex items-center"},ft=["disabled"],ht={class:"flex items-center"},yt=["disabled"],wt={key:0,class:"rounded-md border border-yellow-200 bg-yellow-50 p-4"},bt={class:"flex"},kt={class:"ml-3"},_t={class:"mt-2 text-sm text-yellow-700"},$t={key:0},Ct={key:1},At={key:1,class:"rounded-md border border-red-200 bg-red-50 p-4"},Ut={class:"flex"},Mt={class:"ml-3"},jt={class:"text-sm text-red-700"},zt={class:"flex justify-end space-x-3 pt-4"},Bt=["disabled"],Vt=["disabled"],Lt={key:0,class:"flex items-center"},Rt={key:1},St={__name:"ChangeRoleModal",props:{show:{type:Boolean,default:!1},user:{type:Object,default:null}},emits:["close","updated"],setup(m,{emit:k}){const g=m,_=k,v=x(!1),c=x(""),d=x(""),$=async()=>{var p,l;if(!(!g.user||d.value===g.user.role)){v.value=!0,c.value="";try{const s=await te(g.user.id,{role:d.value});s.success?(M(`User role updated to ${d.value}`,"success"),_("updated")):c.value=s.message||"Failed to update user role"}catch(s){console.error("Update user role error:",s),c.value=((l=(p=s.response)==null?void 0:p.data)==null?void 0:l.message)||s.message||"Failed to update user role"}finally{v.value=!1}}};return O([()=>g.show,()=>g.user],([p,l])=>{p&&l&&(d.value=l.role,c.value="",v.value=!1)}),(p,l)=>m.show?(n(),i("div",lt,[e("div",at,[e("div",rt,[e("div",it,[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]=s=>p.$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)]))]),m.user?(n(),i("div",nt,[e("div",dt,[e("div",ut,[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",ct,[e("p",mt,a(m.user.displayName||m.user.username),1),e("p",vt,"@"+a(m.user.username),1),e("div",xt,[e("span",{class:B(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",m.user.role==="admin"?"bg-purple-100 text-purple-800":"bg-blue-100 text-blue-800"])}," Current: "+a(m.user.role),3)])])])]),e("form",{class:"space-y-4",onSubmit:W($,["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",gt,[e("label",pt,[j(e("input",{"onUpdate:modelValue":l[1]||(l[1]=s=>d.value=s),class:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500",disabled:v.value,type:"radio",value:"user"},null,8,ft),[[K,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",ht,[j(e("input",{"onUpdate:modelValue":l[2]||(l[2]=s=>d.value=s),class:"h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500",disabled:v.value,type:"radio",value:"admin"},null,8,yt),[[K,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!==m.user.role?(n(),i("div",wt,[e("div",bt,[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",kt,[l[10]||(l[10]=e("h3",{class:"text-sm font-medium text-yellow-800"},"Role Change Warning",-1)),e("div",_t,[d.value==="admin"?(n(),i("p",$t," 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",Ct," Removing admin privileges will restrict this user to only managing their own API keys and viewing their own usage statistics. "))])])])])):b("",!0),c.value?(n(),i("div",At,[e("div",Ut,[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",Mt,[e("p",jt,a(c.value),1)])])])):b("",!0),e("div",zt,[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:v.value,type:"button",onClick:l[3]||(l[3]=s=>p.$emit("close"))}," Cancel ",8,Bt),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:v.value||d.value===m.user.role,type:"submit"},[v.value?(n(),i("span",Lt,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),N(" Updating... ",-1)]))):(n(),i("span",Rt,"Update Role"))],8,Vt)])],32)])):b("",!0)])])])):b("",!0)}},Tt={class:"space-y-6"},Ft={class:"sm:flex sm:items-center"},Dt={class:"mt-4 sm:ml-16 sm:mt-0 sm:flex-none"},It=["disabled"],Pt={class:"grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-4"},Nt={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},Ht={class:"p-5"},qt={class:"flex items-center"},Kt={class:"ml-5 w-0 flex-1"},Ot={class:"text-lg font-medium text-gray-900 dark:text-white"},Et={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},Qt={class:"p-5"},Gt={class:"flex items-center"},Wt={class:"ml-5 w-0 flex-1"},Yt={class:"text-lg font-medium text-gray-900 dark:text-white"},Jt={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},Xt={class:"p-5"},Zt={class:"flex items-center"},es={class:"ml-5 w-0 flex-1"},ts={class:"text-lg font-medium text-gray-900 dark:text-white"},ss={class:"overflow-hidden rounded-lg bg-white shadow dark:bg-gray-800"},os={class:"p-5"},ls={class:"flex items-center"},as={class:"ml-5 w-0 flex-1"},rs={class:"text-lg font-medium text-gray-900 dark:text-white"},is={class:"rounded-lg bg-white shadow dark:bg-gray-800"},ns={class:"px-4 py-5 sm:p-6"},ds={class:"sm:flex sm:items-center sm:justify-between"},us={class:"space-y-4 sm:flex sm:items-center sm:space-x-4 sm:space-y-0"},cs={class:"min-w-0 flex-1"},ms={class:"relative rounded-md shadow-sm"},vs={class:"overflow-hidden bg-white shadow dark:bg-gray-800 sm:rounded-md"},xs={class:"border-b border-gray-200 px-4 py-5 dark:border-gray-700 sm:px-6"},gs={class:"text-lg font-medium leading-6 text-gray-900 dark:text-white"},ps={key:0,class:"text-sm text-gray-500 dark:text-gray-400"},fs={key:0,class:"py-12 text-center"},hs={key:1,class:"divide-y divide-gray-200 dark:divide-gray-700",role:"list"},ys={class:"flex items-center justify-between"},ws={class:"flex min-w-0 flex-1 items-center"},bs={class:"ml-4 min-w-0 flex-1"},ks={class:"flex items-center"},_s={class:"truncate text-sm font-medium text-gray-900 dark:text-white"},$s={class:"ml-2 flex items-center space-x-2"},Cs={class:"mt-1 flex items-center space-x-4 text-sm text-gray-500 dark:text-gray-400"},As={key:0},Us={key:1},Ms={key:2},js={key:0,class:"mt-1 flex items-center space-x-4 text-xs text-gray-400 dark:text-gray-500"},zs={class:"flex items-center space-x-2"},Bs=["onClick"],Vs=["disabled","onClick"],Ls=["title","onClick"],Rs={key:0,class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Ss={key:1,class:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Ts=["onClick"],Fs={key:2,class:"py-12 text-center"},Ds={class:"mt-1 text-sm text-gray-500 dark:text-gray-400"},Ks={__name:"UserManagementView",setup(m){const k=x(!0),g=x([]),_=x(null),v=x(""),c=x(""),d=x(""),$=x(!1),p=x(!1),l=x(!1),s=x(null),y=x({title:"",message:"",confirmText:"",confirmClass:"",action:null}),U=Y(()=>{let o=g.value;if(v.value){const t=v.value.toLowerCase();o=o.filter(u=>{var f,w;return u.username.toLowerCase().includes(t)||((f=u.displayName)==null?void 0:f.toLowerCase().includes(t))||((w=u.email)==null?void 0:w.toLowerCase().includes(t))})}if(c.value&&(o=o.filter(t=>t.role===c.value)),d.value!==""){const t=d.value==="true";o=o.filter(u=>u.isActive===t)}return o}),C=async()=>{k.value=!0;try{const o={};c.value&&c.value.trim()!==""&&(o.role=c.value),d.value!==""&&(o.isActive=d.value);const[t,u]=await Promise.all([se(o),oe()]);t.success&&(g.value=t.users),u.success&&(_.value=u.stats)}catch(o){console.error("Failed to load users:",o),M("Failed to load users","error")}finally{k.value=!1}},z=ie(()=>{},300),V=o=>{s.value=o,$.value=!0},L=o=>{s.value=o,y.value={title:o.isActive?"Disable User":"Enable User",message:o.isActive?`Are you sure you want to disable user "${o.username}"? This will prevent them from logging in.`:`Are you sure you want to enable user "${o.username}"?`,confirmText:o.isActive?"Disable":"Enable",confirmClass:o.isActive?"bg-red-600 hover:bg-red-700":"bg-green-600 hover:bg-green-700",action:"toggleStatus"},p.value=!0},R=o=>{o.apiKeyCount!==0&&(s.value=o,y.value={title:"Disable All API Keys",message:`Are you sure you want to disable all ${o.apiKeyCount} API keys for user "${o.username}"? This will prevent them from using the service.`,confirmText:"Disable Keys",confirmClass:"bg-red-600 hover:bg-red-700",action:"disableKeys"},p.value=!0)},S=o=>{s.value=o,l.value=!0},T=async()=>{const o=s.value,t=y.value.action;try{if(t==="toggleStatus"){if((await le(o.id,{isActive:!o.isActive})).success){const f=g.value.findIndex(w=>w.id===o.id);f!==-1&&(g.value[f].isActive=!o.isActive),M(`User ${o.isActive?"disabled":"enabled"} successfully`,"success")}}else if(t==="disableKeys"){const u=await ae(o.id);u.success&&(M(`Disabled ${u.disabledCount} API keys`,"success"),await C())}}catch(u){console.error(`Failed to ${t}:`,u),M(`Failed to ${t}`,"error")}finally{p.value=!1,s.value=null}},F=()=>{l.value=!1,s.value=null,C()};return J(()=>{C()}),(o,t)=>{var u,f,w,H,q;return n(),i("div",Tt,[e("div",Ft,[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",Dt,[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),N(" Refresh ",-1)]),8,It)])]),e("div",Pt,[e("div",Nt,[e("div",Ht,[e("div",qt,[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",Kt,[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",Ot,a(((u=_.value)==null?void 0:u.totalUsers)||0),1)])])])])]),e("div",Et,[e("div",Qt,[e("div",Gt,[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",Wt,[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",Yt,a(((f=_.value)==null?void 0:f.activeUsers)||0),1)])])])])]),e("div",Jt,[e("div",Xt,[e("div",Zt,[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",es,[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",ts,a(((w=_.value)==null?void 0:w.totalApiKeys)||0),1)])])])])]),e("div",ss,[e("div",os,[e("div",ls,[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",as,[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",rs," $"+a((((q=(H=_.value)==null?void 0:H.totalUsage)==null?void 0:q.totalCost)||0).toFixed(4)),1)])])])])])]),e("div",is,[e("div",ns,[e("div",ds,[e("div",us,[e("div",cs,[e("div",ms,[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)),j(e("input",{"onUpdate:modelValue":t[0]||(t[0]=r=>v.value=r),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]=(...r)=>h(z)&&h(z)(...r))},null,544),[[X,v.value]])])]),e("div",null,[j(e("select",{"onUpdate:modelValue":t[2]||(t[2]=r=>c.value=r),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,c.value]])]),e("div",null,[j(e("select",{"onUpdate:modelValue":t[3]||(t[3]=r=>d.value=r),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",vs,[e("div",xs,[e("h3",gs,[t[20]||(t[20]=N(" Users ",-1)),k.value?b("",!0):(n(),i("span",ps,"("+a(U.value.length)+" of "+a(g.value.length)+")",1))])]),k.value?(n(),i("div",fs,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)]))):U.value.length>0?(n(),i("ul",hs,[(n(!0),i(E,null,Q(U.value,r=>(n(),i("li",{key:r.id,class:"px-6 py-4"},[e("div",ys,[e("div",ws,[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",bs,[e("div",ks,[e("p",_s,a(r.displayName||r.username),1),e("div",$s,[e("span",{class:B(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",r.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"])},a(r.isActive?"Active":"Disabled"),3),e("span",{class:B(["inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium",r.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"])},a(r.role),3)])]),e("div",Cs,[e("span",null,"@"+a(r.username),1),r.email?(n(),i("span",As,a(r.email),1)):b("",!0),e("span",null,a(r.apiKeyCount||0)+" API keys",1),r.lastLoginAt?(n(),i("span",Us,"Last login: "+a(h(G)(r.lastLoginAt)),1)):(n(),i("span",Ms,"Never logged in"))]),r.totalUsage?(n(),i("div",js,[e("span",null,a(h(A)(r.totalUsage.requests||0))+" requests",1),e("span",null,"$"+a((r.totalUsage.totalCost||0).toFixed(4))+" total cost",1)])):b("",!0)])]),e("div",zs,[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:D=>V(r)},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,Bs),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:r.apiKeyCount===0,title:"Disable All API Keys",onClick:D=>R(r)},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,Vs),e("button",{class:B(["inline-flex items-center rounded border border-transparent p-1",r.isActive?"text-gray-400 hover:text-red-600":"text-gray-400 hover:text-green-600"]),title:r.isActive?"Disable User":"Enable User",onClick:D=>L(r)},[r.isActive?(n(),i("svg",Rs,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",Ss,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,Ls),e("button",{class:"inline-flex items-center rounded border border-transparent p-1 text-gray-400 hover:text-purple-600",title:"Change Role",onClick:D=>S(r)},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,Ts)])])]))),128))])):(n(),i("div",Fs,[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",Ds,a(v.value?"No users match your search criteria.":"No users have been created yet."),1)]))]),I(ot,{show:$.value,user:s.value,onClose:t[4]||(t[4]=r=>$.value=!1)},null,8,["show","user"]),I(re,{"confirm-class":y.value.confirmClass,"confirm-text":y.value.confirmText,message:y.value.message,show:p.value,title:y.value.title,onCancel:t[5]||(t[5]=r=>p.value=!1),onConfirm:T},null,8,["confirm-class","confirm-text","message","show","title"]),I(St,{show:l.value,user:s.value,onClose:t[6]||(t[6]=r=>l.value=!1),onUpdated:F},null,8,["show","user"])])}}};export{Ks as default};
|