import{E as ft}from"./element-plus-BaMaLFJp.js";import{aR as et,r as M,c as W,q as Ie,V as gt,o as ke,x as d,y as a,z as e,I as oe,C as U,P as c,R as ne,J as yt,L as b,B as he,K as V,aq as X,Q as Y,ac as Z,T as bt,a5 as fe,D as vt,_ as De,Y as ce,an as ue,O as k,aa as Ke,aX as Se,al as ge}from"./vue-vendor-DfnFpxGJ.js";import{s as G}from"./toast-BvwA7Mwb.js";import{a as B,_ as me}from"./index-Bj8Dr0GB.js";import{_ as Te}from"./WindowCountdown-RaAYa1A3.js";import{C as Ze}from"./CustomDropdown-CV6ud8Ww.js";import"./vendor-BDiMbLwQ.js";const Re=et("clients",{state:()=>({supportedClients:[],loading:!1,error:null}),actions:{async loadSupportedClients(){if(this.supportedClients.length>0)return this.supportedClients;this.loading=!0,this.error=null;try{const v=await B.get("/admin/supported-clients");return v.success?this.supportedClients=v.data||[]:(this.error=v.message||"加载支持的客户端失败",console.error("Failed to load supported clients:",this.error)),this.supportedClients}catch(v){return this.error=v.message||"加载支持的客户端失败",console.error("Error loading supported clients:",v),[]}finally{this.loading=!1}}}}),tt=et("apiKeys",()=>{const v=M([]),H=M(!1),u=M(null),P=M("all"),E=M(""),h=M("asc"),C=async()=>{H.value=!0,u.value=null;try{const K=await B.get("/admin/api-keys");if(K.success)v.value=K.data||[];else throw new Error(K.message||"获取API Keys失败")}catch(K){throw u.value=K.message,K}finally{H.value=!1}};return{apiKeys:v,loading:H,error:u,statsTimeRange:P,sortBy:E,sortOrder:h,fetchApiKeys:C,createApiKey:async K=>{H.value=!0,u.value=null;try{const A=await B.post("/admin/api-keys",K);if(A.success)return await C(),A.data;throw new Error(A.message||"创建API Key失败")}catch(A){throw u.value=A.message,A}finally{H.value=!1}},updateApiKey:async(K,A)=>{H.value=!0,u.value=null;try{const f=await B.put(`/admin/api-keys/${K}`,A);if(f.success)return await C(),f;throw new Error(f.message||"更新API Key失败")}catch(f){throw u.value=f.message,f}finally{H.value=!1}},toggleApiKey:async K=>{H.value=!0,u.value=null;try{const A=await B.put(`/admin/api-keys/${K}/toggle`);if(A.success)return await C(),A;throw new Error(A.message||"切换状态失败")}catch(A){throw u.value=A.message,A}finally{H.value=!1}},renewApiKey:async(K,A)=>{H.value=!0,u.value=null;try{const f=await B.put(`/admin/api-keys/${K}`,A);if(f.success)return await C(),f;throw new Error(f.message||"续期失败")}catch(f){throw u.value=f.message,f}finally{H.value=!1}},deleteApiKey:async K=>{H.value=!0,u.value=null;try{const A=await B.delete(`/admin/api-keys/${K}`);if(A.success)return await C(),A;throw new Error(A.message||"删除失败")}catch(A){throw u.value=A.message,A}finally{H.value=!1}},fetchApiKeyStats:async(K,A="all")=>{try{const f=await B.get(`/admin/api-keys/${K}/stats`,{params:{timeRange:A}});if(f.success)return f.stats;throw new Error(f.message||"获取统计失败")}catch(f){return console.error("获取API Key统计失败:",f),null}},fetchTags:async()=>{try{const K=await B.get("/admin/api-keys/tags");if(K.success)return K.data||[];throw new Error(K.message||"获取标签失败")}catch(K){return console.error("获取标签失败:",K),[]}},sortApiKeys:K=>{E.value===K?h.value=h.value==="asc"?"desc":"asc":(E.value=K,h.value="asc")},reset:()=>{v.value=[],H.value=!1,u.value=null,P.value="all",E.value="",h.value="asc"}}}),wt={class:"flex-shrink-0 border-b border-gray-200 p-3"},ht={class:"relative"},$t={class:"custom-scrollbar flex-1 overflow-y-auto"},At={class:"text-gray-700"},Ct={key:0},kt=["onClick"],Kt={class:"flex items-center justify-between"},It={class:"text-gray-700"},Dt={class:"text-xs text-gray-500"},_t={key:1},Lt={class:"bg-gray-50 px-4 py-2 text-xs font-semibold text-gray-500"},Mt=["onClick"],Tt={class:"flex items-center justify-between"},St={class:"text-gray-700"},Rt={class:"text-xs text-gray-400"},jt={key:2},Et=["onClick"],Pt={class:"flex items-center justify-between"},Vt={class:"text-gray-700"},Ut={class:"text-xs text-gray-400"},qt={key:3,class:"px-4 py-8 text-center text-gray-500"},Gt={__name:"AccountSelector",props:{modelValue:{type:String,default:""},platform:{type:String,required:!0,validator:v=>["claude","gemini"].includes(v)},accounts:{type:Array,default:()=>[]},groups:{type:Array,default:()=>[]},disabled:{type:Boolean,default:!1},placeholder:{type:String,default:"请选择账号"},defaultOptionText:{type:String,default:"使用共享账号池"}},emits:["update:modelValue"],setup(v,{emit:H}){const u=v,P=H,E=M(!1),h=M(""),C=M(null),F=M(null),I=M({}),O=M(null),j=M(""),y=W(()=>{if(!u.modelValue)return u.defaultOptionText;if(u.modelValue.startsWith("group:")){const $=u.modelValue.substring(6),L=u.groups.find(w=>w.id===$);return L?`${L.name} (${L.memberCount||0} 个成员)`:""}if(u.modelValue.startsWith("console:")){const $=u.modelValue.substring(8),L=u.accounts.find(w=>w.id===$&&w.platform==="claude-console");return L?`${L.name} (${T(L)})`:""}const m=u.accounts.find($=>$.id===u.modelValue);return m?`${m.name} (${T(m)})`:""}),T=m=>{if(!m)return"未知";if(m.isActive===!1)switch(m.status){case"unauthorized":return"未授权";case"error":return"Token错误";case"created":return"待验证";case"rate_limited":return"限流中";default:return"异常"}return"正常"},i=W(()=>[...u.accounts].sort((m,$)=>{const L=new Date(m.createdAt||0);return new Date($.createdAt||0)-L})),l=W(()=>{if(!h.value)return u.groups;const m=h.value.toLowerCase();return u.groups.filter($=>$.name.toLowerCase().includes(m))}),Q=W(()=>{let m=i.value.filter($=>$.accountType==="dedicated"&&(u.platform==="claude"?$.platform==="claude-oauth":$.platform!=="claude-console"));if(h.value){const $=h.value.toLowerCase();m=m.filter(L=>L.name.toLowerCase().includes($))}return m}),K=W(()=>{if(u.platform!=="claude")return[];let m=i.value.filter($=>$.accountType==="dedicated"&&$.platform==="claude-console");if(h.value){const $=h.value.toLowerCase();m=m.filter(L=>L.name.toLowerCase().includes($))}return m}),A=W(()=>l.value.length>0||Q.value.length>0||K.value.length>0),f=m=>{if(!m)return"";const $=new Date(m),w=(new Date-$)/(1e3*60*60);return w<24?"今天创建":w<48?"昨天创建":w<168?`${Math.floor(w/24)} 天前`:$.toLocaleDateString("zh-CN",{month:"2-digit",day:"2-digit"})},N=()=>{if(!E.value||!F.value||!O.value)return;const m=O.value;if(!m)return;const $=m.getBoundingClientRect(),L=window.innerHeight,w=window.innerWidth,o=L-$.bottom,x=$.top,q=8,ee=o-q,se=x-q;let le=!1,de=ee;j.value==="above"&&se>=150?(le=!0,de=se):j.value==="below"&&ee>=150?(le=!1,de=ee):se>ee&&ee<200&&(le=!0,de=se),j.value=le?"above":"below";let J=$.left;const ae=$.width;J+ae>w-q&&(J=w-ae-q),J{if(!E.value&&O.value){const m=O.value.getBoundingClientRect(),L=window.innerHeight-m.bottom,w=8;I.value={position:"fixed",left:`${m.left}px`,width:`${m.width}px`,maxHeight:`${Math.min(L-w,400)}px`,top:`${m.bottom}px`}}E.value=!E.value,E.value&&vt(()=>{var m;N(),(m=C.value)==null||m.focus()})},D=m=>{P("update:modelValue",m||""),E.value=!1,h.value=""},p=()=>{},ie=()=>{var m;h.value="",(m=C.value)==null||m.focus()},R=m=>{var $,L;!(($=O.value)!=null&&$.contains(m.target))&&!((L=F.value)!=null&&L.contains(m.target))&&(E.value=!1)},r=()=>{E.value&&N()};return Ie(()=>{document.addEventListener("click",R),window.addEventListener("scroll",r,!0),window.addEventListener("resize",N)}),gt(()=>{document.removeEventListener("click",R),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",N)}),ke(E,m=>{m||(h.value="",j.value="")}),(m,$)=>(a(),d("div",{ref_key:"triggerRef",ref:O,class:"relative"},[e("div",{class:U(["form-input flex w-full cursor-pointer items-center justify-between",{"opacity-50":v.disabled}]),onClick:$[0]||($[0]=L=>!v.disabled&&te())},[e("span",{class:U(v.modelValue?"text-gray-900":"text-gray-500")},c(y.value),3),e("i",{class:U(["fas fa-chevron-down text-gray-400 transition-transform duration-200",{"rotate-180":E.value}])},null,2)],2),(a(),oe(fe,{to:"body"},[ne(bt,{"enter-active-class":"transition ease-out duration-100","enter-from-class":"transform opacity-0 scale-95","enter-to-class":"transform opacity-100 scale-100","leave-active-class":"transition ease-in duration-75","leave-from-class":"transform opacity-100 scale-100","leave-to-class":"transform opacity-0 scale-95"},{default:yt(()=>[E.value?(a(),d("div",{key:0,ref_key:"dropdownRef",ref:F,class:"absolute z-50 flex flex-col rounded-lg border border-gray-200 bg-white shadow-lg",style:he(I.value)},[e("div",wt,[e("div",ht,[V(e("input",{ref_key:"searchInput",ref:C,"onUpdate:modelValue":$[1]||($[1]=L=>h.value=L),class:"form-input w-full text-sm",placeholder:"搜索账号名称...",style:{"padding-left":"40px","padding-right":"36px"},type:"text",onInput:p},null,544),[[X,h.value]]),$[4]||($[4]=e("i",{class:"fas fa-search pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-sm text-gray-400"},null,-1)),h.value?(a(),d("button",{key:0,class:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600",type:"button",onClick:ie},$[3]||($[3]=[e("i",{class:"fas fa-times text-sm"},null,-1)]))):b("",!0)])]),e("div",$t,[e("div",{class:U(["cursor-pointer px-4 py-2 transition-colors hover:bg-gray-50",{"bg-blue-50":!v.modelValue}]),onClick:$[2]||($[2]=L=>D(null))},[e("span",At,c(v.defaultOptionText),1)],2),l.value.length>0?(a(),d("div",Ct,[$[5]||($[5]=e("div",{class:"bg-gray-50 px-4 py-2 text-xs font-semibold text-gray-500"},"调度分组",-1)),(a(!0),d(Y,null,Z(l.value,L=>(a(),d("div",{key:`group:${L.id}`,class:U(["cursor-pointer px-4 py-2 transition-colors hover:bg-gray-50",{"bg-blue-50":v.modelValue===`group:${L.id}`}]),onClick:w=>D(`group:${L.id}`)},[e("div",Kt,[e("span",It,c(L.name),1),e("span",Dt,c(L.memberCount||0)+" 个成员",1)])],10,kt))),128))])):b("",!0),Q.value.length>0?(a(),d("div",_t,[e("div",Lt,c(v.platform==="claude"?"Claude OAuth 专属账号":"OAuth 专属账号"),1),(a(!0),d(Y,null,Z(Q.value,L=>(a(),d("div",{key:L.id,class:U(["cursor-pointer px-4 py-2 transition-colors hover:bg-gray-50",{"bg-blue-50":v.modelValue===L.id}]),onClick:w=>D(L.id)},[e("div",Tt,[e("div",null,[e("span",St,c(L.name),1),e("span",{class:U(["ml-2 rounded-full px-2 py-0.5 text-xs",L.isActive?"bg-green-100 text-green-700":L.status==="unauthorized"?"bg-orange-100 text-orange-700":"bg-red-100 text-red-700"])},c(T(L)),3)]),e("span",Rt,c(f(L.createdAt)),1)])],10,Mt))),128))])):b("",!0),v.platform==="claude"&&K.value.length>0?(a(),d("div",jt,[$[6]||($[6]=e("div",{class:"bg-gray-50 px-4 py-2 text-xs font-semibold text-gray-500"}," Claude Console 专属账号 ",-1)),(a(!0),d(Y,null,Z(K.value,L=>(a(),d("div",{key:L.id,class:U(["cursor-pointer px-4 py-2 transition-colors hover:bg-gray-50",{"bg-blue-50":v.modelValue===`console:${L.id}`}]),onClick:w=>D(`console:${L.id}`)},[e("div",Pt,[e("div",null,[e("span",Vt,c(L.name),1),e("span",{class:U(["ml-2 rounded-full px-2 py-0.5 text-xs",L.isActive?"bg-green-100 text-green-700":L.status==="unauthorized"?"bg-orange-100 text-orange-700":"bg-red-100 text-red-700"])},c(T(L)),3)]),e("span",Ut,c(f(L.createdAt)),1)])],10,Et))),128))])):b("",!0),h.value&&!A.value?(a(),d("div",qt,$[7]||($[7]=[e("i",{class:"fas fa-search mb-2 text-2xl"},null,-1),e("p",{class:"text-sm"},"没有找到匹配的账号",-1)]))):b("",!0)])],4)):b("",!0)]),_:1})]))],512))}},be=me(Gt,[["__scopeId","data-v-b315d95a"]]),Ot={class:"modal fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"},Wt={class:"modal-content mx-auto flex max-h-[90vh] w-full max-w-4xl flex-col p-4 sm:p-6"},Ft={class:"mb-4 flex items-center justify-between"},zt={class:"rounded-lg border border-blue-200 bg-gradient-to-r from-blue-50 to-indigo-50 p-3 sm:p-4"},Bt={class:"flex items-center gap-3 sm:gap-4"},Ht={class:"flex cursor-pointer items-center"},Nt={class:"flex cursor-pointer items-center"},Yt={key:0,class:"mt-3"},Qt={class:"flex items-center gap-4"},Jt={class:"flex-1"},Xt={class:"flex items-center gap-2"},Zt={class:"mt-2 flex items-start text-xs text-amber-600"},es=["placeholder"],ts={key:0,class:"mt-1 text-xs text-red-500"},ss={class:"space-y-4"},ls={key:0},os={class:"flex flex-wrap gap-2"},ns=["onClick"],is={key:1},as={class:"flex flex-wrap gap-2"},rs=["onClick"],ds={class:"flex gap-2"},us=["onKeypress"],cs={class:"rounded-lg border border-blue-200 bg-blue-50 p-3"},ms={class:"space-y-2"},ps={class:"grid grid-cols-1 gap-2 lg:grid-cols-3"},xs={class:"space-y-2"},fs={class:"flex gap-2"},gs={key:0,class:"mt-3"},ys=["min"],bs={key:1,class:"mt-2 text-xs text-gray-500"},vs={class:"flex gap-4"},ws={class:"flex cursor-pointer items-center"},hs={class:"flex cursor-pointer items-center"},$s={class:"flex cursor-pointer items-center"},As={class:"flex cursor-pointer items-center"},Cs={class:"mb-2 flex items-center justify-between"},ks=["disabled"],Ks={class:"grid grid-cols-1 gap-3"},Is={class:"mb-2 flex items-center"},Ds={key:0,class:"space-y-3"},_s={class:"mb-3 flex min-h-[32px] flex-wrap gap-2 rounded-lg border border-gray-200 bg-gray-50 p-2"},Ls=["onClick"],Ms={key:0,class:"text-sm text-gray-400"},Ts={class:"space-y-3"},Ss={class:"flex flex-wrap gap-2"},Rs=["onClick"],js={key:0,class:"text-sm italic text-gray-400"},Es={class:"flex gap-2"},Ps=["onKeydown"],Vs={class:"mb-2 flex items-center"},Us={key:0,class:"rounded-lg border border-green-200 bg-green-50 p-3"},qs={class:"space-y-1"},Gs=["id","value"],Os=["for"],Ws={class:"text-sm font-medium text-gray-700"},Fs={class:"block text-xs text-gray-500"},zs={class:"flex gap-3 pt-2"},Bs=["disabled"],Hs={key:0,class:"loading-spinner mr-2"},Ns={key:1,class:"fas fa-plus mr-2"},Ys={__name:"CreateApiKeyModal",props:{accounts:{type:Object,default:()=>({claude:[],gemini:[]})}},emits:["close","success","batch-success"],setup(v,{emit:H}){const u=v,P=H,E=Re(),h=tt(),C=M(!1),F=M(!1),I=M({claude:[],gemini:[],openai:[],claudeGroups:[],geminiGroups:[],openaiGroups:[]}),O=M({name:""}),j=M(""),y=M([]),T=W(()=>y.value.filter(w=>!l.tags.includes(w))),i=M([]),l=De({createType:"single",batchCount:10,name:"",description:"",tokenLimit:"",rateLimitWindow:"",rateLimitRequests:"",concurrencyLimit:"",dailyCostLimit:"",expireDuration:"",customExpireDate:"",expiresAt:null,permissions:"all",claudeAccountId:"",geminiAccountId:"",openaiAccountId:"",enableModelRestriction:!1,restrictedModels:[],modelInput:"",enableClientRestriction:!1,allowedClients:[],tags:[]});Ie(async()=>{i.value=await E.loadSupportedClients(),y.value=await h.fetchTags(),u.accounts&&(I.value={claude:u.accounts.claude||[],gemini:u.accounts.gemini||[],openai:u.accounts.openai||[],claudeGroups:u.accounts.claudeGroups||[],geminiGroups:u.accounts.geminiGroups||[],openaiGroups:u.accounts.openaiGroups||[]})});const Q=async()=>{var w,o;F.value=!0;try{const[x,q,ee,se,le]=await Promise.all([B.get("/admin/claude-accounts"),B.get("/admin/claude-console-accounts"),B.get("/admin/gemini-accounts"),B.get("/admin/openai-accounts"),B.get("/admin/account-groups")]),de=[];if(x.success&&((w=x.data)==null||w.forEach(J=>{de.push({...J,platform:"claude-oauth",isDedicated:J.accountType==="dedicated"})})),q.success&&((o=q.data)==null||o.forEach(J=>{de.push({...J,platform:"claude-console",isDedicated:J.accountType==="dedicated"})})),I.value.claude=de,ee.success&&(I.value.gemini=(ee.data||[]).map(J=>({...J,isDedicated:J.accountType==="dedicated"}))),se.success&&(I.value.openai=(se.data||[]).map(J=>({...J,isDedicated:J.accountType==="dedicated"}))),le.success){const J=le.data||[];I.value.claudeGroups=J.filter(ae=>ae.platform==="claude"),I.value.geminiGroups=J.filter(ae=>ae.platform==="gemini"),I.value.openaiGroups=J.filter(ae=>ae.platform==="openai")}G("账号列表已刷新","success")}catch{G("刷新账号列表失败","error")}finally{F.value=!1}},K=W(()=>{const w=new Date;return w.setMinutes(w.getMinutes()+1),w.toISOString().slice(0,16)}),A=()=>{if(!l.expireDuration){l.expiresAt=null;return}if(l.expireDuration==="custom")return;const w=new Date,x=l.expireDuration.match(/(\d+)([dhmy])/);if(x){const[,q,ee]=x,se=parseInt(q);switch(ee){case"d":w.setDate(w.getDate()+se);break;case"h":w.setHours(w.getHours()+se);break;case"m":w.setMonth(w.getMonth()+se);break;case"y":w.setFullYear(w.getFullYear()+se);break}l.expiresAt=w.toISOString()}},f=()=>{l.customExpireDate&&(l.expiresAt=new Date(l.customExpireDate).toISOString())},N=w=>new Date(w).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),te=()=>{l.modelInput&&!l.restrictedModels.includes(l.modelInput)&&(l.restrictedModels.push(l.modelInput),l.modelInput="")},D=w=>{l.restrictedModels.splice(w,1)},p=M(["claude-opus-4-20250514","claude-opus-4-1-20250805"]),ie=W(()=>p.value.filter(w=>!l.restrictedModels.includes(w))),R=w=>{l.restrictedModels.includes(w)||l.restrictedModels.push(w)},r=()=>{if(j.value&&j.value.trim()){const w=j.value.trim();l.tags.includes(w)||l.tags.push(w),j.value=""}},m=w=>{l.tags.includes(w)||l.tags.push(w)},$=w=>{l.tags.splice(w,1)},L=async()=>{if(O.value.name="",!l.name||!l.name.trim()){O.value.name="请输入API Key名称";return}if(l.createType==="batch"&&(!l.batchCount||l.batchCount<2||l.batchCount>500)){G("批量创建数量必须在 2-500 之间","error");return}C.value=!0;try{const w={description:l.description||void 0,tokenLimit:l.tokenLimit!==""&&l.tokenLimit!==null?parseInt(l.tokenLimit):null,rateLimitWindow:l.rateLimitWindow!==""&&l.rateLimitWindow!==null?parseInt(l.rateLimitWindow):null,rateLimitRequests:l.rateLimitRequests!==""&&l.rateLimitRequests!==null?parseInt(l.rateLimitRequests):null,concurrencyLimit:l.concurrencyLimit!==""&&l.concurrencyLimit!==null?parseInt(l.concurrencyLimit):0,dailyCostLimit:l.dailyCostLimit!==""&&l.dailyCostLimit!==null?parseFloat(l.dailyCostLimit):0,expiresAt:l.expiresAt||void 0,permissions:l.permissions,tags:l.tags.length>0?l.tags:void 0,enableModelRestriction:l.enableModelRestriction,restrictedModels:l.restrictedModels,enableClientRestriction:l.enableClientRestriction,allowedClients:l.allowedClients};if(l.claudeAccountId&&(l.claudeAccountId.startsWith("console:")?(w.claudeConsoleAccountId=l.claudeAccountId.substring(8),delete w.claudeAccountId):(w.claudeAccountId=l.claudeAccountId,delete w.claudeConsoleAccountId)),l.geminiAccountId&&(w.geminiAccountId=l.geminiAccountId),l.openaiAccountId&&(w.openaiAccountId=l.openaiAccountId),l.createType==="single"){const o={...w,name:l.name},x=await B.post("/admin/api-keys",o);x.success?(G("API Key 创建成功","success"),P("success",x.data),P("close")):G(x.message||"创建失败","error")}else{const o={...w,createType:"batch",baseName:l.name,count:l.batchCount},x=await B.post("/admin/api-keys/batch",o);x.success?(G(`成功创建 ${x.data.length} 个 API Key`,"success"),P("batch-success",x.data),P("close")):G(x.message||"批量创建失败","error")}}catch{G("创建失败","error")}finally{C.value=!1}};return(w,o)=>(a(),oe(fe,{to:"body"},[e("div",Ot,[e("div",Wt,[e("div",Ft,[o[32]||(o[32]=e("div",{class:"flex items-center gap-2 sm:gap-3"},[e("div",{class:"flex h-8 w-8 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 sm:h-10 sm:w-10 sm:rounded-xl"},[e("i",{class:"fas fa-key text-sm text-white sm:text-base"})]),e("h3",{class:"text-lg font-bold text-gray-900 sm:text-xl"},"创建新的 API Key")],-1)),e("button",{class:"p-1 text-gray-400 transition-colors hover:text-gray-600",onClick:o[0]||(o[0]=x=>w.$emit("close"))},o[31]||(o[31]=[e("i",{class:"fas fa-times text-lg sm:text-xl"},null,-1)]))]),e("form",{class:"modal-scroll-content custom-scrollbar flex-1 space-y-4",onSubmit:ce(L,["prevent"])},[e("div",zt,[e("div",{class:U(["flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",l.createType==="batch"?"mb-3":""])},[o[35]||(o[35]=e("label",{class:"flex h-full items-center text-xs font-semibold text-gray-700 sm:text-sm"},"创建类型",-1)),e("div",Bt,[e("label",Ht,[V(e("input",{"onUpdate:modelValue":o[1]||(o[1]=x=>l.createType=x),class:"mr-1.5 text-blue-600 sm:mr-2",type:"radio",value:"single"},null,512),[[ue,l.createType]]),o[33]||(o[33]=e("span",{class:"flex items-center text-xs text-gray-700 sm:text-sm"},[e("i",{class:"fas fa-key mr-1 text-xs"}),k(" 单个创建 ")],-1))]),e("label",Nt,[V(e("input",{"onUpdate:modelValue":o[2]||(o[2]=x=>l.createType=x),class:"mr-1.5 text-blue-600 sm:mr-2",type:"radio",value:"batch"},null,512),[[ue,l.createType]]),o[34]||(o[34]=e("span",{class:"flex items-center text-xs text-gray-700 sm:text-sm"},[e("i",{class:"fas fa-layer-group mr-1 text-xs"}),k(" 批量创建 ")],-1))])])],2),l.createType==="batch"?(a(),d("div",Yt,[e("div",Qt,[e("div",Jt,[o[37]||(o[37]=e("label",{class:"mb-1 block text-xs font-medium text-gray-600"},"创建数量",-1)),e("div",Xt,[V(e("input",{"onUpdate:modelValue":o[3]||(o[3]=x=>l.batchCount=x),class:"form-input w-full text-sm",max:"500",min:"2",placeholder:"输入数量 (2-500)",required:"",type:"number"},null,512),[[X,l.batchCount,void 0,{number:!0}]]),o[36]||(o[36]=e("div",{class:"whitespace-nowrap text-xs text-gray-500"},"最大支持 500 个",-1))])])]),e("p",Zt,[o[38]||(o[38]=e("i",{class:"fas fa-info-circle mr-1 mt-0.5 flex-shrink-0"},null,-1)),e("span",null,"批量创建时,每个 Key 的名称会自动添加序号后缀,例如:"+c(l.name||"MyKey")+"_1, "+c(l.name||"MyKey")+"_2 ...",1)])])):b("",!0)]),e("div",null,[o[39]||(o[39]=e("label",{class:"mb-1.5 block text-xs font-semibold text-gray-700 sm:mb-2 sm:text-sm"},[k("名称 "),e("span",{class:"text-red-500"},"*")],-1)),V(e("input",{"onUpdate:modelValue":o[4]||(o[4]=x=>l.name=x),class:U(["form-input w-full text-sm",{"border-red-500":O.value.name}]),placeholder:l.createType==="batch"?"输入基础名称(将自动添加序号)":"为您的 API Key 取一个名称",required:"",type:"text",onInput:o[5]||(o[5]=x=>O.value.name="")},null,42,es),[[X,l.name]]),O.value.name?(a(),d("p",ts,c(O.value.name),1)):b("",!0)]),e("div",null,[o[47]||(o[47]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"标签",-1)),e("div",ss,[l.tags.length>0?(a(),d("div",ls,[o[41]||(o[41]=e("div",{class:"mb-2 text-xs font-medium text-gray-600"},"已选择的标签:",-1)),e("div",os,[(a(!0),d(Y,null,Z(l.tags,(x,q)=>(a(),d("span",{key:"selected-"+q,class:"inline-flex items-center gap-1 rounded-full bg-blue-100 px-3 py-1 text-sm text-blue-800"},[k(c(x)+" ",1),e("button",{class:"ml-1 hover:text-blue-900",type:"button",onClick:ee=>$(q)},o[40]||(o[40]=[e("i",{class:"fas fa-times text-xs"},null,-1)]),8,ns)]))),128))])])):b("",!0),T.value.length>0?(a(),d("div",is,[o[43]||(o[43]=e("div",{class:"mb-2 text-xs font-medium text-gray-600"},"点击选择已有标签:",-1)),e("div",as,[(a(!0),d(Y,null,Z(T.value,x=>(a(),d("button",{key:"available-"+x,class:"inline-flex items-center gap-1 rounded-full bg-gray-100 px-3 py-1 text-sm text-gray-700 transition-colors hover:bg-blue-100 hover:text-blue-700",type:"button",onClick:q=>m(x)},[o[42]||(o[42]=e("i",{class:"fas fa-tag text-xs text-gray-500"},null,-1)),k(" "+c(x),1)],8,rs))),128))])])):b("",!0),e("div",null,[o[45]||(o[45]=e("div",{class:"mb-2 text-xs font-medium text-gray-600"},"创建新标签:",-1)),e("div",ds,[V(e("input",{"onUpdate:modelValue":o[6]||(o[6]=x=>j.value=x),class:"form-input flex-1",placeholder:"输入新标签名称",type:"text",onKeypress:Ke(ce(r,["prevent"]),["enter"])},null,40,us),[[X,j.value]]),e("button",{class:"rounded-lg bg-green-500 px-4 py-2 text-white transition-colors hover:bg-green-600",type:"button",onClick:r},o[44]||(o[44]=[e("i",{class:"fas fa-plus"},null,-1)]))])]),o[46]||(o[46]=e("p",{class:"text-xs text-gray-500"},"用于标记不同团队或用途,方便筛选管理",-1))])]),e("div",cs,[o[55]||(o[55]=e("div",{class:"mb-2 flex items-center gap-2"},[e("div",{class:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded bg-blue-500"},[e("i",{class:"fas fa-tachometer-alt text-xs text-white"})]),e("h4",{class:"text-sm font-semibold text-gray-800"},"速率限制设置 (可选)")],-1)),e("div",ms,[e("div",ps,[e("div",null,[o[48]||(o[48]=e("label",{class:"mb-1 block text-xs font-medium text-gray-700"},"时间窗口 (分钟)",-1)),V(e("input",{"onUpdate:modelValue":o[7]||(o[7]=x=>l.rateLimitWindow=x),class:"form-input w-full text-sm",min:"1",placeholder:"无限制",type:"number"},null,512),[[X,l.rateLimitWindow]]),o[49]||(o[49]=e("p",{class:"ml-2 mt-0.5 text-xs text-gray-500"},"时间段单位",-1))]),e("div",null,[o[50]||(o[50]=e("label",{class:"mb-1 block text-xs font-medium text-gray-700"},"请求次数限制",-1)),V(e("input",{"onUpdate:modelValue":o[8]||(o[8]=x=>l.rateLimitRequests=x),class:"form-input w-full text-sm",min:"1",placeholder:"无限制",type:"number"},null,512),[[X,l.rateLimitRequests]]),o[51]||(o[51]=e("p",{class:"ml-2 mt-0.5 text-xs text-gray-500"},"窗口内最大请求",-1))]),e("div",null,[o[52]||(o[52]=e("label",{class:"mb-1 block text-xs font-medium text-gray-700"},"Token 限制",-1)),V(e("input",{"onUpdate:modelValue":o[9]||(o[9]=x=>l.tokenLimit=x),class:"form-input w-full text-sm",placeholder:"无限制",type:"number"},null,512),[[X,l.tokenLimit]]),o[53]||(o[53]=e("p",{class:"ml-2 mt-0.5 text-xs text-gray-500"},"窗口内最大Token",-1))])]),o[54]||(o[54]=e("div",{class:"rounded-lg bg-blue-100 p-2"},[e("h5",{class:"mb-1 text-xs font-semibold text-blue-800"},"💡 使用示例"),e("div",{class:"space-y-0.5 text-xs text-blue-700"},[e("div",null,[e("strong",null,"示例1:"),k(" 时间窗口=60,请求次数=1000 → 每60分钟最多1000次请求 ")]),e("div",null,[e("strong",null,"示例2:"),k(" 时间窗口=1,Token=10000 → 每分钟最多10,000个Token ")]),e("div",null,[e("strong",null,"示例3:"),k(" 窗口=30,请求=50,Token=100000 → 每30分钟50次请求且不超10万Token ")])])],-1))])]),e("div",null,[o[57]||(o[57]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"每日费用限制 (美元)",-1)),e("div",xs,[e("div",fs,[e("button",{class:"rounded bg-gray-100 px-2 py-1 text-xs font-medium hover:bg-gray-200",type:"button",onClick:o[10]||(o[10]=x=>l.dailyCostLimit="50")}," $50 "),e("button",{class:"rounded bg-gray-100 px-2 py-1 text-xs font-medium hover:bg-gray-200",type:"button",onClick:o[11]||(o[11]=x=>l.dailyCostLimit="100")}," $100 "),e("button",{class:"rounded bg-gray-100 px-2 py-1 text-xs font-medium hover:bg-gray-200",type:"button",onClick:o[12]||(o[12]=x=>l.dailyCostLimit="200")}," $200 "),e("button",{class:"rounded bg-gray-100 px-2 py-1 text-xs font-medium hover:bg-gray-200",type:"button",onClick:o[13]||(o[13]=x=>l.dailyCostLimit="")}," 自定义 ")]),V(e("input",{"onUpdate:modelValue":o[14]||(o[14]=x=>l.dailyCostLimit=x),class:"form-input w-full",min:"0",placeholder:"0 表示无限制",step:"0.01",type:"number"},null,512),[[X,l.dailyCostLimit]]),o[56]||(o[56]=e("p",{class:"text-xs text-gray-500"}," 设置此 API Key 每日的费用限制,超过限制将拒绝请求,0 或留空表示无限制 ",-1))])]),e("div",null,[o[58]||(o[58]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"并发限制 (可选)",-1)),V(e("input",{"onUpdate:modelValue":o[15]||(o[15]=x=>l.concurrencyLimit=x),class:"form-input w-full",min:"0",placeholder:"0 表示无限制",type:"number"},null,512),[[X,l.concurrencyLimit]]),o[59]||(o[59]=e("p",{class:"mt-2 text-xs text-gray-500"}," 设置此 API Key 可同时处理的最大请求数,0 或留空表示无限制 ",-1))]),e("div",null,[o[60]||(o[60]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"备注 (可选)",-1)),V(e("textarea",{"onUpdate:modelValue":o[16]||(o[16]=x=>l.description=x),class:"form-input w-full resize-none text-sm",placeholder:"描述此 API Key 的用途...",rows:"2"},null,512),[[X,l.description]])]),e("div",null,[o[62]||(o[62]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"有效期限",-1)),V(e("select",{"onUpdate:modelValue":o[17]||(o[17]=x=>l.expireDuration=x),class:"form-input w-full",onChange:A},o[61]||(o[61]=[e("option",{value:""},"永不过期",-1),e("option",{value:"1d"},"1 天",-1),e("option",{value:"7d"},"7 天",-1),e("option",{value:"30d"},"30 天",-1),e("option",{value:"90d"},"90 天",-1),e("option",{value:"180d"},"180 天",-1),e("option",{value:"365d"},"365 天",-1),e("option",{value:"custom"},"自定义日期",-1)]),544),[[Se,l.expireDuration]]),l.expireDuration==="custom"?(a(),d("div",gs,[V(e("input",{"onUpdate:modelValue":o[18]||(o[18]=x=>l.customExpireDate=x),class:"form-input w-full",min:K.value,type:"datetime-local",onChange:f},null,40,ys),[[X,l.customExpireDate]])])):b("",!0),l.expiresAt?(a(),d("p",bs," 将于 "+c(N(l.expiresAt))+" 过期 ",1)):b("",!0)]),e("div",null,[o[67]||(o[67]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"服务权限",-1)),e("div",vs,[e("label",ws,[V(e("input",{"onUpdate:modelValue":o[19]||(o[19]=x=>l.permissions=x),class:"mr-2",type:"radio",value:"all"},null,512),[[ue,l.permissions]]),o[63]||(o[63]=e("span",{class:"text-sm text-gray-700"},"全部服务",-1))]),e("label",hs,[V(e("input",{"onUpdate:modelValue":o[20]||(o[20]=x=>l.permissions=x),class:"mr-2",type:"radio",value:"claude"},null,512),[[ue,l.permissions]]),o[64]||(o[64]=e("span",{class:"text-sm text-gray-700"},"仅 Claude",-1))]),e("label",$s,[V(e("input",{"onUpdate:modelValue":o[21]||(o[21]=x=>l.permissions=x),class:"mr-2",type:"radio",value:"gemini"},null,512),[[ue,l.permissions]]),o[65]||(o[65]=e("span",{class:"text-sm text-gray-700"},"仅 Gemini",-1))]),e("label",As,[V(e("input",{"onUpdate:modelValue":o[22]||(o[22]=x=>l.permissions=x),class:"mr-2",type:"radio",value:"openai"},null,512),[[ue,l.permissions]]),o[66]||(o[66]=e("span",{class:"text-sm text-gray-700"},"仅 OpenAI",-1))])]),o[68]||(o[68]=e("p",{class:"mt-2 text-xs text-gray-500"},"控制此 API Key 可以访问哪些服务",-1))]),e("div",null,[e("div",Cs,[o[69]||(o[69]=e("label",{class:"text-sm font-semibold text-gray-700"},"专属账号绑定 (可选)",-1)),e("button",{class:"flex items-center gap-1 text-sm text-blue-600 transition-colors hover:text-blue-800 disabled:cursor-not-allowed disabled:opacity-50",disabled:F.value,title:"刷新账号列表",type:"button",onClick:Q},[e("i",{class:U(["fas",F.value?"fa-spinner fa-spin":"fa-sync-alt","text-xs"])},null,2),e("span",null,c(F.value?"刷新中...":"刷新账号"),1)],8,ks)]),e("div",Ks,[e("div",null,[o[70]||(o[70]=e("label",{class:"mb-1 block text-sm font-medium text-gray-600"},"Claude 专属账号",-1)),ne(be,{modelValue:l.claudeAccountId,"onUpdate:modelValue":o[23]||(o[23]=x=>l.claudeAccountId=x),accounts:I.value.claude,"default-option-text":"使用共享账号池",disabled:l.permissions==="gemini"||l.permissions==="openai",groups:I.value.claudeGroups,placeholder:"请选择Claude账号",platform:"claude"},null,8,["modelValue","accounts","disabled","groups"])]),e("div",null,[o[71]||(o[71]=e("label",{class:"mb-1 block text-sm font-medium text-gray-600"},"Gemini 专属账号",-1)),ne(be,{modelValue:l.geminiAccountId,"onUpdate:modelValue":o[24]||(o[24]=x=>l.geminiAccountId=x),accounts:I.value.gemini,"default-option-text":"使用共享账号池",disabled:l.permissions==="claude"||l.permissions==="openai",groups:I.value.geminiGroups,placeholder:"请选择Gemini账号",platform:"gemini"},null,8,["modelValue","accounts","disabled","groups"])]),e("div",null,[o[72]||(o[72]=e("label",{class:"mb-1 block text-sm font-medium text-gray-600"},"OpenAI 专属账号",-1)),ne(be,{modelValue:l.openaiAccountId,"onUpdate:modelValue":o[25]||(o[25]=x=>l.openaiAccountId=x),accounts:I.value.openai,"default-option-text":"使用共享账号池",disabled:l.permissions==="claude"||l.permissions==="gemini",groups:I.value.openaiGroups,placeholder:"请选择OpenAI账号",platform:"openai"},null,8,["modelValue","accounts","disabled","groups"])])]),o[73]||(o[73]=e("p",{class:"mt-2 text-xs text-gray-500"}," 选择专属账号后,此API Key将只使用该账号,不选择则使用共享账号池 ",-1))]),e("div",null,[e("div",Is,[V(e("input",{id:"enableModelRestriction","onUpdate:modelValue":o[26]||(o[26]=x=>l.enableModelRestriction=x),class:"h-4 w-4 rounded border-gray-300 bg-gray-100 text-blue-600 focus:ring-blue-500",type:"checkbox"},null,512),[[ge,l.enableModelRestriction]]),o[74]||(o[74]=e("label",{class:"ml-2 cursor-pointer text-sm font-semibold text-gray-700",for:"enableModelRestriction"}," 启用模型限制 ",-1))]),l.enableModelRestriction?(a(),d("div",Ds,[e("div",null,[o[77]||(o[77]=e("label",{class:"mb-2 block text-sm font-medium text-gray-600"},"限制的模型列表",-1)),e("div",_s,[(a(!0),d(Y,null,Z(l.restrictedModels,(x,q)=>(a(),d("span",{key:q,class:"inline-flex items-center rounded-full bg-red-100 px-3 py-1 text-sm text-red-800"},[k(c(x)+" ",1),e("button",{class:"ml-2 text-red-600 hover:text-red-800",type:"button",onClick:ee=>D(q)},o[75]||(o[75]=[e("i",{class:"fas fa-times text-xs"},null,-1)]),8,Ls)]))),128)),l.restrictedModels.length===0?(a(),d("span",Ms," 暂无限制的模型 ")):b("",!0)]),e("div",Ts,[e("div",Ss,[(a(!0),d(Y,null,Z(ie.value,x=>(a(),d("button",{key:x,class:"flex-shrink-0 rounded-lg bg-gray-100 px-3 py-1 text-xs text-gray-700 transition-colors hover:bg-gray-200 sm:text-sm",type:"button",onClick:q=>R(x)},c(x),9,Rs))),128)),ie.value.length===0?(a(),d("span",js," 所有常用模型已在限制列表中 ")):b("",!0)]),e("div",Es,[V(e("input",{"onUpdate:modelValue":o[27]||(o[27]=x=>l.modelInput=x),class:"form-input flex-1",placeholder:"输入模型名称,按回车添加",type:"text",onKeydown:Ke(ce(te,["prevent"]),["enter"])},null,40,Ps),[[X,l.modelInput]]),e("button",{class:"rounded-lg bg-red-500 px-4 py-2 text-white transition-colors hover:bg-red-600",type:"button",onClick:te},o[76]||(o[76]=[e("i",{class:"fas fa-plus"},null,-1)]))])]),o[78]||(o[78]=e("p",{class:"mt-2 text-xs text-gray-500"}," 设置此API Key无法访问的模型,例如:claude-opus-4-20250514 ",-1))])])):b("",!0)]),e("div",null,[e("div",Vs,[V(e("input",{id:"enableClientRestriction","onUpdate:modelValue":o[28]||(o[28]=x=>l.enableClientRestriction=x),class:"h-4 w-4 rounded border-gray-300 bg-gray-100 text-blue-600 focus:ring-blue-500",type:"checkbox"},null,512),[[ge,l.enableClientRestriction]]),o[79]||(o[79]=e("label",{class:"ml-2 cursor-pointer text-sm font-semibold text-gray-700",for:"enableClientRestriction"}," 启用客户端限制 ",-1))]),l.enableClientRestriction?(a(),d("div",Us,[e("div",null,[o[80]||(o[80]=e("label",{class:"mb-2 block text-xs font-medium text-gray-700"},"允许的客户端",-1)),e("div",qs,[(a(!0),d(Y,null,Z(i.value,x=>(a(),d("div",{key:x.id,class:"flex items-start"},[V(e("input",{id:`client_${x.id}`,"onUpdate:modelValue":o[29]||(o[29]=q=>l.allowedClients=q),class:"mt-0.5 h-4 w-4 rounded border-gray-300 bg-gray-100 text-blue-600 focus:ring-blue-500",type:"checkbox",value:x.id},null,8,Gs),[[ge,l.allowedClients]]),e("label",{class:"ml-2 flex-1 cursor-pointer",for:`client_${x.id}`},[e("span",Ws,c(x.name),1),e("span",Fs,c(x.description),1)],8,Os)]))),128))])])])):b("",!0)]),e("div",zs,[e("button",{class:"flex-1 rounded-lg bg-gray-100 px-4 py-2.5 text-sm font-semibold text-gray-700 transition-colors hover:bg-gray-200",type:"button",onClick:o[30]||(o[30]=x=>w.$emit("close"))}," 取消 "),e("button",{class:"btn btn-primary flex-1 px-4 py-2.5 text-sm font-semibold",disabled:C.value,type:"submit"},[C.value?(a(),d("div",Hs)):(a(),d("i",Ns)),k(" "+c(C.value?"创建中...":"创建"),1)],8,Bs)])],32)])])]))}},Qs=me(Ys,[["__scopeId","data-v-1627c224"]]),Js={class:"modal fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"},Xs={class:"modal-content mx-auto flex max-h-[90vh] w-full max-w-4xl flex-col p-4 sm:p-6 md:p-8"},Zs={class:"mb-4 flex items-center justify-between sm:mb-6"},el=["value"],tl={class:"space-y-4"},sl={key:0},ll={class:"flex flex-wrap gap-2"},ol=["onClick"],nl={key:1},il={class:"flex flex-wrap gap-2"},al=["onClick"],rl={class:"flex gap-2"},dl=["onKeypress"],ul={class:"rounded-lg border border-blue-200 bg-blue-50 p-3"},cl={class:"space-y-2"},ml={class:"grid grid-cols-1 gap-2 lg:grid-cols-3"},pl={class:"space-y-3"},xl={class:"flex gap-2"},fl={class:"mb-3 flex items-center"},gl={class:"flex gap-4"},yl={class:"flex cursor-pointer items-center"},bl={class:"flex cursor-pointer items-center"},vl={class:"flex cursor-pointer items-center"},wl={class:"flex cursor-pointer items-center"},hl={class:"mb-3 flex items-center justify-between"},$l=["disabled"],Al={class:"grid grid-cols-1 gap-3"},Cl={class:"mb-3 flex items-center"},kl={key:0,class:"space-y-3"},Kl={class:"mb-3 flex min-h-[32px] flex-wrap gap-2 rounded-lg border border-gray-200 bg-gray-50 p-2"},Il=["onClick"],Dl={key:0,class:"text-sm text-gray-400"},_l={class:"space-y-3"},Ll={class:"flex flex-wrap gap-2"},Ml=["onClick"],Tl={key:0,class:"text-sm italic text-gray-400"},Sl={class:"flex gap-2"},Rl=["onKeydown"],jl={class:"mb-3 flex items-center"},El={key:0,class:"space-y-3"},Pl={class:"space-y-2"},Vl=["id","value"],Ul=["for"],ql={class:"text-sm font-medium text-gray-700"},Gl={class:"block text-xs text-gray-500"},Ol={class:"flex gap-3 pt-4"},Wl=["disabled"],Fl={key:0,class:"loading-spinner mr-2"},zl={key:1,class:"fas fa-save mr-2"},Bl={__name:"EditApiKeyModal",props:{apiKey:{type:Object,required:!0},accounts:{type:Object,default:()=>({claude:[],gemini:[]})}},emits:["close","success"],setup(v,{emit:H}){const u=v,P=H,E=Re(),h=tt(),C=M(!1),F=M(!1),I=M({claude:[],gemini:[],openai:[],claudeGroups:[],geminiGroups:[],openaiGroups:[]}),O=M([]),j=M(""),y=M([]),T=W(()=>y.value.filter(R=>!i.tags.includes(R))),i=De({name:"",tokenLimit:"",rateLimitWindow:"",rateLimitRequests:"",concurrencyLimit:"",dailyCostLimit:"",permissions:"all",claudeAccountId:"",geminiAccountId:"",openaiAccountId:"",enableModelRestriction:!1,restrictedModels:[],modelInput:"",enableClientRestriction:!1,allowedClients:[],tags:[],isActive:!0}),l=()=>{i.modelInput&&!i.restrictedModels.includes(i.modelInput)&&(i.restrictedModels.push(i.modelInput),i.modelInput="")},Q=R=>{i.restrictedModels.splice(R,1)},K=M(["claude-opus-4-20250514","claude-opus-4-1-20250805"]),A=W(()=>K.value.filter(R=>!i.restrictedModels.includes(R))),f=R=>{i.restrictedModels.includes(R)||i.restrictedModels.push(R)},N=()=>{if(j.value&&j.value.trim()){const R=j.value.trim();i.tags.includes(R)||i.tags.push(R),j.value=""}},te=R=>{i.tags.includes(R)||i.tags.push(R)},D=R=>{i.tags.splice(R,1)},p=async()=>{C.value=!0;try{const R={tokenLimit:i.tokenLimit!==""&&i.tokenLimit!==null?parseInt(i.tokenLimit):0,rateLimitWindow:i.rateLimitWindow!==""&&i.rateLimitWindow!==null?parseInt(i.rateLimitWindow):0,rateLimitRequests:i.rateLimitRequests!==""&&i.rateLimitRequests!==null?parseInt(i.rateLimitRequests):0,concurrencyLimit:i.concurrencyLimit!==""&&i.concurrencyLimit!==null?parseInt(i.concurrencyLimit):0,dailyCostLimit:i.dailyCostLimit!==""&&i.dailyCostLimit!==null?parseFloat(i.dailyCostLimit):0,permissions:i.permissions,tags:i.tags};i.claudeAccountId?i.claudeAccountId.startsWith("console:")?(R.claudeConsoleAccountId=i.claudeAccountId.substring(8),R.claudeAccountId=null):(i.claudeAccountId.startsWith("group:"),R.claudeAccountId=i.claudeAccountId,R.claudeConsoleAccountId=null):(R.claudeAccountId=null,R.claudeConsoleAccountId=null),i.geminiAccountId?R.geminiAccountId=i.geminiAccountId:R.geminiAccountId=null,i.openaiAccountId?R.openaiAccountId=i.openaiAccountId:R.openaiAccountId=null,R.enableModelRestriction=i.enableModelRestriction,R.restrictedModels=i.restrictedModels,R.enableClientRestriction=i.enableClientRestriction,R.allowedClients=i.allowedClients,R.isActive=i.isActive;const r=await B.put(`/admin/api-keys/${u.apiKey.id}`,R);r.success?(P("success"),P("close")):G(r.message||"更新失败","error")}catch{G("更新失败","error")}finally{C.value=!1}},ie=async()=>{var R,r;F.value=!0;try{const[m,$,L,w,o]=await Promise.all([B.get("/admin/claude-accounts"),B.get("/admin/claude-console-accounts"),B.get("/admin/gemini-accounts"),B.get("/admin/openai-accounts"),B.get("/admin/account-groups")]),x=[];if(m.success&&((R=m.data)==null||R.forEach(q=>{x.push({...q,platform:"claude-oauth",isDedicated:q.accountType==="dedicated"})})),$.success&&((r=$.data)==null||r.forEach(q=>{x.push({...q,platform:"claude-console",isDedicated:q.accountType==="dedicated"})})),I.value.claude=x,L.success&&(I.value.gemini=(L.data||[]).map(q=>({...q,isDedicated:q.accountType==="dedicated"}))),w.success&&(I.value.openai=(w.data||[]).map(q=>({...q,isDedicated:q.accountType==="dedicated"}))),o.success){const q=o.data||[];I.value.claudeGroups=q.filter(ee=>ee.platform==="claude"),I.value.geminiGroups=q.filter(ee=>ee.platform==="gemini"),I.value.openaiGroups=q.filter(ee=>ee.platform==="openai")}G("账号列表已刷新","success")}catch{G("刷新账号列表失败","error")}finally{F.value=!1}};return Ie(async()=>{O.value=await E.loadSupportedClients(),y.value=await h.fetchTags(),u.accounts&&(I.value={claude:u.accounts.claude||[],gemini:u.accounts.gemini||[],openai:u.accounts.openai||[],claudeGroups:u.accounts.claudeGroups||[],geminiGroups:u.accounts.geminiGroups||[],openaiGroups:u.accounts.openaiGroups||[]}),i.name=u.apiKey.name,i.tokenLimit=u.apiKey.tokenLimit||"",i.rateLimitWindow=u.apiKey.rateLimitWindow||"",i.rateLimitRequests=u.apiKey.rateLimitRequests||"",i.concurrencyLimit=u.apiKey.concurrencyLimit||"",i.dailyCostLimit=u.apiKey.dailyCostLimit||"",i.permissions=u.apiKey.permissions||"all",u.apiKey.claudeConsoleAccountId?i.claudeAccountId=`console:${u.apiKey.claudeConsoleAccountId}`:i.claudeAccountId=u.apiKey.claudeAccountId||"",i.geminiAccountId=u.apiKey.geminiAccountId||"",i.openaiAccountId=u.apiKey.openaiAccountId||"",i.restrictedModels=u.apiKey.restrictedModels||[],i.allowedClients=u.apiKey.allowedClients||[],i.tags=u.apiKey.tags||[],i.enableModelRestriction=u.apiKey.enableModelRestriction||!1,i.enableClientRestriction=u.apiKey.enableClientRestriction||!1,i.isActive=u.apiKey.isActive!==void 0?u.apiKey.isActive:!0}),(R,r)=>(a(),oe(fe,{to:"body"},[e("div",Js,[e("div",Xs,[e("div",Zs,[r[25]||(r[25]=e("div",{class:"flex items-center gap-2 sm:gap-3"},[e("div",{class:"flex h-8 w-8 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 sm:h-10 sm:w-10 sm:rounded-xl"},[e("i",{class:"fas fa-edit text-sm text-white sm:text-base"})]),e("h3",{class:"text-lg font-bold text-gray-900 sm:text-xl"},"编辑 API Key")],-1)),e("button",{class:"p-1 text-gray-400 transition-colors hover:text-gray-600",onClick:r[0]||(r[0]=m=>R.$emit("close"))},r[24]||(r[24]=[e("i",{class:"fas fa-times text-lg sm:text-xl"},null,-1)]))]),e("form",{class:"modal-scroll-content custom-scrollbar flex-1 space-y-4 sm:space-y-6",onSubmit:ce(p,["prevent"])},[e("div",null,[r[26]||(r[26]=e("label",{class:"mb-1.5 block text-xs font-semibold text-gray-700 sm:mb-3 sm:text-sm"},"名称",-1)),e("input",{class:"form-input w-full cursor-not-allowed bg-gray-100 text-sm",disabled:"",type:"text",value:i.name},null,8,el),r[27]||(r[27]=e("p",{class:"mt-1 text-xs text-gray-500 sm:mt-2"},"名称不可修改",-1))]),e("div",null,[r[35]||(r[35]=e("label",{class:"mb-1.5 block text-xs font-semibold text-gray-700 sm:mb-3 sm:text-sm"},"标签",-1)),e("div",tl,[i.tags.length>0?(a(),d("div",sl,[r[29]||(r[29]=e("div",{class:"mb-2 text-xs font-medium text-gray-600"},"已选择的标签:",-1)),e("div",ll,[(a(!0),d(Y,null,Z(i.tags,(m,$)=>(a(),d("span",{key:"selected-"+$,class:"inline-flex items-center gap-1 rounded-full bg-blue-100 px-3 py-1 text-sm text-blue-800"},[k(c(m)+" ",1),e("button",{class:"ml-1 hover:text-blue-900",type:"button",onClick:L=>D($)},r[28]||(r[28]=[e("i",{class:"fas fa-times text-xs"},null,-1)]),8,ol)]))),128))])])):b("",!0),T.value.length>0?(a(),d("div",nl,[r[31]||(r[31]=e("div",{class:"mb-2 text-xs font-medium text-gray-600"},"点击选择已有标签:",-1)),e("div",il,[(a(!0),d(Y,null,Z(T.value,m=>(a(),d("button",{key:"available-"+m,class:"inline-flex items-center gap-1 rounded-full bg-gray-100 px-3 py-1 text-sm text-gray-700 transition-colors hover:bg-blue-100 hover:text-blue-700",type:"button",onClick:$=>te(m)},[r[30]||(r[30]=e("i",{class:"fas fa-tag text-xs text-gray-500"},null,-1)),k(" "+c(m),1)],8,al))),128))])])):b("",!0),e("div",null,[r[33]||(r[33]=e("div",{class:"mb-2 text-xs font-medium text-gray-600"},"创建新标签:",-1)),e("div",rl,[V(e("input",{"onUpdate:modelValue":r[1]||(r[1]=m=>j.value=m),class:"form-input flex-1",placeholder:"输入新标签名称",type:"text",onKeypress:Ke(ce(N,["prevent"]),["enter"])},null,40,dl),[[X,j.value]]),e("button",{class:"rounded-lg bg-green-500 px-4 py-2 text-white transition-colors hover:bg-green-600",type:"button",onClick:N},r[32]||(r[32]=[e("i",{class:"fas fa-plus"},null,-1)]))])]),r[34]||(r[34]=e("p",{class:"text-xs text-gray-500"},"用于标记不同团队或用途,方便筛选管理",-1))])]),e("div",ul,[r[43]||(r[43]=e("div",{class:"mb-2 flex items-center gap-2"},[e("div",{class:"flex h-6 w-6 flex-shrink-0 items-center justify-center rounded bg-blue-500"},[e("i",{class:"fas fa-tachometer-alt text-xs text-white"})]),e("h4",{class:"text-sm font-semibold text-gray-800"},"速率限制设置 (可选)")],-1)),e("div",cl,[e("div",ml,[e("div",null,[r[36]||(r[36]=e("label",{class:"mb-1 block text-xs font-medium text-gray-700"},"时间窗口 (分钟)",-1)),V(e("input",{"onUpdate:modelValue":r[2]||(r[2]=m=>i.rateLimitWindow=m),class:"form-input w-full text-sm",min:"1",placeholder:"无限制",type:"number"},null,512),[[X,i.rateLimitWindow]]),r[37]||(r[37]=e("p",{class:"ml-2 mt-0.5 text-xs text-gray-500"},"时间段单位",-1))]),e("div",null,[r[38]||(r[38]=e("label",{class:"mb-1 block text-xs font-medium text-gray-700"},"请求次数限制",-1)),V(e("input",{"onUpdate:modelValue":r[3]||(r[3]=m=>i.rateLimitRequests=m),class:"form-input w-full text-sm",min:"1",placeholder:"无限制",type:"number"},null,512),[[X,i.rateLimitRequests]]),r[39]||(r[39]=e("p",{class:"ml-2 mt-0.5 text-xs text-gray-500"},"窗口内最大请求",-1))]),e("div",null,[r[40]||(r[40]=e("label",{class:"mb-1 block text-xs font-medium text-gray-700"},"Token 限制",-1)),V(e("input",{"onUpdate:modelValue":r[4]||(r[4]=m=>i.tokenLimit=m),class:"form-input w-full text-sm",placeholder:"无限制",type:"number"},null,512),[[X,i.tokenLimit]]),r[41]||(r[41]=e("p",{class:"ml-2 mt-0.5 text-xs text-gray-500"},"窗口内最大Token",-1))])]),r[42]||(r[42]=e("div",{class:"rounded-lg bg-blue-100 p-2"},[e("h5",{class:"mb-1 text-xs font-semibold text-blue-800"},"💡 使用示例"),e("div",{class:"space-y-0.5 text-xs text-blue-700"},[e("div",null,[e("strong",null,"示例1:"),k(" 时间窗口=60,请求次数=1000 → 每60分钟最多1000次请求 ")]),e("div",null,[e("strong",null,"示例2:"),k(" 时间窗口=1,Token=10000 → 每分钟最多10,000个Token ")]),e("div",null,[e("strong",null,"示例3:"),k(" 窗口=30,请求=50,Token=100000 → 每30分钟50次请求且不超10万Token ")])])],-1))])]),e("div",null,[r[45]||(r[45]=e("label",{class:"mb-3 block text-sm font-semibold text-gray-700"},"每日费用限制 (美元)",-1)),e("div",pl,[e("div",xl,[e("button",{class:"rounded-lg bg-gray-100 px-3 py-1 text-sm font-medium hover:bg-gray-200",type:"button",onClick:r[5]||(r[5]=m=>i.dailyCostLimit="50")}," $50 "),e("button",{class:"rounded-lg bg-gray-100 px-3 py-1 text-sm font-medium hover:bg-gray-200",type:"button",onClick:r[6]||(r[6]=m=>i.dailyCostLimit="100")}," $100 "),e("button",{class:"rounded-lg bg-gray-100 px-3 py-1 text-sm font-medium hover:bg-gray-200",type:"button",onClick:r[7]||(r[7]=m=>i.dailyCostLimit="200")}," $200 "),e("button",{class:"rounded-lg bg-gray-100 px-3 py-1 text-sm font-medium hover:bg-gray-200",type:"button",onClick:r[8]||(r[8]=m=>i.dailyCostLimit="")}," 自定义 ")]),V(e("input",{"onUpdate:modelValue":r[9]||(r[9]=m=>i.dailyCostLimit=m),class:"form-input w-full",min:"0",placeholder:"0 表示无限制",step:"0.01",type:"number"},null,512),[[X,i.dailyCostLimit]]),r[44]||(r[44]=e("p",{class:"text-xs text-gray-500"}," 设置此 API Key 每日的费用限制,超过限制将拒绝请求,0 或留空表示无限制 ",-1))])]),e("div",null,[r[46]||(r[46]=e("label",{class:"mb-3 block text-sm font-semibold text-gray-700"},"并发限制",-1)),V(e("input",{"onUpdate:modelValue":r[10]||(r[10]=m=>i.concurrencyLimit=m),class:"form-input w-full",min:"0",placeholder:"0 表示无限制",type:"number"},null,512),[[X,i.concurrencyLimit]]),r[47]||(r[47]=e("p",{class:"mt-2 text-xs text-gray-500"},"设置此 API Key 可同时处理的最大请求数",-1))]),e("div",null,[e("div",fl,[V(e("input",{id:"editIsActive","onUpdate:modelValue":r[11]||(r[11]=m=>i.isActive=m),class:"h-4 w-4 rounded border-gray-300 bg-gray-100 text-blue-600 focus:ring-blue-500",type:"checkbox"},null,512),[[ge,i.isActive]]),r[48]||(r[48]=e("label",{class:"ml-2 cursor-pointer text-sm font-semibold text-gray-700",for:"editIsActive"}," 激活账号 ",-1))]),r[49]||(r[49]=e("p",{class:"mb-4 text-xs text-gray-500"}," 取消勾选将禁用此 API Key,暂停所有请求,客户端返回 401 错误 ",-1))]),e("div",null,[r[54]||(r[54]=e("label",{class:"mb-3 block text-sm font-semibold text-gray-700"},"服务权限",-1)),e("div",gl,[e("label",yl,[V(e("input",{"onUpdate:modelValue":r[12]||(r[12]=m=>i.permissions=m),class:"mr-2",type:"radio",value:"all"},null,512),[[ue,i.permissions]]),r[50]||(r[50]=e("span",{class:"text-sm text-gray-700"},"全部服务",-1))]),e("label",bl,[V(e("input",{"onUpdate:modelValue":r[13]||(r[13]=m=>i.permissions=m),class:"mr-2",type:"radio",value:"claude"},null,512),[[ue,i.permissions]]),r[51]||(r[51]=e("span",{class:"text-sm text-gray-700"},"仅 Claude",-1))]),e("label",vl,[V(e("input",{"onUpdate:modelValue":r[14]||(r[14]=m=>i.permissions=m),class:"mr-2",type:"radio",value:"gemini"},null,512),[[ue,i.permissions]]),r[52]||(r[52]=e("span",{class:"text-sm text-gray-700"},"仅 Gemini",-1))]),e("label",wl,[V(e("input",{"onUpdate:modelValue":r[15]||(r[15]=m=>i.permissions=m),class:"mr-2",type:"radio",value:"openai"},null,512),[[ue,i.permissions]]),r[53]||(r[53]=e("span",{class:"text-sm text-gray-700"},"仅 OpenAI",-1))])]),r[55]||(r[55]=e("p",{class:"mt-2 text-xs text-gray-500"},"控制此 API Key 可以访问哪些服务",-1))]),e("div",null,[e("div",hl,[r[56]||(r[56]=e("label",{class:"text-sm font-semibold text-gray-700"},"专属账号绑定",-1)),e("button",{class:"flex items-center gap-1 text-sm text-blue-600 transition-colors hover:text-blue-800 disabled:cursor-not-allowed disabled:opacity-50",disabled:F.value,title:"刷新账号列表",type:"button",onClick:ie},[e("i",{class:U(["fas",F.value?"fa-spinner fa-spin":"fa-sync-alt","text-xs"])},null,2),e("span",null,c(F.value?"刷新中...":"刷新账号"),1)],8,$l)]),e("div",Al,[e("div",null,[r[57]||(r[57]=e("label",{class:"mb-1 block text-sm font-medium text-gray-600"},"Claude 专属账号",-1)),ne(be,{modelValue:i.claudeAccountId,"onUpdate:modelValue":r[16]||(r[16]=m=>i.claudeAccountId=m),accounts:I.value.claude,"default-option-text":"使用共享账号池",disabled:i.permissions==="gemini"||i.permissions==="openai",groups:I.value.claudeGroups,placeholder:"请选择Claude账号",platform:"claude"},null,8,["modelValue","accounts","disabled","groups"])]),e("div",null,[r[58]||(r[58]=e("label",{class:"mb-1 block text-sm font-medium text-gray-600"},"Gemini 专属账号",-1)),ne(be,{modelValue:i.geminiAccountId,"onUpdate:modelValue":r[17]||(r[17]=m=>i.geminiAccountId=m),accounts:I.value.gemini,"default-option-text":"使用共享账号池",disabled:i.permissions==="claude"||i.permissions==="openai",groups:I.value.geminiGroups,placeholder:"请选择Gemini账号",platform:"gemini"},null,8,["modelValue","accounts","disabled","groups"])]),e("div",null,[r[59]||(r[59]=e("label",{class:"mb-1 block text-sm font-medium text-gray-600"},"OpenAI 专属账号",-1)),ne(be,{modelValue:i.openaiAccountId,"onUpdate:modelValue":r[18]||(r[18]=m=>i.openaiAccountId=m),accounts:I.value.openai,"default-option-text":"使用共享账号池",disabled:i.permissions==="claude"||i.permissions==="gemini",groups:I.value.openaiGroups,placeholder:"请选择OpenAI账号",platform:"openai"},null,8,["modelValue","accounts","disabled","groups"])])]),r[60]||(r[60]=e("p",{class:"mt-2 text-xs text-gray-500"},"修改绑定账号将影响此API Key的请求路由",-1))]),e("div",null,[e("div",Cl,[V(e("input",{id:"editEnableModelRestriction","onUpdate:modelValue":r[19]||(r[19]=m=>i.enableModelRestriction=m),class:"h-4 w-4 rounded border-gray-300 bg-gray-100 text-blue-600 focus:ring-blue-500",type:"checkbox"},null,512),[[ge,i.enableModelRestriction]]),r[61]||(r[61]=e("label",{class:"ml-2 cursor-pointer text-sm font-semibold text-gray-700",for:"editEnableModelRestriction"}," 启用模型限制 ",-1))]),i.enableModelRestriction?(a(),d("div",kl,[e("div",null,[r[64]||(r[64]=e("label",{class:"mb-2 block text-sm font-medium text-gray-600"},"限制的模型列表",-1)),e("div",Kl,[(a(!0),d(Y,null,Z(i.restrictedModels,(m,$)=>(a(),d("span",{key:$,class:"inline-flex items-center rounded-full bg-red-100 px-3 py-1 text-sm text-red-800"},[k(c(m)+" ",1),e("button",{class:"ml-2 text-red-600 hover:text-red-800",type:"button",onClick:L=>Q($)},r[62]||(r[62]=[e("i",{class:"fas fa-times text-xs"},null,-1)]),8,Il)]))),128)),i.restrictedModels.length===0?(a(),d("span",Dl," 暂无限制的模型 ")):b("",!0)]),e("div",_l,[e("div",Ll,[(a(!0),d(Y,null,Z(A.value,m=>(a(),d("button",{key:m,class:"flex-shrink-0 rounded-lg bg-gray-100 px-3 py-1 text-xs text-gray-700 transition-colors hover:bg-gray-200 sm:text-sm",type:"button",onClick:$=>f(m)},c(m),9,Ml))),128)),A.value.length===0?(a(),d("span",Tl," 所有常用模型已在限制列表中 ")):b("",!0)]),e("div",Sl,[V(e("input",{"onUpdate:modelValue":r[20]||(r[20]=m=>i.modelInput=m),class:"form-input flex-1",placeholder:"输入模型名称,按回车添加",type:"text",onKeydown:Ke(ce(l,["prevent"]),["enter"])},null,40,Rl),[[X,i.modelInput]]),e("button",{class:"rounded-lg bg-red-500 px-4 py-2 text-white transition-colors hover:bg-red-600",type:"button",onClick:l},r[63]||(r[63]=[e("i",{class:"fas fa-plus"},null,-1)]))])]),r[65]||(r[65]=e("p",{class:"mt-2 text-xs text-gray-500"}," 设置此API Key无法访问的模型,例如:claude-opus-4-20250514 ",-1))])])):b("",!0)]),e("div",null,[e("div",jl,[V(e("input",{id:"editEnableClientRestriction","onUpdate:modelValue":r[21]||(r[21]=m=>i.enableClientRestriction=m),class:"h-4 w-4 rounded border-gray-300 bg-gray-100 text-blue-600 focus:ring-blue-500",type:"checkbox"},null,512),[[ge,i.enableClientRestriction]]),r[66]||(r[66]=e("label",{class:"ml-2 cursor-pointer text-sm font-semibold text-gray-700",for:"editEnableClientRestriction"}," 启用客户端限制 ",-1))]),i.enableClientRestriction?(a(),d("div",El,[e("div",null,[r[67]||(r[67]=e("label",{class:"mb-2 block text-sm font-medium text-gray-600"},"允许的客户端",-1)),r[68]||(r[68]=e("p",{class:"mb-3 text-xs text-gray-500"},"勾选允许使用此API Key的客户端",-1)),e("div",Pl,[(a(!0),d(Y,null,Z(O.value,m=>(a(),d("div",{key:m.id,class:"flex items-start"},[V(e("input",{id:`edit_client_${m.id}`,"onUpdate:modelValue":r[22]||(r[22]=$=>i.allowedClients=$),class:"mt-0.5 h-4 w-4 rounded border-gray-300 bg-gray-100 text-blue-600 focus:ring-blue-500",type:"checkbox",value:m.id},null,8,Vl),[[ge,i.allowedClients]]),e("label",{class:"ml-2 flex-1 cursor-pointer",for:`edit_client_${m.id}`},[e("span",ql,c(m.name),1),e("span",Gl,c(m.description),1)],8,Ul)]))),128))])])])):b("",!0)]),e("div",Ol,[e("button",{class:"flex-1 rounded-xl bg-gray-100 px-6 py-3 font-semibold text-gray-700 transition-colors hover:bg-gray-200",type:"button",onClick:r[23]||(r[23]=m=>R.$emit("close"))}," 取消 "),e("button",{class:"btn btn-primary flex-1 px-6 py-3 font-semibold",disabled:C.value,type:"submit"},[C.value?(a(),d("div",Fl)):(a(),d("i",zl)),k(" "+c(C.value?"保存中...":"保存修改"),1)],8,Wl)])],32)])])]))}},Hl=me(Bl,[["__scopeId","data-v-944d12b4"]]),Nl={class:"modal fixed inset-0 z-50 flex items-center justify-center p-4"},Yl={class:"modal-content mx-auto flex max-h-[90vh] w-full max-w-md flex-col p-8"},Ql={class:"mb-6 flex items-center justify-between"},Jl={class:"modal-scroll-content custom-scrollbar flex-1 space-y-6"},Xl={class:"rounded-lg border border-blue-200 bg-blue-50 p-4"},Zl={class:"flex items-start gap-3"},eo={class:"text-sm text-gray-700"},to={class:"mt-1 text-xs text-gray-600"},so={key:0,class:"mt-3"},lo=["min"],oo={key:1,class:"mt-2 text-xs text-gray-500"},no={class:"flex gap-3 pt-4"},io=["disabled"],ao={key:0,class:"loading-spinner mr-2"},ro={key:1,class:"fas fa-clock mr-2"},uo={__name:"RenewApiKeyModal",props:{apiKey:{type:Object,required:!0}},emits:["close","success"],setup(v,{emit:H}){const u=v,P=H,E=M(!1),h=De({renewDuration:"30d",customExpireDate:"",newExpiresAt:null}),C=W(()=>{const y=new Date;return u.apiKey.expiresAt&&new Date(u.apiKey.expiresAt)>y?new Date(u.apiKey.expiresAt).toISOString().slice(0,16):(y.setMinutes(y.getMinutes()+1),y.toISOString().slice(0,16))}),F=y=>new Date(y).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}),I=()=>{if(!h.renewDuration){h.newExpiresAt=null;return}if(h.renewDuration==="permanent"){h.newExpiresAt=null;return}if(h.renewDuration==="custom")return;const y=u.apiKey.expiresAt&&new Date(u.apiKey.expiresAt)>new Date?new Date(u.apiKey.expiresAt):new Date,i=h.renewDuration.match(/(\d+)([dhmy])/);if(i){const[,l,Q]=i,K=parseInt(l);switch(Q){case"d":y.setDate(y.getDate()+K);break;case"h":y.setHours(y.getHours()+K);break;case"m":y.setMonth(y.getMonth()+K);break;case"y":y.setFullYear(y.getFullYear()+K);break}h.newExpiresAt=y.toISOString()}},O=()=>{h.customExpireDate&&(h.newExpiresAt=new Date(h.customExpireDate).toISOString())},j=async()=>{E.value=!0;try{const y={expiresAt:h.renewDuration==="permanent"?null:h.newExpiresAt},T=await B.put(`/admin/api-keys/${u.apiKey.id}`,y);T.success?(G("API Key 续期成功","success"),P("success"),P("close")):G(T.message||"续期失败","error")}catch{G("续期失败","error")}finally{E.value=!1}};return I(),(y,T)=>(a(),oe(fe,{to:"body"},[e("div",Nl,[e("div",Yl,[e("div",Ql,[T[5]||(T[5]=e("div",{class:"flex items-center gap-3"},[e("div",{class:"flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br from-green-500 to-green-600"},[e("i",{class:"fas fa-clock text-white"})]),e("h3",{class:"text-xl font-bold text-gray-900"},"续期 API Key")],-1)),e("button",{class:"text-gray-400 transition-colors hover:text-gray-600",onClick:T[0]||(T[0]=i=>y.$emit("close"))},T[4]||(T[4]=[e("i",{class:"fas fa-times text-xl"},null,-1)]))]),e("div",Jl,[e("div",Xl,[e("div",Zl,[T[7]||(T[7]=e("div",{class:"flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-blue-500"},[e("i",{class:"fas fa-info text-sm text-white"})],-1)),e("div",null,[T[6]||(T[6]=e("h4",{class:"mb-1 font-semibold text-gray-800"},"API Key 信息",-1)),e("p",eo,c(v.apiKey.name),1),e("p",to," 当前过期时间:"+c(v.apiKey.expiresAt?F(v.apiKey.expiresAt):"永不过期"),1)])])]),e("div",null,[T[9]||(T[9]=e("label",{class:"mb-3 block text-sm font-semibold text-gray-700"},"续期时长",-1)),V(e("select",{"onUpdate:modelValue":T[1]||(T[1]=i=>h.renewDuration=i),class:"form-input w-full",onChange:I},T[8]||(T[8]=[e("option",{value:"7d"},"延长 7 天",-1),e("option",{value:"30d"},"延长 30 天",-1),e("option",{value:"90d"},"延长 90 天",-1),e("option",{value:"180d"},"延长 180 天",-1),e("option",{value:"365d"},"延长 365 天",-1),e("option",{value:"custom"},"自定义日期",-1),e("option",{value:"permanent"},"设为永不过期",-1)]),544),[[Se,h.renewDuration]]),h.renewDuration==="custom"?(a(),d("div",so,[V(e("input",{"onUpdate:modelValue":T[2]||(T[2]=i=>h.customExpireDate=i),class:"form-input w-full",min:C.value,type:"datetime-local",onChange:O},null,40,lo),[[X,h.customExpireDate]])])):b("",!0),h.newExpiresAt?(a(),d("p",oo," 新的过期时间:"+c(F(h.newExpiresAt)),1)):b("",!0)])]),e("div",no,[e("button",{class:"flex-1 rounded-xl bg-gray-100 px-6 py-3 font-semibold text-gray-700 transition-colors hover:bg-gray-200",type:"button",onClick:T[3]||(T[3]=i=>y.$emit("close"))}," 取消 "),e("button",{class:"btn btn-primary flex-1 px-6 py-3 font-semibold",disabled:E.value||!h.renewDuration,type:"button",onClick:j},[E.value?(a(),d("div",ao)):(a(),d("i",ro)),k(" "+c(E.value?"续期中...":"确认续期"),1)],8,io)])])])]))}},co=me(uo,[["__scopeId","data-v-2fba52a3"]]),mo={class:"modal fixed inset-0 z-50 flex items-center justify-center p-4"},po={class:"modal-content custom-scrollbar mx-auto max-h-[90vh] w-full max-w-lg overflow-y-auto p-8"},xo={class:"mb-6 space-y-4"},fo={class:"rounded-lg border bg-gray-50 p-3"},go={class:"font-medium text-gray-900"},yo={key:0},bo={class:"rounded-lg border bg-gray-50 p-3"},vo={class:"text-gray-700"},wo={class:"relative"},ho={class:"flex min-h-[60px] items-center break-all rounded-lg border bg-gray-900 p-4 pr-14 font-mono text-sm text-white"},$o={class:"absolute right-3 top-3"},Ao=["title"],Co={__name:"NewApiKeyModal",props:{apiKey:{type:Object,required:!0}},emits:["close"],setup(v,{emit:H}){const u=v,P=H,E=M(!1),h=()=>{E.value=!E.value},C=()=>{const j=u.apiKey.apiKey||u.apiKey.key||"";return j?E.value||j.length<=12?j:j.substring(0,8)+"●".repeat(Math.max(0,j.length-12))+j.substring(j.length-4):""},F=async()=>{const j=u.apiKey.apiKey||u.apiKey.key||"";if(!j){G("API Key 不存在","error");return}try{await navigator.clipboard.writeText(j),G("API Key 已复制到剪贴板","success")}catch(y){console.error("Failed to copy:",y);const T=document.createElement("textarea");T.value=j,document.body.appendChild(T),T.select();try{document.execCommand("copy"),G("API Key 已复制到剪贴板","success")}catch{G("复制失败,请手动复制","error")}finally{document.body.removeChild(T)}}},I=async()=>{window.showConfirm?await window.showConfirm("关闭提醒",`关闭后将无法再次查看完整的API Key,请确保已经妥善保存。 确定要关闭吗?`,"确定关闭","取消")&&P("close"):confirm(`关闭后将无法再次查看完整的API Key,请确保已经妥善保存。 确定要关闭吗?`)&&P("close")},O=async()=>{window.showConfirm?await window.showConfirm("确定要关闭吗?",`您还没有保存API Key,关闭后将无法再次查看。 建议您先复制API Key再关闭。`,"仍然关闭","返回复制")&&P("close"):confirm(`您还没有保存API Key,关闭后将无法再次查看。 确定要关闭吗?`)&&P("close")};return(j,y)=>(a(),oe(fe,{to:"body"},[e("div",mo,[e("div",po,[e("div",{class:"mb-6 flex items-center justify-between"},[y[1]||(y[1]=e("div",{class:"flex items-center gap-3"},[e("div",{class:"flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-green-500 to-green-600"},[e("i",{class:"fas fa-check text-lg text-white"})]),e("div",null,[e("h3",{class:"text-xl font-bold text-gray-900"},"API Key 创建成功"),e("p",{class:"text-sm text-gray-600"},"请妥善保存您的 API Key")])],-1)),e("button",{class:"text-gray-400 transition-colors hover:text-gray-600",title:"直接关闭(不推荐)",onClick:O},y[0]||(y[0]=[e("i",{class:"fas fa-times text-xl"},null,-1)]))]),y[7]||(y[7]=e("div",{class:"mb-6 border-l-4 border-amber-400 bg-amber-50 p-4"},[e("div",{class:"flex items-start"},[e("div",{class:"mt-0.5 flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-lg bg-amber-400"},[e("i",{class:"fas fa-exclamation-triangle text-sm text-white"})]),e("div",{class:"ml-3"},[e("h5",{class:"mb-1 font-semibold text-amber-900"},"重要提醒"),e("p",{class:"text-sm text-amber-800"}," 这是您唯一能看到完整 API Key 的机会。关闭此窗口后,系统将不再显示完整的 API Key。请立即复制并妥善保存。 ")])])],-1)),e("div",xo,[e("div",null,[y[2]||(y[2]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"API Key 名称",-1)),e("div",fo,[e("span",go,c(v.apiKey.name),1)])]),v.apiKey.description?(a(),d("div",yo,[y[3]||(y[3]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"备注",-1)),e("div",bo,[e("span",vo,c(v.apiKey.description||"无描述"),1)])])):b("",!0),e("div",null,[y[4]||(y[4]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"API Key",-1)),e("div",wo,[e("div",ho,c(C()),1),e("div",$o,[e("button",{class:"btn-icon-sm bg-gray-700 hover:bg-gray-800",title:E.value?"隐藏API Key":"显示完整API Key",type:"button",onClick:h},[e("i",{class:U(["fas",E.value?"fa-eye-slash":"fa-eye","text-gray-300"])},null,2)],8,Ao)])]),y[5]||(y[5]=e("p",{class:"mt-2 text-xs text-gray-500"}," 点击眼睛图标切换显示模式,使用下方按钮复制完整 API Key ",-1))])]),e("div",{class:"flex gap-3"},[e("button",{class:"btn btn-primary flex flex-1 items-center justify-center gap-2 px-6 py-3 font-semibold",onClick:F},y[6]||(y[6]=[e("i",{class:"fas fa-copy"},null,-1),k(" 复制 API Key ",-1)])),e("button",{class:"rounded-xl border border-gray-300 bg-gray-200 px-6 py-3 font-semibold text-gray-800 transition-colors hover:bg-gray-300",onClick:I}," 我已保存 ")])])])]))}},ko=me(Co,[["__scopeId","data-v-75e2b028"]]),Ko={class:"modal fixed inset-0 z-50 flex items-center justify-center p-4"},Io={class:"modal-content custom-scrollbar mx-auto max-h-[90vh] w-full max-w-2xl overflow-y-auto p-8"},Do={class:"mb-6 flex items-center justify-between"},_o={class:"flex items-center gap-3"},Lo={class:"text-sm text-gray-600"},Mo={class:"mb-6 grid grid-cols-2 gap-4 md:grid-cols-4"},To={class:"rounded-lg border border-blue-200 bg-gradient-to-br from-blue-50 to-blue-100 p-4"},So={class:"flex items-center justify-between"},Ro={class:"mt-1 text-2xl font-bold text-blue-900"},jo={class:"rounded-lg border border-green-200 bg-gradient-to-br from-green-50 to-green-100 p-4"},Eo={class:"flex items-center justify-between"},Po={class:"mt-1 truncate text-lg font-bold text-green-900"},Vo={class:"rounded-lg border border-purple-200 bg-gradient-to-br from-purple-50 to-purple-100 p-4"},Uo={class:"flex items-center justify-between"},qo={class:"mt-1 text-lg font-bold text-purple-900"},Go={class:"rounded-lg border border-orange-200 bg-gradient-to-br from-orange-50 to-orange-100 p-4"},Oo={class:"flex items-center justify-between"},Wo={class:"mt-1 text-lg font-bold text-orange-900"},Fo={class:"mb-6"},zo={class:"mb-3 flex items-center justify-between"},Bo={class:"flex items-center gap-2"},Ho={key:0,class:"custom-scrollbar max-h-48 overflow-y-auto rounded-lg bg-gray-900 p-4"},No={class:"font-mono text-xs text-gray-300"},Yo={__name:"BatchApiKeyModal",props:{apiKeys:{type:Array,required:!0}},emits:["close"],setup(v,{emit:H}){const u=v,P=H,E=M(!1),h=W(()=>{if(u.apiKeys.length>0){const i=u.apiKeys[0],l=i.name.match(/^(.+)_\d+$/);return l?l[1]:i.name}return""}),C=()=>{if(u.apiKeys.length===0)return"未知";const i=u.apiKeys[0].permissions;return{all:"全部服务",claude:"仅 Claude",gemini:"仅 Gemini"}[i]||i},F=()=>{if(u.apiKeys.length===0)return"未知";const i=u.apiKeys[0].expiresAt;if(!i)return"永不过期";const l=new Date(i),K=Math.ceil((l-new Date)/(1e3*60*60*24));return K<=7?`${K}天`:K<=30?`${Math.ceil(K/7)}周`:K<=365?`${Math.ceil(K/30)}个月`:`${Math.ceil(K/365)}年`},I=()=>{E.value=!E.value},O=()=>{const l=u.apiKeys.slice(0,10).map(Q=>`${Q.name}: ${Q.apiKey||Q.key||""}`);return u.apiKeys.length>10&&l.push(`... 还有 ${u.apiKeys.length-10} 个 API Key`),l.join(` `)},j=()=>{const i=u.apiKeys.map(f=>`${f.name}: ${f.apiKey||f.key||""}`).join(` `),l=new Blob([i],{type:"text/plain;charset=utf-8"}),Q=URL.createObjectURL(l),K=document.createElement("a");K.href=Q;const A=new Date().toISOString().replace(/[:.]/g,"-").slice(0,-5);K.download=`api-keys-${h.value}-${A}.txt`,document.body.appendChild(K),K.click(),document.body.removeChild(K),URL.revokeObjectURL(Q),G("API Keys 文件已下载","success")},y=async()=>{window.showConfirm?await window.showConfirm("关闭提醒",`关闭后将无法再次查看这些 API Key,请确保已经下载并妥善保存。 确定要关闭吗?`,"确定关闭","返回下载")&&P("close"):confirm(`关闭后将无法再次查看这些 API Key,请确保已经下载并妥善保存。 确定要关闭吗?`)&&P("close")},T=async()=>{window.showConfirm?await window.showConfirm("确定要关闭吗?",`您还没有下载 API Keys,关闭后将无法再次查看。 强烈建议您先下载保存。`,"仍然关闭","返回下载")&&P("close"):confirm(`您还没有下载 API Keys,关闭后将无法再次查看。 确定要关闭吗?`)&&P("close")};return(i,l)=>(a(),oe(fe,{to:"body"},[e("div",Ko,[e("div",Io,[e("div",Do,[e("div",_o,[l[1]||(l[1]=e("div",{class:"flex h-12 w-12 items-center justify-center rounded-xl bg-gradient-to-br from-green-500 to-green-600"},[e("i",{class:"fas fa-layer-group text-lg text-white"})],-1)),e("div",null,[l[0]||(l[0]=e("h3",{class:"text-xl font-bold text-gray-900"},"批量创建成功",-1)),e("p",Lo,"成功创建 "+c(v.apiKeys.length)+" 个 API Key",1)])]),e("button",{class:"text-gray-400 transition-colors hover:text-gray-600",title:"直接关闭(不推荐)",onClick:T},l[2]||(l[2]=[e("i",{class:"fas fa-times text-xl"},null,-1)]))]),l[14]||(l[14]=e("div",{class:"mb-6 border-l-4 border-amber-400 bg-amber-50 p-4"},[e("div",{class:"flex items-start"},[e("div",{class:"mt-0.5 flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-lg bg-amber-400"},[e("i",{class:"fas fa-exclamation-triangle text-sm text-white"})]),e("div",{class:"ml-3"},[e("h5",{class:"mb-1 font-semibold text-amber-900"},"重要提醒"),e("p",{class:"text-sm text-amber-800"}," 这是您唯一能看到所有 API Key 的机会。关闭此窗口后,系统将不再显示完整的 API Key。请立即下载并妥善保存。 ")])])],-1)),e("div",Mo,[e("div",To,[e("div",So,[e("div",null,[l[3]||(l[3]=e("p",{class:"text-xs font-medium text-blue-600"},"创建数量",-1)),e("p",Ro,c(v.apiKeys.length),1)]),l[4]||(l[4]=e("div",{class:"flex h-10 w-10 items-center justify-center rounded-lg bg-blue-500 bg-opacity-20"},[e("i",{class:"fas fa-key text-blue-600"})],-1))])]),e("div",jo,[e("div",Eo,[e("div",null,[l[5]||(l[5]=e("p",{class:"text-xs font-medium text-green-600"},"基础名称",-1)),e("p",Po,c(h.value),1)]),l[6]||(l[6]=e("div",{class:"flex h-10 w-10 items-center justify-center rounded-lg bg-green-500 bg-opacity-20"},[e("i",{class:"fas fa-tag text-green-600"})],-1))])]),e("div",Vo,[e("div",Uo,[e("div",null,[l[7]||(l[7]=e("p",{class:"text-xs font-medium text-purple-600"},"权限范围",-1)),e("p",qo,c(C()),1)]),l[8]||(l[8]=e("div",{class:"flex h-10 w-10 items-center justify-center rounded-lg bg-purple-500 bg-opacity-20"},[e("i",{class:"fas fa-shield-alt text-purple-600"})],-1))])]),e("div",Go,[e("div",Oo,[e("div",null,[l[9]||(l[9]=e("p",{class:"text-xs font-medium text-orange-600"},"过期时间",-1)),e("p",Wo,c(F()),1)]),l[10]||(l[10]=e("div",{class:"flex h-10 w-10 items-center justify-center rounded-lg bg-orange-500 bg-opacity-20"},[e("i",{class:"fas fa-clock text-orange-600"})],-1))])])]),e("div",Fo,[e("div",zo,[l[12]||(l[12]=e("label",{class:"text-sm font-semibold text-gray-700"},"API Keys 预览",-1)),e("div",Bo,[e("button",{class:"flex items-center gap-1 text-xs text-blue-600 hover:text-blue-800",type:"button",onClick:I},[e("i",{class:U(["fas",E.value?"fa-eye-slash":"fa-eye"])},null,2),k(" "+c(E.value?"隐藏":"显示")+"预览 ",1)]),l[11]||(l[11]=e("span",{class:"text-xs text-gray-500"},"(最多显示前10个)",-1))])]),E.value?(a(),d("div",Ho,[e("pre",No,c(O()),1)])):b("",!0)]),e("div",{class:"flex gap-3"},[e("button",{class:"btn btn-primary flex flex-1 items-center justify-center gap-2 px-6 py-3 font-semibold",onClick:j},l[13]||(l[13]=[e("i",{class:"fas fa-download"},null,-1),k(" 下载所有 API Keys ",-1)])),e("button",{class:"rounded-xl border border-gray-300 bg-gray-200 px-6 py-3 font-semibold text-gray-800 transition-colors hover:bg-gray-300",onClick:y}," 我已保存 ")]),l[15]||(l[15]=e("div",{class:"mt-4 rounded-lg border border-blue-200 bg-blue-50 p-3"},[e("p",{class:"flex items-start text-xs text-blue-700"},[e("i",{class:"fas fa-info-circle mr-2 mt-0.5 flex-shrink-0"}),e("span",null," 下载的文件格式为文本文件(.txt),每行包含一个 API Key。 请将文件保存在安全的位置,避免泄露。 ")])],-1))])])]))}},Qo=me(Yo,[["__scopeId","data-v-b0b904b9"]]),Jo={key:0,class:"modal fixed inset-0 z-50 flex items-center justify-center p-4"},Xo={class:"modal-content mx-auto w-full max-w-lg p-8"},Zo={class:"mb-6 flex items-center justify-between"},en={class:"flex items-center gap-3"},tn={class:"text-sm text-gray-600"},sn={class:"space-y-6"},ln={class:"rounded-lg border border-gray-200 bg-gradient-to-r from-gray-50 to-gray-100 p-4"},on={class:"flex items-center justify-between"},nn={class:"text-sm font-semibold text-gray-800"},an={class:"flex h-12 w-12 items-center justify-center rounded-lg bg-white shadow-sm"},rn={class:"mb-3 grid grid-cols-3 gap-2"},dn=["onClick"],un={key:0,class:"animate-fadeIn"},cn=["min"],mn={key:1,class:"rounded-lg border border-blue-200 bg-gradient-to-r from-blue-50 to-indigo-50 p-4"},pn={class:"flex items-center justify-between"},xn={class:"text-sm font-semibold text-blue-900"},fn={class:"flex gap-3 pt-2"},gn=["disabled"],yn={key:0,class:"loading-spinner mr-2"},bn={key:1,class:"fas fa-save mr-2"},vn={__name:"ExpiryEditModal",props:{show:{type:Boolean,required:!0},apiKey:{type:Object,required:!0}},emits:["close","save"],setup(v,{expose:H,emit:u}){const P=v,E=u,h=M(!1),C=De({expireDuration:"",customExpireDate:"",expiresAt:null}),F=[{value:"",label:"永不过期"},{value:"1d",label:"1 天"},{value:"7d",label:"7 天"},{value:"30d",label:"30 天"},{value:"90d",label:"90 天"},{value:"180d",label:"180 天"},{value:"365d",label:"1 年"},{value:"730d",label:"2 年"}],I=W(()=>{const A=new Date;return A.setMinutes(A.getMinutes()+1),A.toISOString().slice(0,16)});ke(()=>P.show,A=>{A&&O()}),ke(()=>{var A;return(A=P.apiKey)==null?void 0:A.id},A=>{A&&P.show&&O()});const O=()=>{h.value=!1,P.apiKey.expiresAt?(C.expireDuration="custom",C.customExpireDate=new Date(P.apiKey.expiresAt).toISOString().slice(0,16),C.expiresAt=P.apiKey.expiresAt):(C.expireDuration="",C.customExpireDate="",C.expiresAt=null)},j=A=>{if(C.expireDuration=A,!A){C.expiresAt=null;return}if(A==="custom")return;const f=new Date,N=A.match(/(\d+)([dhmy])/);if(N){const[,te,D]=N,p=parseInt(te);switch(D){case"d":f.setDate(f.getDate()+p);break;case"h":f.setHours(f.getHours()+p);break;case"m":f.setMonth(f.getMonth()+p);break;case"y":f.setFullYear(f.getFullYear()+p);break}C.expiresAt=f.toISOString()}},y=()=>{C.customExpireDate&&(C.expiresAt=new Date(C.customExpireDate).toISOString())},T=A=>A?new Date(A).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}):"",i=A=>A?new Date(A){if(!A)return null;const f=new Date,te=new Date(A)-f,D=Math.ceil(te/(1e3*60*60*24));return te<0?{text:"已过期",class:"text-red-600"}:D<=7?{text:`${D} 天后过期`,class:"text-orange-600"}:D<=30?{text:`${D} 天后过期`,class:"text-yellow-600"}:{text:`${Math.ceil(D/30)} 个月后过期`,class:"text-green-600"}},Q=()=>{h.value=!0,E("save",{keyId:P.apiKey.id,expiresAt:C.expiresAt})};return H({resetSaving:()=>{h.value=!1}}),(A,f)=>(a(),oe(fe,{to:"body"},[v.show?(a(),d("div",Jo,[e("div",Xo,[e("div",Zo,[e("div",en,[f[5]||(f[5]=e("div",{class:"flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br from-amber-500 to-orange-600"},[e("i",{class:"fas fa-clock text-white"})],-1)),e("div",null,[f[4]||(f[4]=e("h3",{class:"text-xl font-bold text-gray-900"},"修改过期时间",-1)),e("p",tn,' 为 "'+c(v.apiKey.name||"API Key")+'" 设置新的过期时间 ',1)])]),e("button",{class:"text-gray-400 transition-colors hover:text-gray-600",onClick:f[0]||(f[0]=N=>A.$emit("close"))},f[6]||(f[6]=[e("i",{class:"fas fa-times text-xl"},null,-1)]))]),e("div",sn,[e("div",ln,[e("div",on,[e("div",null,[f[9]||(f[9]=e("p",{class:"mb-1 text-xs font-medium text-gray-600"},"当前过期时间",-1)),e("p",nn,[v.apiKey.expiresAt?(a(),d(Y,{key:0},[k(c(T(v.apiKey.expiresAt))+" ",1),l(v.apiKey.expiresAt)?(a(),d("span",{key:0,class:U(["ml-2 text-xs font-normal",l(v.apiKey.expiresAt).class])}," ("+c(l(v.apiKey.expiresAt).text)+") ",3)):b("",!0)],64)):(a(),d(Y,{key:1},[f[7]||(f[7]=e("i",{class:"fas fa-infinity mr-1 text-gray-500"},null,-1)),f[8]||(f[8]=k(" 永不过期 ",-1))],64))])]),e("div",an,[e("i",{class:U(["fas fa-hourglass-half text-lg",v.apiKey.expiresAt&&i(v.apiKey.expiresAt)?"text-red-500":"text-gray-400"])},null,2)])])]),e("div",null,[f[11]||(f[11]=e("label",{class:"mb-3 block text-sm font-semibold text-gray-700"},"选择新的期限",-1)),e("div",rn,[(a(),d(Y,null,Z(F,N=>e("button",{key:N.value,class:U(["rounded-lg px-3 py-2 text-sm font-medium transition-all",C.expireDuration===N.value?"bg-blue-500 text-white shadow-md":"bg-gray-100 text-gray-700 hover:bg-gray-200"]),onClick:te=>j(N.value)},c(N.label),11,dn)),64)),e("button",{class:U(["rounded-lg px-3 py-2 text-sm font-medium transition-all",C.expireDuration==="custom"?"bg-blue-500 text-white shadow-md":"bg-gray-100 text-gray-700 hover:bg-gray-200"]),onClick:f[1]||(f[1]=N=>j("custom"))},f[10]||(f[10]=[e("i",{class:"fas fa-calendar-alt mr-1"},null,-1),k(" 自定义 ",-1)]),2)])]),C.expireDuration==="custom"?(a(),d("div",un,[f[12]||(f[12]=e("label",{class:"mb-2 block text-sm font-semibold text-gray-700"},"选择日期和时间",-1)),V(e("input",{"onUpdate:modelValue":f[2]||(f[2]=N=>C.customExpireDate=N),class:"form-input w-full",min:I.value,type:"datetime-local",onChange:y},null,40,cn),[[X,C.customExpireDate]]),f[13]||(f[13]=e("p",{class:"mt-2 text-xs text-gray-500"},"选择一个未来的日期和时间作为过期时间",-1))])):b("",!0),C.expiresAt!==v.apiKey.expiresAt?(a(),d("div",mn,[e("div",pn,[e("div",null,[f[16]||(f[16]=e("p",{class:"mb-1 text-xs font-medium text-blue-700"},[e("i",{class:"fas fa-arrow-right mr-1"}),k(" 新的过期时间 ")],-1)),e("p",xn,[C.expiresAt?(a(),d(Y,{key:0},[k(c(T(C.expiresAt))+" ",1),l(C.expiresAt)?(a(),d("span",{key:0,class:U(["ml-2 text-xs font-normal",l(C.expiresAt).class])}," ("+c(l(C.expiresAt).text)+") ",3)):b("",!0)],64)):(a(),d(Y,{key:1},[f[14]||(f[14]=e("i",{class:"fas fa-infinity mr-1"},null,-1)),f[15]||(f[15]=k(" 永不过期 ",-1))],64))])]),f[17]||(f[17]=e("div",{class:"flex h-12 w-12 items-center justify-center rounded-lg bg-white shadow-sm"},[e("i",{class:"fas fa-check text-lg text-green-500"})],-1))])])):b("",!0),e("div",fn,[e("button",{class:"flex-1 rounded-lg bg-gray-100 px-4 py-2.5 font-semibold text-gray-700 transition-colors hover:bg-gray-200",onClick:f[3]||(f[3]=N=>A.$emit("close"))}," 取消 "),e("button",{class:"btn btn-primary flex-1 px-4 py-2.5 font-semibold",disabled:h.value||C.expiresAt===v.apiKey.expiresAt,onClick:Q},[h.value?(a(),d("div",yn)):(a(),d("i",bn)),k(" "+c(h.value?"保存中...":"保存更改"),1)],8,gn)])])])])):b("",!0)]))}},wn=me(vn,[["__scopeId","data-v-cfb0d627"]]),hn={key:0,class:"modal fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"},$n={class:"modal-content relative mx-auto flex max-h-[90vh] w-[95%] max-w-2xl flex-col p-4 sm:w-full sm:max-w-3xl sm:p-6 md:p-8"},An={class:"mb-4 flex items-center justify-between sm:mb-6"},Cn={class:"flex items-center gap-2 sm:gap-3"},kn={class:"text-lg font-bold text-gray-900 sm:text-xl"},Kn={class:"modal-scroll-content custom-scrollbar flex-1 overflow-y-auto"},In={class:"mb-6 grid grid-cols-1 gap-4 md:grid-cols-2"},Dn={class:"rounded-lg border border-blue-200 bg-gradient-to-br from-blue-50 to-blue-100 p-4"},_n={class:"text-2xl font-bold text-gray-900"},Ln={class:"mt-1 text-xs text-gray-600"},Mn={class:"rounded-lg border border-green-200 bg-gradient-to-br from-green-50 to-green-100 p-4"},Tn={class:"text-2xl font-bold text-gray-900"},Sn={class:"mt-1 text-xs text-gray-600"},Rn={class:"rounded-lg border border-yellow-200 bg-gradient-to-br from-yellow-50 to-yellow-100 p-4"},jn={class:"text-2xl font-bold text-gray-900"},En={class:"mt-1 text-xs text-gray-600"},Pn={class:"rounded-lg border border-purple-200 bg-gradient-to-br from-purple-50 to-purple-100 p-4"},Vn={class:"space-y-1 text-sm"},Un={class:"flex justify-between"},qn={class:"font-semibold"},Gn={class:"flex justify-between"},On={class:"font-semibold"},Wn={class:"mb-6"},Fn={class:"space-y-3 rounded-lg bg-gray-50 p-4"},zn={class:"flex items-center justify-between"},Bn={class:"text-sm font-semibold text-gray-900"},Hn={class:"flex items-center justify-between"},Nn={class:"text-sm font-semibold text-gray-900"},Yn={key:0,class:"flex items-center justify-between"},Qn={class:"text-sm font-semibold text-purple-600"},Jn={key:1,class:"flex items-center justify-between"},Xn={class:"text-sm font-semibold text-purple-600"},Zn={key:0,class:"mb-6"},ei={class:"space-y-3 rounded-lg bg-gray-50 p-4"},ti={key:0,class:"space-y-2"},si={class:"flex items-center justify-between text-sm"},li={class:"font-semibold text-gray-900"},oi={class:"h-2 w-full rounded-full bg-gray-200"},ni={class:"text-right text-xs text-gray-500"},ii={key:1,class:"flex items-center justify-between text-sm"},ai={class:"font-semibold text-purple-600"},ri={key:2,class:"space-y-2"},di={__name:"UsageDetailModal",props:{show:{type:Boolean,required:!0},apiKey:{type:Object,required:!0}},emits:["close"],setup(v,{emit:H}){const u=v,P=H,E=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.total)==null?void 0:p.requests)||0}),h=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.daily)==null?void 0:p.requests)||0}),C=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.total)==null?void 0:p.tokens)||0}),F=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.daily)==null?void 0:p.tokens)||0}),I=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.total)==null?void 0:p.cost)||0}),O=W(()=>u.apiKey.dailyCost||0),j=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.total)==null?void 0:p.inputTokens)||0}),y=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.total)==null?void 0:p.outputTokens)||0}),T=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.total)==null?void 0:p.cacheCreateTokens)||0}),i=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.total)==null?void 0:p.cacheReadTokens)||0}),l=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.averages)==null?void 0:p.rpm)||0}),Q=W(()=>{var D,p;return((p=(D=u.apiKey.usage)==null?void 0:D.averages)==null?void 0:p.tpm)||0}),K=W(()=>u.apiKey.dailyCostLimit>0||u.apiKey.concurrencyLimit>0||u.apiKey.rateLimitWindow>0||u.apiKey.tokenLimit>0),A=W(()=>!u.apiKey.dailyCostLimit||u.apiKey.dailyCostLimit===0?0:O.value/u.apiKey.dailyCostLimit*100),f=D=>!D&&D!==0?"0":D.toLocaleString("zh-CN"),N=D=>D>=1e6?(D/1e6).toFixed(1)+"M":D>=1e3?(D/1e3).toFixed(1)+"K":D.toString(),te=()=>{P("close")};return(D,p)=>(a(),oe(fe,{to:"body"},[v.show?(a(),d("div",hn,[e("div",{class:"fixed inset-0 bg-gray-900 bg-opacity-50 backdrop-blur-sm",onClick:te}),e("div",$n,[e("div",An,[e("div",Cn,[p[0]||(p[0]=e("div",{class:"flex h-8 w-8 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500 to-blue-600 sm:h-10 sm:w-10 sm:rounded-xl"},[e("i",{class:"fas fa-chart-line text-sm text-white sm:text-base"})],-1)),e("h3",kn," 使用统计详情 - "+c(v.apiKey.name),1)]),e("button",{class:"p-1 text-gray-400 transition-colors hover:text-gray-600",onClick:te},p[1]||(p[1]=[e("i",{class:"fas fa-times text-lg sm:text-xl"},null,-1)]))]),e("div",Kn,[e("div",In,[e("div",Dn,[p[2]||(p[2]=e("div",{class:"mb-3 flex items-center justify-between"},[e("span",{class:"text-sm font-medium text-gray-700"},"总请求数"),e("i",{class:"fas fa-paper-plane text-blue-500"})],-1)),e("div",_n,c(f(E.value)),1),e("div",Ln," 今日: "+c(f(h.value))+" 次 ",1)]),e("div",Mn,[p[3]||(p[3]=e("div",{class:"mb-3 flex items-center justify-between"},[e("span",{class:"text-sm font-medium text-gray-700"},"总Token数"),e("i",{class:"fas fa-coins text-green-500"})],-1)),e("div",Tn,c(N(C.value)),1),e("div",Sn," 今日: "+c(N(F.value)),1)]),e("div",Rn,[p[4]||(p[4]=e("div",{class:"mb-3 flex items-center justify-between"},[e("span",{class:"text-sm font-medium text-gray-700"},"总费用"),e("i",{class:"fas fa-dollar-sign text-yellow-600"})],-1)),e("div",jn,"$"+c(I.value.toFixed(4)),1),e("div",En,"今日: $"+c(O.value.toFixed(4)),1)]),e("div",Pn,[p[7]||(p[7]=e("div",{class:"mb-3 flex items-center justify-between"},[e("span",{class:"text-sm font-medium text-gray-700"},"平均速率"),e("i",{class:"fas fa-tachometer-alt text-purple-500"})],-1)),e("div",Vn,[e("div",Un,[p[5]||(p[5]=e("span",{class:"text-gray-600"},"RPM:",-1)),e("span",qn,c(l.value),1)]),e("div",Gn,[p[6]||(p[6]=e("span",{class:"text-gray-600"},"TPM:",-1)),e("span",On,c(Q.value),1)])])])]),e("div",Wn,[p[12]||(p[12]=e("h4",{class:"mb-3 flex items-center text-sm font-semibold text-gray-700"},[e("i",{class:"fas fa-chart-pie mr-2 text-indigo-500"}),k(" Token 使用分布 ")],-1)),e("div",Fn,[e("div",zn,[p[8]||(p[8]=e("div",{class:"flex items-center"},[e("i",{class:"fas fa-arrow-down mr-2 text-green-500"}),e("span",{class:"text-sm text-gray-600"},"输入 Token")],-1)),e("span",Bn,c(N(j.value)),1)]),e("div",Hn,[p[9]||(p[9]=e("div",{class:"flex items-center"},[e("i",{class:"fas fa-arrow-up mr-2 text-blue-500"}),e("span",{class:"text-sm text-gray-600"},"输出 Token")],-1)),e("span",Nn,c(N(y.value)),1)]),T.value>0?(a(),d("div",Yn,[p[10]||(p[10]=e("div",{class:"flex items-center"},[e("i",{class:"fas fa-save mr-2 text-purple-500"}),e("span",{class:"text-sm text-gray-600"},"缓存创建 Token")],-1)),e("span",Qn,c(N(T.value)),1)])):b("",!0),i.value>0?(a(),d("div",Jn,[p[11]||(p[11]=e("div",{class:"flex items-center"},[e("i",{class:"fas fa-download mr-2 text-purple-500"}),e("span",{class:"text-sm text-gray-600"},"缓存读取 Token")],-1)),e("span",Xn,c(N(i.value)),1)])):b("",!0)])]),K.value?(a(),d("div",Zn,[p[16]||(p[16]=e("h4",{class:"mb-3 flex items-center text-sm font-semibold text-gray-700"},[e("i",{class:"fas fa-shield-alt mr-2 text-red-500"}),k(" 限制设置 ")],-1)),e("div",ei,[v.apiKey.dailyCostLimit>0?(a(),d("div",ti,[e("div",si,[p[13]||(p[13]=e("span",{class:"text-gray-600"},"每日费用限制",-1)),e("span",li," $"+c(v.apiKey.dailyCostLimit.toFixed(2)),1)]),e("div",oi,[e("div",{class:U(["h-2 rounded-full transition-all duration-300",A.value>=100?"bg-red-500":A.value>=80?"bg-yellow-500":"bg-green-500"]),style:he({width:Math.min(A.value,100)+"%"})},null,6)]),e("div",ni," 已使用 "+c(A.value.toFixed(1))+"% ",1)])):b("",!0),v.apiKey.concurrencyLimit>0?(a(),d("div",ii,[p[14]||(p[14]=e("span",{class:"text-gray-600"},"并发限制",-1)),e("span",ai,c(v.apiKey.currentConcurrency||0)+" / "+c(v.apiKey.concurrencyLimit),1)])):b("",!0),v.apiKey.rateLimitWindow>0?(a(),d("div",ri,[p[15]||(p[15]=e("h5",{class:"text-sm font-medium text-gray-700"},[e("i",{class:"fas fa-clock mr-1 text-blue-500"}),k(" 时间窗口限制 ")],-1)),ne(Te,{"current-requests":v.apiKey.currentWindowRequests,"current-tokens":v.apiKey.currentWindowTokens,label:"窗口状态","rate-limit-window":v.apiKey.rateLimitWindow,"request-limit":v.apiKey.rateLimitRequests,"show-progress":!0,"show-tooltip":!0,"token-limit":v.apiKey.tokenLimit,"window-end-time":v.apiKey.windowEndTime,"window-remaining-seconds":v.apiKey.windowRemainingSeconds,"window-start-time":v.apiKey.windowStartTime},null,8,["current-requests","current-tokens","rate-limit-window","request-limit","token-limit","window-end-time","window-remaining-seconds","window-start-time"])])):b("",!0)])])):b("",!0)]),e("div",{class:"mt-4 flex justify-end gap-2 sm:mt-6 sm:gap-3"},[e("button",{class:"btn btn-secondary px-4 py-2 text-sm",type:"button",onClick:te}," 关闭 ")])])])):b("",!0)]))}},ui=me(di,[["__scopeId","data-v-cbed7d44"]]),ci={class:"tab-content"},mi={class:"card p-4 sm:p-6"},pi={class:"mb-4 flex flex-col gap-4 sm:mb-6"},xi={class:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"},fi={class:"flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-3"},gi={class:"group relative min-w-[140px]"},yi={class:"group relative min-w-[140px]"},bi={class:"relative"},vi={key:0,class:"absolute -right-2 -top-2 z-10 flex h-5 w-5 items-center justify-center rounded-full bg-purple-500 text-xs text-white shadow-sm"},wi={class:"group relative min-w-[200px]"},hi={class:"relative flex items-center"},$i=["disabled"],Ai={key:0,class:"py-12 text-center"},Ci={key:1,class:"py-12 text-center"},ki={key:2,class:"table-container hidden md:block"},Ki={class:"w-full table-fixed"},Ii={class:"bg-gray-50/80 backdrop-blur-sm"},Di={key:1,class:"fas fa-sort ml-1 text-gray-400"},_i={key:1,class:"fas fa-sort ml-1 text-gray-400"},Li={class:"w-[17%] min-w-[140px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700"},Mi={key:1,class:"fas fa-sort ml-1 text-gray-400"},Ti={key:1,class:"fas fa-sort ml-1 text-gray-400"},Si={key:1,class:"fas fa-sort ml-1 text-gray-400"},Ri={class:"divide-y divide-gray-200/50"},ji={class:"table-row"},Ei={class:"px-3 py-4"},Pi={class:"flex items-center"},Vi={class:"min-w-0"},Ui=["title"],qi=["title"],Gi={class:"mt-1.5 space-y-1"},Oi={key:0,class:"flex items-center gap-1 text-xs"},Wi={class:"truncate text-gray-600"},Fi={key:1,class:"flex items-center gap-1 text-xs"},zi={class:"truncate text-gray-600"},Bi={key:2,class:"flex items-center gap-1 text-xs"},Hi={class:"truncate text-gray-600"},Ni={key:3,class:"text-xs text-gray-500"},Yi={class:"px-3 py-4"},Qi={class:"flex flex-wrap gap-1"},Ji={key:0,class:"text-xs text-gray-400"},Xi={class:"whitespace-nowrap px-3 py-4"},Zi={class:"px-3 py-4"},ea={class:"space-y-2"},ta={class:"mb-2"},sa={class:"mb-1 flex items-center justify-between text-sm"},la={class:"font-semibold text-gray-900"},oa={class:"flex items-center justify-between text-sm"},na={class:"font-semibold text-green-600"},ia={class:"flex items-center justify-between text-sm"},aa={class:"font-medium text-gray-700"},ra={key:0,class:"space-y-1"},da={class:"flex items-center justify-between text-xs"},ua={class:"text-gray-700"},ca={class:"h-1.5 w-full rounded-full bg-gray-200"},ma={class:"pt-1"},pa=["onClick"],xa={class:"whitespace-nowrap px-3 py-4 text-sm text-gray-500"},fa={class:"whitespace-nowrap px-3 py-4 text-sm"},ga={class:"inline-flex items-center gap-1.5"},ya={key:0},ba={key:0,class:"inline-flex items-center text-red-600"},va={key:1,class:"inline-flex items-center text-orange-600"},wa={key:2,class:"text-gray-600"},ha={key:1,class:"inline-flex items-center text-gray-400"},$a=["onClick"],Aa={class:"whitespace-nowrap px-3 py-4 text-sm"},Ca={class:"flex gap-1"},ka=["onClick"],Ka=["onClick"],Ia=["onClick"],Da=["onClick"],_a=["title","onClick"],La={class:"ml-1 hidden xl:inline"},Ma=["onClick"],Ta={key:0},Sa={class:"bg-gray-50 px-3 py-4",colspan:"7"},Ra={key:0,class:"py-4 text-center"},ja={class:"space-y-4"},Ea={class:"mb-4 flex items-center justify-between"},Pa={class:"flex items-center gap-2"},Va={key:0,class:"rounded-full bg-gray-100 px-2 py-1 text-xs text-gray-500"},Ua={class:"flex items-center gap-1"},qa={class:"flex gap-1 rounded bg-gray-100 p-1"},Ga=["onClick"],Oa={key:0,class:"py-8 text-center"},Wa={class:"mb-3 flex items-center justify-center gap-2"},Fa=["onClick"],za={key:1,class:"grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"},Ba={class:"mb-3 flex items-start justify-between"},Ha={class:"flex-1"},Na={class:"mb-1 block text-sm font-semibold text-gray-800"},Ya={class:"rounded-full bg-blue-50 px-2 py-1 text-xs text-gray-500"},Qa={class:"mb-3 space-y-2"},Ja={class:"flex items-center justify-between text-sm"},Xa={class:"font-semibold text-gray-900"},Za={class:"flex items-center justify-between text-sm"},er={class:"font-semibold text-green-600"},tr={class:"mt-2 border-t border-gray-100 pt-2"},sr={class:"flex items-center justify-between text-xs text-gray-500"},lr={class:"font-medium"},or={class:"flex items-center justify-between text-xs text-gray-500"},nr={class:"font-medium"},ir={key:0,class:"flex items-center justify-between text-xs text-purple-600"},ar={class:"font-medium"},rr={key:1,class:"flex items-center justify-between text-xs text-purple-600"},dr={class:"font-medium"},ur={class:"mt-3 h-2 w-full rounded-full bg-gray-200"},cr={class:"mt-1 text-right"},mr={class:"text-xs font-medium text-indigo-600"},pr={key:2,class:"mt-4 rounded-lg border border-indigo-100 bg-gradient-to-r from-indigo-50 to-purple-50 p-3"},xr={class:"flex items-center justify-between text-sm"},fr={class:"flex gap-4 text-xs"},gr={class:"text-gray-600"},yr={class:"font-semibold text-gray-800"},br={class:"text-gray-600"},vr={class:"font-semibold text-gray-800"},wr={key:3,class:"space-y-3 md:hidden"},hr={class:"mb-3 flex items-start justify-between"},$r={class:"flex items-center gap-3"},Ar={class:"text-sm font-semibold text-gray-900"},Cr={class:"mt-0.5 text-xs text-gray-500"},kr={class:"mb-3 space-y-1.5"},Kr={key:0,class:"flex flex-wrap items-center gap-1 text-xs"},Ir={class:"text-gray-600"},Dr={key:1,class:"flex flex-wrap items-center gap-1 text-xs"},_r={class:"text-gray-600"},Lr={key:2,class:"flex flex-wrap items-center gap-1 text-xs"},Mr={class:"text-gray-600"},Tr={key:3,class:"text-xs text-gray-500"},Sr={class:"mb-3 space-y-2"},Rr={class:"rounded-lg bg-gray-50 p-3"},jr={class:"mb-2 flex items-center justify-between"},Er=["onClick"],Pr={class:"grid grid-cols-2 gap-3"},Vr={class:"text-sm font-semibold text-gray-900"},Ur={class:"text-sm font-semibold text-green-600"},qr={class:"mt-2 flex items-center justify-between"},Gr={class:"text-xs font-medium text-gray-700"},Or={key:0,class:"space-y-1"},Wr={class:"flex items-center justify-between text-xs"},Fr={class:"text-gray-700"},zr={class:"h-2 w-full rounded-full bg-gray-200"},Br={class:"mb-3 text-xs text-gray-500"},Hr={class:"mb-1 flex justify-between"},Nr={class:"flex items-center justify-between"},Yr={class:"flex items-center gap-1"},Qr=["onClick"],Jr={key:0,class:"mb-3 flex flex-wrap gap-1"},Xr={class:"mt-3 flex gap-2 border-t border-gray-100 pt-3"},Zr=["onClick"],ed=["onClick"],td=["onClick"],sd=["onClick"],ld=["onClick"],od={key:4,class:"mt-4 flex flex-col items-center justify-between gap-4 sm:mt-6 sm:flex-row"},nd={class:"flex w-full flex-col items-center gap-3 sm:w-auto sm:flex-row"},id={class:"text-xs text-gray-600 sm:text-sm"},ad={class:"flex items-center gap-2"},rd=["value"],dd={class:"flex items-center gap-2"},ud=["disabled"],cd={class:"flex items-center gap-1"},md={key:1,class:"hidden px-2 text-gray-500 sm:inline"},pd=["onClick"],xd={key:2,class:"hidden px-2 text-gray-500 sm:inline"},fd=["disabled"],gd={__name:"ApiKeysView",setup(v){const H=Re(),u=M([]),P=M(!1),E=M("today"),h=M(""),C=M("asc"),F=M({}),I=M({}),O=M({}),j=M([new Date(2e3,1,1,0,0,0),new Date(2e3,2,1,23,59,59)]),y=M({claude:[],gemini:[],openai:[],claudeGroups:[],geminiGroups:[],openaiGroups:[]}),T=M(null),i=M(null),l=M(!1),Q=M(null),K=M(""),A=M([]),f=M(""),N=M([{value:"today",label:"今日",icon:"fa-clock"},{value:"7days",label:"最近7天",icon:"fa-calendar-week"},{value:"monthly",label:"本月",icon:"fa-calendar"},{value:"all",label:"全部时间",icon:"fa-infinity"}]),te=W(()=>{const n=[{value:"",label:"所有标签",icon:"fa-asterisk"}];return A.value.forEach(t=>{n.push({value:t,label:t,icon:"fa-tag"})}),n}),D=W(()=>K.value?u.value.filter(n=>n.tags&&n.tags.includes(K.value)).length:0),p=M(1),ie=M(10),R=[10,20,50,100],r=M(!1),m=M(!1),$=M(!1),L=M(!1),w=M(!1),o=M(null),x=M(null),q=M(null),ee=M([]),se=W(()=>{let n=u.value;if(K.value&&(n=u.value.filter(g=>g.tags&&g.tags.includes(K.value))),f.value){const g=f.value.toLowerCase().trim();n=n.filter(s=>s.name&&s.name.toLowerCase().includes(g))}return h.value?[...n].sort((g,s)=>{let S=g[h.value],z=s[h.value];return h.value==="status"?(S=g.isActive?1:0,z=s.isActive?1:0):h.value==="cost"?(S=parseFloat(Ee(g.usage).replace("$","")),z=parseFloat(Ee(s.usage).replace("$",""))):(h.value==="createdAt"||h.value==="expiresAt")&&(S=S?new Date(S).getTime():0,z=z?new Date(z).getTime():0),Sz?C.value==="asc"?1:-1:0}):n}),le=W(()=>{const n=se.value.length;return Math.ceil(n/ie.value)||0}),de=W(()=>{const n=[],t=p.value,g=le.value;if(g<=7)for(let s=1;s<=g;s++)n.push(s);else{let s=Math.max(1,t-2),S=Math.min(g,t+2);t<=3?S=5:t>=g-2&&(s=g-4);for(let z=s;z<=S;z++)n.push(z)}return n}),J=W(()=>{const n=(p.value-1)*ie.value,t=n+ie.value;return se.value.slice(n,t)}),ae=async()=>{try{const[n,t,g,s,S]=await Promise.all([B.get("/admin/claude-accounts"),B.get("/admin/claude-console-accounts"),B.get("/admin/gemini-accounts"),B.get("/admin/openai-accounts"),B.get("/admin/account-groups")]);if(n.success&&(y.value.claude=n.data||[]),t.success){const z=(t.data||[]).map(_=>({..._,platform:"claude-console"}));y.value.claude=[...y.value.claude,...z]}if(g.success&&(y.value.gemini=g.data||[]),s.success&&(y.value.openai=s.data||[]),S.success){const z=S.data||[];y.value.claudeGroups=z.filter(_=>_.platform==="claude"),y.value.geminiGroups=z.filter(_=>_.platform==="gemini"),y.value.openaiGroups=z.filter(_=>_.platform==="openai")}}catch(n){console.error("加载账户列表失败:",n)}},pe=async()=>{P.value=!0;try{const n=await B.get(`/admin/api-keys?timeRange=${E.value}`);if(n.success){u.value=n.data||[];const t=new Set;u.value.forEach(g=>{g.tags&&Array.isArray(g.tags)&&g.tags.forEach(s=>t.add(s))}),A.value=Array.from(t).sort()}}catch{G("加载 API Keys 失败","error")}finally{P.value=!1}},ve=n=>{h.value===n?C.value=C.value==="asc"?"desc":"asc":(h.value=n,C.value="asc")},je=n=>!n&&n!==0?"0":n.toLocaleString("zh-CN"),Ee=n=>!n||!n.total?"$0.0000":`$${(n.total.cost||0).toFixed(4)}`,_e=n=>{if(!n)return"未知账户";if(n.startsWith("group:")){const S=n.substring(6),z=y.value.claudeGroups.find(we=>we.id===S);if(z)return`分组-${z.name}`;const _=y.value.geminiGroups.find(we=>we.id===S);if(_)return`分组-${_.name}`;const re=y.value.openaiGroups.find(we=>we.id===S);return re?`分组-${re.name}`:`分组-${S.substring(0,8)}`}const t=y.value.claude.find(S=>S.id===n);if(t)return`${t.name}`;const g=y.value.gemini.find(S=>S.id===n);if(g)return`${g.name}`;const s=y.value.openai.find(S=>S.id===n);return s?`${s.name}`:`${n.substring(0,8)}`},Pe=n=>{if(n.claudeAccountId){const t=_e(n.claudeAccountId);if(n.claudeAccountId.startsWith("group:"))return t;const g=y.value.claude.find(s=>s.id===n.claudeAccountId);return g?g.accountType==="dedicated"?`🔒 专属-${t}`:t:`⚠️ ${t} (账户不存在)`}if(n.claudeConsoleAccountId){const t=y.value.claude.find(g=>g.id===n.claudeConsoleAccountId&&g.platform==="claude-console");return t?`Console-${t.name}`:"⚠️ Console账户不存在"}return""},Ve=n=>{if(n.geminiAccountId){const t=_e(n.geminiAccountId);if(n.geminiAccountId.startsWith("group:"))return t;const g=y.value.gemini.find(s=>s.id===n.geminiAccountId);return g?g.accountType==="dedicated"?`🔒 专属-${t}`:t:`⚠️ ${t} (账户不存在)`}return""},Ue=n=>{if(n.openaiAccountId){const t=_e(n.openaiAccountId);if(n.openaiAccountId.startsWith("group:"))return t;const g=y.value.openai.find(s=>s.id===n.openaiAccountId);return g?g.accountType==="dedicated"?`🔒 专属-${t}`:t:`⚠️ ${t} (账户不存在)`}return""},$e=n=>n?new Date(n)!n||$e(n)?!1:(new Date(n)-new Date)/(1e3*60*60*24)<=7,qe=n=>n?new Date(n).toLocaleDateString("zh-CN"):"",st=async n=>{F.value[n]?F.value[n]=!1:(F.value[n]=!0,O.value[n]||Oe(n),await Ce(n,!0))},Ce=async(n,t=!1)=>{if(!t&&I.value[n]&&I.value[n].length>0)return;const g=xe(n);try{let s=`/admin/api-keys/${n}/model-stats`;const S=new URLSearchParams;if(g.customStart&&g.customEnd)S.append("startDate",g.customStart),S.append("endDate",g.customEnd),S.append("period","custom");else{const _=g.preset==="today"||g.preset==="7days"?"daily":"monthly";S.append("period",_)}s+="?"+S.toString();const z=await B.get(s);z.success&&(I.value[n]=z.data||[])}catch{G("加载模型统计失败","error"),I.value[n]=[]}},Ge=(n,t)=>{const g=t.reduce((s,S)=>s+(S.allTokens||0),0);return g===0?0:Math.round(n/g*100)},lt=n=>n.formatted&&n.formatted.total?n.formatted.total:n.cost!==void 0?`$${n.cost.toFixed(6)}`:"$0.000000",Oe=n=>{const t=new Date,g=new Date(t);g.setDate(t.getDate()-6),O.value[n]={type:"preset",preset:"7days",customStart:g.toISOString().split("T")[0],customEnd:t.toISOString().split("T")[0],customRange:null,presetOptions:[{value:"today",label:"今日",days:1},{value:"7days",label:"7天",days:7},{value:"30days",label:"30天",days:30}]}},xe=n=>(O.value[n]||Oe(n),O.value[n]),We=(n,t)=>{const g=xe(t);g.type="preset",g.preset=n;const s=g.presetOptions.find(S=>S.value===n);if(s){const S=new Date,z=new Date(S);z.setDate(S.getDate()-(s.days-1)),g.customStart=z.toISOString().split("T")[0],g.customEnd=S.toISOString().split("T")[0];const _=re=>re.getFullYear()+"-"+String(re.getMonth()+1).padStart(2,"0")+"-"+String(re.getDate()).padStart(2,"0")+" 00:00:00";g.customRange=[_(z),_(S)]}Ce(t,!0)},ot=(n,t)=>{const g=xe(n);t&&t.length===2?(g.type="custom",g.preset="",g.customRange=t,g.customStart=t[0].split(" ")[0],g.customEnd=t[1].split(" ")[0],Ce(n,!0)):t===null&&We("7days",n)},nt=n=>n>new Date,it=n=>{const t=xe(n);t.type="preset",t.preset="7days";const g=new Date,s=new Date(g);s.setDate(g.getDate()-6),t.customStart=s.toISOString().split("T")[0],t.customEnd=g.toISOString().split("T")[0],t.customRange=null,Ce(n,!0),G("已重置筛选条件并刷新数据","info")},at=async()=>{await ae(),r.value=!0},Fe=async n=>{await ae(),o.value=n,m.value=!0},ze=n=>{x.value=n,$.value=!0},rt=n=>{r.value=!1,q.value=n,L.value=!0,pe()},dt=n=>{r.value=!1,ee.value=n,w.value=!0,pe()},ut=()=>{m.value=!1,G("API Key 更新成功","success"),pe()},ct=()=>{$.value=!1,G("API Key 续期成功","success"),pe()},Be=async n=>{let t=!0;if(n.isActive&&(window.showConfirm?t=await window.showConfirm("禁用 API Key",`确定要禁用 API Key "${n.name}" 吗?禁用后所有使用此 Key 的请求将返回 401 错误。`,"确定禁用","取消"):t=confirm(`确定要禁用 API Key "${n.name}" 吗?禁用后所有使用此 Key 的请求将返回 401 错误。`)),!!t)try{const g=await B.put(`/admin/api-keys/${n.id}`,{isActive:!n.isActive});if(g.success){G(`API Key 已${n.isActive?"禁用":"激活"}`,"success");const s=u.value.find(S=>S.id===n.id);s&&(s.isActive=!n.isActive)}else G(g.message||"操作失败","error")}catch{G("操作失败","error")}},He=async n=>{let t=!1;if(window.showConfirm?t=await window.showConfirm("删除 API Key","确定要删除这个 API Key 吗?此操作不可恢复。","确定删除","取消"):t=confirm("确定要删除这个 API Key 吗?此操作不可恢复。"),!!t)try{const g=await B.delete(`/admin/api-keys/${n}`);g.success?(G("API Key 已删除","success"),pe()):G(g.message||"删除失败","error")}catch{G("删除失败","error")}},mt=n=>{const g=`${window.location.origin}/admin-next/api-stats?apiId=${n.id}`,s=document.createElement("textarea");s.value=g,s.style.position="fixed",s.style.opacity="0",s.style.left="-9999px",document.body.appendChild(s),s.select(),s.setSelectionRange(0,99999);try{document.execCommand("copy")?G("已复制统计页面链接","success"):(G("复制失败,请手动复制","error"),console.log("统计页面链接:",g))}catch(S){G("复制失败,请手动复制","error"),console.error("复制错误:",S),console.log("统计页面链接:",g)}finally{document.body.removeChild(s)}},Ne=n=>{T.value=n},Ye=()=>{T.value=null},pt=async({keyId:n,expiresAt:t})=>{try{const g=await B.put(`/admin/api-keys/${n}`,{expiresAt:t||null});if(g.success){G("过期时间已更新","success");const s=u.value.find(S=>S.id===n);s&&(s.expiresAt=t||null),Ye()}else G(g.message||"更新失败","error"),i.value&&i.value.resetSaving()}catch{G("更新失败","error"),i.value&&i.value.resetSaving()}},Qe=n=>n?new Date(n).toLocaleDateString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).replace(/\//g,"-"):"",Le=n=>{if(!n.dailyCostLimit||n.dailyCostLimit===0)return 0;const t=(n.dailyCost||0)/n.dailyCostLimit*100;return Math.min(t,100)},Je=n=>{const t=Le(n);return t>=100?"bg-red-500":t>=80?"bg-yellow-500":"bg-green-500"},Me=n=>{Q.value=n,l.value=!0},ye=n=>n>=1e6?(n/1e6).toFixed(1)+"M":n>=1e3?(n/1e3).toFixed(1)+"K":n.toString(),Xe=n=>{if(!n)return"从未使用";const t=new Date(n),s=new Date-t;return s<6e4?"刚刚":s<36e5?`${Math.floor(s/6e4)} 分钟前`:s<864e5?`${Math.floor(s/36e5)} 小时前`:s<6048e5?`${Math.floor(s/864e5)} 天前`:t.toLocaleDateString("zh-CN")},xt=()=>{f.value="",p.value=1};return ke([K,E,f],()=>{p.value=1}),Ie(async()=>{await Promise.all([H.loadSupportedClients(),ae(),pe()])}),(n,t)=>{const g=ft;return a(),d("div",ci,[e("div",mi,[e("div",pi,[t[32]||(t[32]=e("div",null,[e("h3",{class:"mb-1 text-lg font-bold text-gray-900 sm:mb-2 sm:text-xl"},"API Keys 管理"),e("p",{class:"text-sm text-gray-600 sm:text-base"},"管理和监控您的 API 密钥")],-1)),e("div",xi,[e("div",fi,[e("div",gi,[t[24]||(t[24]=e("div",{class:"absolute -inset-0.5 rounded-lg bg-gradient-to-r from-blue-500 to-purple-500 opacity-0 blur transition duration-300 group-hover:opacity-20"},null,-1)),ne(Ze,{modelValue:E.value,"onUpdate:modelValue":t[0]||(t[0]=s=>E.value=s),icon:"fa-calendar-alt","icon-color":"text-blue-500",options:N.value,placeholder:"选择时间范围",onChange:t[1]||(t[1]=s=>pe())},null,8,["modelValue","options"])]),e("div",yi,[t[25]||(t[25]=e("div",{class:"absolute -inset-0.5 rounded-lg bg-gradient-to-r from-purple-500 to-pink-500 opacity-0 blur transition duration-300 group-hover:opacity-20"},null,-1)),e("div",bi,[ne(Ze,{modelValue:K.value,"onUpdate:modelValue":t[2]||(t[2]=s=>K.value=s),icon:"fa-tags","icon-color":"text-purple-500",options:te.value,placeholder:"所有标签",onChange:t[3]||(t[3]=s=>p.value=1)},null,8,["modelValue","options"]),K.value?(a(),d("span",vi,c(D.value),1)):b("",!0)])]),e("div",wi,[t[28]||(t[28]=e("div",{class:"absolute -inset-0.5 rounded-lg bg-gradient-to-r from-cyan-500 to-teal-500 opacity-0 blur transition duration-300 group-hover:opacity-20"},null,-1)),e("div",hi,[V(e("input",{"onUpdate:modelValue":t[4]||(t[4]=s=>f.value=s),class:"w-full rounded-lg border border-gray-200 bg-white px-3 py-2 pl-9 text-sm text-gray-700 placeholder-gray-400 shadow-sm transition-all duration-200 hover:border-gray-300 focus:border-cyan-500 focus:outline-none focus:ring-2 focus:ring-cyan-500/20",placeholder:"搜索名称...",type:"text",onInput:t[5]||(t[5]=s=>p.value=1)},null,544),[[X,f.value]]),t[27]||(t[27]=e("i",{class:"fas fa-search absolute left-3 text-sm text-cyan-500"},null,-1)),f.value?(a(),d("button",{key:0,class:"absolute right-2 flex h-5 w-5 items-center justify-center rounded-full text-gray-400 hover:bg-gray-100 hover:text-gray-600",onClick:xt},t[26]||(t[26]=[e("i",{class:"fas fa-times text-xs"},null,-1)]))):b("",!0)])]),e("button",{class:"group relative flex items-center justify-center gap-2 rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm transition-all duration-200 hover:border-gray-300 hover:shadow-md disabled:cursor-not-allowed disabled:opacity-50 sm:w-auto",disabled:P.value,onClick:t[6]||(t[6]=s=>pe())},[t[29]||(t[29]=e("div",{class:"absolute -inset-0.5 rounded-lg bg-gradient-to-r from-green-500 to-teal-500 opacity-0 blur transition duration-300 group-hover:opacity-20"},null,-1)),e("i",{class:U(["fas relative text-green-500",P.value?"fa-spinner fa-spin":"fa-sync-alt"])},null,2),t[30]||(t[30]=e("span",{class:"relative"},"刷新",-1))],8,$i)]),e("button",{class:"flex w-full items-center justify-center gap-2 rounded-lg bg-gradient-to-r from-blue-500 to-blue-600 px-5 py-2.5 text-sm font-medium text-white shadow-md transition-all duration-200 hover:from-blue-600 hover:to-blue-700 hover:shadow-lg sm:w-auto",onClick:ce(at,["stop"])},t[31]||(t[31]=[e("i",{class:"fas fa-plus"},null,-1),e("span",null,"创建新 Key",-1)]))])]),P.value?(a(),d("div",Ai,t[33]||(t[33]=[e("div",{class:"loading-spinner mx-auto mb-4"},null,-1),e("p",{class:"text-gray-500"},"正在加载 API Keys...",-1)]))):u.value.length===0?(a(),d("div",Ci,t[34]||(t[34]=[e("div",{class:"mx-auto mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-gray-100"},[e("i",{class:"fas fa-key text-xl text-gray-400"})],-1),e("p",{class:"text-lg text-gray-500"},"暂无 API Keys",-1),e("p",{class:"mt-2 text-sm text-gray-400"},"点击上方按钮创建您的第一个 API Key",-1)]))):(a(),d("div",ki,[e("table",Ki,[e("thead",Ii,[e("tr",null,[e("th",{class:"w-[25%] min-w-[200px] cursor-pointer px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 hover:bg-gray-100",onClick:t[7]||(t[7]=s=>ve("name"))},[t[35]||(t[35]=k(" 名称 ",-1)),h.value==="name"?(a(),d("i",{key:0,class:U(["fas",C.value==="asc"?"fa-sort-up":"fa-sort-down","ml-1"])},null,2)):(a(),d("i",Di))]),t[42]||(t[42]=e("th",{class:"w-[10%] min-w-[80px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700"}," 标签 ",-1)),e("th",{class:"w-[8%] min-w-[70px] cursor-pointer px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 hover:bg-gray-100",onClick:t[8]||(t[8]=s=>ve("status"))},[t[36]||(t[36]=k(" 状态 ",-1)),h.value==="status"?(a(),d("i",{key:0,class:U(["fas",C.value==="asc"?"fa-sort-up":"fa-sort-down","ml-1"])},null,2)):(a(),d("i",_i))]),e("th",Li,[t[39]||(t[39]=k(" 使用统计 ",-1)),e("span",{class:"cursor-pointer rounded px-2 py-1 hover:bg-gray-100",onClick:t[9]||(t[9]=s=>ve("cost"))},[t[37]||(t[37]=k(" (费用 ",-1)),h.value==="cost"?(a(),d("i",{key:0,class:U(["fas",C.value==="asc"?"fa-sort-up":"fa-sort-down","ml-1"])},null,2)):(a(),d("i",Mi)),t[38]||(t[38]=k(") ",-1))])]),e("th",{class:"w-[10%] min-w-[90px] cursor-pointer px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 hover:bg-gray-100",onClick:t[10]||(t[10]=s=>ve("createdAt"))},[t[40]||(t[40]=k(" 创建时间 ",-1)),h.value==="createdAt"?(a(),d("i",{key:0,class:U(["fas",C.value==="asc"?"fa-sort-up":"fa-sort-down","ml-1"])},null,2)):(a(),d("i",Ti))]),e("th",{class:"w-[10%] min-w-[90px] cursor-pointer px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700 hover:bg-gray-100",onClick:t[11]||(t[11]=s=>ve("expiresAt"))},[t[41]||(t[41]=k(" 过期时间 ",-1)),h.value==="expiresAt"?(a(),d("i",{key:0,class:U(["fas",C.value==="asc"?"fa-sort-up":"fa-sort-down","ml-1"])},null,2)):(a(),d("i",Si))]),t[43]||(t[43]=e("th",{class:"w-[20%] min-w-[180px] px-3 py-4 text-left text-xs font-bold uppercase tracking-wider text-gray-700"}," 操作 ",-1))])]),e("tbody",Ri,[(a(!0),d(Y,null,Z(J.value,s=>{var S,z;return a(),d(Y,{key:s.id},[e("tr",ji,[e("td",Ei,[e("div",Pi,[t[48]||(t[48]=e("div",{class:"mr-2 flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500 to-blue-600"},[e("i",{class:"fas fa-key text-xs text-white"})],-1)),e("div",Vi,[e("div",{class:"truncate text-sm font-semibold text-gray-900",title:s.name},c(s.name),9,Ui),e("div",{class:"truncate text-xs text-gray-500",title:s.id},c(s.id),9,qi),e("div",Gi,[s.claudeAccountId||s.claudeConsoleAccountId?(a(),d("div",Oi,[t[44]||(t[44]=e("span",{class:"inline-flex items-center rounded bg-indigo-100 px-1.5 py-0.5 text-indigo-700"},[e("i",{class:"fas fa-brain mr-1 text-[10px]"}),k(" Claude ")],-1)),e("span",Wi,c(Pe(s)),1)])):b("",!0),s.geminiAccountId?(a(),d("div",Fi,[t[45]||(t[45]=e("span",{class:"inline-flex items-center rounded bg-yellow-100 px-1.5 py-0.5 text-yellow-700"},[e("i",{class:"fas fa-robot mr-1 text-[10px]"}),k(" Gemini ")],-1)),e("span",zi,c(Ve(s)),1)])):b("",!0),s.openaiAccountId?(a(),d("div",Bi,[t[46]||(t[46]=e("span",{class:"inline-flex items-center rounded bg-gray-100 px-1.5 py-0.5 text-gray-700"},[e("i",{class:"fa-openai mr-1 text-[10px]"}),k(" OpenAI ")],-1)),e("span",Hi,c(Ue(s)),1)])):b("",!0),!s.claudeAccountId&&!s.claudeConsoleAccountId&&!s.geminiAccountId&&!s.openaiAccountId?(a(),d("div",Ni,t[47]||(t[47]=[e("i",{class:"fas fa-share-alt mr-1"},null,-1),k(" 使用共享池 ",-1)]))):b("",!0)])])])]),e("td",Yi,[e("div",Qi,[(a(!0),d(Y,null,Z(s.tags||[],_=>(a(),d("span",{key:_,class:"inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-xs text-blue-800"},c(_),1))),128)),!s.tags||s.tags.length===0?(a(),d("span",Ji,"无标签")):b("",!0)])]),e("td",Xi,[e("span",{class:U(["inline-flex items-center rounded-full px-3 py-1 text-xs font-semibold",s.isActive?"bg-green-100 text-green-800":"bg-red-100 text-red-800"])},[e("div",{class:U(["mr-2 h-2 w-2 rounded-full",s.isActive?"bg-green-500":"bg-red-500"])},null,2),k(" "+c(s.isActive?"活跃":"禁用"),1)],2)]),e("td",Zi,[e("div",ea,[e("div",ta,[e("div",sa,[t[49]||(t[49]=e("span",{class:"text-gray-600"},"今日请求",-1)),e("span",la,c(je(((z=(S=s.usage)==null?void 0:S.daily)==null?void 0:z.requests)||0))+"次",1)]),e("div",oa,[t[50]||(t[50]=e("span",{class:"text-gray-600"},"今日费用",-1)),e("span",na,"$"+c((s.dailyCost||0).toFixed(4)),1)]),e("div",ia,[t[51]||(t[51]=e("span",{class:"text-gray-600"},"最后使用",-1)),e("span",aa,c(Xe(s.lastUsedAt)),1)])]),s.dailyCostLimit>0?(a(),d("div",ra,[e("div",da,[t[52]||(t[52]=e("span",{class:"text-gray-500"},"费用限额",-1)),e("span",ua," $"+c((s.dailyCost||0).toFixed(2))+" / $"+c(s.dailyCostLimit.toFixed(2)),1)]),e("div",ca,[e("div",{class:U(["h-1.5 rounded-full transition-all duration-300",Je(s)]),style:he({width:Le(s)+"%"})},null,6)])])):b("",!0),s.rateLimitWindow>0?(a(),oe(Te,{key:1,"current-requests":s.currentWindowRequests,"current-tokens":s.currentWindowTokens,"rate-limit-window":s.rateLimitWindow,"request-limit":s.rateLimitRequests,"show-progress":!0,"show-tooltip":!1,"token-limit":s.tokenLimit,"window-end-time":s.windowEndTime,"window-remaining-seconds":s.windowRemainingSeconds,"window-start-time":s.windowStartTime},null,8,["current-requests","current-tokens","rate-limit-window","request-limit","token-limit","window-end-time","window-remaining-seconds","window-start-time"])):b("",!0),e("div",ma,[e("button",{class:"flex w-full items-center justify-center gap-1 rounded py-1 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-50 hover:text-blue-800",onClick:_=>Me(s)},t[53]||(t[53]=[e("i",{class:"fas fa-chart-line"},null,-1),k(" 查看详细统计 ",-1)]),8,pa)])])]),e("td",xa,c(new Date(s.createdAt).toLocaleDateString()),1),e("td",fa,[e("div",ga,[s.expiresAt?(a(),d("span",ya,[$e(s.expiresAt)?(a(),d("span",ba,t[54]||(t[54]=[e("i",{class:"fas fa-exclamation-circle mr-1"},null,-1),k(" 已过期 ",-1)]))):Ae(s.expiresAt)?(a(),d("span",va,[t[55]||(t[55]=e("i",{class:"fas fa-clock mr-1"},null,-1)),k(" "+c(qe(s.expiresAt)),1)])):(a(),d("span",wa,c(qe(s.expiresAt)),1))])):(a(),d("span",ha,t[56]||(t[56]=[e("i",{class:"fas fa-infinity mr-1"},null,-1),k(" 永不过期 ",-1)]))),e("button",{class:"inline-flex h-6 w-6 items-center justify-center rounded-md text-gray-300 transition-all duration-200 hover:bg-blue-50 hover:text-blue-500",title:"编辑过期时间",onClick:ce(_=>Ne(s),["stop"])},t[57]||(t[57]=[e("svg",{class:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)]),8,$a)])]),e("td",Aa,[e("div",Ca,[s&&s.id?(a(),d("button",{key:0,class:"rounded px-2 py-1 text-xs font-medium text-indigo-600 transition-colors hover:bg-indigo-50 hover:text-indigo-900",title:"模型使用分布",onClick:_=>st(s.id)},[e("i",{class:U(["fas",F.value[s.id]?"fa-chevron-up":"fa-chevron-down"])},null,2),t[58]||(t[58]=e("span",{class:"ml-1 hidden xl:inline"},"模型",-1))],8,ka)):b("",!0),e("button",{class:"rounded px-2 py-1 text-xs font-medium text-purple-600 transition-colors hover:bg-purple-50 hover:text-purple-900",title:"复制统计页面链接",onClick:_=>mt(s)},t[59]||(t[59]=[e("i",{class:"fas fa-chart-bar"},null,-1),e("span",{class:"ml-1 hidden xl:inline"},"统计",-1)]),8,Ka),e("button",{class:"rounded px-2 py-1 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-50 hover:text-blue-900",title:"编辑",onClick:_=>Fe(s)},t[60]||(t[60]=[e("i",{class:"fas fa-edit"},null,-1),e("span",{class:"ml-1 hidden xl:inline"},"编辑",-1)]),8,Ia),s.expiresAt&&($e(s.expiresAt)||Ae(s.expiresAt))?(a(),d("button",{key:1,class:"rounded px-2 py-1 text-xs font-medium text-green-600 transition-colors hover:bg-green-50 hover:text-green-900",title:"续期",onClick:_=>ze(s)},t[61]||(t[61]=[e("i",{class:"fas fa-clock"},null,-1),e("span",{class:"ml-1 hidden xl:inline"},"续期",-1)]),8,Da)):b("",!0),e("button",{class:U([s.isActive?"text-orange-600 hover:bg-orange-50 hover:text-orange-900":"text-green-600 hover:bg-green-50 hover:text-green-900","rounded px-2 py-1 text-xs font-medium transition-colors"]),title:s.isActive?"禁用":"激活",onClick:_=>Be(s)},[e("i",{class:U(["fas",s.isActive?"fa-ban":"fa-check-circle"])},null,2),e("span",La,c(s.isActive?"禁用":"激活"),1)],10,_a),e("button",{class:"rounded px-2 py-1 text-xs font-medium text-red-600 transition-colors hover:bg-red-50 hover:text-red-900",title:"删除",onClick:_=>He(s.id)},t[62]||(t[62]=[e("i",{class:"fas fa-trash"},null,-1),e("span",{class:"ml-1 hidden xl:inline"},"删除",-1)]),8,Ma)])])]),s&&s.id&&F.value[s.id]?(a(),d("tr",Ta,[e("td",Sa,[I.value[s.id]?b("",!0):(a(),d("div",Ra,t[63]||(t[63]=[e("div",{class:"loading-spinner mx-auto"},null,-1),e("p",{class:"mt-2 text-sm text-gray-500"},"加载模型统计...",-1)]))),e("div",ja,[e("div",Ea,[t[64]||(t[64]=e("h5",{class:"flex items-center text-sm font-semibold text-gray-700"},[e("i",{class:"fas fa-chart-pie mr-2 text-indigo-500"}),k(" 模型使用分布 ")],-1)),e("div",Pa,[I.value[s.id]&&I.value[s.id].length>0?(a(),d("span",Va,c(I.value[s.id].length)+" 个模型 ",1)):b("",!0),e("div",Ua,[e("div",qa,[(a(!0),d(Y,null,Z(xe(s.id).presetOptions,_=>(a(),d("button",{key:_.value,class:U(["rounded px-2 py-1 text-xs font-medium transition-colors",xe(s.id).preset===_.value&&xe(s.id).type==="preset"?"bg-white text-blue-600 shadow-sm":"text-gray-600 hover:text-gray-900"]),onClick:re=>We(_.value,s.id)},c(_.label),11,Ga))),128))]),ne(g,{class:"api-key-date-picker",clearable:!0,"default-time":j.value,"disabled-date":nt,"end-placeholder":"结束日期",format:"YYYY-MM-DD HH:mm:ss","model-value":xe(s.id).customRange,"range-separator":"至",size:"small","start-placeholder":"开始日期",style:{width:"280px"},type:"datetimerange","unlink-panels":!1,"value-format":"YYYY-MM-DD HH:mm:ss","onUpdate:modelValue":_=>ot(s.id,_)},null,8,["default-time","model-value","onUpdate:modelValue"])])])]),I.value[s.id]&&I.value[s.id].length===0?(a(),d("div",Oa,[e("div",Wa,[t[66]||(t[66]=e("i",{class:"fas fa-chart-line text-lg text-gray-400"},null,-1)),t[67]||(t[67]=e("p",{class:"text-sm text-gray-500"},"暂无模型使用数据",-1)),e("button",{class:"ml-2 flex items-center gap-1 text-sm text-blue-500 transition-colors hover:text-blue-700",title:"重置筛选条件并刷新",onClick:_=>it(s.id)},t[65]||(t[65]=[e("i",{class:"fas fa-sync-alt text-xs"},null,-1),e("span",{class:"text-xs"},"刷新",-1)]),8,Fa)]),t[68]||(t[68]=e("p",{class:"text-xs text-gray-400"},"尝试调整时间范围或点击刷新重新加载数据",-1))])):I.value[s.id]&&I.value[s.id].length>0?(a(),d("div",za,[(a(!0),d(Y,null,Z(I.value[s.id],_=>(a(),d("div",{key:_.model,class:"rounded-xl border border-gray-200 bg-gradient-to-br from-white to-gray-50 p-4 transition-all duration-200 hover:border-indigo-300 hover:shadow-lg"},[e("div",Ba,[e("div",Ha,[e("span",Na,c(_.model),1),e("span",Ya,c(_.requests)+" 次请求",1)])]),e("div",Qa,[e("div",Ja,[t[69]||(t[69]=e("span",{class:"flex items-center text-gray-600"},[e("i",{class:"fas fa-coins mr-1 text-xs text-yellow-500"}),k(" 总Token: ")],-1)),e("span",Xa,c(ye(_.allTokens)),1)]),e("div",Za,[t[70]||(t[70]=e("span",{class:"flex items-center text-gray-600"},[e("i",{class:"fas fa-dollar-sign mr-1 text-xs text-green-500"}),k(" 费用: ")],-1)),e("span",er,c(lt(_)),1)]),e("div",tr,[e("div",sr,[t[71]||(t[71]=e("span",{class:"flex items-center"},[e("i",{class:"fas fa-arrow-down mr-1 text-green-500"}),k(" 输入: ")],-1)),e("span",lr,c(ye(_.inputTokens)),1)]),e("div",or,[t[72]||(t[72]=e("span",{class:"flex items-center"},[e("i",{class:"fas fa-arrow-up mr-1 text-blue-500"}),k(" 输出: ")],-1)),e("span",nr,c(ye(_.outputTokens)),1)]),_.cacheCreateTokens>0?(a(),d("div",ir,[t[73]||(t[73]=e("span",{class:"flex items-center"},[e("i",{class:"fas fa-save mr-1"}),k(" 缓存创建: ")],-1)),e("span",ar,c(ye(_.cacheCreateTokens)),1)])):b("",!0),_.cacheReadTokens>0?(a(),d("div",rr,[t[74]||(t[74]=e("span",{class:"flex items-center"},[e("i",{class:"fas fa-download mr-1"}),k(" 缓存读取: ")],-1)),e("span",dr,c(ye(_.cacheReadTokens)),1)])):b("",!0)])]),e("div",ur,[e("div",{class:"h-2 rounded-full bg-gradient-to-r from-indigo-500 to-purple-600 transition-all duration-500",style:he({width:Ge(_.allTokens,I.value[s.id])+"%"})},null,4)]),e("div",cr,[e("span",mr,c(Ge(_.allTokens,I.value[s.id]))+"% ",1)])]))),128))])):b("",!0),I.value[s.id]&&I.value[s.id].length>0?(a(),d("div",pr,[e("div",xr,[t[77]||(t[77]=e("span",{class:"flex items-center font-semibold text-gray-700"},[e("i",{class:"fas fa-calculator mr-2 text-indigo-500"}),k(" 总计统计 ")],-1)),e("div",fr,[e("span",gr,[t[75]||(t[75]=k(" 总请求: ",-1)),e("span",yr,c(I.value[s.id].reduce((_,re)=>_+re.requests,0)),1)]),e("span",br,[t[76]||(t[76]=k(" 总Token: ",-1)),e("span",vr,c(ye(I.value[s.id].reduce((_,re)=>_+re.allTokens,0))),1)])])])])):b("",!0)])])])):b("",!0)],64)}),128))])])])),!P.value&&se.value.length>0?(a(),d("div",wr,[(a(!0),d(Y,null,Z(J.value,s=>{var S,z;return a(),d("div",{key:s.id,class:"card p-4 transition-shadow hover:shadow-lg"},[e("div",hr,[e("div",$r,[t[78]||(t[78]=e("div",{class:"flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-blue-500 to-blue-600"},[e("i",{class:"fas fa-key text-sm text-white"})],-1)),e("div",null,[e("h4",Ar,c(s.name),1),e("p",Cr,c(s.id),1)])]),e("span",{class:U(["inline-flex items-center rounded-full px-2 py-1 text-xs font-semibold",s.isActive?"bg-green-100 text-green-800":"bg-red-100 text-red-800"])},[e("div",{class:U(["mr-1.5 h-1.5 w-1.5 rounded-full",s.isActive?"bg-green-500":"bg-red-500"])},null,2),k(" "+c(s.isActive?"活跃":"已停用"),1)],2)]),e("div",kr,[s.claudeAccountId||s.claudeConsoleAccountId?(a(),d("div",Kr,[t[79]||(t[79]=e("span",{class:"inline-flex items-center rounded bg-indigo-100 px-2 py-0.5 text-indigo-700"},[e("i",{class:"fas fa-brain mr-1"}),k(" Claude ")],-1)),e("span",Ir,c(Pe(s)),1)])):b("",!0),s.geminiAccountId?(a(),d("div",Dr,[t[80]||(t[80]=e("span",{class:"inline-flex items-center rounded bg-yellow-100 px-2 py-0.5 text-yellow-700"},[e("i",{class:"fas fa-robot mr-1"}),k(" Gemini ")],-1)),e("span",_r,c(Ve(s)),1)])):b("",!0),s.openaiAccountId?(a(),d("div",Lr,[t[81]||(t[81]=e("span",{class:"inline-flex items-center rounded bg-gray-100 px-2 py-0.5 text-gray-700"},[e("i",{class:"fa-openai mr-1"}),k(" OpenAI ")],-1)),e("span",Mr,c(Ue(s)),1)])):b("",!0),!s.claudeAccountId&&!s.claudeConsoleAccountId&&!s.geminiAccountId&&!s.openaiAccountId?(a(),d("div",Tr,t[82]||(t[82]=[e("i",{class:"fas fa-share-alt mr-1"},null,-1),k(" 使用共享池 ",-1)]))):b("",!0)]),e("div",Sr,[e("div",Rr,[e("div",jr,[t[84]||(t[84]=e("span",{class:"text-xs text-gray-600"},"今日使用",-1)),e("button",{class:"text-xs text-blue-600 hover:text-blue-800",onClick:_=>Me(s)},t[83]||(t[83]=[e("i",{class:"fas fa-chart-line mr-1"},null,-1),k("详情 ",-1)]),8,Er)]),e("div",Pr,[e("div",null,[e("p",Vr,c(je(((z=(S=s.usage)==null?void 0:S.daily)==null?void 0:z.requests)||0))+" 次 ",1),t[85]||(t[85]=e("p",{class:"text-xs text-gray-500"},"请求",-1))]),e("div",null,[e("p",Ur," $"+c((s.dailyCost||0).toFixed(4)),1),t[86]||(t[86]=e("p",{class:"text-xs text-gray-500"},"费用",-1))])]),e("div",qr,[t[87]||(t[87]=e("span",{class:"text-xs text-gray-600"},"最后使用",-1)),e("span",Gr,c(Xe(s.lastUsedAt)),1)])]),s.dailyCostLimit>0?(a(),d("div",Or,[e("div",Wr,[t[88]||(t[88]=e("span",{class:"text-gray-500"},"每日费用限额",-1)),e("span",Fr," $"+c((s.dailyCost||0).toFixed(2))+" / $"+c(s.dailyCostLimit.toFixed(2)),1)]),e("div",zr,[e("div",{class:U(["h-2 rounded-full transition-all duration-300",Je(s)]),style:he({width:Le(s)+"%"})},null,6)])])):b("",!0),s.rateLimitWindow>0&&(s.rateLimitRequests>0||s.tokenLimit>0)?(a(),oe(Te,{key:1,"current-requests":s.currentWindowRequests,"current-tokens":s.currentWindowTokens,"rate-limit-window":s.rateLimitWindow,"request-limit":s.rateLimitRequests,"show-progress":!0,"show-tooltip":!1,"token-limit":s.tokenLimit,"window-end-time":s.windowEndTime,"window-remaining-seconds":s.windowRemainingSeconds,"window-start-time":s.windowStartTime},null,8,["current-requests","current-tokens","rate-limit-window","request-limit","token-limit","window-end-time","window-remaining-seconds","window-start-time"])):b("",!0)]),e("div",Br,[e("div",Hr,[t[89]||(t[89]=e("span",null,"创建时间",-1)),e("span",null,c(Qe(s.createdAt)),1)]),e("div",Nr,[t[91]||(t[91]=e("span",null,"过期时间",-1)),e("div",Yr,[e("span",{class:U(Ae(s.expiresAt)?"font-semibold text-orange-600":"")},c(s.expiresAt?Qe(s.expiresAt):"永不过期"),3),e("button",{class:"inline-flex h-5 w-5 items-center justify-center rounded text-gray-300 transition-all duration-200 hover:bg-blue-50 hover:text-blue-500",title:"编辑过期时间",onClick:ce(_=>Ne(s),["stop"])},t[90]||(t[90]=[e("svg",{class:"h-3 w-3",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2"})],-1)]),8,Qr)])])]),s.tags&&s.tags.length>0?(a(),d("div",Jr,[(a(!0),d(Y,null,Z(s.tags,_=>(a(),d("span",{key:_,class:"inline-flex items-center rounded-full bg-blue-100 px-2 py-0.5 text-xs text-blue-800"},c(_),1))),128))])):b("",!0),e("div",Xr,[e("button",{class:"flex flex-1 items-center justify-center gap-1 rounded-lg bg-blue-50 px-3 py-2 text-xs text-blue-600 transition-colors hover:bg-blue-100",onClick:_=>Me(s)},t[92]||(t[92]=[e("i",{class:"fas fa-chart-line"},null,-1),k(" 查看详情 ",-1)]),8,Zr),e("button",{class:"flex-1 rounded-lg bg-gray-50 px-3 py-2 text-xs text-gray-600 transition-colors hover:bg-gray-100",onClick:_=>Fe(s)},t[93]||(t[93]=[e("i",{class:"fas fa-edit mr-1"},null,-1),k(" 编辑 ",-1)]),8,ed),s.expiresAt&&($e(s.expiresAt)||Ae(s.expiresAt))?(a(),d("button",{key:0,class:"flex-1 rounded-lg bg-orange-50 px-3 py-2 text-xs text-orange-600 transition-colors hover:bg-orange-100",onClick:_=>ze(s)},t[94]||(t[94]=[e("i",{class:"fas fa-clock mr-1"},null,-1),k(" 续期 ",-1)]),8,td)):b("",!0),e("button",{class:U([s.isActive?"bg-orange-50 text-orange-600 hover:bg-orange-100":"bg-green-50 text-green-600 hover:bg-green-100","rounded-lg px-3 py-2 text-xs transition-colors"]),onClick:_=>Be(s)},[e("i",{class:U(["fas",s.isActive?"fa-ban":"fa-check-circle","mr-1"])},null,2),k(" "+c(s.isActive?"禁用":"激活"),1)],10,sd),e("button",{class:"rounded-lg bg-red-50 px-3 py-2 text-xs text-red-600 transition-colors hover:bg-red-100",onClick:_=>He(s.id)},t[95]||(t[95]=[e("i",{class:"fas fa-trash"},null,-1)]),8,ld)])])}),128))])):b("",!0),se.value.length>0?(a(),d("div",od,[e("div",nd,[e("span",id," 共 "+c(se.value.length)+" 条记录 ",1),e("div",ad,[t[96]||(t[96]=e("span",{class:"text-xs text-gray-600 sm:text-sm"},"每页显示",-1)),V(e("select",{"onUpdate:modelValue":t[12]||(t[12]=s=>ie.value=s),class:"rounded-md border border-gray-200 bg-white px-2 py-1 text-xs text-gray-700 transition-colors hover:border-gray-300 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-blue-500 sm:text-sm",onChange:t[13]||(t[13]=s=>p.value=1)},[(a(),d(Y,null,Z(R,s=>e("option",{key:s,value:s},c(s),9,rd)),64))],544),[[Se,ie.value]]),t[97]||(t[97]=e("span",{class:"text-xs text-gray-600 sm:text-sm"},"条",-1))])]),e("div",dd,[e("button",{class:"rounded-md border border-gray-300 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50 sm:py-1 sm:text-sm",disabled:p.value===1,onClick:t[14]||(t[14]=s=>p.value--)},t[98]||(t[98]=[e("i",{class:"fas fa-chevron-left"},null,-1)]),8,ud),e("div",cd,[p.value>3?(a(),d("button",{key:0,class:"hidden rounded-md border border-gray-300 bg-white px-3 py-1 text-sm font-medium text-gray-700 hover:bg-gray-50 sm:block",onClick:t[15]||(t[15]=s=>p.value=1)}," 1 ")):b("",!0),p.value>4?(a(),d("span",md,"...")):b("",!0),(a(!0),d(Y,null,Z(de.value,s=>(a(),d("button",{key:s,class:U(["rounded-md px-2 py-1 text-xs font-medium sm:px-3 sm:text-sm",s===p.value?"bg-blue-600 text-white":"border border-gray-300 bg-white text-gray-700 hover:bg-gray-50"]),onClick:S=>p.value=s},c(s),11,pd))),128)),p.value1&&p.valuep.value=le.value)},c(le.value),1)):b("",!0)]),e("button",{class:"rounded-md border border-gray-300 bg-white px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50 sm:py-1 sm:text-sm",disabled:p.value===le.value||le.value===0,onClick:t[17]||(t[17]=s=>p.value++)},t[99]||(t[99]=[e("i",{class:"fas fa-chevron-right"},null,-1)]),8,fd)])])):b("",!0)]),r.value?(a(),oe(Qs,{key:0,accounts:y.value,onBatchSuccess:dt,onClose:t[18]||(t[18]=s=>r.value=!1),onSuccess:rt},null,8,["accounts"])):b("",!0),m.value?(a(),oe(Hl,{key:1,accounts:y.value,"api-key":o.value,onClose:t[19]||(t[19]=s=>m.value=!1),onSuccess:ut},null,8,["accounts","api-key"])):b("",!0),$.value?(a(),oe(co,{key:2,"api-key":x.value,onClose:t[20]||(t[20]=s=>$.value=!1),onSuccess:ct},null,8,["api-key"])):b("",!0),L.value?(a(),oe(ko,{key:3,"api-key":q.value,onClose:t[21]||(t[21]=s=>L.value=!1)},null,8,["api-key"])):b("",!0),w.value?(a(),oe(Qo,{key:4,"api-keys":ee.value,onClose:t[22]||(t[22]=s=>w.value=!1)},null,8,["api-keys"])):b("",!0),ne(wn,{ref_key:"expiryEditModalRef",ref:i,"api-key":T.value||{id:null,expiresAt:null,name:""},show:!!T.value,onClose:Ye,onSave:pt},null,8,["api-key","show"]),ne(ui,{"api-key":Q.value||{},show:l.value,onClose:t[23]||(t[23]=s=>l.value=!1)},null,8,["api-key","show"])])}}},Cd=me(gd,[["__scopeId","data-v-99508535"]]);export{Cd as default};