@lightharu/krouter 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -113,7 +113,7 @@ email----password----refreshToken----clientId----clientSecret`:`JSON 格式:
113
113
  `):r.map(M=>`${M.email}${M.nickname?` (${M.nickname})`:""} - ${M.subscription?.title||"未知订阅"}`).join(`
114
114
  `);default:return""}},T=async()=>{const S=j(o),k=r.length;if(o==="clipboard"){await navigator.clipboard.writeText(S),p(!0),setTimeout(()=>{p(!1),s()},1500);return}const R={json:"json",oidc:"json",txt:"txt",csv:"csv",kami:"txt"},I=`kiro-accounts-${new Date().toISOString().slice(0,10)}.${R[o]}`;await window.api.exportToFile(S,I)&&(alert(v?`Exported ${k} accounts`:`已导出 ${k} 个账号`),s())};return Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:s}),e.jsxs("div",{className:"relative bg-background rounded-xl shadow-2xl w-[450px] animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ns,{className:"h-5 w-5"}),e.jsx("h2",{className:"text-lg font-semibold",children:v?"Export Accounts":"导出账号"}),e.jsx($e,{variant:"secondary",children:i>0?v?`${i} selected`:`${i} 个选中`:v?`All ${r.length}`:`全部 ${r.length} 个`})]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:s,children:e.jsx(ns,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 gap-3",children:N.map(S=>{const k=S.icon,R=o===S.id;return e.jsxs("button",{onClick:()=>d(S.id),className:me("p-4 rounded-lg border-2 text-left transition-all",R?"border-primary bg-primary/5":"border-muted hover:border-muted-foreground/30"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(k,{className:me("h-4 w-4",R&&"text-primary")}),e.jsx("span",{className:me("font-medium",R&&"text-primary"),children:S.name})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:S.desc})]},S.id)})}),o==="oidc"&&e.jsx("div",{className:"p-3 bg-muted rounded-lg",children:e.jsx("p",{className:"text-xs text-muted-foreground",children:v?"Minimal JSON array (email / password / refreshToken / clientId / clientSecret / provider). Paste directly into the OIDC batch import box.":"精简 JSON 数组,含 邮箱 / 密码 / RefreshToken / ClientId / ClientSecret / provider,可直接粘贴到「OIDC 批量添加」输入框。"})}),o==="kami"&&e.jsx("div",{className:"p-3 bg-muted rounded-lg",children:e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v?"Format: email----password----refreshToken----clientId----clientSecret":"格式:邮箱----密码----RefreshToken----ClientId----ClientSecret",e.jsx("br",{}),v?"One account per line, empty lines are ignored. Supports auto-detection of separators (----, spaces, tabs)":"每行一个账号,空行无效。导入时支持自动识别分隔符(----、空格、Tab)"]})}),o==="json"&&e.jsxs("label",{className:"flex items-center gap-2 p-3 bg-muted rounded-lg cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:u,onChange:S=>h(S.target.checked),className:"w-4 h-4 rounded"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:v?"Include credentials":"包含凭证信息"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:v?"Include sensitive data for full import":"包含 Token 等敏感数据,可用于完整导入"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-3 px-6 py-4 border-t bg-muted/30",children:[e.jsx(D,{variant:"outline",onClick:s,children:v?"Cancel":"取消"}),(o==="kami"||o==="oidc")&&e.jsx(D,{variant:"outline",disabled:f,onClick:async()=>{const S=j(o);await navigator.clipboard.writeText(S),p(!0),setTimeout(()=>{p(!1),s()},1500)},children:f?e.jsxs(e.Fragment,{children:[e.jsx(Pt,{className:"h-4 w-4 mr-2"}),v?"Copied":"已复制"]}):e.jsxs(e.Fragment,{children:[e.jsx(vf,{className:"h-4 w-4 mr-2"}),v?"Copy":"复制到剪贴板"]})}),e.jsx(D,{onClick:T,disabled:f,children:f?e.jsxs(e.Fragment,{children:[e.jsx(Pt,{className:"h-4 w-4 mr-2"}),v?"Copied":"已复制"]}):o==="clipboard"?e.jsxs(e.Fragment,{children:[e.jsx(vf,{className:"h-4 w-4 mr-2"}),v?"Copy":"复制到剪贴板"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),v?"Export":"导出"]})})]})]})]}),document.body)}function hI({onBack:n}){const{isLoading:s,accounts:r,importFromExportData:i,importAccounts:o,selectedIds:d,activeGroupTab:u,groups:h}=vt(),[f,p]=g.useState(!1),[y,b]=g.useState(null),[v,N]=g.useState(!1),[j,T]=g.useState(!1),[S,k]=g.useState(!1),[R,I]=g.useState(!1),[M,G]=g.useState(()=>localStorage.getItem("accounts_viewMode")==="list"?"list":"grid");g.useEffect(()=>{localStorage.setItem("accounts_viewMode",M)},[M]);const{t:W}=Ut(),U=W("common.unknown")==="Unknown",q=()=>{const te=Array.from(r.values());return d.size>0?te.filter(Y=>d.has(Y.id)):te},V=()=>{k(!0)},le=te=>{const Y=[];let P="",F=!1;for(let fe=0;fe<te.length;fe++){const pe=te[fe];pe==='"'?F&&te[fe+1]==='"'?(P+='"',fe++):F=!F:pe===","&&!F?(Y.push(P.trim()),P=""):P+=pe}return Y.push(P.trim()),Y},B=async()=>{const te=u!=="all"&&u!=="ungrouped"&&h.has(u)?u:void 0,Y=te?h.get(te)?.name??"未分组":"未分组",P=await window.api.importFromFile();if(!P)return;const{content:F,format:fe}=P;try{if(fe==="json"){const pe=JSON.parse(F);if(pe.version&&pe.accounts){const C=i(pe),z=C.errors.find(re=>re.id==="skipped"),X=z?`,${z.error}`:"";alert(`导入完成:成功 ${C.success} 个${X}`)}else alert("无效的 JSON 文件格式")}else if(fe==="csv"){const pe=F.split(`
115
115
  `).filter(X=>X.trim());if(pe.length<2){alert("CSV 文件为空或只有标题行");return}const C=pe.slice(1).map(X=>{const re=le(X);return{email:re[0]||"",nickname:re[1]||void 0,idp:re[2]||"Google",refreshToken:re[3]||"",clientId:re[4]||"",clientSecret:re[5]||"",region:re[6]||"us-east-1",groupId:te}}).filter(X=>X.email&&X.refreshToken);if(C.length===0){alert("未找到有效的账号数据(需要邮箱和 RefreshToken)");return}const z=o(C);alert(`导入完成:成功 ${z.success} 个,失败 ${z.failed} 个(分组:${Y})`)}else if(fe==="txt"){const pe=F.split(`
116
- `).filter(z=>z.trim()&&!z.startsWith("#"));if(pe.some(z=>z.includes("----"))){const z=pe.map(re=>{const xe=LN(re),Oe=xe[1]?.trim(),Ee=xe[3]?.trim()||void 0,Qe=xe[4]?.trim()||void 0,st=xe[5]?.trim()||(!Ee&&!Qe?"Google":"BuilderId");return{email:xe[0]?.trim()||"",password:Oe&&Oe!=="no_password"?Oe:void 0,refreshToken:xe[2]?.trim()||"",clientId:Ee,clientSecret:Qe,idp:st,groupId:te}}).filter(re=>re.email&&re.refreshToken);if(z.length===0){alert("未找到有效的卡密数据(格式:邮箱----密码----RefreshToken----ClientId----ClientSecret)");return}const X=o(z);alert(`卡密导入完成:成功 ${X.success} 个,失败 ${X.failed} 个(分组:${Y})`)}else{const z=pe.map(re=>{const xe=re.includes("|")?re.split("|"):re.split(",");return{email:xe[0]?.trim()||"",refreshToken:xe[1]?.trim()||"",nickname:xe[2]?.trim()||void 0,idp:xe[3]?.trim()||"Google",groupId:te}}).filter(re=>re.email&&re.refreshToken);if(z.length===0){alert("未找到有效的账号数据(格式:邮箱,RefreshToken 或 卡密格式:邮箱----密码----Token----ID----Secret)");return}const X=o(z);alert(`导入完成:成功 ${X.success} 个,失败 ${X.failed} 个(分组:${Y})`)}}else alert(`不支持的文件格式:${fe}`)}catch(pe){console.error("Import error:",pe),alert("解析导入文件失败")}},be=()=>{N(!0)},K=()=>{T(!0)},se=te=>{b(te)};return s?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(bt,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:"加载账号数据..."})]})}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("header",{className:"relative z-20 flex items-center justify-between gap-4 px-3 py-3 glass-toolbar",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[n&&e.jsx(D,{variant:"ghost",size:"icon",onClick:n,children:e.jsx(i3,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Fn,{className:"h-5 w-5 text-primary"})}),e.jsx("h1",{className:"text-lg font-semibold text-primary",children:U?"Accounts":"账户管理"})]})]}),e.jsx(lI,{onAddAccount:()=>p(!0),onImport:B,onExport:V,viewMode:M,onViewModeChange:G,onManageGroups:be,onManageTags:K,isFilterExpanded:R,onToggleFilter:()=>I(!R)})]}),e.jsx("div",{className:"flex-1 overflow-hidden flex flex-col px-3 py-3 gap-3",children:e.jsx("div",{className:"flex-1 overflow-hidden",children:M==="grid"?e.jsx(VE,{onAddAccount:()=>p(!0),onEditAccount:se}):e.jsx(eI,{onAddAccount:()=>p(!0),onEditAccount:se})})}),e.jsx(oI,{isOpen:f,onClose:()=>p(!1)}),e.jsx(cI,{open:!!y,onOpenChange:te=>!te&&b(null),account:y}),e.jsx(dI,{isOpen:v,onClose:()=>N(!1)}),e.jsx(uI,{isOpen:j,onClose:()=>T(!1)}),e.jsx(sw,{open:S,onClose:()=>k(!1),accounts:q(),selectedCount:d.size})]})}const Ac="data:image/svg+xml,%3csvg%20width='96'%20height='96'%20viewBox='0%200%2096%2096'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%20role='img'%20aria-label='Krouter'%3e%3crect%20x='8'%20y='8'%20width='80'%20height='80'%20rx='22'%20fill='%230B1220'/%3e%3cpath%20d='M28%2068V28h10v16.8L54.2%2028H67L49.8%2045.5%2068.5%2068H55.4L42.9%2052.7%2038%2057.7V68H28Z'%20fill='%23FFFFFF'/%3e%3cpath%20d='M63%2028h5v5h-5v-5Z'%20fill='%2322C55E'/%3e%3cpath%20d='M69%2034h5v5h-5v-5Z'%20fill='%2338BDF8'/%3e%3cpath%20d='M63%2040h5v5h-5v-5Z'%20fill='%23F59E0B'/%3e%3cpath%20d='M62.5%2032.5%2049.5%2045.5M68.5%2036.5%2052%2052M62.5%2042.5%2055.5%2056'%20stroke='%2394A3B8'%20stroke-width='2'%20stroke-linecap='round'/%3e%3ccircle%20cx='48'%20cy='48'%20r='5'%20fill='%2338BDF8'/%3e%3c/svg%3e",oa="Krouter",tj="LightHaru",Pf="https://github.com/LightHaru/Krouter",nw="Kiro account routing, quota balancing, and API proxy control from one web dashboard.",aw="Dashboard web cho tai khoan Kiro, can bang quota va Kiro API proxy.",mI=[{id:"home",labelKey:"nav.home",icon:xA},{id:"accounts",labelKey:"nav.accounts",icon:Fn},{id:"machineId",labelKey:"nav.machineId",icon:eo},{id:"kiroSettings",labelKey:"nav.kiroSettings",icon:Hi},{id:"proxy",labelKey:"nav.proxy",icon:Sc},{id:"kproxy",labelKey:"nav.kproxy",icon:Vn},{id:"proxyPool",labelKey:"nav.proxyPool",icon:Ki},{id:"register",labelKey:"nav.register",icon:zu},{id:"subscription",labelKey:"nav.subscription",icon:$a},{id:"webhooks",labelKey:"nav.webhooks",icon:kp},{id:"diagnose",labelKey:"nav.diagnose",icon:jx},{id:"configSync",labelKey:"nav.configSync",icon:zN},{id:"logs",labelKey:"nav.logs",icon:lM},{id:"settings",labelKey:"nav.settings",icon:Ap},{id:"about",labelKey:"nav.about",icon:Va}];function fI({currentPage:n,onPageChange:s,collapsed:r,onToggleCollapse:i}){const{t:o}=Ut(),[d,u]=g.useState(!1);g.useEffect(()=>{const f=window.matchMedia("(max-width: 767px)"),p=()=>u(f.matches);return p(),f.addEventListener("change",p),()=>f.removeEventListener("change",p)},[]);const h=r||d;return e.jsxs(za.aside,{initial:!1,animate:{width:d?"100%":r?64:224,height:d?64:"auto"},transition:{type:"spring",stiffness:320,damping:30},className:me("glass-sidebar flex overflow-hidden shrink-0",d?"rounded-2xl flex-row":"rounded-3xl flex-col"),children:[e.jsx("div",{className:me("flex items-center justify-center gap-2 overflow-hidden border-white/10 dark:border-white/5",d?"h-full w-14 px-2 border-r":"h-14 px-3 border-b"),children:e.jsx(fc,{mode:"wait",initial:!1,children:h?e.jsx(za.img,{src:Ac,alt:oa,initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},transition:{duration:.2},className:"h-10 w-10 object-contain"},"logo-small"):e.jsxs(za.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},exit:{opacity:0,x:-10},transition:{duration:.2},className:"flex items-center gap-2",children:[e.jsx("img",{src:Ac,alt:oa,className:"h-7 w-auto shrink-0"}),e.jsx("span",{className:"font-semibold text-foreground whitespace-nowrap text-sm",children:oa})]},"logo-full")})}),e.jsx("nav",{className:me("flex-1 overflow-auto",d?"h-full py-2 px-1 flex items-center gap-1 overflow-y-hidden":"py-3 px-2 space-y-1 overflow-y-auto"),children:mI.map(f=>{const p=f.icon,y=n===f.id,b=o(f.labelKey);return e.jsxs("button",{onClick:()=>s(f.id),className:me("group relative w-full flex items-center rounded-xl text-sm font-medium transition-all overflow-hidden focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",y?"text-primary-foreground shadow-[0_4px_16px_rgba(91,140,255,0.35)]":"text-muted-foreground hover:text-foreground hover:bg-white/40 dark:hover:bg-white/5",d?"w-10 h-10 justify-center p-2.5 shrink-0":h?"justify-center p-2.5":"gap-3 px-3 py-2.5"),title:h?b:void 0,children:[y&&e.jsx(za.span,{layoutId:"sidebar-active-pill",className:"absolute inset-0 rounded-xl",style:{background:"linear-gradient(135deg, var(--gradient-from), var(--gradient-to))"},transition:{type:"spring",stiffness:380,damping:32}}),e.jsx(p,{className:me("h-5 w-5 shrink-0 relative z-10",y?"text-white":"")}),e.jsx(fc,{initial:!1,children:!h&&e.jsx(za.span,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},exit:{opacity:0,x:-8},transition:{duration:.15},className:me("whitespace-nowrap relative z-10",y&&"text-white"),children:b},"label")})]},f.id)})}),!d&&e.jsx("div",{className:"p-2 border-t border-white/10 dark:border-white/5",children:e.jsxs("button",{onClick:i,className:"group w-full flex items-center justify-center gap-2 px-3 py-2 rounded-xl text-sm text-muted-foreground hover:text-primary hover:bg-white/40 dark:hover:bg-white/5 transition-all overflow-hidden focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",title:r?"Mo rong thanh ben":"Thu gon thanh ben",children:[e.jsx(za.div,{animate:{rotate:r?0:180},transition:{duration:.3,ease:[.4,0,.2,1]},className:"shrink-0",children:e.jsx(_N,{className:"h-4 w-4"})}),e.jsx(fc,{initial:!1,children:!r&&e.jsx(za.span,{initial:{opacity:0,width:0},animate:{opacity:1,width:"auto"},exit:{opacity:0,width:0},transition:{duration:.15},className:"whitespace-nowrap overflow-hidden",children:"Thu gon"},"collapse-label")})]})})]})}const rw="kiro-task-history",pI=200;function Ll(n){try{const s=Array.from(n.values()).filter(r=>r.status!=="running"&&r.status!=="paused").sort((r,i)=>i.updatedAt-r.updatedAt).slice(0,pI).map(({onCancel:r,onPause:i,onResume:o,...d})=>d);localStorage.setItem(rw,JSON.stringify(s))}catch{}}function xI(){try{const n=localStorage.getItem(rw);if(!n)return new Map;const s=JSON.parse(n),r=new Map;for(const i of s){const o=i.status==="running"||i.status==="paused"?"cancelled":i.status;r.set(i.id,{...i,status:o})}return r}catch{return new Map}}const Vs=Nx()((n,s)=>({tasks:xI(),createTask:r=>{const i=r.fixedId||Oi(),o=Date.now(),d={id:i,kind:r.kind,title:r.title,subtitle:r.subtitle,status:r.status??"running",progress:r.progress??0,done:r.done??0,total:r.total,successCount:r.successCount??0,failedCount:r.failedCount??0,lastMessage:r.lastMessage,error:r.error,onCancel:r.onCancel,onPause:r.onPause,onResume:r.onResume,createdAt:o,updatedAt:o};return n(u=>{const h=new Map(u.tasks);return h.set(i,d),{tasks:h}}),i},updateTask:(r,i)=>{n(o=>{const d=new Map(o.tasks),u=d.get(r);return u?(d.set(r,{...u,...i,updatedAt:Date.now()}),{tasks:d}):o})},completeTask:(r,i)=>{n(o=>{const d=new Map(o.tasks),u=d.get(r);if(!u)return o;const h=i?.successCount??u.successCount,f=i?.failedCount??u.failedCount,p=i?.error||f>0&&h===0?"failed":"success";return d.set(r,{...u,status:p,progress:100,successCount:h,failedCount:f,error:i?.error,finishedAt:Date.now(),updatedAt:Date.now()}),{tasks:d}}),Ll(s().tasks)},failTask:(r,i)=>{n(o=>{const d=new Map(o.tasks),u=d.get(r);return u?(d.set(r,{...u,status:"failed",error:i,finishedAt:Date.now(),updatedAt:Date.now()}),{tasks:d}):o}),Ll(s().tasks)},cancelTask:r=>{const i=s().tasks.get(r);try{i?.onCancel?.()}catch{}n(o=>{const d=new Map(o.tasks),u=d.get(r);return u?(d.set(r,{...u,status:"cancelled",finishedAt:Date.now(),updatedAt:Date.now()}),{tasks:d}):o}),Ll(s().tasks)},removeTask:r=>{n(i=>{const o=new Map(i.tasks);return o.delete(r),{tasks:o}}),Ll(s().tasks)},clearFinished:()=>{n(r=>{const i=new Map;for(const[o,d]of r.tasks)(d.status==="running"||d.status==="paused")&&i.set(o,d);return{tasks:i}}),Ll(s().tasks)},clearAll:()=>{n({tasks:new Map}),Ll(s().tasks)},getActiveCount:()=>{let r=0;for(const i of s().tasks.values())(i.status==="running"||i.status==="paused")&&r++;return r}})),gI={"register-batch":zu,"subscription-batch":$a,"overage-batch":Ds,"proxy-validation":Ki,"token-refresh":Mt,"account-check":Mt,other:qu};function yI(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",[r,i]=g.useState(!1),o=Vs(p=>p.tasks),{activeCount:d,finishedCount:u,hasFailure:h,totalProgress:f}=g.useMemo(()=>{let p=0,y=0,b=!1,v=0,N=0;for(const j of o.values())j.status==="running"||j.status==="paused"?(p++,v+=j.done,N+=j.total):(y++,j.status==="failed"&&(b=!0));return{activeCount:p,finishedCount:y,hasFailure:b,totalProgress:N>0?Math.round(v/N*100):0}},[o]);return o.size===0?null:e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>i(!0),title:s?"Task Center":"任务中心",className:me("flex items-center gap-1.5 px-2 h-6 rounded-md text-xs transition-colors","hover:bg-foreground/10",d>0?"text-primary":h?"text-red-500":"text-muted-foreground"),style:{WebkitAppRegion:"no-drag"},children:[d>0?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ks,{className:"h-3.5 w-3.5"}),d>0&&e.jsx("span",{className:"tabular-nums font-medium",children:d}),d>0&&f>0&&e.jsxs("span",{className:"opacity-60 tabular-nums",children:[f,"%"]}),d===0&&u>0&&e.jsx("span",{className:"tabular-nums opacity-60",children:u})]}),e.jsx(bI,{open:r,onClose:()=>i(!1)})]})}function bI({open:n,onClose:s}){const{t:r}=Ut(),i=r("common.unknown")==="Unknown",o=Vs(b=>b.tasks),d=Vs(b=>b.cancelTask),u=Vs(b=>b.removeTask),h=Vs(b=>b.clearFinished),f=()=>{const b=Array.from(o.values()).filter(v=>v.status==="running"||v.status==="paused");if(b.length!==0&&confirm(i?`Cancel ${b.length} running task(s)?`:`取消正在进行的 ${b.length} 个任务?`))for(const v of b)d(v.id)},p=Array.from(o.values()).filter(b=>b.status==="running"||b.status==="paused").length,y=g.useMemo(()=>Array.from(o.values()).sort((b,v)=>{const N=b.status==="running"||b.status==="paused",j=v.status==="running"||v.status==="paused";return N!==j?N?-1:1:v.updatedAt-b.updatedAt}),[o]);return Tn.createPortal(e.jsx(fc,{children:n&&e.jsxs("div",{style:{WebkitAppRegion:"no-drag"},children:[e.jsx(za.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-[9998] bg-black/30 backdrop-blur-sm",onClick:s}),e.jsxs(za.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",stiffness:300,damping:30},className:"fixed right-0 top-0 bottom-0 z-[9999] w-[420px] bg-background border-l shadow-2xl flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"h-4 w-4 text-primary"}),e.jsx("h2",{className:"text-sm font-semibold",children:i?"Task Center":"任务中心"}),e.jsx($e,{variant:"secondary",className:"h-5 text-[10px] tabular-nums",children:y.length})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[p>0&&e.jsxs(D,{variant:"ghost",size:"sm",onClick:f,className:"text-destructive hover:text-destructive",title:i?`Cancel all ${p} running tasks`:`取消所有 ${p} 个正在进行的任务`,children:[e.jsx(fs,{className:"h-3.5 w-3.5 mr-1"}),i?"Cancel all":"全部取消"]}),e.jsxs(D,{variant:"ghost",size:"sm",onClick:h,children:[e.jsx(Vt,{className:"h-3.5 w-3.5 mr-1"}),i?"Clear finished":"清理已完成"]}),e.jsx("button",{onClick:s,className:"p-1.5 rounded-md hover:bg-muted",children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:y.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground py-12",children:[e.jsx(qu,{className:"h-10 w-10 opacity-30 mb-3"}),e.jsx("p",{className:"text-sm",children:i?"No tasks":"暂无任务"})]}):e.jsx("div",{className:"divide-y",children:y.map(b=>e.jsx(vI,{task:b,onCancel:()=>d(b.id),onRemove:()=>u(b.id)},b.id))})})]})]})}),document.body)}function vI({task:n,onCancel:s,onRemove:r}){const{t:i}=Ut(),o=i("common.unknown")==="Unknown",d=gI[n.kind]||qu,u=n.status==="running"||n.status==="paused",h=(n.finishedAt||Date.now())-n.createdAt,f=(()=>{switch(n.status){case"running":return e.jsx($e,{className:"bg-primary text-primary-foreground",children:o?"Running":"运行中"});case"paused":return e.jsx($e,{variant:"outline",className:"text-amber-600 border-amber-200",children:o?"Paused":"已暂停"});case"success":return e.jsx($e,{variant:"outline",className:"text-green-600 border-green-200",children:o?"Done":"已完成"});case"failed":return e.jsx($e,{variant:"outline",className:"text-red-600 border-red-200",children:o?"Failed":"失败"});case"cancelled":return e.jsx($e,{variant:"outline",className:"text-muted-foreground",children:o?"Cancelled":"已取消"})}})();return e.jsx("div",{className:"p-3 hover:bg-muted/30 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:me("p-1.5 rounded-md flex-shrink-0",n.status==="success"&&"bg-green-500/15 text-green-600",n.status==="failed"&&"bg-red-500/15 text-red-600",n.status==="cancelled"&&"bg-muted text-muted-foreground",u&&"bg-primary/15 text-primary"),children:n.status==="running"?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):n.status==="success"?e.jsx(an,{className:"h-3.5 w-3.5"}):n.status==="failed"?e.jsx(fs,{className:"h-3.5 w-3.5"}):n.status==="paused"?e.jsx(Tp,{className:"h-3.5 w-3.5"}):e.jsx(d,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium truncate",title:n.title,children:n.title}),f]}),n.subtitle&&e.jsx("p",{className:"text-[10px] text-muted-foreground truncate mt-0.5",title:n.subtitle,children:n.subtitle}),(n.total>0||u)&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:me("h-full transition-all",n.status==="failed"&&"bg-red-500",n.status==="success"&&"bg-green-500",u&&"bg-primary",n.status==="cancelled"&&"bg-muted-foreground"),style:{width:`${n.progress}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground tabular-nums",children:[e.jsxs("span",{children:[n.done,"/",n.total,n.successCount>0&&e.jsxs("span",{className:"text-green-600 ml-1.5",children:["✓",n.successCount]}),n.failedCount>0&&e.jsxs("span",{className:"text-red-500 ml-1",children:["✗",n.failedCount]})]}),e.jsx("span",{children:jI(h)})]})]}),n.error&&e.jsxs("div",{className:"mt-2 flex items-start gap-1.5 text-[10px] text-red-500",children:[e.jsx(Rs,{className:"h-3 w-3 flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"break-all",children:n.error})]}),n.lastMessage&&!n.error&&e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1 truncate",title:n.lastMessage,children:n.lastMessage}),e.jsxs("div",{className:"mt-2 flex items-center gap-1",children:[n.status==="running"&&n.onPause&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px]",onClick:n.onPause,children:[e.jsx(Tp,{className:"h-3 w-3 mr-1"})," ",o?"Pause":"暂停"]}),n.status==="paused"&&n.onResume&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px]",onClick:n.onResume,children:[e.jsx(Ba,{className:"h-3 w-3 mr-1"})," ",o?"Resume":"恢复"]}),u&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px] text-destructive hover:text-destructive",onClick:s,children:[e.jsx(fs,{className:"h-3 w-3 mr-1"})," ",o?"Cancel":"取消"]}),!u&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px]",onClick:r,children:[e.jsx(Vt,{className:"h-3 w-3 mr-1"})," ",o?"Remove":"移除"]})]})]})]})})}function jI(n){if(n<1e3)return`${n}ms`;const s=Math.floor(n/1e3);if(s<60)return`${s}s`;const r=Math.floor(s/60);return r<60?`${r}m ${s%60}s`:`${Math.floor(r/60)}h ${r%60}m`}function NI(){Ut();const[n,s]=g.useState("win32"),[r,i]=g.useState(!1),[o,d]=g.useState("");g.useEffect(()=>{let h;return(async()=>{try{const p=await window.api.window.getPlatform();s(p);const y=await window.api.window.isMaximized();i(y)}catch(p){console.warn("[TitleBar] init failed",p)}h=window.api.window.onMaximizeChange(p=>i(p))})(),window.api.getAppVersion().then(d).catch(()=>{}),()=>h?.()},[]);const u=n==="darwin";return e.jsxs("div",{className:me("flex items-center h-8 w-full select-none flex-shrink-0","bg-[var(--titlebar-bg)] text-foreground/80","border-b border-foreground/5"),style:{WebkitAppRegion:"drag",paddingLeft:u?80:12,paddingRight:u?12:0},children:[e.jsxs("div",{className:me("flex items-center gap-2 text-xs",u?"flex-1 justify-center":"flex-1"),children:[!u&&e.jsx("img",{src:Ac,alt:"",className:"h-4 w-4 opacity-90",onError:h=>h.target.style.display="none"}),e.jsxs("span",{className:"font-medium tracking-wide text-foreground/70",children:[oa,o&&` v${o}`]})]}),e.jsx("div",{className:"flex items-center gap-1 px-2",style:{WebkitAppRegion:"no-drag"},children:e.jsx(yI,{})}),!u&&e.jsxs("div",{className:"flex items-stretch h-full",style:{WebkitAppRegion:"no-drag"},children:[e.jsx(Lf,{onClick:()=>window.api.window.minimize(),title:"Thu nhỏ",children:e.jsx(wc,{className:"h-3.5 w-3.5",strokeWidth:2})}),e.jsx(Lf,{onClick:()=>window.api.window.maximizeToggle(),title:r?"Khôi phục":"Phóng to",children:r?e.jsx(As,{className:"h-3 w-3",strokeWidth:2}):e.jsx(Cn,{className:"h-3 w-3",strokeWidth:2})}),e.jsx(Lf,{onClick:()=>window.api.window.close(),title:"Đóng",variant:"close",children:e.jsx(ns,{className:"h-3.5 w-3.5",strokeWidth:2})})]})]})}function Lf({onClick:n,title:s,variant:r="default",children:i}){return e.jsx("button",{type:"button",onClick:n,title:s,className:me("flex items-center justify-center w-12 h-full text-foreground/70 transition-colors","hover:text-foreground",r==="close"?"hover:bg-red-500 hover:text-white":"hover:bg-foreground/10"),children:i})}const iw="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzYwIiBoZWlnaHQ9Ijk2IiB2aWV3Qm94PSIwIDAgMzYwIDk2IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHJvbGU9ImltZyIgYXJpYS1sYWJlbD0iS3JvdXRlciI+CiAgPHJlY3QgeD0iOCIgeT0iOCIgd2lkdGg9IjgwIiBoZWlnaHQ9IjgwIiByeD0iMjIiIGZpbGw9IiMwQjEyMjAiLz4KICA8cGF0aCBkPSJNMjggNjhWMjhoMTB2MTYuOEw1NC4yIDI4SDY3TDQ5LjggNDUuNSA2OC41IDY4SDU1LjRMNDIuOSA1Mi43IDM4IDU3LjdWNjhIMjhaIiBmaWxsPSIjRkZGRkZGIi8+CiAgPHBhdGggZD0iTTYzIDI4aDV2NWgtNXYtNVoiIGZpbGw9IiMyMkM1NUUiLz4KICA8cGF0aCBkPSJNNjkgMzRoNXY1aC01di01WiIgZmlsbD0iIzM4QkRGOCIvPgogIDxwYXRoIGQ9Ik02MyA0MGg1djVoLTV2LTVaIiBmaWxsPSIjRjU5RTBCIi8+CiAgPHBhdGggZD0iTTYyLjUgMzIuNSA0OS41IDQ1LjVNNjguNSAzNi41IDUyIDUyTTYyLjUgNDIuNSA1NS41IDU2IiBzdHJva2U9IiM5NEEzQjgiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIi8+CiAgPGNpcmNsZSBjeD0iNDgiIGN5PSI0OCIgcj0iNSIgZmlsbD0iIzM4QkRGOCIvPgogIDx0ZXh0IHg9IjEwOCIgeT0iNTciIGZpbGw9IiMxMTE4MjciIGZvbnQtZmFtaWx5PSJJbnRlciwgU2Vnb2UgVUksIEFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjM4IiBmb250LXdlaWdodD0iODAwIj5Lcm91dGVyPC90ZXh0PgogIDx0ZXh0IHg9IjExMCIgeT0iNzYiIGZpbGw9IiM2NDc0OEIiIGZvbnQtZmFtaWx5PSJJbnRlciwgU2Vnb2UgVUksIEFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE0IiBmb250LXdlaWdodD0iNjAwIj5LaXJvIHF1b3RhIHJvdXRlcjwvdGV4dD4KPC9zdmc+Cg==",wI=(n,s)=>{const r=(s||n).toUpperCase();return r.includes("PRO+")||r.includes("PRO_PLUS")||r.includes("PROPLUS")?"bg-purple-500":r.includes("POWER")?"bg-amber-500":r.includes("PRO")?"bg-blue-500":"bg-gray-500"};function sj(){const{accounts:n,activeAccountId:s,getStats:r,darkMode:i,usagePrecision:o}=vt(),{t:d}=Ut(),u=r(),h=g.useMemo(()=>{let b=0,v=0,N=0;Array.from(n.values()).forEach(S=>{if(S.status==="active"&&S.usage){const k=S.usage.limit??0,R=S.usage.current??0;k>0&&(b+=k,v+=R,N++)}});const j=b-v,T=b>0?v/b*100:0;return{totalLimit:b,totalUsed:v,remaining:j,percentUsed:T,validAccountCount:N}},[n]),f=d("common.unknown")==="Unknown",p=[{label:f?"Total Accounts":"总账号数",value:u.total,icon:Fn,color:"text-blue-500",bgColor:"bg-blue-500/10"},{label:f?"Active":"正常账号",value:u.byStatus?.active||0,icon:Bn,color:"text-green-500",bgColor:"bg-green-500/10"},{label:f?"Banned":"已封禁",value:u.byStatus?.error||0,icon:Rs,color:"text-red-500",bgColor:"bg-red-500/10"},{label:f?"Expiring Soon":"即将过期",value:u.expiringSoonCount,icon:Gn,color:"text-amber-500",bgColor:"bg-amber-500/10"}],y=g.useMemo(()=>s?n.get(s)??null:null,[n,s]);return e.jsxs("div",{className:"flex-1 p-4 md:p-6 space-y-5 md:space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-5 md:p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsx("img",{src:iw,alt:oa,className:me("h-14 sm:h-16 w-auto max-w-full transition-all",i&&"brightness-110")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold text-primary",children:oa}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground max-w-2xl",children:f?nw:aw})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:p.map(b=>{const v=b.icon;return e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2.5 rounded-xl ${b.bgColor}`,children:e.jsx(v,{className:`h-5 w-5 ${b.color}`})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:b.value}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b.label})]})]})})},b.label)})}),h.validAccountCount>0&&e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Lu,{className:"h-4 w-4 text-primary"})}),f?"Usage Stats":"额度统计",e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",f?`Based on ${h.validAccountCount} valid accounts`:`基于 ${h.validAccountCount} 个有效账号`,")"]})]})}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-4",children:[e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(QN,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Total":"总额度"})]}),e.jsx("p",{className:"text-xl font-bold",children:h.totalLimit.toLocaleString()})]}),e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ks,{className:"h-4 w-4 text-orange-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Used":"已使用"})]}),e.jsx("p",{className:"text-xl font-bold",children:h.totalUsed.toLocaleString()})]}),e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ds,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Remaining":"剩余额度"})]}),e.jsx("p",{className:"text-xl font-bold text-green-600",children:h.remaining.toLocaleString()})]}),e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Lu,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Usage %":"使用率"})]}),e.jsxs("p",{className:"text-xl font-bold",children:[h.percentUsed.toFixed(o?2:1),"%"]})]})]}),(()=>{const b=h.percentUsed>100,v=b?h.percentUsed-100:0,N=b?Math.abs(h.remaining):0,j=b?Math.min(v/h.percentUsed*100,60):0,T=o?2:1;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Overall Progress":"总体使用进度"}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-muted-foreground",children:[h.totalUsed.toLocaleString(void 0,{maximumFractionDigits:2})," / ",h.totalLimit.toLocaleString()]}),e.jsxs("span",{className:me("font-bold px-2 py-0.5 rounded-md",b&&"bg-red-500/15 text-red-600 dark:text-red-400",!b&&h.percentUsed>=80&&"bg-orange-500/15 text-orange-600 dark:text-orange-400",!b&&h.percentUsed>=50&&h.percentUsed<80&&"bg-yellow-500/15 text-yellow-600 dark:text-yellow-400",!b&&h.percentUsed<50&&"bg-green-500/15 text-green-600 dark:text-green-400"),children:[h.percentUsed.toFixed(T),"%"]})]})]}),e.jsxs("div",{className:"relative h-3 bg-muted rounded-full overflow-hidden",children:[e.jsx("div",{className:me("absolute inset-y-0 left-0 transition-all",b&&"bg-red-500",!b&&h.percentUsed>=80&&"bg-orange-500",!b&&h.percentUsed>=50&&h.percentUsed<80&&"bg-yellow-500",!b&&h.percentUsed<50&&"bg-green-500"),style:{width:`${Math.min(h.percentUsed,100)}%`}}),b&&e.jsx("div",{className:"absolute inset-y-0 right-0 bg-gradient-to-r from-red-600 via-red-700 to-red-800 animate-pulse",style:{width:`${j}%`,backgroundImage:"repeating-linear-gradient(45deg, rgba(255,255,255,0.15) 0, rgba(255,255,255,0.15) 8px, transparent 8px, transparent 16px)",backgroundSize:"22px 22px"}})]}),b&&e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-2 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/30",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 text-red-500 shrink-0"}),e.jsx("span",{className:"font-bold text-red-600 dark:text-red-400",children:f?"Over Quota":"已超额"}),e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-red-500/20 text-red-600 dark:text-red-400 font-bold",children:["+",v.toFixed(T),"%"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Excess: ":"超额积分:"}),e.jsx("span",{className:"font-bold text-red-600 dark:text-red-400",children:N.toLocaleString(void 0,{maximumFractionDigits:2})})]})]})]})})()]})]}),y&&e.jsxs(De,{className:"hover-lift bg-gradient-to-r from-primary/5 to-primary/10",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ds,{className:"h-4 w-4 text-primary"}),f?"Current Account":"当前使用账号"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/20 flex items-center justify-center text-primary font-bold",children:(y.nickname||y.email||"?")[0].toUpperCase()}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:y.nickname||y.email}),e.jsx("p",{className:"text-sm text-muted-foreground",children:y.email})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("span",{className:me("inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium text-white",wI(y.subscription?.type||"Free",y.subscription?.title)),children:y.subscription?.title||y.subscription?.type||"Free"})})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Monthly Usage":"本月用量"}),e.jsxs("p",{className:"text-sm font-medium",children:[y.usage?.current||0," / ",y.usage?.limit||0]}),e.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${(y.usage?.percentUsed||0)>.8?"bg-red-500":(y.usage?.percentUsed||0)>.5?"bg-amber-500":"bg-green-500"}`,style:{width:`${Math.min((y.usage?.percentUsed||0)*100,100)}%`}})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Subscription":"订阅剩余"}),e.jsx("p",{className:"text-sm font-medium",children:y.subscription?.daysRemaining!=null?f?`${y.subscription.daysRemaining} days`:`${y.subscription.daysRemaining} 天`:f?"Permanent":"永久"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Token Status":"Token 状态"}),(()=>{const b=y.credentials?.expiresAt;if(!b)return e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:f?"Unknown":"未知"});const v=Date.now(),N=b-v;if(N<=0)return e.jsx("p",{className:"text-sm font-medium text-red-500",children:f?"Expired":"已过期"});const j=Math.floor(N/6e4);if(j<60)return e.jsx("p",{className:"text-sm font-medium text-amber-500",children:f?`${j} min`:`${j} 分钟`});const T=Math.floor(j/60);return e.jsx("p",{className:"text-sm font-medium text-green-500",children:f?`${T} hours`:`${T} 小时`})})()]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Auth Method":"登录方式"}),e.jsx("p",{className:"text-sm font-medium",children:y.credentials?.authMethod==="social"?y.credentials?.provider||"Social":"Builder ID"})]})]}),e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:f?"Subscription Details":"订阅详情"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Type:":"订阅类型:"}),e.jsx("span",{className:"font-medium",children:y.subscription?.title||y.subscription?.type||"Free"})]}),y.subscription?.rawType&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Raw Type:":"原始类型:"}),e.jsx("span",{className:"font-mono text-[10px]",children:y.subscription.rawType})]}),y.subscription?.expiresAt&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Expires:":"到期时间:"}),e.jsx("span",{className:"font-medium",children:new Date(y.subscription.expiresAt).toLocaleDateString("zh-CN")})]}),y.subscription?.upgradeCapability&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Upgradeable:":"可升级:"}),e.jsx("span",{className:"font-medium",children:y.subscription.upgradeCapability})]}),y.subscription?.overageCapability&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Overage:":"超额能力:"}),e.jsx("span",{className:"font-medium",children:y.subscription.overageCapability})]})]})]}),(y.usage?.baseLimit||y.usage?.freeTrialLimit||y.usage?.bonuses?.length)&&e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:f?"Quota Details":"额度明细"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[y.usage?.baseLimit!==void 0&&y.usage.baseLimit>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"}),e.jsx("span",{className:"text-muted-foreground",children:f?"Base:":"基础额度:"}),e.jsxs("span",{className:"font-medium",children:[y.usage.baseCurrent??0," / ",y.usage.baseLimit]})]}),y.usage?.freeTrialLimit!==void 0&&y.usage.freeTrialLimit>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-purple-500"}),e.jsx("span",{className:"text-muted-foreground",children:f?"Trial:":"试用额度:"}),e.jsxs("span",{className:"font-medium",children:[y.usage.freeTrialCurrent??0," / ",y.usage.freeTrialLimit]}),y.usage.freeTrialExpiry&&e.jsxs("span",{className:"text-muted-foreground/70 text-[10px]",children:["(至 ",(()=>{const b=y.usage.freeTrialExpiry;try{return(typeof b=="string"?b:new Date(b).toISOString()).split("T")[0]}catch{return""}})(),")"]})]}),y.usage?.bonuses?.map(b=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-cyan-500"}),e.jsxs("span",{className:"text-muted-foreground truncate",children:[b.name,":"]}),e.jsxs("span",{className:"font-medium",children:[b.current," / ",b.limit]}),b.expiresAt&&e.jsxs("span",{className:"text-muted-foreground/70 text-[10px]",children:["(至 ",(()=>{const v=b.expiresAt;try{return(typeof v=="string"?v:new Date(v).toISOString()).split("T")[0]}catch{return""}})(),")"]})]},b.code))]})]}),e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:f?"Account Info":"账户信息"}),e.jsxs("div",{className:"space-y-1.5 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:"User ID:"}),e.jsx("span",{className:"font-mono text-[10px] break-all select-all",children:y.userId})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"IDP:"}),e.jsx("span",{className:"font-medium",children:y.idp||"BuilderId"})]}),y.usage?.nextResetDate&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Reset Date:":"重置日期:"}),e.jsx("span",{className:"font-medium",children:(()=>{const b=y.usage.nextResetDate;try{return(typeof b=="string"?b:new Date(b).toISOString()).split("T")[0]}catch{return f?"Unknown":"未知"}})()})]})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Vn,{className:"h-4 w-4 text-primary"})}),f?"Quick Tips":"快速提示"]})}),e.jsx(Pe,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-muted-foreground",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?'Click "Accounts" to view and manage all accounts':"点击左侧「账户管理」可以查看和管理所有账号"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?"Click power icon on account card to switch":"在账号卡片上点击电源图标可以快速切换账号"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?"Tokens auto-refresh 5 minutes before expiry":"Token 会在过期前 5 分钟自动刷新,无需手动操作"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?'Use "Privacy Mode" to hide sensitive info':"使用「隐私模式」可以隐藏邮箱和账号信息"]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(eo,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:f?"Machine ID":"机器码管理"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:f?"Modify device ID, auto-switch, account binding":"修改设备标识符,切号时自动更换,支持账户绑定"})]})]})})}),e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Cp,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:f?"Groups":"分组管理"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:f?"Batch set groups for selected accounts":"多选账户后可批量设置分组,一键移动账号"})]})]})})}),e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Xl,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:f?"Tags":"标签管理"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:f?"Batch add/remove tags, multi-tag support":"多选账户后可批量添加/移除标签,支持多标签"})]})]})})})]})]})}function kI(){const[n,s]=g.useState("..."),[r,i]=g.useState(!1),[o,d]=g.useState(null),[u,h]=g.useState(!1),{t:f}=Ut(),p=f("common.unknown")==="Unknown";g.useEffect(()=>{window.api.getAppVersion().then(s).catch(()=>s("unknown"))},[]);const y=async()=>{i(!0);try{const T=await window.api.checkForUpdatesManual();d(T),h(!0)}catch(T){d({hasUpdate:!1,error:T instanceof Error?T.message:"Check update failed"}),h(!0)}finally{i(!1)}},b=T=>{T&&window.api.openExternal(T)},v=T=>T<1024?`${T} B`:T<1024*1024?`${(T/1024).toFixed(1)} KB`:`${(T/(1024*1024)).toFixed(1)} MB`,N=[{icon:aM,title:p?"Account router":"Router tai khoan",body:p?"Rotates requests across healthy Kiro accounts by model, quota, and runtime state.":"Xoay request qua cac tai khoan Kiro con khoe theo model, quota va trang thai runtime."},{icon:ii,title:p?"Client API keys":"Key cho client",body:p?"Creates OpenAI-compatible keys for OpenClaw, Aira, Codex, and other dev tools.":"Tao key tuong thich OpenAI cho OpenClaw, Aira, Codex va cac cong cu dev."},{icon:hM,title:"Backend runtime",body:p?"Keeps the proxy service alive from the backend/CLI instead of relying on a browser tab.":"Giu API proxy chay bang backend/CLI thay vi phu thuoc vao tab trinh duyet."},{icon:Ki,title:p?"Localhost or tunnel":"Localhost hoac tunnel",body:p?"Runs local-first and exposes the dashboard publicly only when a tunnel is enabled.":"Uu tien localhost va chi public dashboard khi bat tunnel."}],j=[{icon:$N,label:"OpenClaw / Aira",detail:p?"One client endpoint":"Mot endpoint client"},{icon:Ds,label:oa,detail:"Key, model, quota router"},{icon:Vn,label:p?"Kiro accounts":"Tai khoan Kiro",detail:"Health, quota, profile ARN"}];return e.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-4 md:p-6 md:space-y-6",children:[e.jsx("div",{className:"page-hero overflow-hidden p-5 md:p-8",children:e.jsxs("div",{className:"relative grid gap-6 lg:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)] lg:items-center",children:[e.jsxs("div",{className:"min-w-0 space-y-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[e.jsx("img",{src:iw,alt:oa,className:"h-16 w-auto max-w-full shrink-0 md:h-20"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold text-primary md:text-3xl",children:oa}),e.jsx("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground md:text-base",children:p?nw:aw}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:[p?"Version":"Phien ban"," ",n," · ",tj]})]})]}),e.jsxs("div",{className:"grid gap-2 text-sm text-muted-foreground sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-primary/10 bg-white/45 p-3 dark:bg-white/5",children:[e.jsx("p",{className:"font-semibold text-foreground",children:p?"Web dashboard":"Dashboard web"}),e.jsx("p",{className:"mt-1 text-xs",children:p?"Account control surface":"Noi quan ly tai khoan"})]}),e.jsxs("div",{className:"rounded-xl border border-primary/10 bg-white/45 p-3 dark:bg-white/5",children:[e.jsx("p",{className:"font-semibold text-foreground",children:"CLI runtime"}),e.jsx("p",{className:"mt-1 text-xs",children:p?"Setup and tunnel control":"Setup va tunnel"})]}),e.jsxs("div",{className:"rounded-xl border border-primary/10 bg-white/45 p-3 dark:bg-white/5",children:[e.jsx("p",{className:"font-semibold text-foreground",children:"OpenClaw"}),e.jsx("p",{className:"mt-1 text-xs",children:"provider: krouter"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",onClick:y,disabled:r,children:[e.jsx(Mt,{className:me("h-4 w-4",r&&"animate-spin")}),r?p?"Checking...":"Dang kiem tra...":p?"Check updates":"Kiem tra cap nhat"]}),e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>b(Pf),children:[e.jsx(jf,{className:"h-4 w-4"}),"GitHub",e.jsx(Xs,{className:"h-3 w-3"})]})]})]}),e.jsxs("div",{className:"relative min-h-[260px] rounded-2xl border border-primary/10 bg-white/55 p-5 shadow-inner dark:bg-white/5",children:[e.jsx("div",{className:"absolute right-5 top-5 rounded-full bg-primary/10 p-3",children:e.jsx("img",{src:Ac,alt:oa,className:"h-12 w-12"})}),e.jsx("div",{className:"flex h-full flex-col justify-end gap-4 pt-20",children:j.map((T,S)=>{const k=T.icon;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-primary text-primary-foreground shadow-sm",children:e.jsx(k,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-xl border border-primary/10 bg-background/70 px-3 py-2",children:[e.jsx("p",{className:"truncate text-sm font-semibold",children:T.label}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:T.detail})]}),S<j.length-1&&e.jsx(wp,{className:"hidden h-4 w-4 text-primary md:block"})]},T.label)})})]})]})}),u&&o&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>h(!1)}),e.jsx("div",{className:"relative z-10 max-h-[80vh] w-full max-w-md overflow-y-auto rounded-xl bg-card p-6 shadow-xl",children:o.hasUpdate?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-success/10 p-2",children:e.jsx(Ns,{className:"h-6 w-6 text-success"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:p?"New version available":"Co ban moi"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[o.currentVersion," -> ",o.latestVersion]})]})]}),o.releaseName&&e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:o.releaseName}),o.publishedAt&&e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(o.publishedAt).toLocaleDateString(p?"en-US":"vi-VN")})]}),o.releaseNotes&&e.jsx("div",{className:"max-h-32 overflow-y-auto whitespace-pre-wrap rounded-lg bg-muted/30 p-3 text-sm text-muted-foreground",children:o.releaseNotes}),o.assets&&o.assets.length>0&&e.jsx("div",{className:"space-y-1",children:o.assets.slice(0,6).map(T=>e.jsxs("div",{className:"flex items-center justify-between rounded bg-muted/30 px-2 py-1 text-xs",children:[e.jsx("span",{className:"truncate",children:T.name}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:v(T.size)})]},T.downloadUrl))}),e.jsxs(D,{className:"w-full gap-2",onClick:()=>b(o.releaseUrl),children:[e.jsx(Xs,{className:"h-4 w-4"}),p?"Open release page":"Mo trang phat hanh"]})]}):o.error?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-red-500/10 p-2",children:e.jsx(ln,{className:"h-6 w-6 text-red-500"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:p?"Check failed":"Kiem tra loi"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o.error})]})]}),e.jsx(D,{variant:"outline",className:"w-full",onClick:y,children:p?"Retry":"Thu lai"})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-success/10 p-2",children:e.jsx(Bn,{className:"h-6 w-6 text-success"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:p?"Up to date":"Dang la ban moi nhat"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p?`Version ${o.currentVersion}`:`Phien ban ${o.currentVersion}`})]})]})})})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4",children:N.map(T=>{const S=T.icon;return e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(S,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold",children:T.title}),e.jsx("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:T.body})]})]})})},T.title)})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-[1.05fr_0.95fr]",children:[e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(Hi,{className:"h-4 w-4 text-primary"})}),p?"What Krouter is for":"Krouter dung de lam gi"]})}),e.jsxs(Pe,{className:"space-y-3 text-sm leading-relaxed text-muted-foreground",children:[e.jsx("p",{children:p?"Krouter is the control plane for a Kiro-based AI coding setup: it keeps account state visible, exposes one compatible API endpoint, and routes each request to a usable account.":"Krouter la control plane cho workflow AI coding dung Kiro: hien thi trang thai tai khoan, mo mot API endpoint tuong thich va dieu huong moi request den tai khoan dang dung duoc."}),e.jsx("p",{children:p?"The web dashboard handles operations. The backend service and CLI keep proxy, tunnel, API keys, and client imports running outside the browser.":"Dashboard web xu ly thao tac quan ly. Backend service va CLI giu API proxy, tunnel, API key va import client chay doc lap voi trinh duyet."})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(kM,{className:"h-4 w-4 text-primary"})}),p?"Runtime commands":"Lenh runtime"]})}),e.jsx(Pe,{children:e.jsx("div",{className:"grid gap-2 text-xs",children:["krouter setup","krouter status","krouter tunnel start","krouter openclaw import"].map(T=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-muted/40 px-3 py-2 font-mono",children:[e.jsx(U3,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{children:T})]},T))})})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx($A,{className:"h-4 w-4 text-primary"})}),p?"Client integration":"Ket noi client"]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid gap-3 text-sm md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl bg-muted/30 p-3",children:[e.jsx("p",{className:"font-semibold",children:"Endpoint"}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:"http://localhost:5580/v1"})]}),e.jsxs("div",{className:"rounded-xl bg-muted/30 p-3",children:[e.jsx("p",{className:"font-semibold",children:"API key"}),e.jsx("p",{className:"mt-1 font-mono text-xs text-muted-foreground",children:"sk-..."})]}),e.jsxs("div",{className:"rounded-xl bg-muted/30 p-3",children:[e.jsx("p",{className:"font-semibold",children:"OpenClaw"}),e.jsx("p",{className:"mt-1 font-mono text-xs text-muted-foreground",children:"provider: krouter"})]})]})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(jf,{className:"h-4 w-4 text-primary"})}),p?"Project":"Du an"]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium",children:tj}),e.jsx("p",{className:"break-all text-sm text-muted-foreground",children:Pf})]}),e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>b(Pf),children:[e.jsx(jf,{className:"h-4 w-4"}),"GitHub",e.jsx(Xs,{className:"h-3 w-3"})]})]})})]})]})}const SI=[{name:"蓝色系",themes:[{id:"default",name:"天空蓝",color:"#3b82f6"},{id:"indigo",name:"靖蓝",color:"#6366f1"},{id:"cyan",name:"清新青",color:"#06b6d4"},{id:"sky",name:"晴空蓝",color:"#0ea5e9"},{id:"teal",name:"水鸭蓝",color:"#14b8a6"}]},{name:"紫红系",themes:[{id:"purple",name:"优雅紫",color:"#a855f7"},{id:"violet",name:"紫罗兰",color:"#8b5cf6"},{id:"fuchsia",name:"洋红",color:"#d946ef"},{id:"pink",name:"粉红",color:"#ec4899"},{id:"rose",name:"玑瑰红",color:"#f43f5e"}]},{name:"暖色系",themes:[{id:"red",name:"热情红",color:"#ef4444"},{id:"orange",name:"活力橙",color:"#f97316"},{id:"amber",name:"琥珀金",color:"#f59e0b"},{id:"yellow",name:"明黄",color:"#eab308"}]},{name:"绿色系",themes:[{id:"emerald",name:"翠绿",color:"#10b981"},{id:"green",name:"草绿",color:"#22c55e"},{id:"lime",name:"青柠",color:"#84cc16"}]},{name:"中性色",themes:[{id:"slate",name:"石板灰",color:"#64748b"},{id:"zinc",name:"锌灰",color:"#71717a"},{id:"stone",name:"暖灰",color:"#78716c"},{id:"neutral",name:"中性灰",color:"#737373"}]},{name:"奢华配色",themes:[{id:"gold",name:"奢华金",color:"#C9A227"},{id:"navy",name:"海军蓝",color:"#1E40AF"},{id:"wine",name:"酒红",color:"#9F1239"},{id:"champagne",name:"香槟",color:"#B89968"}]},{name:"莫兰迪",themes:[{id:"dustyblue",name:"烟雾蓝",color:"#64748B"},{id:"terracotta",name:"陶土橙",color:"#B45434"},{id:"sage",name:"鼠尾草",color:"#6B8E5A"},{id:"mauve",name:"烟紫",color:"#8E7CC3"}]},{name:"自然深色",themes:[{id:"coral",name:"珊瑚粉",color:"#F87171"},{id:"forest",name:"森林绿",color:"#166534"},{id:"ocean",name:"深海青",color:"#155E75"}]}],CI=[{name:"Blue",themes:[{id:"default",name:"Sky Blue",color:"#3b82f6"},{id:"indigo",name:"Indigo",color:"#6366f1"},{id:"cyan",name:"Cyan",color:"#06b6d4"},{id:"sky",name:"Sky",color:"#0ea5e9"},{id:"teal",name:"Teal",color:"#14b8a6"}]},{name:"Purple",themes:[{id:"purple",name:"Purple",color:"#a855f7"},{id:"violet",name:"Violet",color:"#8b5cf6"},{id:"fuchsia",name:"Fuchsia",color:"#d946ef"},{id:"pink",name:"Pink",color:"#ec4899"},{id:"rose",name:"Rose",color:"#f43f5e"}]},{name:"Warm",themes:[{id:"red",name:"Red",color:"#ef4444"},{id:"orange",name:"Orange",color:"#f97316"},{id:"amber",name:"Amber",color:"#f59e0b"},{id:"yellow",name:"Yellow",color:"#eab308"}]},{name:"Green",themes:[{id:"emerald",name:"Emerald",color:"#10b981"},{id:"green",name:"Green",color:"#22c55e"},{id:"lime",name:"Lime",color:"#84cc16"}]},{name:"Neutral",themes:[{id:"slate",name:"Slate",color:"#64748b"},{id:"zinc",name:"Zinc",color:"#71717a"},{id:"stone",name:"Stone",color:"#78716c"},{id:"neutral",name:"Neutral",color:"#737373"}]},{name:"Luxury",themes:[{id:"gold",name:"Gold",color:"#C9A227"},{id:"navy",name:"Navy",color:"#1E40AF"},{id:"wine",name:"Wine",color:"#9F1239"},{id:"champagne",name:"Champagne",color:"#B89968"}]},{name:"Morandi",themes:[{id:"dustyblue",name:"Dusty Blue",color:"#64748B"},{id:"terracotta",name:"Terracotta",color:"#B45434"},{id:"sage",name:"Sage",color:"#6B8E5A"},{id:"mauve",name:"Mauve",color:"#8E7CC3"}]},{name:"Natural",themes:[{id:"coral",name:"Coral",color:"#F87171"},{id:"forest",name:"Forest",color:"#166534"},{id:"ocean",name:"Ocean",color:"#155E75"}]}];function TI(){const{privacyMode:n,setPrivacyMode:s,usagePrecision:r,setUsagePrecision:i,autoRefreshEnabled:o,autoRefreshInterval:d,autoRefreshConcurrency:u,autoRefreshSyncInfo:h,proactiveRenewalEnabled:f,proactiveRenewalLeadMinutes:p,setProactiveRenewalEnabled:y,setAutoRefresh:b,setAutoRefreshConcurrency:v,setAutoRefreshSyncInfo:N,checkAndRefreshExpiringTokens:j,proxyEnabled:T,proxyUrl:S,setProxy:k,autoSwitchEnabled:R,autoSwitchThreshold:I,autoSwitchInterval:M,setAutoSwitch:G,batchImportConcurrency:W,setBatchImportConcurrency:U,loginPrivateMode:q,setLoginPrivateMode:V,switchTarget:le,setSwitchTarget:B,theme:be,darkMode:K,setTheme:se,setDarkMode:te,language:Y,setLanguage:P,accounts:F,importFromExportData:fe}=vt(),{t:pe}=Ut(),C=pe("common.unknown")==="Unknown",[z,X]=g.useState(!1),[re,xe]=g.useState(!1),[Oe,Ee]=g.useState(S),[Qe,_e]=g.useState(!1),[st,oe]=g.useState(!1),[ue,ae]=g.useState({enabled:!0,closeAction:"ask",showNotifications:!0,minimizeOnStart:!1}),[L,we]=g.useState(!0),[Ue,Lt]=g.useState(""),[xt,Qt]=g.useState(!0),[ft,Et]=g.useState(""),[Ge,gt]=g.useState(!1);g.useEffect(()=>{(async()=>{try{const He=await window.api.getShowWindowShortcut();Lt(He)}catch(He){console.error("Failed to load shortcut:",He)}finally{Qt(!1)}})()},[]);const Ze=async je=>{Lt(je),Et("");try{const He=await window.api.setShowWindowShortcut(je);He.success||Et(He.error||"Failed to set shortcut")}catch(He){Et(String(He))}},J=je=>{if(!Ge)return;je.preventDefault();const He=[];je.ctrlKey&&He.push("Ctrl"),je.metaKey&&He.push("Command"),je.altKey&&He.push("Alt"),je.shiftKey&&He.push("Shift");const Tt=je.key;if(!["Control","Meta","Alt","Shift"].includes(Tt)){const H=Tt.length===1?Tt.toUpperCase():Tt;He.push(H);const Se=He.join("+");Ze(Se),gt(!1)}},[Ne,et]=g.useState("rest"),[qe,Je]=g.useState(!0);g.useEffect(()=>{(async()=>{try{const He=await window.api.getUsageApiType();et(He)}catch(He){console.error("Failed to load usage API type:",He)}finally{Je(!1)}})()},[]);const Kt=async je=>{et(je);try{await window.api.setUsageApiType(je)}catch(He){console.error("Failed to save usage API type:",He)}},[Ye,qt]=g.useState(!1),[Jt,Ct]=g.useState(!0);g.useEffect(()=>{(async()=>{try{const He=await window.api.getUseKProxyForApi();qt(He)}catch(He){console.error("Failed to load K-Proxy settings:",He)}finally{Ct(!1)}})()},[]);const O=async je=>{qt(je);try{await window.api.setUseKProxyForApi(je)}catch(He){console.error("Failed to save K-Proxy settings:",He)}};g.useEffect(()=>{(async()=>{try{const He=await window.api.getTraySettings();ae(He)}catch(He){console.error("Failed to load tray settings:",He)}finally{we(!1)}})()},[]);const ne=async(je,He)=>{const Tt={...ue,[je]:He};ae(Tt);try{await window.api.saveTraySettings({[je]:He})}catch(H){console.error("Failed to save tray settings:",H)}},ze=async()=>{oe(!0);try{await j()}finally{oe(!1)}},_=C?CI:SI,ce=()=>{X(!0)},Ce=async()=>{xe(!0);try{const je=await window.api.importFromFile();if(je&&je.format==="json"){const He=JSON.parse(je.content),Tt=fe(He);alert(`导入完成:成功 ${Tt.success} 个,失败 ${Tt.failed} 个`)}else je&&alert("设置页面仅支持 JSON 格式导入,请使用账号管理页面导入 CSV/TXT")}catch(je){alert(`导入失败: ${je instanceof Error?je.message:"未知错误"}`)}finally{xe(!1)}},Ve=()=>{confirm("确定要清除所有账号数据吗?此操作不可恢复!")&&confirm("再次确认:这将删除所有账号、分组和标签数据!")&&(Array.from(F.keys()).forEach(je=>{vt.getState().removeAccount(je)}),alert("所有数据已清除"))};return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary shadow-lg shadow-primary/25",children:e.jsx(Ap,{className:"h-6 w-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:pe("settings.title")}),e.jsx("p",{className:"text-muted-foreground",children:pe("settings.title")==="Settings"?"Configure app features":"配置应用的各项功能"})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),"语言 / Language"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"显示语言 / Display Language"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"选择界面显示语言 / Select interface language"})]}),e.jsxs("select",{className:"w-[160px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:Y,onChange:je=>P(je.target.value),children:[e.jsx("option",{value:"auto",children:"🌐 自动 (Auto)"}),e.jsx("option",{value:"zh",children:"🇨🇳 简体中文"}),e.jsx("option",{value:"en",children:"🇺🇸 English"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsx("p",{children:"• 自动模式会根据系统语言自动选择"}),e.jsx("p",{children:"• Auto mode will follow system language"}),e.jsx("p",{children:"• 支持自定义翻译文件扩展(开发中)"})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(qN,{className:"h-4 w-4 text-primary"})}),C?"Theme":"主题设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Dark Mode":"深色模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Toggle dark/light theme":"切换深色/浅色主题"})]}),e.jsxs(D,{variant:K?"default":"outline",size:"sm",onClick:()=>te(!K),children:[K?e.jsx(VA,{className:"h-4 w-4 mr-2"}):e.jsx(AM,{className:"h-4 w-4 mr-2"}),K?C?"Dark":"深色":C?"Light":"浅色"]})]}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsxs("button",{className:"flex items-center justify-between w-full text-left",onClick:()=>_e(!Qe),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-medium",children:C?"Theme Color":"主题颜色"}),!Qe&&e.jsx("div",{className:"w-5 h-5 rounded-full ring-2 ring-primary ring-offset-1",style:{backgroundColor:_.flatMap(je=>je.themes).find(je=>je.id===be)?.color||"#3b82f6"}})]}),Qe?e.jsx(zi,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(va,{className:"h-4 w-4 text-muted-foreground"})]}),Qe&&e.jsx("div",{className:"space-y-3 mt-3",children:_.map(je=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground w-14 shrink-0",children:je.name}),e.jsx("div",{className:"flex flex-wrap gap-2",children:je.themes.map(He=>e.jsx("button",{className:`group relative w-7 h-7 rounded-full transition-all ${be===He.id?"ring-2 ring-primary ring-offset-2 scale-110":"hover:scale-110 hover:shadow-md"}`,style:{backgroundColor:He.color},onClick:()=>se(He.id),title:He.name,children:e.jsx("span",{className:"absolute -bottom-6 left-1/2 -translate-x-1/2 text-[10px] text-muted-foreground whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity bg-popover px-1.5 py-0.5 rounded shadow-sm border pointer-events-none z-10",children:He.name})},He.id))})]},je.name))})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:n?e.jsx(Jl,{className:"h-4 w-4 text-primary"}):e.jsx(Nc,{className:"h-4 w-4 text-primary"})}),C?"Privacy":"隐私设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Privacy Mode":"隐私模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Hide emails and sensitive info":"隐藏邮箱和账号敏感信息"})]}),e.jsxs(D,{variant:n?"default":"outline",size:"sm",onClick:()=>s(!n),children:[n?e.jsx(Jl,{className:"h-4 w-4 mr-2"}):e.jsx(Nc,{className:"h-4 w-4 mr-2"}),n?C?"On":"已开启":C?"Off":"已关闭"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Usage Precision":"使用量精度"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Show decimal places for usage values":"显示使用量的小数精度(如 1.22 而非 1)"})]}),e.jsx(D,{variant:r?"default":"outline",size:"sm",onClick:()=>i(!r),children:r?C?"Decimal":"小数":C?"Integer":"整数"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Switch Target":"切号目标"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Which client to switch account credentials to":"切换账号凭证写入的客户端"})]}),e.jsxs("select",{className:"h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:le,onChange:je=>B(je.target.value),children:[e.jsx("option",{value:"ide",children:"Kiro IDE"}),e.jsx("option",{value:"cli",children:"Kiro CLI"}),e.jsx("option",{value:"both",children:C?"Both (IDE + CLI)":"两者 (IDE + CLI)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Login Private Mode":"登录隐私模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Open browser in incognito/private mode when logging in":"在线登录时使用浏览器无痕/隐私模式打开"})]}),e.jsxs(D,{variant:q?"default":"outline",size:"sm",onClick:()=>V(!q),children:[e.jsx(KM,{className:"h-4 w-4 mr-2"}),q?C?"On":"已开启":C?"Off":"已关闭"]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Mt,{className:"h-4 w-4 text-primary"})}),C?"Auto Refresh":"自动刷新"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Auto Refresh":"自动刷新"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Auto refresh tokens before expiration":"Token 过期前自动刷新,并同步更新账户信息"})]}),e.jsx(D,{variant:o?"default":"outline",size:"sm",onClick:()=>b(!o),children:o?C?"On":"已开启":C?"Off":"已关闭"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-900 rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-700 dark:text-amber-300",children:C?"About Kiro IDE auto refresh":"关于 Kiro IDE 自动刷新"}),e.jsx("p",{children:C?"• Kiro IDE has its own internal refresh loop (independent of this app). Disabling Auto Refresh here only stops this app from refreshing — it does NOT stop Kiro IDE.":'• Kiro IDE 自带独立的刷新循环,关闭本工具的"自动刷新"不会停止 IDE 自己的刷新。'}),e.jsx("p",{children:C?"• When switching accounts or refreshing tokens here, the new token is synced to ~/.aws/sso/cache/kiro-auth-token.json only for the IDE current active account; other accounts only update the local store.":"• 切号 / 刷新 Token 时,仅当该账号是 Kiro IDE 当前激活账号才会同步到磁盘文件;非激活账号仅更新本工具内部 store。"}),e.jsx("p",{children:C?"• If IDE refreshes the token itself, this app detects the file change and syncs the new token back to its store (bidirectional sync).":"• 当 Kiro IDE 自己 refresh 后,本工具会监听磁盘文件变化并反向同步到 store(双向同步)。"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-3 border-t",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[C?"Proactive Token Renewal for IDE":"IDE 主动续期",e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",C?"Advanced":"进阶",")"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?`Renew IDE's active token ~${p} min before expiry, so Kiro IDE never refreshes by itself (eliminates all race conditions).`:`在 IDE 激活账号的 token 剩 ~${p} 分钟时抢先 refresh,让 Kiro IDE 永远不自己 refresh(彻底消除竞争条件)。`})]}),e.jsx(D,{variant:f?"default":"outline",size:"sm",onClick:async()=>{const je=await y(!f);!je.success&&je.error&&alert((C?"Failed to toggle proactive renewal: ":"切换主动续期失败:")+je.error)},children:f?C?"On":"已开启":C?"Off":"已关闭"})]}),f&&e.jsxs("div",{className:"text-xs text-muted-foreground bg-emerald-50 dark:bg-emerald-950/30 border border-emerald-200 dark:border-emerald-900 rounded-lg p-3 space-y-1",children:[e.jsx("p",{children:C?`• On: a single in-process timer renews token ${p} min before expiry; Kiro IDE keeps seeing fresh tokens (≥${60-p} min remaining) and never invokes OIDC by itself.`:`• 启用后:账号管理器主进程会在 token 剩 ${p} 分钟时自动续期,Kiro IDE 始终看到剩余 ≥ ${60-p} 分钟的 token,永远不会自己调 OIDC。`}),e.jsx("p",{children:C?"• Only the IDE current active account is renewed. Switching accounts re-schedules the timer for the new active account.":"• 仅对 IDE 当前激活账号续期。切号时 timer 会自动重新调度到新账号。"}),e.jsx("p",{children:C?"• If a renewal fails (e.g. server outage), the timer stops; IDE's own refresh loop takes over as fallback.":"• 续期失败时 timer 停止,由 IDE 自己的 refresh loop 接管(双向同步仍生效)。"})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",C?"Auto refresh tokens to keep login":"Token 即将过期时自动刷新,保持登录状态"]}),e.jsxs("p",{children:["• ",C?"Update usage and subscription info after refresh":"Token 刷新后自动更新账户用量、订阅等信息"]}),e.jsxs("p",{children:["• ",C?"Check all balances when auto-switch is on":"开启自动换号时,会定期检查所有账户余额"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Check Interval":"检查间隔"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"How often to check account status":"每隔多久检查一次账户状态"})]}),e.jsxs("select",{className:"w-[120px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:d,onChange:je=>b(!0,parseInt(je.target.value)),children:[e.jsx("option",{value:"1",children:C?"1 min":"1 分钟"}),e.jsx("option",{value:"3",children:C?"3 min":"3 分钟"}),e.jsx("option",{value:"5",children:C?"5 min":"5 分钟"}),e.jsx("option",{value:"10",children:C?"10 min":"10 分钟"}),e.jsx("option",{value:"15",children:C?"15 min":"15 分钟"}),e.jsx("option",{value:"20",children:C?"20 min":"20 分钟"}),e.jsx("option",{value:"30",children:C?"30 min":"30 分钟"}),e.jsx("option",{value:"45",children:C?"45 min":"45 分钟"}),e.jsx("option",{value:"60",children:C?"60 min":"60 分钟"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Concurrency":"刷新并发数"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Number of accounts to refresh simultaneously":"同时刷新的账号数量,过大可能卡顿"})]}),e.jsx("input",{type:"number",className:"w-24 h-9 px-3 rounded-lg border bg-background text-sm text-center focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:u,min:1,max:500,onChange:je=>v(parseInt(je.target.value)||50)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Sync Account Info":"同步检测账户信息"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Detect usage, subscription, and ban status":"刷新 Token 时同步检测用量、订阅、封禁状态"})]}),e.jsx(D,{variant:h?"default":"outline",size:"sm",onClick:()=>N(!h),children:h?C?"On":"已开启":C?"Off":"已关闭"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Manual Trigger":"手动触发"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Manually trigger auto-refresh for debugging":"手动触发一次自动刷新流程(用于调试)"})]}),e.jsx(D,{variant:"outline",size:"sm",onClick:ze,disabled:st,children:st?C?"Refreshing...":"刷新中...":C?"Trigger Now":"立即触发"})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Sp,{className:"h-4 w-4 text-primary"})}),C?"API Settings":"API 设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Usage API Type":"用量查询 API"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Select API type for querying usage limits":"选择查询账户用量的 API 类型"})]}),e.jsxs("select",{className:"w-[180px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:Ne,onChange:je=>Kt(je.target.value),disabled:qe,children:[e.jsx("option",{value:"rest",children:"REST (GetUsageLimits)"}),e.jsx("option",{value:"cbor",children:"CBOR (GetUserUsageAndLimits)"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",e.jsx("strong",{children:"REST"}),": ",C?"Official Kiro IDE format, recommended":"官方 Kiro IDE 使用的格式,推荐使用"]}),e.jsxs("p",{children:["• ",e.jsx("strong",{children:"CBOR"}),": ",C?"Web portal format, may have different fields":"网页端格式,字段可能有差异"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Use K-Proxy for API":"API 请求走 K-Proxy"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Route API requests through K-Proxy MITM proxy":"API 请求通过 K-Proxy MITM 代理发送"})]}),e.jsx(D,{variant:Ye?"default":"outline",size:"sm",onClick:()=>O(!Ye),disabled:Jt,children:Ye?C?"On":"已开启":C?"Off":"已关闭"})]}),Ye&&e.jsx("div",{className:"text-xs text-amber-500 bg-amber-500/10 rounded-lg p-3",children:C?"⚠️ K-Proxy must be running for this to work":"⚠️ 需要先启动 K-Proxy MITM 代理才能生效"})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),C?"Proxy":"代理设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Enable Proxy":"启用代理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"All requests through proxy server":"所有网络请求将通过代理服务器"})]}),e.jsx(D,{variant:T?"default":"outline",size:"sm",onClick:()=>k(!T,Oe),children:T?C?"On":"已开启":C?"Off":"已关闭"})]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsx("label",{className:"text-sm font-medium",children:C?"Proxy URL":"代理地址"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",className:"flex-1 h-9 px-3 rounded-lg border bg-background text-sm font-mono focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",placeholder:C?"http://127.0.0.1:7890 or socks5://127.0.0.1:1080":"http://127.0.0.1:7890 或 socks5://127.0.0.1:1080",value:Oe,onChange:je=>Ee(je.target.value)}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>k(T,Oe),disabled:Oe===S,children:C?"Save":"保存"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:C?"Supports HTTP/HTTPS/SOCKS5, format: protocol://host:port":"支持 HTTP/HTTPS/SOCKS5 代理,格式: protocol://host:port"})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(YN,{className:"h-4 w-4 text-primary"})}),C?"Auto Switch":"自动换号"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Enable Auto Switch":"启用自动换号"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Auto switch when balance is low":"余额不足时自动切换到其他可用账号"})]}),e.jsx(D,{variant:R?"default":"outline",size:"sm",onClick:()=>G(!R),children:R?C?"On":"已开启":C?"Off":"已关闭"})]}),R&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Balance Threshold":"余额阈值"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Switch when balance below this":"余额低于此值时自动切换"})]}),e.jsx("input",{type:"number",className:"w-20 h-9 px-3 rounded-lg border bg-background text-sm text-center focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:I,min:0,onChange:je=>G(!0,parseInt(je.target.value)||0)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium flex items-center gap-2",children:[e.jsx(Gn,{className:"h-4 w-4"}),C?"Check Interval":"检查间隔"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"How often to check balance":"每隔多久检查一次余额"})]}),e.jsxs("select",{className:"h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:M,onChange:je=>G(!0,void 0,parseInt(je.target.value)),children:[e.jsx("option",{value:"1",children:C?"1 min":"1 分钟"}),e.jsx("option",{value:"3",children:C?"3 min":"3 分钟"}),e.jsx("option",{value:"5",children:C?"5 min":"5 分钟"}),e.jsx("option",{value:"10",children:C?"10 min":"10 分钟"}),e.jsx("option",{value:"15",children:C?"15 min":"15 分钟"}),e.jsx("option",{value:"30",children:C?"30 min":"30 分钟"})]})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(wA,{className:"h-4 w-4 text-primary"})}),C?"Batch Import":"批量导入"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Concurrency":"并发数"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Too high may cause API rate limiting":"同时验证的账号数量,过大可能导致 API 限流"})]}),e.jsx("input",{type:"number",className:"w-24 h-9 px-3 rounded-lg border bg-background text-sm text-center focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:W,min:1,max:500,onChange:je=>U(parseInt(je.target.value)||100)})]}),e.jsx("p",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-2",children:C?"Recommended: 10-100. Too high may cause failures, too low is slow.":"建议范围: 10-100。设置过大可能导致大量「验证失败」,设置过小则导入速度较慢。"})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Vl,{className:"h-4 w-4 text-primary"})}),C?"System Tray":"系统托盘"]})}),e.jsx(Pe,{className:"space-y-4",children:L?e.jsx("div",{className:"text-sm text-muted-foreground",children:C?"Loading...":"加载中..."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Enable System Tray":"启用系统托盘"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Show icon in system tray":"在系统托盘显示图标"})]}),e.jsx(D,{variant:ue.enabled?"default":"outline",size:"sm",onClick:()=>ne("enabled",!ue.enabled),children:ue.enabled?C?"On":"已开启":C?"Off":"已关闭"})]}),ue.enabled&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Close Button Action":"关闭按钮行为"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"What happens when you click X":"点击关闭按钮时的行为"})]}),e.jsxs("select",{className:"w-[140px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:ue.closeAction,onChange:je=>ne("closeAction",je.target.value),children:[e.jsx("option",{value:"ask",children:C?"Ask every time":"每次询问"}),e.jsx("option",{value:"minimize",children:C?"Minimize to tray":"最小化到托盘"}),e.jsx("option",{value:"quit",children:C?"Quit application":"退出程序"})]})]})}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",C?"Double-click tray icon to show window":"双击托盘图标可以显示主窗口"]}),e.jsxs("p",{children:["• ",C?"Right-click tray icon to show menu":"右键托盘图标可以显示菜单"]}),e.jsxs("p",{children:["• ",C?"Tray menu shows current account info and usage":"托盘菜单可以查看当前账户信息和用量"]})]})]})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Ap,{className:"h-4 w-4 text-primary"})}),C?"Keyboard Shortcuts":"快捷键"]})}),e.jsx(Pe,{className:"space-y-4",children:xt?e.jsx("div",{className:"text-sm text-muted-foreground",children:C?"Loading...":"加载中..."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Show Window":"显示主窗口"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Global shortcut to show main window":"全局快捷键唤起主窗口"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",className:`w-[160px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary text-center ${Ge?"border-primary ring-1 ring-primary animate-pulse":""}`,value:Ge?C?"Press keys...":"请按键...":Ue,onKeyDown:J,onFocus:()=>gt(!0),onBlur:()=>gt(!1),readOnly:!0,placeholder:C?"Click to record":"点击录制"}),Ue&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-9 px-2",onClick:()=>Ze(""),children:e.jsx(Vt,{className:"h-4 w-4"})})]})]}),ft&&e.jsx("p",{className:"text-sm text-destructive",children:ft}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",C?"Click input and press key combination to record":"点击输入框后按下组合键自动录制"]}),e.jsxs("p",{children:["• ",C?"macOS use Command, Windows/Linux use Ctrl":"macOS 使用 Command,Windows/Linux 使用 Ctrl"]}),e.jsxs("p",{children:["• ",C?"Click trash icon to clear shortcut":"点击垃圾桶图标可清除快捷键"]})]})]})})]}),e.jsx(De,{className:"hover-lift bg-primary/5",children:e.jsx(Pe,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(eo,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-sm",children:C?"Machine ID":"机器码管理"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:C?"Device identifier, auto-switch, account binding":"修改设备标识符、切号自动换码、账户机器码绑定等功能"})]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Va,{className:"h-3 w-3"}),e.jsx("span",{children:C?'Set in sidebar "Machine ID"':"请在侧边栏「机器码」中设置"})]})]})})}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Sp,{className:"h-4 w-4 text-primary"})}),C?"Data Management":"数据管理"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Export Data":"导出数据"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Supports JSON, TXT, CSV, Clipboard":"支持 JSON、TXT、CSV、剪贴板等多种格式"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:ce,children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),C?"Export":"导出"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Import Data":"导入数据"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Import accounts from JSON file":"从 JSON 文件导入账号数据"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:Ce,disabled:re,children:[e.jsx(Fa,{className:"h-4 w-4 mr-2"}),re?C?"Importing...":"导入中...":C?"Import":"导入"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-destructive",children:C?"Clear All Data":"清除所有数据"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Delete all accounts, groups and tags":"删除所有账号、分组和标签"})]}),e.jsxs(D,{variant:"destructive",size:"sm",onClick:Ve,children:[e.jsx(Vt,{className:"h-4 w-4 mr-2"}),C?"Clear":"清除"]})]})]})]}),e.jsx(AI,{isEn:C}),e.jsx(sw,{open:z,onClose:()=>X(!1),accounts:Array.from(F.values()),selectedCount:0})]})}function AI({isEn:n}){const s=vt(u=>u.proxyPool),r=vt(u=>u.proxyPoolConfig),i=["kiro-register-config","kiro-register-history","kiro-register-templates","kiro-register-ratelimit-enabled","kiro-register-ratelimit-max","kiro-register-autobackoff","kiro-register-dailyquota-limit","kiro-register-schedule-enabled","kiro-register-schedule-time","kiro-register-mixed-sources","kiro-webhooks","accounts_viewMode","accounts_activeGroupTab","systemLogs_displayLimit","kiro-diagnose-moemail","proxyLogs_timeRange","proxyLogs_displayLimit"],o=()=>{const u={};for(const b of i){const v=localStorage.getItem(b);v!=null&&(u[b]=v)}const h={version:1,type:"krouter-config",exportedAt:Date.now(),proxyPool:Object.fromEntries(s),proxyPoolConfig:r,localStorage:u},f=new Blob([JSON.stringify(h,null,2)],{type:"application/json"}),p=URL.createObjectURL(f),y=document.createElement("a");y.href=p,y.download=`krouter-config-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,y.click(),URL.revokeObjectURL(p)},d=async()=>{const u=await window.api.importFromFile();if(!u||u.format!=="json"){alert(n?"Please select a JSON file":"请选择 JSON 文件");return}try{const h=JSON.parse(u.content);if(h.type!=="krouter-config"&&h.type!=="kiro-account-manager-config"){alert(n?"Not a valid config file":"不是有效的配置文件");return}if(!confirm(n?"This will overwrite proxy pool / webhooks / templates. Continue?":"这将覆盖代理池 / Webhook / 模板等配置,确定继续?"))return;if(h.localStorage&&typeof h.localStorage=="object"){for(const[f,p]of Object.entries(h.localStorage))if(i.includes(f)&&typeof p=="string")try{localStorage.setItem(f,p)}catch{}}h.proxyPool&&typeof h.proxyPool=="object"&&(vt.getState().clearProxyPool(),vt.setState({proxyPool:new Map(Object.entries(h.proxyPool))})),h.proxyPoolConfig&&vt.getState().setProxyPoolConfig(h.proxyPoolConfig),alert(n?"Config imported. Please restart the app to fully apply.":"配置已导入。建议重启应用以完全生效。")}catch(h){alert((n?"Import failed: ":"导入失败: ")+(h instanceof Error?h.message:String(h)))}};return e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(YN,{className:"h-4 w-4 text-primary"})}),n?"Configuration Sync":"配置同步"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n?"Export all non-sensitive settings (proxy pool, webhooks, templates, rate limits, UI preferences) to a file, for backup or multi-device sync. Does NOT include account tokens or credentials.":'导出所有"非敏感"配置(代理池、Webhook、注册模板、限速、UI 偏好等)到文件,便于备份或多设备同步。不含账号 Token 与凭据。'}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:o,children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),n?"Export Config":"导出配置"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(Fa,{className:"h-4 w-4 mr-2"}),n?"Import Config":"导入配置"]})]})]})]})}function MI(){const{machineIdConfig:n,currentMachineId:s,originalMachineId:r,originalBackupTime:i,accountMachineIds:o,machineIdHistory:d,accounts:u,setMachineIdConfig:h,refreshCurrentMachineId:f,changeMachineId:p,restoreOriginalMachineId:y,clearMachineIdHistory:b,bindMachineIdToAccount:v}=vt(),{t:N}=Ut(),j=N("common.unknown")==="Unknown",[T,S]=g.useState(!1),[k,R]=g.useState(null),[I,M]=g.useState("unknown"),[G,W]=g.useState(""),[U,q]=g.useState(!1),[V,le]=g.useState(!1),[B,be]=g.useState(null),[K,se]=g.useState(""),[te,Y]=g.useState(""),[P,F]=g.useState(null);g.useEffect(()=>{(async()=>{S(!0);try{const Ue=await window.api.machineIdGetOSType();M(Ue);const Lt=await window.api.machineIdCheckAdmin();R(Lt),await f()}catch(Ue){console.error("初始化失败:",Ue)}finally{S(!1)}})()},[f]);const fe=(we,Ue="default")=>{navigator.clipboard.writeText(we),F(Ue),setTimeout(()=>F(null),1500)},pe=async()=>{S(!0);try{await p(),await f()}finally{S(!1)}},C=async()=>{if(G.trim()){S(!0);try{await p(G.trim()),await f(),W("")}finally{S(!1)}}},z=async()=>{S(!0);try{await y(),await f()}finally{S(!1)}},X=async()=>{s&&await window.api.machineIdBackupToFile(s)},re=async()=>{S(!0);try{const we=await window.api.machineIdRestoreFromFile();we.success&&we.machineId&&(await p(we.machineId),await f())}finally{S(!1)}},xe=async()=>{await window.api.machineIdRequestAdminRestart()},Oe=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,we=>{const Ue=Math.random()*16|0;return(we==="x"?Ue:Ue&3|8).toString(16)}),Ee=we=>{be(we),se(o[we]||"")},Qe=we=>{K.trim()&&v(we,K.trim()),be(null),se("")},_e=()=>{be(null),se("")},st=we=>{const Ue=Oe();v(we,Ue),B===we&&se(Ue)},oe=we=>{const{accountMachineIds:Ue}=vt.getState(),Lt={...Ue};delete Lt[we],vt.setState({accountMachineIds:Lt}),vt.getState().saveToStorage()},ue=we=>new Date(we).toLocaleString("zh-CN"),ae=()=>{switch(I){case"windows":return"Windows";case"macos":return"macOS";case"linux":return"Linux";default:return j?"Unknown":"未知"}},L=Object.keys(o).length;return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero",children:[e.jsx("div",{className:"absolute inset-0 bg-grid-white/5"}),e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-3xl -translate-y-1/2 translate-x-1/2"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-3xl translate-y-1/2 -translate-x-1/2"}),e.jsxs("div",{className:"relative p-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-4 rounded-2xl bg-gradient-to-br from-primary to-primary/80 shadow-lg shadow-primary/25",children:e.jsx(eo,{className:"h-8 w-8 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:j?"Machine ID":"机器码管理"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:j?"Manage device identifier to prevent account bans":"管理设备标识符,防止账号关联和封禁"})]})]}),e.jsxs($e,{variant:"outline",className:"bg-background/80 backdrop-blur-sm",children:[e.jsx(Vl,{className:"h-3 w-3 mr-1"}),ae()]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 mt-6",children:[e.jsx("div",{className:"p-4 rounded-xl bg-background/60 backdrop-blur-sm border border-white/10",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(eo,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:d.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"History":"变更记录"})]})]})}),e.jsx("div",{className:"p-4 rounded-xl bg-background/60 backdrop-blur-sm border border-white/10",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ql,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:L}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Bound Accounts":"已绑定账户"})]})]})}),e.jsx("div",{className:"p-4 rounded-xl bg-background/60 backdrop-blur-sm border border-white/10",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Vn,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r?j?"Backed":"已备份":j?"None":"未备份"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Original ID":"原始机器码"})]})]})})]})]})]}),k===!1&&e.jsx(De,{className:"border-warning/50 bg-gradient-to-r from-warning/10 to-warning/5 overflow-hidden",children:e.jsx(Pe,{className:"py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-warning/20",children:e.jsx(Rs,{className:"h-5 w-5 text-warning"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-warning",children:j?"Admin Required":"需要管理员权限"}),e.jsx("p",{className:"text-sm text-warning/80",children:j?"Run as administrator to modify machine ID":"修改机器码需要以管理员身份运行应用"})]})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:xe,className:"border-warning/50 hover:bg-warning/10",children:[e.jsx(Vn,{className:"h-4 w-4 mr-1"}),j?"Restart as Admin":"以管理员重启"]})]})})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(De,{className:"group relative overflow-hidden hover:shadow-lg transition-all duration-300",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/5 to-primary/10 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none"}),e.jsx(at,{className:"pb-3 relative z-10",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Vl,{className:"h-4 w-4 text-primary"})}),j?"Current Machine ID":"当前机器码",s&&s!==r&&e.jsx($e,{className:"ml-auto bg-primary/10 text-primary border-primary/20",children:j?"Modified":"已修改"})]})}),e.jsxs(Pe,{className:"space-y-4 relative z-10",children:[e.jsx("div",{className:"relative group/code",children:e.jsx("div",{className:"p-4 bg-muted rounded-xl font-mono text-sm break-all border border-border text-foreground",children:T?e.jsxs("span",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(Mt,{className:"h-4 w-4 animate-spin"}),j?"Loading...":"加载中..."]}):s||e.jsx("span",{className:"text-muted-foreground",children:j?"Unable to get":"无法获取"})})}),d.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(tc,{className:"h-3 w-3"}),j?"Last modified:":"最后修改:"," ",ue(d[d.length-1].timestamp)]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>fe(s,"current"),disabled:!s,className:"flex-1",children:[P==="current"?e.jsx(Pt,{className:"h-4 w-4 mr-1 text-success"}):e.jsx(As,{className:"h-4 w-4 mr-1"}),P==="current"?j?"Copied!":"已复制":j?"Copy":"复制"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:async()=>{S(!0);try{await f()}finally{S(!1)}},disabled:T,className:"flex-1",children:[e.jsx(Mt,{className:me("h-4 w-4 mr-1",T&&"animate-spin")}),j?"Refresh":"刷新"]})]})]})]}),e.jsxs(De,{className:"group relative overflow-hidden hover:shadow-lg transition-all duration-300",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/5 to-primary/10 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none"}),e.jsx(at,{className:"pb-3 relative z-10",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Vn,{className:"h-4 w-4 text-primary"})}),j?"Original Machine ID Backup":"原始机器码备份",r&&e.jsxs($e,{className:"ml-auto bg-primary/10 text-primary border-primary/20",children:[e.jsx(Bn,{className:"h-3 w-3 mr-1"}),j?"Backed Up":"已备份"]})]})}),e.jsx(Pe,{className:"space-y-4 relative z-10",children:r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-4 bg-gradient-to-br from-primary/5 to-primary/10 rounded-xl font-mono text-sm break-all border border-primary/20",children:r}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(Bn,{className:"h-3 w-3 text-primary"}),j?"Backup time:":"备份时间:"," ",i?ue(i):j?"Unknown":"未知"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>fe(r,"original"),className:"flex-1",children:[P==="original"?e.jsx(Pt,{className:"h-4 w-4 mr-1 text-success"}):e.jsx(As,{className:"h-4 w-4 mr-1"}),P==="original"?j?"Copied!":"已复制":j?"Copy":"复制"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:z,disabled:T||s===r,className:"flex-1 border-primary/50 hover:bg-primary/10 hover:text-primary",children:[e.jsx(gr,{className:"h-4 w-4 mr-1"}),j?"Restore":"恢复原始"]})]})]}):e.jsxs("div",{className:"p-6 text-center rounded-xl border-2 border-dashed border-muted",children:[e.jsx(Vn,{className:"h-8 w-8 mx-auto text-muted-foreground/50 mb-2"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:j?"Original ID will be backed up on first change":"首次修改机器码时将自动备份原始值"})]})})]})]}),e.jsxs(De,{className:"overflow-hidden",children:[e.jsx(at,{className:"bg-gradient-to-r from-primary/5 to-primary/10 border-b",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Kn,{className:"h-4 w-4 text-primary"})}),j?"Operations":"机器码操作"]})}),e.jsxs(Pe,{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"group p-5 rounded-xl border-2 border-dashed hover:border-primary/50 hover:bg-primary/5 transition-all space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-primary to-primary/80 text-white",children:e.jsx(Kn,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold",children:j?"Random Generate":"随机生成"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Generate UUID format machine ID":"一键生成 UUID 格式机器码"})]})]}),e.jsxs(D,{onClick:pe,disabled:T,className:"w-full bg-primary hover:bg-primary/90 text-primary-foreground shadow-lg shadow-primary/25",children:[e.jsx(Kn,{className:"h-4 w-4 mr-2"}),j?"Generate & Apply":"随机生成并应用"]})]}),e.jsxs("div",{className:"group p-5 rounded-xl border-2 border-dashed hover:border-primary/50 hover:bg-primary/5 transition-all space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-primary/80 to-primary text-white",children:e.jsx(Nf,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold",children:j?"Custom Input":"自定义输入"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Enter a specific machine ID":"输入指定的机器码"})]})]}),e.jsx("input",{type:"text",placeholder:j?"Enter UUID format machine ID...":"输入 UUID 格式机器码...",value:G,onChange:we=>W(we.target.value),className:"w-full px-4 py-2.5 text-sm border-2 rounded-xl bg-background focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all"}),e.jsx(D,{onClick:C,disabled:T||!G.trim(),variant:"outline",className:"w-full border-2 hover:bg-primary/10 hover:border-primary/50",children:j?"Apply Custom ID":"应用自定义机器码"})]})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:X,disabled:!s,className:"flex-1 h-10",children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),j?"Export to File":"导出到文件"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:re,disabled:T,className:"flex-1 h-10",children:[e.jsx(Fa,{className:"h-4 w-4 mr-2"}),j?"Import from File":"从文件导入"]})]})]})]}),e.jsxs(De,{className:"overflow-hidden",children:[e.jsx(at,{className:"bg-gradient-to-r from-primary/5 to-primary/10 border-b",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(ql,{className:"h-4 w-4 text-primary"})}),j?"Automation":"自动化设置"]})}),e.jsxs(Pe,{className:"p-0 divide-y",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:me("p-2.5 rounded-xl transition-colors",n.autoSwitchOnAccountChange?"bg-primary/10":"bg-muted"),children:e.jsx(Mt,{className:me("h-5 w-5 transition-colors",n.autoSwitchOnAccountChange?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:j?"Auto Change on Switch":"切换账号时自动更换机器码"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Auto generate new ID when switching accounts":"每次切换账号时自动生成并应用新的机器码"})]})]}),e.jsx(D,{variant:n.autoSwitchOnAccountChange?"default":"outline",size:"sm",onClick:()=>h({autoSwitchOnAccountChange:!n.autoSwitchOnAccountChange}),className:me("min-w-[80px]",n.autoSwitchOnAccountChange&&"bg-primary hover:bg-primary/90"),children:n.autoSwitchOnAccountChange?j?"On":"已开启":j?"Off":"已关闭"})]}),e.jsxs("div",{className:"flex items-center justify-between p-5 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:me("p-2.5 rounded-xl transition-colors",n.bindMachineIdToAccount?"bg-primary/10":"bg-muted"),children:e.jsx(ql,{className:me("h-5 w-5 transition-colors",n.bindMachineIdToAccount?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium flex items-center gap-2",children:[j?"Account ID Binding":"账户机器码绑定",L>0&&e.jsx($e,{className:"bg-primary/10 text-primary border-primary/20",children:j?`${L} accounts`:`${L} 个账户`})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Assign unique ID per account, auto-apply on switch":"为每个账户分配唯一的机器码,切换时自动使用"})]})]}),e.jsx(D,{variant:n.bindMachineIdToAccount?"default":"outline",size:"sm",onClick:()=>h({bindMachineIdToAccount:!n.bindMachineIdToAccount}),className:me("min-w-[80px]",n.bindMachineIdToAccount&&"bg-primary hover:bg-primary/90"),children:n.bindMachineIdToAccount?j?"On":"已开启":j?"Off":"已关闭"})]}),n.bindMachineIdToAccount&&e.jsxs("div",{className:"flex items-center justify-between p-5 pl-16 bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:me("p-2 rounded-lg transition-colors",n.useBindedMachineId?"bg-primary/10":"bg-muted"),children:e.jsx(Bn,{className:me("h-4 w-4 transition-colors",n.useBindedMachineId?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:j?"Use bound machine ID":"使用绑定的唯一机器码"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"When off, generates new ID on each switch":"关闭时每次切换将随机生成新机器码"})]})]}),e.jsx(D,{variant:n.useBindedMachineId?"default":"outline",size:"sm",onClick:()=>h({useBindedMachineId:!n.useBindedMachineId}),className:me("min-w-[80px]",n.useBindedMachineId&&"bg-primary hover:bg-primary/90"),children:n.useBindedMachineId?j?"On":"已开启":j?"Off":"已关闭"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(De,{className:"group cursor-pointer hover:shadow-lg transition-all duration-300 hover:border-primary/50",onClick:()=>le(!0),children:e.jsx(Pe,{className:"p-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-gradient-to-br from-primary/10 to-primary/5 group-hover:from-primary/20 group-hover:to-primary/10 transition-colors",children:e.jsx(Fn,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-semibold group-hover:text-primary transition-colors",children:j?"Account Machine ID":"账户机器码管理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"View and manage bound machine IDs":"查看和管理每个账户绑定的机器码"})]}),e.jsx("div",{className:"p-2 rounded-lg bg-muted group-hover:bg-primary/10 transition-colors",children:e.jsx(Nf,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors"})})]})})}),e.jsx(De,{className:"group cursor-pointer hover:shadow-lg transition-all duration-300 hover:border-primary/50",onClick:()=>q(!0),children:e.jsx(Pe,{className:"p-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-gradient-to-br from-primary/10 to-primary/5 group-hover:from-primary/20 group-hover:to-primary/10 transition-colors",children:e.jsx(tc,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-semibold group-hover:text-primary transition-colors",children:j?"Change History":"变更历史记录"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?`${d.length} records`:`共 ${d.length} 条历史记录`})]}),e.jsx("div",{className:"p-2 rounded-lg bg-muted group-hover:bg-primary/10 transition-colors",children:e.jsx(tc,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors"})})]})})})]}),V&&Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>le(!1)}),e.jsxs("div",{className:"relative bg-background rounded-xl shadow-2xl w-[600px] max-h-[80vh] flex flex-col animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fn,{className:"h-5 w-5"}),e.jsx("h2",{className:"text-lg font-semibold",children:j?"Account Machine ID":"账户机器码管理"}),e.jsxs($e,{variant:"secondary",children:[u.size," ",j?"accounts":"个账户"]})]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>le(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"px-4 pt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx(to,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx("input",{type:"text",value:te,onChange:we=>Y(we.target.value),placeholder:j?"Search accounts...":"搜索账户...",className:"w-full pl-9 pr-3 py-2 text-sm bg-muted border-0 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary"}),te&&e.jsx(D,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>Y(""),children:e.jsx(ns,{className:"h-3 w-3"})})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-2",children:[Array.from(u.values()).filter(we=>{if(!te.trim())return!0;const Ue=te.toLowerCase();return we.email?.toLowerCase().includes(Ue)||we.nickname?.toLowerCase().includes(Ue)||o[we.id]?.toLowerCase().includes(Ue)}).map(we=>{const Ue=o[we.id],Lt=B===we.id;return e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center text-primary text-sm font-medium",children:(we.nickname||we.email||"?")[0].toUpperCase()}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-sm truncate max-w-[200px]",children:we.nickname||we.email}),we.nickname&&we.email&&e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[200px]",children:we.email})]}),Ue&&e.jsx($e,{variant:"secondary",className:"text-xs bg-success/10 text-success",children:j?"Bound":"已绑定"})]}),e.jsx("div",{className:"flex items-center gap-1",children:Lt?e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"default",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>Qe(we.id),children:[e.jsx(Pt,{className:"h-3.5 w-3.5 mr-1"}),j?"Save":"保存"]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:_e,children:j?"Cancel":"取消"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>st(we.id),title:j?"Random":"随机",children:e.jsx(Kn,{className:"h-3.5 w-3.5"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Ee(we.id),title:j?"Edit":"编辑",children:e.jsx(Nf,{className:"h-3.5 w-3.5"})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>st(we.id),title:j?"Random":"随机",children:e.jsx(Kn,{className:"h-3.5 w-3.5"})}),Ue&&e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>fe(Ue),title:j?"Copy":"复制",children:e.jsx(As,{className:"h-3.5 w-3.5"})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>oe(we.id),title:j?"Delete":"删除",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]})]})})]}),Lt?e.jsx("input",{type:"text",value:K,onChange:xt=>se(xt.target.value),placeholder:j?"Enter UUID format machine ID":"输入 UUID 格式机器码",className:"w-full px-2 py-1.5 text-xs font-mono bg-background border rounded focus:outline-none focus:ring-2 focus:ring-primary",autoFocus:!0}):Ue?e.jsx("div",{className:"flex items-center gap-2 px-2 py-1.5 bg-background rounded border",children:e.jsx("code",{className:"text-xs font-mono flex-1",children:Ue})}):e.jsx("div",{className:"px-2 py-1.5 bg-background/50 rounded border border-dashed text-center",children:e.jsx("span",{className:"text-xs text-muted-foreground",children:j?"Not bound":"未绑定"})})]},we.id)}),u.size===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Fn,{className:"h-12 w-12 mx-auto text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:j?"No accounts":"暂无账户"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Please add accounts first":"请先添加账户"})]}),u.size>0&&te&&Array.from(u.values()).filter(we=>{const Ue=te.toLowerCase();return we.email?.toLowerCase().includes(Ue)||we.nickname?.toLowerCase().includes(Ue)||o[we.id]?.toLowerCase().includes(Ue)}).length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx(to,{className:"h-10 w-10 mx-auto text-muted-foreground/50 mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:j?"No matches found":"未找到匹配的账户"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Try other keywords":"尝试其他关键词"})]})]}),e.jsx("div",{className:"px-6 py-3 border-t bg-muted/50 text-xs text-muted-foreground",children:j?"💡 Tip: After binding, switching to this account will auto-apply the bound machine ID":"💡 提示:绑定机器码后,切换到该账户时会自动应用对应的机器码"})]})]}),document.body),U&&Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>q(!1)}),e.jsxs("div",{className:"relative bg-background rounded-xl shadow-2xl w-[550px] max-h-[80vh] flex flex-col animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tc,{className:"h-5 w-5"}),e.jsx("h2",{className:"text-lg font-semibold",children:j?"Change History":"变更历史"}),e.jsxs($e,{variant:"secondary",children:[d.length," ",j?"records":"条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d.length>0&&e.jsxs(D,{variant:"ghost",size:"sm",onClick:b,className:"text-destructive hover:text-destructive",children:[e.jsx(Vt,{className:"h-4 w-4 mr-1"}),j?"Clear":"清空"]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>q(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:d.length>0?e.jsx("div",{className:"space-y-2",children:[...d].reverse().map((we,Ue)=>e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["#",d.length-Ue]}),e.jsxs($e,{variant:"secondary",className:me("text-xs whitespace-nowrap",we.action==="initial"&&"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300",we.action==="manual"&&"bg-purple-100 text-purple-700 dark:bg-purple-900 dark:text-purple-300",we.action==="auto_switch"&&"bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300",we.action==="restore"&&"bg-orange-100 text-orange-700 dark:bg-orange-900 dark:text-orange-300",we.action==="bind"&&"bg-cyan-100 text-cyan-700 dark:bg-cyan-900 dark:text-cyan-300"),children:[we.action==="initial"&&(j?"Init":"初始"),we.action==="manual"&&(j?"Manual":"手动"),we.action==="auto_switch"&&(j?"Auto":"自动"),we.action==="restore"&&(j?"Restore":"恢复"),we.action==="bind"&&(j?"Bind":"绑定")]})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:ue(we.timestamp)})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-background rounded border",children:[e.jsx("code",{className:"text-sm flex-1 font-mono",children:we.machineId}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 shrink-0",onClick:()=>fe(we.machineId),title:j?"Copy":"复制",children:e.jsx(As,{className:"h-3 w-3"})})]}),we.accountId&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[j?"Account: ":"关联账户: ",u.get(we.accountId)?.nickname||u.get(we.accountId)?.email||we.accountId]})]},we.id))}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(tc,{className:"h-12 w-12 mx-auto text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:j?"No change records":"暂无变更记录"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Changes will be recorded automatically":"机器码变更后将自动记录"})]})})]})]}),document.body),e.jsx(De,{className:"overflow-hidden bg-gradient-to-br from-muted/50 to-muted/30",children:e.jsx(Pe,{className:"p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-primary/10 shrink-0",children:e.jsx(Vn,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"font-semibold",children:j?"Platform Notes":"平台说明"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-primary/5 border border-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Vl,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:"Windows"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Modifies registry MachineGuid, requires admin":"修改注册表 MachineGuid,需要管理员权限"})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-primary/5 border border-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Vl,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:"macOS"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"App-level override, hardware UUID unchanged":"应用层覆盖方式,原生硬件 UUID 无法修改"})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-primary/5 border border-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Vl,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:"Linux"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Modifies /etc/machine-id, requires root":"修改 /etc/machine-id,需要 root 权限"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-warning/10 border border-warning/20",children:[e.jsx(Rs,{className:"h-4 w-4 text-warning shrink-0"}),e.jsx("p",{className:"text-xs text-warning",children:j?"Changing machine ID may affect some software licenses, proceed with caution":"修改机器码可能影响部分软件的授权,请谨慎操作"})]})]})]})})})]})}function EI({filename:n,onClose:s,onSaved:r}){const[i,o]=g.useState(""),[d,u]=g.useState(!0),[h,f]=g.useState(!1),[p,y]=g.useState(null),[b,v]=g.useState(!1),{t:N}=Ut(),j=N("common.unknown")==="Unknown";g.useEffect(()=>{T()},[n]);const T=async()=>{u(!0),y(null);try{const I=await window.api.readKiroSteeringFile(n);I.success&&I.content!==void 0?(o(I.content),v(!1)):y(I.error||(j?"Failed to read file":"读取文件失败"))}catch(I){y(j?"Failed to read file":"读取文件失败"),console.error(I)}finally{u(!1)}},S=async()=>{f(!0),y(null);try{const I=await window.api.saveKiroSteeringFile(n,i);I.success?(v(!1),r?.()):y(I.error||(j?"Failed to save file":"保存文件失败"))}catch(I){y(j?"Failed to save file":"保存文件失败"),console.error(I)}finally{f(!1)}},k=()=>{b?confirm(j?"File modified. Close anyway? Unsaved changes will be lost.":"文件已修改,确定要关闭吗?未保存的更改将丢失。")&&s():s()},R=I=>{o(I),v(!0)};return Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:k}),e.jsxs("div",{className:"relative bg-background rounded-lg shadow-xl w-[90vw] max-w-4xl h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"font-semibold",children:j?"Edit Steering File":"编辑 Steering 文件"}),e.jsx("span",{className:"text-sm text-muted-foreground font-mono",children:n}),b&&e.jsxs("span",{className:"text-xs text-warning",children:["● ",j?"Modified":"已修改"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:"ghost",size:"sm",onClick:T,disabled:d,children:e.jsx(Mt,{className:`h-4 w-4 ${d?"animate-spin":""}`})}),e.jsxs(D,{variant:"default",size:"sm",onClick:S,disabled:h||!b,children:[e.jsx(vx,{className:"h-4 w-4 mr-1"}),h?j?"Saving...":"保存中...":j?"Save":"保存"]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:k,children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),p&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm",children:p}),e.jsx("div",{className:"flex-1 p-4 overflow-hidden",children:d?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Mt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx("textarea",{value:i,onChange:I=>R(I.target.value),className:"w-full h-full p-4 font-mono text-sm bg-muted rounded-lg border-0 resize-none focus:outline-none focus:ring-2 focus:ring-primary",placeholder:j?"Edit steering rules here...":"在此编辑 Steering 规则...",spellCheck:!1})}),e.jsx("div",{className:"px-4 py-2 border-t text-xs text-muted-foreground",children:j?"Tip: Steering files use Markdown format to define AI assistant behavior rules":"提示:Steering 文件使用 Markdown 格式,用于定义 AI 助手的行为规则"})]})]}),document.body)}function II({serverName:n,server:s,onClose:r,onSaved:i}){const[o,d]=g.useState(n||""),[u,h]=g.useState(s?.command||""),[f,p]=g.useState(s?.args||[]),[y,b]=g.useState(s?.env?Object.entries(s.env).map(([B,be])=>({key:B,value:be})):[]),[v,N]=g.useState(!1),[j,T]=g.useState(null),[S,k]=g.useState(""),R=!!n,{t:I}=Ut(),M=I("common.unknown")==="Unknown",G=async()=>{if(!o.trim()){T(M?"Please enter server name":"请输入服务器名称");return}if(!u.trim()){T(M?"Please enter command":"请输入命令");return}N(!0),T(null);try{const B={command:u.trim(),args:f.filter(K=>K.trim()),env:y.reduce((K,{key:se,value:te})=>(se.trim()&&(K[se.trim()]=te),K),{})};B.args?.length===0&&delete B.args,Object.keys(B.env||{}).length===0&&delete B.env;const be=await window.api.saveMcpServer(o.trim(),B,R?n:void 0);be.success?(i(),r()):T(be.error||(M?"Save failed":"保存失败"))}catch(B){T(M?"Save failed":"保存失败"),console.error(B)}finally{N(!1)}},W=()=>{S.trim()&&(p([...f,S.trim()]),k(""))},U=B=>{p(f.filter((be,K)=>K!==B))},q=()=>{b([...y,{key:"",value:""}])},V=(B,be,K)=>{const se=[...y];se[B][be]=K,b(se)},le=B=>{b(y.filter((be,K)=>K!==B))};return Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:r}),e.jsxs("div",{className:"relative bg-background rounded-lg shadow-xl w-[90vw] max-w-lg max-h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsx("h2",{className:"font-semibold",children:R?M?"Edit MCP Server":"编辑 MCP 服务器":M?"Add MCP Server":"添加 MCP 服务器"}),e.jsx(D,{variant:"ghost",size:"sm",onClick:r,children:e.jsx(ns,{className:"h-4 w-4"})})]}),j&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm",children:j}),e.jsxs("div",{className:"flex-1 p-4 space-y-4 overflow-auto",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Server Name":"服务器名称"}),e.jsx("input",{type:"text",value:o,onChange:B=>d(B.target.value),placeholder:M?"e.g.: fetch, exa, context7":"例如: fetch, exa, context7",className:"w-full px-3 py-2 rounded-md border bg-background text-sm",disabled:R})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Command":"命令"}),e.jsx("input",{type:"text",value:u,onChange:B=>h(B.target.value),placeholder:M?"e.g.: uvx, npx, node":"例如: uvx, npx, node",className:"w-full px-3 py-2 rounded-md border bg-background text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Arguments":"参数"}),e.jsxs("div",{className:"space-y-2",children:[f.map((B,be)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:B}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>U(be),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},be)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:S,onChange:B=>k(B.target.value),placeholder:M?"Add argument":"添加参数",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:B=>B.key==="Enter"&&W()}),e.jsx(D,{variant:"outline",size:"sm",onClick:W,children:e.jsx(Ts,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Environment Variables":"环境变量"}),e.jsxs("div",{className:"space-y-2",children:[y.map((B,be)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:B.key,onChange:K=>V(be,"key",K.target.value),placeholder:M?"Key":"变量名",className:"w-1/3 px-2 py-1.5 rounded-md border bg-background text-sm"}),e.jsx("input",{type:"text",value:B.value,onChange:K=>V(be,"value",K.target.value),placeholder:M?"Value":"值",className:"flex-1 px-2 py-1.5 rounded-md border bg-background text-sm"}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>le(be),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},be)),e.jsxs(D,{variant:"outline",size:"sm",onClick:q,children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),M?"Add Env Var":"添加环境变量"]})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 border-t",children:[e.jsx(D,{variant:"outline",onClick:r,children:M?"Cancel":"取消"}),e.jsxs(D,{onClick:G,disabled:v,children:[e.jsx(vx,{className:"h-4 w-4 mr-1"}),v?M?"Saving...":"保存中...":M?"Save":"保存"]})]})]})]}),document.body)}const RI=["rm -rf *","rm -rf /","rm -rf ~","del /f /s /q *","format","mkfs","dd if=",":(){:|:&};:","chmod -R 777 /","chown -R","> /dev/sda","wget * | sh","curl * | sh","shutdown","reboot","init 0","init 6"],nj={agentAutonomy:"Autopilot",modelSelection:"auto",enableDebugLogs:!1,enableTabAutocomplete:!1,enableCodebaseIndexing:!1,usageSummary:!0,codeReferences:!1,configureMCP:"Enabled",trustedCommands:[],trustedTools:{},commandDenylist:[],ignoreFiles:[],mcpApprovedEnvVars:[],notificationsActionRequired:!0,notificationsFailure:!1,notificationsSuccess:!1,notificationsBilling:!0},DI=[{value:"Autopilot",label:"Autopilot (自动执行)",description:"Agent 自动执行任务"},{value:"Supervised",label:"Supervised (需确认)",description:"每个步骤需要手动确认"}],PI=[{value:"Autopilot",label:"Autopilot (Auto)",description:"Agent executes tasks automatically"},{value:"Supervised",label:"Supervised (Confirm)",description:"Manual confirmation for each step"}],LI=[{value:"Enabled",label:"启用",description:"允许 MCP 服务器连接"},{value:"Disabled",label:"禁用",description:"禁用所有 MCP 功能"}],OI=[{value:"Enabled",label:"Enabled",description:"Allow MCP server connections"},{value:"Disabled",label:"Disabled",description:"Disable all MCP features"}];function zI(){const[n,s]=g.useState(nj),[r,i]=g.useState({mcpServers:{}}),[o,d]=g.useState([]),[u,h]=g.useState(!0),[f,p]=g.useState(!1),[y,b]=g.useState(null),[v,N]=g.useState([]),[j,T]=g.useState(!1),[S,k]=g.useState({agent:!0,mcp:!0,steering:!0,commands:!1}),[R,I]=g.useState(""),[M,G]=g.useState(""),[W,U]=g.useState(""),[q,V]=g.useState(null),[le,B]=g.useState(null),{t:be}=Ut(),K=be("common.unknown")==="Unknown",se=K?PI:DI,te=K?OI:LI;g.useEffect(()=>{P(),Y()},[]);const Y=async()=>{T(!0);try{const ae=await window.api.getKiroAvailableModels();ae.models&&ae.models.length>0&&N(ae.models)}catch(ae){console.error("Failed to load models:",ae)}finally{T(!1)}},P=async()=>{h(!0),b(null);try{const ae=await window.api.getKiroSettings();if(ae.settings){const L=Object.fromEntries(Object.entries(ae.settings).filter(([,we])=>we!==void 0));s({...nj,...L})}ae.mcpConfig&&i(ae.mcpConfig),ae.steeringFiles&&d(ae.steeringFiles)}catch(ae){b(K?"Failed to load Kiro settings":"加载 Kiro 设置失败"),console.error(ae)}finally{h(!1)}},F=async()=>{p(!0),b(null);try{await window.api.saveKiroSettings(n)}catch(ae){b(K?"Failed to save settings":"保存设置失败"),console.error(ae)}finally{p(!1)}},fe=ae=>{k(L=>({...L,[ae]:!L[ae]}))},pe=async()=>{try{await window.api.openKiroSettingsFile()}catch(ae){console.error(ae)}},C=async ae=>{try{await window.api.openKiroMcpConfig(ae)}catch(L){console.error(L)}},z=async()=>{try{await window.api.openKiroSteeringFolder()}catch(ae){console.error(ae)}},X=ae=>{V(ae)},re=async ae=>{try{await window.api.openKiroSteeringFile(ae)}catch(L){console.error(L)}},xe=async()=>{try{(await window.api.createKiroDefaultRules()).success&&await P()}catch(ae){console.error(ae)}},Oe=async ae=>{if(confirm(K?`Delete "${ae}"? This cannot be undone.`:`确定要删除 "${ae}" 吗?此操作无法撤销。`))try{const L=await window.api.deleteKiroSteeringFile(ae);L.success?await P():b(L.error||(K?"Failed to delete file":"删除文件失败"))}catch(L){console.error(L),b(K?"Failed to delete file":"删除文件失败")}},Ee=async ae=>{if(confirm(K?`Delete MCP server "${ae}"?`:`确定要删除 MCP 服务器 "${ae}" 吗?`))try{const L=await window.api.deleteMcpServer(ae);L.success?await P():b(L.error||(K?"Failed to delete server":"删除服务器失败"))}catch(L){console.error(L),b(K?"Failed to delete server":"删除服务器失败")}},Qe=()=>{R.trim()&&(s(ae=>({...ae,trustedCommands:[...ae.trustedCommands,R.trim()]})),I(""))},_e=ae=>{s(L=>({...L,trustedCommands:L.trustedCommands.filter((we,Ue)=>Ue!==ae)}))},st=()=>{W.trim()&&(s(ae=>({...ae,commandDenylist:[...ae.commandDenylist,W.trim()]})),U(""))},oe=()=>{s(ae=>{const L=RI.filter(we=>!ae.commandDenylist.includes(we));return{...ae,commandDenylist:[...ae.commandDenylist,...L]}})},ue=ae=>{s(L=>({...L,commandDenylist:L.commandDenylist.filter((we,Ue)=>Ue!==ae)}))};return u?e.jsx("div",{className:"flex-1 p-6 flex items-center justify-center",children:e.jsx(Mt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary shadow-lg shadow-primary/25",children:e.jsx(Hi,{className:"h-6 w-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:K?"Kiro Settings":"Kiro 设置"}),e.jsx("p",{className:"text-muted-foreground",children:K?"Manage Kiro IDE config, MCP servers and user rules":"管理 Kiro IDE 的配置、MCP 服务器和用户规则"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:P,className:"bg-background/50 backdrop-blur-sm",children:[e.jsx(Mt,{className:"h-4 w-4 mr-2"}),K?"Refresh":"刷新"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:pe,className:"bg-background/50 backdrop-blur-sm",children:[e.jsx(Xs,{className:"h-4 w-4 mr-2"}),K?"Open File":"打开设置文件"]}),e.jsxs(D,{size:"sm",onClick:F,disabled:f,children:[e.jsx(vx,{className:"h-4 w-4 mr-2"}),f?K?"Saving...":"保存中...":K?"Save":"保存设置"]})]})]})]}),y&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-destructive/10 text-destructive rounded-lg",children:[e.jsx(ln,{className:"h-4 w-4"}),y]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("agent"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Ka,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"Agent Settings":"Agent 设置"})]}),S.agent?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.agent&&e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent Autonomy":"Agent 自主模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Determines whether the agent will ask for accept/reject at each checkpoint in the workflow.":"决定 Agent 在工作流的每个检查点是否要求接受/拒绝"})]}),e.jsx(ei,{value:n.agentAutonomy,options:se,onChange:ae=>s(L=>({...L,agentAutonomy:ae})),className:"w-[200px]"})]}),e.jsxs("div",{className:"flex items-center justify-between border-t pt-4",children:[e.jsxs("div",{className:"flex-1 mr-4",children:[e.jsx("p",{className:"font-medium",children:K?"Model Selection":"模型选择"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Select model to use for agent operations.":"选择 Agent 操作使用的模型"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v.length>0?e.jsx(ei,{value:n.modelSelection,options:v.map(ae=>({value:ae.id,label:ae.name||ae.id,description:ae.description})),onChange:ae=>s(L=>({...L,modelSelection:ae})),className:"w-[240px]"}):e.jsx("input",{type:"text",value:n.modelSelection,onChange:ae=>s(L=>({...L,modelSelection:ae.target.value})),placeholder:"claude-haiku-4.5",className:"w-[240px] px-3 py-1.5 rounded-md border bg-background text-sm"}),e.jsx(D,{variant:"ghost",size:"sm",onClick:Y,disabled:j,title:K?"Refresh models":"刷新模型列表",children:e.jsx(Mt,{className:`h-4 w-4 ${j?"animate-spin":""}`})})]})]}),e.jsxs("div",{className:"border-t pt-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable Tab Autocomplete":"Tab 自动补全"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Tab Autocomplete allows Kiro Agent to provide code suggestions in the editor as you type.":"Tab 自动补全允许 Kiro Agent 在输入时提供代码建议"})]}),e.jsx(Pa,{checked:n.enableTabAutocomplete,onChange:ae=>s(L=>({...L,enableTabAutocomplete:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Usage Summary":"使用统计"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Display usage summary and elapsed time for agent executions.":"显示 Agent 执行的用量摘要和耗时"})]}),e.jsx(Pa,{checked:n.usageSummary,onChange:ae=>s(L=>({...L,usageSummary:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Code References: Reference Tracker":"代码引用追踪"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Allow Kiro to generate code with code references. Sometimes code generated by Kiro may be similar to publicly available code.":"允许 Kiro 生成带代码引用的代码。Kiro 生成的代码可能与公开可用代码相似。"})]}),e.jsx(Pa,{checked:n.codeReferences,onChange:ae=>s(L=>({...L,codeReferences:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable Codebase Indexing":"代码库索引"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Enable Repo Indexing (Experimental). This is an experimental feature which does not work with multi-folder workspaces.":"启用仓库索引(实验性)。这是一个实验性功能,不支持多文件夹工作区。"})]}),e.jsx(Pa,{checked:n.enableCodebaseIndexing,onChange:ae=>s(L=>({...L,enableCodebaseIndexing:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable Debug Logs":"调试日志"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Enable Kiro Debug Logs in the Output panel.":"在输出面板启用 Kiro 调试日志"})]}),e.jsx(Pa,{checked:n.enableDebugLogs,onChange:ae=>s(L=>({...L,enableDebugLogs:ae}))})]})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("p",{className:"font-medium mb-3",children:K?"Notifications":"通知设置"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent: Action Required":"Agent: 需要操作"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show desktop notification when the agent requires input, e.g. for a shell command.":"Agent 需要输入时显示桌面通知,如执行 Shell 命令时"})]}),e.jsx(Pa,{checked:n.notificationsActionRequired,onChange:ae=>s(L=>({...L,notificationsActionRequired:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent: Failure":"Agent: 失败"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show desktop notification when the agent encounters an unexpected failure.":"Agent 遇到意外失败时显示桌面通知"})]}),e.jsx(Pa,{checked:n.notificationsFailure,onChange:ae=>s(L=>({...L,notificationsFailure:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent: Success":"Agent: 成功"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show desktop notifications when the agent successfully completes a task.":"Agent 成功完成任务时显示桌面通知"})]}),e.jsx(Pa,{checked:n.notificationsSuccess,onChange:ae=>s(L=>({...L,notificationsSuccess:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Billing":"账单"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show in-app notifications for billing and usage events (usage resets, low resources, overages).":"显示账单和用量事件的应用内通知(用量重置、资源不足、超额)"})]}),e.jsx(Pa,{checked:n.notificationsBilling,onChange:ae=>s(L=>({...L,notificationsBilling:ae}))})]})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("mcp"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Ds,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"MCP Servers":"MCP 服务器"}),e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-primary/10 text-primary",children:Object.keys(r.mcpServers).length})]}),S.mcp?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.mcp&&e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable MCP":"启用 MCP"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Allow connections to external tools and data sources":"允许连接外部工具和数据源"})]}),e.jsx(ei,{value:n.configureMCP,options:te,onChange:ae=>s(L=>({...L,configureMCP:ae}))})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("p",{className:"font-medium mb-2",children:K?"Configured MCP Servers":"已配置的 MCP 服务器"}),Object.keys(r.mcpServers).length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"No MCP servers configured":"暂无配置的 MCP 服务器"}):e.jsx("div",{className:"space-y-2",children:Object.entries(r.mcpServers).map(([ae,L])=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-muted rounded-md",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-sm",children:ae}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:L.command})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>B({name:ae,server:L}),title:K?"Edit":"编辑",children:e.jsx(Ou,{className:"h-4 w-4 text-primary"})}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>Ee(ae),title:K?"Delete":"删除",children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]})]},ae))})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>B({}),children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),K?"Add MCP Server":"添加 MCP 服务器"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>C("user"),children:[e.jsx(Vi,{className:"h-4 w-4 mr-2"}),K?"User MCP Config":"用户 MCP 配置"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>C("workspace"),children:[e.jsx(Vi,{className:"h-4 w-4 mr-2"}),K?"Workspace MCP Config":"工作区 MCP 配置"]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("steering"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(xr,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"User Rules (Steering)":"用户规则 (Steering)"}),e.jsxs("span",{className:"px-2 py-0.5 text-xs rounded-full bg-primary/10 text-primary",children:[o.length," ",K?"files":"个文件"]})]}),S.steering?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.steering&&e.jsxs(Pe,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Steering files define AI assistant behavior rules and context":"Steering 文件用于定义 AI 助手的行为规则和上下文"}),o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"No steering files":"暂无 Steering 文件"}):e.jsx("div",{className:"space-y-2",children:o.map((ae,L)=>e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted rounded-md",children:[e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-mono flex-1",children:ae}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>X(ae),title:K?"Edit internally":"内部编辑",children:e.jsx(Ou,{className:"h-4 w-4 text-primary"})}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>re(ae),title:K?"Open externally":"外部打开",children:e.jsx(Xs,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>Oe(ae),title:K?"Delete":"删除",children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},L))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:xe,children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),K?"Create Rules":"创建规则文件"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:z,children:[e.jsx(Vi,{className:"h-4 w-4 mr-2"}),K?"Open Steering Folder":"打开 Steering 目录"]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("commands"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(WN,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"Command Config":"命令配置"})]}),S.commands?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.commands&&e.jsxs(Pe,{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 rounded-lg bg-muted/50 border border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Vn,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"font-medium",children:K?"Trusted Commands":"信任的命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:K?"These commands will auto-execute without confirmation":"这些命令将自动执行,无需确认"}),e.jsxs("div",{className:"space-y-2",children:[n.trustedCommands.map((ae,L)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:ae}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>_e(L),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},L)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:R,onChange:ae=>I(ae.target.value),placeholder:K?"e.g.: npm *":"如: npm *",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:ae=>ae.key==="Enter"&&Qe()}),e.jsx(D,{variant:"outline",size:"sm",onClick:Qe,children:e.jsx(Ts,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-muted/50 border border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ds,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"font-medium",children:K?"Trusted Tools":"信任的工具"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:K?"Tools to auto-accept if requested by the Agent. Each tool name maps to a boolean indicating whether it should be trusted.":"当 Agent 请求使用这些工具时自动批准。每个工具名称对应是否信任的布尔值。"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(n.trustedTools).map(([ae,L])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:ae}),e.jsx(Pa,{checked:L,onChange:we=>s(Ue=>({...Ue,trustedTools:{...Ue.trustedTools,[ae]:we}}))}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{s(we=>{const Ue={...we.trustedTools};return delete Ue[ae],{...we,trustedTools:Ue}})},children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},ae)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:M,onChange:ae=>G(ae.target.value),placeholder:K?"Tool name":"工具名称",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:ae=>{ae.key==="Enter"&&M.trim()&&(s(L=>({...L,trustedTools:{...L.trustedTools,[M.trim()]:!0}})),G(""))}}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{M.trim()&&(s(ae=>({...ae,trustedTools:{...ae.trustedTools,[M.trim()]:!0}})),G(""))},children:e.jsx(Ts,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-destructive/5 border border-destructive/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ln,{className:"h-4 w-4 text-destructive"}),e.jsx("p",{className:"font-medium text-destructive",children:K?"Blocked Commands":"禁止的命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:K?"These commands always require manual confirmation":"这些命令总是需要手动确认"}),e.jsxs("div",{className:"space-y-2",children:[n.commandDenylist.map((ae,L)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:ae}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>ue(L),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},L)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:W,onChange:ae=>U(ae.target.value),placeholder:K?"e.g.: rm -rf *":"如: rm -rf *",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:ae=>ae.key==="Enter"&&st()}),e.jsx(D,{variant:"outline",size:"sm",onClick:st,children:e.jsx(Ts,{className:"h-4 w-4"})})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:oe,className:"mt-2",children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),K?"Add Default Blocked":"添加默认禁止命令"]})]})]})]})]}),q&&e.jsx(EI,{filename:q,onClose:()=>V(null),onSaved:P}),le&&e.jsx(II,{serverName:le.name,server:le.server,onClose:()=>B(null),onSaved:P})]})}function UI({config:n,setConfig:s,isRunning:r,isEn:i}){const[o,d]=g.useState(!1),[u,h]=g.useState(!1),[f,p]=g.useState(!1),[y,b]=g.useState(null),[v,N]=g.useState([]),[j,T]=g.useState(!1),[S,k]=g.useState(!1),[R,I]=g.useState(!1),M=!!(n.enableMultiAccount&&(n.accountSelectionStrategy||"round-robin")!=="sticky"),[G,W]=g.useState((n.allowedIPs||[]).join(`
116
+ `).filter(z=>z.trim()&&!z.startsWith("#"));if(pe.some(z=>z.includes("----"))){const z=pe.map(re=>{const xe=LN(re),Oe=xe[1]?.trim(),Ee=xe[3]?.trim()||void 0,Qe=xe[4]?.trim()||void 0,st=xe[5]?.trim()||(!Ee&&!Qe?"Google":"BuilderId");return{email:xe[0]?.trim()||"",password:Oe&&Oe!=="no_password"?Oe:void 0,refreshToken:xe[2]?.trim()||"",clientId:Ee,clientSecret:Qe,idp:st,groupId:te}}).filter(re=>re.email&&re.refreshToken);if(z.length===0){alert("未找到有效的卡密数据(格式:邮箱----密码----RefreshToken----ClientId----ClientSecret)");return}const X=o(z);alert(`卡密导入完成:成功 ${X.success} 个,失败 ${X.failed} 个(分组:${Y})`)}else{const z=pe.map(re=>{const xe=re.includes("|")?re.split("|"):re.split(",");return{email:xe[0]?.trim()||"",refreshToken:xe[1]?.trim()||"",nickname:xe[2]?.trim()||void 0,idp:xe[3]?.trim()||"Google",groupId:te}}).filter(re=>re.email&&re.refreshToken);if(z.length===0){alert("未找到有效的账号数据(格式:邮箱,RefreshToken 或 卡密格式:邮箱----密码----Token----ID----Secret)");return}const X=o(z);alert(`导入完成:成功 ${X.success} 个,失败 ${X.failed} 个(分组:${Y})`)}}else alert(`不支持的文件格式:${fe}`)}catch(pe){console.error("Import error:",pe),alert("解析导入文件失败")}},be=()=>{N(!0)},K=()=>{T(!0)},se=te=>{b(te)};return s?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(bt,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:"加载账号数据..."})]})}):e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("header",{className:"relative z-20 flex items-center justify-between gap-4 px-3 py-3 glass-toolbar",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[n&&e.jsx(D,{variant:"ghost",size:"icon",onClick:n,children:e.jsx(i3,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Fn,{className:"h-5 w-5 text-primary"})}),e.jsx("h1",{className:"text-lg font-semibold text-primary",children:U?"Accounts":"账户管理"})]})]}),e.jsx(lI,{onAddAccount:()=>p(!0),onImport:B,onExport:V,viewMode:M,onViewModeChange:G,onManageGroups:be,onManageTags:K,isFilterExpanded:R,onToggleFilter:()=>I(!R)})]}),e.jsx("div",{className:"flex-1 overflow-hidden flex flex-col px-3 py-3 gap-3",children:e.jsx("div",{className:"flex-1 overflow-hidden",children:M==="grid"?e.jsx(VE,{onAddAccount:()=>p(!0),onEditAccount:se}):e.jsx(eI,{onAddAccount:()=>p(!0),onEditAccount:se})})}),e.jsx(oI,{isOpen:f,onClose:()=>p(!1)}),e.jsx(cI,{open:!!y,onOpenChange:te=>!te&&b(null),account:y}),e.jsx(dI,{isOpen:v,onClose:()=>N(!1)}),e.jsx(uI,{isOpen:j,onClose:()=>T(!1)}),e.jsx(sw,{open:S,onClose:()=>k(!1),accounts:q(),selectedCount:d.size})]})}const Ac="data:image/svg+xml,%3csvg%20width='96'%20height='96'%20viewBox='0%200%2096%2096'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%20role='img'%20aria-label='Krouter'%3e%3crect%20x='8'%20y='8'%20width='80'%20height='80'%20rx='22'%20fill='%230B1220'/%3e%3cpath%20d='M28%2068V28h10v16.8L54.2%2028H67L49.8%2045.5%2068.5%2068H55.4L42.9%2052.7%2038%2057.7V68H28Z'%20fill='%23FFFFFF'/%3e%3cpath%20d='M63%2028h5v5h-5v-5Z'%20fill='%2322C55E'/%3e%3cpath%20d='M69%2034h5v5h-5v-5Z'%20fill='%2338BDF8'/%3e%3cpath%20d='M63%2040h5v5h-5v-5Z'%20fill='%23F59E0B'/%3e%3cpath%20d='M62.5%2032.5%2049.5%2045.5M68.5%2036.5%2052%2052M62.5%2042.5%2055.5%2056'%20stroke='%2394A3B8'%20stroke-width='2'%20stroke-linecap='round'/%3e%3ccircle%20cx='48'%20cy='48'%20r='5'%20fill='%2338BDF8'/%3e%3c/svg%3e",oa="Krouter",tj="LightHaru",Pf="https://github.com/LightHaru/Krouter",nw="Kiro account routing, quota balancing, and API proxy control from one web dashboard.",aw="Dashboard web cho tai khoan Kiro, can bang quota va Kiro API proxy.",mI=[{id:"home",labelKey:"nav.home",icon:xA},{id:"accounts",labelKey:"nav.accounts",icon:Fn},{id:"machineId",labelKey:"nav.machineId",icon:eo},{id:"kiroSettings",labelKey:"nav.kiroSettings",icon:Hi},{id:"proxy",labelKey:"nav.proxy",icon:Sc},{id:"kproxy",labelKey:"nav.kproxy",icon:Vn},{id:"proxyPool",labelKey:"nav.proxyPool",icon:Ki},{id:"register",labelKey:"nav.register",icon:zu},{id:"subscription",labelKey:"nav.subscription",icon:$a},{id:"webhooks",labelKey:"nav.webhooks",icon:kp},{id:"diagnose",labelKey:"nav.diagnose",icon:jx},{id:"configSync",labelKey:"nav.configSync",icon:zN},{id:"logs",labelKey:"nav.logs",icon:lM},{id:"settings",labelKey:"nav.settings",icon:Ap},{id:"about",labelKey:"nav.about",icon:Va}];function fI({currentPage:n,onPageChange:s,collapsed:r,onToggleCollapse:i}){const{t:o}=Ut(),[d,u]=g.useState(!1);g.useEffect(()=>{const f=window.matchMedia("(max-width: 767px)"),p=()=>u(f.matches);return p(),f.addEventListener("change",p),()=>f.removeEventListener("change",p)},[]);const h=r||d;return e.jsxs(za.aside,{initial:!1,animate:{width:d?"100%":r?64:224,height:d?64:"auto"},transition:{type:"spring",stiffness:320,damping:30},className:me("glass-sidebar flex overflow-hidden shrink-0",d?"rounded-2xl flex-row":"rounded-3xl flex-col"),children:[e.jsx("div",{className:me("flex items-center justify-center gap-2 overflow-hidden border-white/10 dark:border-white/5",d?"h-full w-14 px-2 border-r":"h-14 px-3 border-b"),children:e.jsx(fc,{mode:"wait",initial:!1,children:h?e.jsx(za.img,{src:Ac,alt:oa,initial:{opacity:0,scale:.8},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.8},transition:{duration:.2},className:"h-10 w-10 object-contain"},"logo-small"):e.jsxs(za.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},exit:{opacity:0,x:-10},transition:{duration:.2},className:"flex items-center gap-2",children:[e.jsx("img",{src:Ac,alt:oa,className:"h-7 w-auto shrink-0"}),e.jsx("span",{className:"font-semibold text-foreground whitespace-nowrap text-sm",children:oa})]},"logo-full")})}),e.jsx("nav",{className:me("flex-1 overflow-auto",d?"h-full py-2 px-1 flex items-center gap-1 overflow-y-hidden":"py-3 px-2 space-y-1 overflow-y-auto"),children:mI.map(f=>{const p=f.icon,y=n===f.id,b=o(f.labelKey);return e.jsxs("button",{onClick:()=>s(f.id),className:me("group relative w-full flex items-center rounded-xl text-sm font-medium transition-all overflow-hidden focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",y?"text-primary-foreground shadow-[0_4px_16px_rgba(91,140,255,0.35)]":"text-muted-foreground hover:text-foreground hover:bg-white/40 dark:hover:bg-white/5",d?"w-10 h-10 justify-center p-2.5 shrink-0":h?"justify-center p-2.5":"gap-3 px-3 py-2.5"),title:h?b:void 0,children:[y&&e.jsx(za.span,{layoutId:"sidebar-active-pill",className:"absolute inset-0 rounded-xl",style:{background:"linear-gradient(135deg, var(--gradient-from), var(--gradient-to))"},transition:{type:"spring",stiffness:380,damping:32}}),e.jsx(p,{className:me("h-5 w-5 shrink-0 relative z-10",y?"text-white":"")}),e.jsx(fc,{initial:!1,children:!h&&e.jsx(za.span,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},exit:{opacity:0,x:-8},transition:{duration:.15},className:me("whitespace-nowrap relative z-10",y&&"text-white"),children:b},"label")})]},f.id)})}),!d&&e.jsx("div",{className:"p-2 border-t border-white/10 dark:border-white/5",children:e.jsxs("button",{onClick:i,className:"group w-full flex items-center justify-center gap-2 px-3 py-2 rounded-xl text-sm text-muted-foreground hover:text-primary hover:bg-white/40 dark:hover:bg-white/5 transition-all overflow-hidden focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",title:r?"Mo rong thanh ben":"Thu gon thanh ben",children:[e.jsx(za.div,{animate:{rotate:r?0:180},transition:{duration:.3,ease:[.4,0,.2,1]},className:"shrink-0",children:e.jsx(_N,{className:"h-4 w-4"})}),e.jsx(fc,{initial:!1,children:!r&&e.jsx(za.span,{initial:{opacity:0,width:0},animate:{opacity:1,width:"auto"},exit:{opacity:0,width:0},transition:{duration:.15},className:"whitespace-nowrap overflow-hidden",children:"Thu gon"},"collapse-label")})]})})]})}const rw="kiro-task-history",pI=200;function Ll(n){try{const s=Array.from(n.values()).filter(r=>r.status!=="running"&&r.status!=="paused").sort((r,i)=>i.updatedAt-r.updatedAt).slice(0,pI).map(({onCancel:r,onPause:i,onResume:o,...d})=>d);localStorage.setItem(rw,JSON.stringify(s))}catch{}}function xI(){try{const n=localStorage.getItem(rw);if(!n)return new Map;const s=JSON.parse(n),r=new Map;for(const i of s){const o=i.status==="running"||i.status==="paused"?"cancelled":i.status;r.set(i.id,{...i,status:o})}return r}catch{return new Map}}const Vs=Nx()((n,s)=>({tasks:xI(),createTask:r=>{const i=r.fixedId||Oi(),o=Date.now(),d={id:i,kind:r.kind,title:r.title,subtitle:r.subtitle,status:r.status??"running",progress:r.progress??0,done:r.done??0,total:r.total,successCount:r.successCount??0,failedCount:r.failedCount??0,lastMessage:r.lastMessage,error:r.error,onCancel:r.onCancel,onPause:r.onPause,onResume:r.onResume,createdAt:o,updatedAt:o};return n(u=>{const h=new Map(u.tasks);return h.set(i,d),{tasks:h}}),i},updateTask:(r,i)=>{n(o=>{const d=new Map(o.tasks),u=d.get(r);return u?(d.set(r,{...u,...i,updatedAt:Date.now()}),{tasks:d}):o})},completeTask:(r,i)=>{n(o=>{const d=new Map(o.tasks),u=d.get(r);if(!u)return o;const h=i?.successCount??u.successCount,f=i?.failedCount??u.failedCount,p=i?.error||f>0&&h===0?"failed":"success";return d.set(r,{...u,status:p,progress:100,successCount:h,failedCount:f,error:i?.error,finishedAt:Date.now(),updatedAt:Date.now()}),{tasks:d}}),Ll(s().tasks)},failTask:(r,i)=>{n(o=>{const d=new Map(o.tasks),u=d.get(r);return u?(d.set(r,{...u,status:"failed",error:i,finishedAt:Date.now(),updatedAt:Date.now()}),{tasks:d}):o}),Ll(s().tasks)},cancelTask:r=>{const i=s().tasks.get(r);try{i?.onCancel?.()}catch{}n(o=>{const d=new Map(o.tasks),u=d.get(r);return u?(d.set(r,{...u,status:"cancelled",finishedAt:Date.now(),updatedAt:Date.now()}),{tasks:d}):o}),Ll(s().tasks)},removeTask:r=>{n(i=>{const o=new Map(i.tasks);return o.delete(r),{tasks:o}}),Ll(s().tasks)},clearFinished:()=>{n(r=>{const i=new Map;for(const[o,d]of r.tasks)(d.status==="running"||d.status==="paused")&&i.set(o,d);return{tasks:i}}),Ll(s().tasks)},clearAll:()=>{n({tasks:new Map}),Ll(s().tasks)},getActiveCount:()=>{let r=0;for(const i of s().tasks.values())(i.status==="running"||i.status==="paused")&&r++;return r}})),gI={"register-batch":zu,"subscription-batch":$a,"overage-batch":Ds,"proxy-validation":Ki,"token-refresh":Mt,"account-check":Mt,other:qu};function yI(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",[r,i]=g.useState(!1),o=Vs(p=>p.tasks),{activeCount:d,finishedCount:u,hasFailure:h,totalProgress:f}=g.useMemo(()=>{let p=0,y=0,b=!1,v=0,N=0;for(const j of o.values())j.status==="running"||j.status==="paused"?(p++,v+=j.done,N+=j.total):(y++,j.status==="failed"&&(b=!0));return{activeCount:p,finishedCount:y,hasFailure:b,totalProgress:N>0?Math.round(v/N*100):0}},[o]);return o.size===0?null:e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>i(!0),title:s?"Task Center":"任务中心",className:me("flex items-center gap-1.5 px-2 h-6 rounded-md text-xs transition-colors","hover:bg-foreground/10",d>0?"text-primary":h?"text-red-500":"text-muted-foreground"),style:{WebkitAppRegion:"no-drag"},children:[d>0?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ks,{className:"h-3.5 w-3.5"}),d>0&&e.jsx("span",{className:"tabular-nums font-medium",children:d}),d>0&&f>0&&e.jsxs("span",{className:"opacity-60 tabular-nums",children:[f,"%"]}),d===0&&u>0&&e.jsx("span",{className:"tabular-nums opacity-60",children:u})]}),e.jsx(bI,{open:r,onClose:()=>i(!1)})]})}function bI({open:n,onClose:s}){const{t:r}=Ut(),i=r("common.unknown")==="Unknown",o=Vs(b=>b.tasks),d=Vs(b=>b.cancelTask),u=Vs(b=>b.removeTask),h=Vs(b=>b.clearFinished),f=()=>{const b=Array.from(o.values()).filter(v=>v.status==="running"||v.status==="paused");if(b.length!==0&&confirm(i?`Cancel ${b.length} running task(s)?`:`取消正在进行的 ${b.length} 个任务?`))for(const v of b)d(v.id)},p=Array.from(o.values()).filter(b=>b.status==="running"||b.status==="paused").length,y=g.useMemo(()=>Array.from(o.values()).sort((b,v)=>{const N=b.status==="running"||b.status==="paused",j=v.status==="running"||v.status==="paused";return N!==j?N?-1:1:v.updatedAt-b.updatedAt}),[o]);return Tn.createPortal(e.jsx(fc,{children:n&&e.jsxs("div",{style:{WebkitAppRegion:"no-drag"},children:[e.jsx(za.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.15},className:"fixed inset-0 z-[9998] bg-black/30 backdrop-blur-sm",onClick:s}),e.jsxs(za.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",stiffness:300,damping:30},className:"fixed right-0 top-0 bottom-0 z-[9999] w-[420px] bg-background border-l shadow-2xl flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"h-4 w-4 text-primary"}),e.jsx("h2",{className:"text-sm font-semibold",children:i?"Task Center":"任务中心"}),e.jsx($e,{variant:"secondary",className:"h-5 text-[10px] tabular-nums",children:y.length})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[p>0&&e.jsxs(D,{variant:"ghost",size:"sm",onClick:f,className:"text-destructive hover:text-destructive",title:i?`Cancel all ${p} running tasks`:`取消所有 ${p} 个正在进行的任务`,children:[e.jsx(fs,{className:"h-3.5 w-3.5 mr-1"}),i?"Cancel all":"全部取消"]}),e.jsxs(D,{variant:"ghost",size:"sm",onClick:h,children:[e.jsx(Vt,{className:"h-3.5 w-3.5 mr-1"}),i?"Clear finished":"清理已完成"]}),e.jsx("button",{onClick:s,className:"p-1.5 rounded-md hover:bg-muted",children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:y.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground py-12",children:[e.jsx(qu,{className:"h-10 w-10 opacity-30 mb-3"}),e.jsx("p",{className:"text-sm",children:i?"No tasks":"暂无任务"})]}):e.jsx("div",{className:"divide-y",children:y.map(b=>e.jsx(vI,{task:b,onCancel:()=>d(b.id),onRemove:()=>u(b.id)},b.id))})})]})]})}),document.body)}function vI({task:n,onCancel:s,onRemove:r}){const{t:i}=Ut(),o=i("common.unknown")==="Unknown",d=gI[n.kind]||qu,u=n.status==="running"||n.status==="paused",h=(n.finishedAt||Date.now())-n.createdAt,f=(()=>{switch(n.status){case"running":return e.jsx($e,{className:"bg-primary text-primary-foreground",children:o?"Running":"运行中"});case"paused":return e.jsx($e,{variant:"outline",className:"text-amber-600 border-amber-200",children:o?"Paused":"已暂停"});case"success":return e.jsx($e,{variant:"outline",className:"text-green-600 border-green-200",children:o?"Done":"已完成"});case"failed":return e.jsx($e,{variant:"outline",className:"text-red-600 border-red-200",children:o?"Failed":"失败"});case"cancelled":return e.jsx($e,{variant:"outline",className:"text-muted-foreground",children:o?"Cancelled":"已取消"})}})();return e.jsx("div",{className:"p-3 hover:bg-muted/30 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:me("p-1.5 rounded-md flex-shrink-0",n.status==="success"&&"bg-green-500/15 text-green-600",n.status==="failed"&&"bg-red-500/15 text-red-600",n.status==="cancelled"&&"bg-muted text-muted-foreground",u&&"bg-primary/15 text-primary"),children:n.status==="running"?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):n.status==="success"?e.jsx(an,{className:"h-3.5 w-3.5"}):n.status==="failed"?e.jsx(fs,{className:"h-3.5 w-3.5"}):n.status==="paused"?e.jsx(Tp,{className:"h-3.5 w-3.5"}):e.jsx(d,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium truncate",title:n.title,children:n.title}),f]}),n.subtitle&&e.jsx("p",{className:"text-[10px] text-muted-foreground truncate mt-0.5",title:n.subtitle,children:n.subtitle}),(n.total>0||u)&&e.jsxs("div",{className:"mt-2 space-y-1",children:[e.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:me("h-full transition-all",n.status==="failed"&&"bg-red-500",n.status==="success"&&"bg-green-500",u&&"bg-primary",n.status==="cancelled"&&"bg-muted-foreground"),style:{width:`${n.progress}%`}})}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground tabular-nums",children:[e.jsxs("span",{children:[n.done,"/",n.total,n.successCount>0&&e.jsxs("span",{className:"text-green-600 ml-1.5",children:["✓",n.successCount]}),n.failedCount>0&&e.jsxs("span",{className:"text-red-500 ml-1",children:["✗",n.failedCount]})]}),e.jsx("span",{children:jI(h)})]})]}),n.error&&e.jsxs("div",{className:"mt-2 flex items-start gap-1.5 text-[10px] text-red-500",children:[e.jsx(Rs,{className:"h-3 w-3 flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"break-all",children:n.error})]}),n.lastMessage&&!n.error&&e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1 truncate",title:n.lastMessage,children:n.lastMessage}),e.jsxs("div",{className:"mt-2 flex items-center gap-1",children:[n.status==="running"&&n.onPause&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px]",onClick:n.onPause,children:[e.jsx(Tp,{className:"h-3 w-3 mr-1"})," ",o?"Pause":"暂停"]}),n.status==="paused"&&n.onResume&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px]",onClick:n.onResume,children:[e.jsx(Ba,{className:"h-3 w-3 mr-1"})," ",o?"Resume":"恢复"]}),u&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px] text-destructive hover:text-destructive",onClick:s,children:[e.jsx(fs,{className:"h-3 w-3 mr-1"})," ",o?"Cancel":"取消"]}),!u&&e.jsxs(D,{size:"sm",variant:"ghost",className:"h-6 text-[10px]",onClick:r,children:[e.jsx(Vt,{className:"h-3 w-3 mr-1"})," ",o?"Remove":"移除"]})]})]})]})})}function jI(n){if(n<1e3)return`${n}ms`;const s=Math.floor(n/1e3);if(s<60)return`${s}s`;const r=Math.floor(s/60);return r<60?`${r}m ${s%60}s`:`${Math.floor(r/60)}h ${r%60}m`}function NI(){Ut();const[n,s]=g.useState("win32"),[r,i]=g.useState(!1),[o,d]=g.useState("");g.useEffect(()=>{let h;return(async()=>{try{const p=await window.api.window.getPlatform();s(p);const y=await window.api.window.isMaximized();i(y)}catch(p){console.warn("[TitleBar] init failed",p)}h=window.api.window.onMaximizeChange(p=>i(p))})(),window.api.getAppVersion().then(d).catch(()=>{}),()=>h?.()},[]);const u=n==="darwin";return e.jsxs("div",{className:me("flex items-center h-8 w-full select-none flex-shrink-0","bg-[var(--titlebar-bg)] text-foreground/80","border-b border-foreground/5"),style:{WebkitAppRegion:"drag",paddingLeft:u?80:12,paddingRight:u?12:0},children:[e.jsxs("div",{className:me("flex items-center gap-2 text-xs",u?"flex-1 justify-center":"flex-1"),children:[!u&&e.jsx("img",{src:Ac,alt:"",className:"h-4 w-4 opacity-90",onError:h=>h.target.style.display="none"}),e.jsxs("span",{className:"font-medium tracking-wide text-foreground/70",children:[oa,o&&` v${o}`]})]}),e.jsx("div",{className:"flex items-center gap-1 px-2",style:{WebkitAppRegion:"no-drag"},children:e.jsx(yI,{})}),!u&&e.jsxs("div",{className:"flex items-stretch h-full",style:{WebkitAppRegion:"no-drag"},children:[e.jsx(Lf,{onClick:()=>window.api.window.minimize(),title:"Thu nhỏ",children:e.jsx(wc,{className:"h-3.5 w-3.5",strokeWidth:2})}),e.jsx(Lf,{onClick:()=>window.api.window.maximizeToggle(),title:r?"Khôi phục":"Phóng to",children:r?e.jsx(As,{className:"h-3 w-3",strokeWidth:2}):e.jsx(Cn,{className:"h-3 w-3",strokeWidth:2})}),e.jsx(Lf,{onClick:()=>window.api.window.close(),title:"Đóng",variant:"close",children:e.jsx(ns,{className:"h-3.5 w-3.5",strokeWidth:2})})]})]})}function Lf({onClick:n,title:s,variant:r="default",children:i}){return e.jsx("button",{type:"button",onClick:n,title:s,className:me("flex items-center justify-center w-12 h-full text-foreground/70 transition-colors","hover:text-foreground",r==="close"?"hover:bg-red-500 hover:text-white":"hover:bg-foreground/10"),children:i})}const iw="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzYwIiBoZWlnaHQ9Ijk2IiB2aWV3Qm94PSIwIDAgMzYwIDk2IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHJvbGU9ImltZyIgYXJpYS1sYWJlbD0iS3JvdXRlciI+CiAgPHJlY3QgeD0iOCIgeT0iOCIgd2lkdGg9IjgwIiBoZWlnaHQ9IjgwIiByeD0iMjIiIGZpbGw9IiMwQjEyMjAiLz4KICA8cGF0aCBkPSJNMjggNjhWMjhoMTB2MTYuOEw1NC4yIDI4SDY3TDQ5LjggNDUuNSA2OC41IDY4SDU1LjRMNDIuOSA1Mi43IDM4IDU3LjdWNjhIMjhaIiBmaWxsPSIjRkZGRkZGIi8+CiAgPHBhdGggZD0iTTYzIDI4aDV2NWgtNXYtNVoiIGZpbGw9IiMyMkM1NUUiLz4KICA8cGF0aCBkPSJNNjkgMzRoNXY1aC01di01WiIgZmlsbD0iIzM4QkRGOCIvPgogIDxwYXRoIGQ9Ik02MyA0MGg1djVoLTV2LTVaIiBmaWxsPSIjRjU5RTBCIi8+CiAgPHBhdGggZD0iTTYyLjUgMzIuNSA0OS41IDQ1LjVNNjguNSAzNi41IDUyIDUyTTYyLjUgNDIuNSA1NS41IDU2IiBzdHJva2U9IiM5NEEzQjgiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIi8+CiAgPGNpcmNsZSBjeD0iNDgiIGN5PSI0OCIgcj0iNSIgZmlsbD0iIzM4QkRGOCIvPgogIDx0ZXh0IHg9IjEwOCIgeT0iNTciIGZpbGw9IiMxMTE4MjciIGZvbnQtZmFtaWx5PSJJbnRlciwgU2Vnb2UgVUksIEFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjM4IiBmb250LXdlaWdodD0iODAwIj5Lcm91dGVyPC90ZXh0PgogIDx0ZXh0IHg9IjExMCIgeT0iNzYiIGZpbGw9IiM2NDc0OEIiIGZvbnQtZmFtaWx5PSJJbnRlciwgU2Vnb2UgVUksIEFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE0IiBmb250LXdlaWdodD0iNjAwIj5LaXJvIHF1b3RhIHJvdXRlcjwvdGV4dD4KPC9zdmc+Cg==",wI=(n,s)=>{const r=(s||n).toUpperCase();return r.includes("PRO+")||r.includes("PRO_PLUS")||r.includes("PROPLUS")?"bg-purple-500":r.includes("POWER")?"bg-amber-500":r.includes("PRO")?"bg-blue-500":"bg-gray-500"};function sj(){const{accounts:n,activeAccountId:s,getStats:r,darkMode:i,usagePrecision:o}=vt(),{t:d}=Ut(),u=r(),h=g.useMemo(()=>{let b=0,v=0,N=0;Array.from(n.values()).forEach(S=>{if(S.status==="active"&&S.usage){const k=S.usage.limit??0,R=S.usage.current??0;k>0&&(b+=k,v+=R,N++)}});const j=b-v,T=b>0?v/b*100:0;return{totalLimit:b,totalUsed:v,remaining:j,percentUsed:T,validAccountCount:N}},[n]),f=d("common.unknown")==="Unknown",p=[{label:f?"Total Accounts":"总账号数",value:u.total,icon:Fn,color:"text-blue-500",bgColor:"bg-blue-500/10"},{label:f?"Active":"正常账号",value:u.byStatus?.active||0,icon:Bn,color:"text-green-500",bgColor:"bg-green-500/10"},{label:f?"Banned":"已封禁",value:u.byStatus?.error||0,icon:Rs,color:"text-red-500",bgColor:"bg-red-500/10"},{label:f?"Expiring Soon":"即将过期",value:u.expiringSoonCount,icon:Gn,color:"text-amber-500",bgColor:"bg-amber-500/10"}],y=g.useMemo(()=>s?n.get(s)??null:null,[n,s]);return e.jsxs("div",{className:"flex-1 p-4 md:p-6 space-y-5 md:space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-5 md:p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex flex-col sm:flex-row sm:items-center gap-4",children:[e.jsx("img",{src:iw,alt:oa,className:me("h-14 sm:h-16 w-auto max-w-full transition-all",i&&"brightness-110")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold text-primary",children:oa}),e.jsx("p",{className:"text-sm sm:text-base text-muted-foreground max-w-2xl",children:f?nw:aw})]})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:p.map(b=>{const v=b.icon;return e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2.5 rounded-xl ${b.bgColor}`,children:e.jsx(v,{className:`h-5 w-5 ${b.color}`})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:b.value}),e.jsx("p",{className:"text-xs text-muted-foreground",children:b.label})]})]})})},b.label)})}),h.validAccountCount>0&&e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Lu,{className:"h-4 w-4 text-primary"})}),f?"Usage Stats":"额度统计",e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",f?`Based on ${h.validAccountCount} valid accounts`:`基于 ${h.validAccountCount} 个有效账号`,")"]})]})}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-4",children:[e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(QN,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Total":"总额度"})]}),e.jsx("p",{className:"text-xl font-bold",children:h.totalLimit.toLocaleString()})]}),e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ks,{className:"h-4 w-4 text-orange-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Used":"已使用"})]}),e.jsx("p",{className:"text-xl font-bold",children:h.totalUsed.toLocaleString()})]}),e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Ds,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Remaining":"剩余额度"})]}),e.jsx("p",{className:"text-xl font-bold text-green-600",children:h.remaining.toLocaleString()})]}),e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Lu,{className:"h-4 w-4 text-purple-500"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:f?"Usage %":"使用率"})]}),e.jsxs("p",{className:"text-xl font-bold",children:[h.percentUsed.toFixed(o?2:1),"%"]})]})]}),(()=>{const b=h.percentUsed>100,v=b?h.percentUsed-100:0,N=b?Math.abs(h.remaining):0,j=b?Math.min(v/h.percentUsed*100,60):0,T=o?2:1;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Overall Progress":"总体使用进度"}),e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-muted-foreground",children:[h.totalUsed.toLocaleString(void 0,{maximumFractionDigits:2})," / ",h.totalLimit.toLocaleString()]}),e.jsxs("span",{className:me("font-bold px-2 py-0.5 rounded-md",b&&"bg-red-500/15 text-red-600 dark:text-red-400",!b&&h.percentUsed>=80&&"bg-orange-500/15 text-orange-600 dark:text-orange-400",!b&&h.percentUsed>=50&&h.percentUsed<80&&"bg-yellow-500/15 text-yellow-600 dark:text-yellow-400",!b&&h.percentUsed<50&&"bg-green-500/15 text-green-600 dark:text-green-400"),children:[h.percentUsed.toFixed(T),"%"]})]})]}),e.jsxs("div",{className:"relative h-3 bg-muted rounded-full overflow-hidden",children:[e.jsx("div",{className:me("absolute inset-y-0 left-0 transition-all",b&&"bg-red-500",!b&&h.percentUsed>=80&&"bg-orange-500",!b&&h.percentUsed>=50&&h.percentUsed<80&&"bg-yellow-500",!b&&h.percentUsed<50&&"bg-green-500"),style:{width:`${Math.min(h.percentUsed,100)}%`}}),b&&e.jsx("div",{className:"absolute inset-y-0 right-0 bg-gradient-to-r from-red-600 via-red-700 to-red-800 animate-pulse",style:{width:`${j}%`,backgroundImage:"repeating-linear-gradient(45deg, rgba(255,255,255,0.15) 0, rgba(255,255,255,0.15) 8px, transparent 8px, transparent 16px)",backgroundSize:"22px 22px"}})]}),b&&e.jsxs("div",{className:"flex items-center justify-between gap-3 mt-2 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/30",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 text-red-500 shrink-0"}),e.jsx("span",{className:"font-bold text-red-600 dark:text-red-400",children:f?"Over Quota":"已超额"}),e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-red-500/20 text-red-600 dark:text-red-400 font-bold",children:["+",v.toFixed(T),"%"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Excess: ":"超额积分:"}),e.jsx("span",{className:"font-bold text-red-600 dark:text-red-400",children:N.toLocaleString(void 0,{maximumFractionDigits:2})})]})]})]})})()]})]}),y&&e.jsxs(De,{className:"hover-lift bg-gradient-to-r from-primary/5 to-primary/10",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ds,{className:"h-4 w-4 text-primary"}),f?"Current Account":"当前使用账号"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-primary/20 flex items-center justify-center text-primary font-bold",children:(y.nickname||y.email||"?")[0].toUpperCase()}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:y.nickname||y.email}),e.jsx("p",{className:"text-sm text-muted-foreground",children:y.email})]})]}),e.jsx("div",{className:"text-right",children:e.jsx("span",{className:me("inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium text-white",wI(y.subscription?.type||"Free",y.subscription?.title)),children:y.subscription?.title||y.subscription?.type||"Free"})})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 pt-2 border-t",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Monthly Usage":"本月用量"}),e.jsxs("p",{className:"text-sm font-medium",children:[y.usage?.current||0," / ",y.usage?.limit||0]}),e.jsx("div",{className:"h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full transition-all ${(y.usage?.percentUsed||0)>.8?"bg-red-500":(y.usage?.percentUsed||0)>.5?"bg-amber-500":"bg-green-500"}`,style:{width:`${Math.min((y.usage?.percentUsed||0)*100,100)}%`}})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Subscription":"订阅剩余"}),e.jsx("p",{className:"text-sm font-medium",children:y.subscription?.daysRemaining!=null?f?`${y.subscription.daysRemaining} days`:`${y.subscription.daysRemaining} 天`:f?"Permanent":"永久"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Token Status":"Token 状态"}),(()=>{const b=y.credentials?.expiresAt;if(!b)return e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:f?"Unknown":"未知"});const v=Date.now(),N=b-v;if(N<=0)return e.jsx("p",{className:"text-sm font-medium text-red-500",children:f?"Expired":"已过期"});const j=Math.floor(N/6e4);if(j<60)return e.jsx("p",{className:"text-sm font-medium text-amber-500",children:f?`${j} min`:`${j} 分钟`});const T=Math.floor(j/60);return e.jsx("p",{className:"text-sm font-medium text-green-500",children:f?`${T} hours`:`${T} 小时`})})()]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:f?"Auth Method":"登录方式"}),e.jsx("p",{className:"text-sm font-medium",children:y.credentials?.authMethod==="social"?y.credentials?.provider||"Social":"Builder ID"})]})]}),e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:f?"Subscription Details":"订阅详情"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Type:":"订阅类型:"}),e.jsx("span",{className:"font-medium",children:y.subscription?.title||y.subscription?.type||"Free"})]}),y.subscription?.rawType&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Raw Type:":"原始类型:"}),e.jsx("span",{className:"font-mono text-[10px]",children:y.subscription.rawType})]}),y.subscription?.expiresAt&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Expires:":"到期时间:"}),e.jsx("span",{className:"font-medium",children:new Date(y.subscription.expiresAt).toLocaleDateString("zh-CN")})]}),y.subscription?.upgradeCapability&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Upgradeable:":"可升级:"}),e.jsx("span",{className:"font-medium",children:y.subscription.upgradeCapability})]}),y.subscription?.overageCapability&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Overage:":"超额能力:"}),e.jsx("span",{className:"font-medium",children:y.subscription.overageCapability})]})]})]}),(y.usage?.baseLimit||y.usage?.freeTrialLimit||y.usage?.bonuses?.length)&&e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:f?"Quota Details":"额度明细"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-2",children:[y.usage?.baseLimit!==void 0&&y.usage.baseLimit>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"}),e.jsx("span",{className:"text-muted-foreground",children:f?"Base:":"基础额度:"}),e.jsxs("span",{className:"font-medium",children:[y.usage.baseCurrent??0," / ",y.usage.baseLimit]})]}),y.usage?.freeTrialLimit!==void 0&&y.usage.freeTrialLimit>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-purple-500"}),e.jsx("span",{className:"text-muted-foreground",children:f?"Trial:":"试用额度:"}),e.jsxs("span",{className:"font-medium",children:[y.usage.freeTrialCurrent??0," / ",y.usage.freeTrialLimit]}),y.usage.freeTrialExpiry&&e.jsxs("span",{className:"text-muted-foreground/70 text-[10px]",children:["(至 ",(()=>{const b=y.usage.freeTrialExpiry;try{return(typeof b=="string"?b:new Date(b).toISOString()).split("T")[0]}catch{return""}})(),")"]})]}),y.usage?.bonuses?.map(b=>e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-cyan-500"}),e.jsxs("span",{className:"text-muted-foreground truncate",children:[b.name,":"]}),e.jsxs("span",{className:"font-medium",children:[b.current," / ",b.limit]}),b.expiresAt&&e.jsxs("span",{className:"text-muted-foreground/70 text-[10px]",children:["(至 ",(()=>{const v=b.expiresAt;try{return(typeof v=="string"?v:new Date(v).toISOString()).split("T")[0]}catch{return""}})(),")"]})]},b.code))]})]}),e.jsxs("div",{className:"pt-3 border-t space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:f?"Account Info":"账户信息"}),e.jsxs("div",{className:"space-y-1.5 text-xs",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:"User ID:"}),e.jsx("span",{className:"font-mono text-[10px] break-all select-all",children:y.userId})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:"IDP:"}),e.jsx("span",{className:"font-medium",children:y.idp||"BuilderId"})]}),y.usage?.nextResetDate&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:f?"Reset Date:":"重置日期:"}),e.jsx("span",{className:"font-medium",children:(()=>{const b=y.usage.nextResetDate;try{return(typeof b=="string"?b:new Date(b).toISOString()).split("T")[0]}catch{return f?"Unknown":"未知"}})()})]})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Vn,{className:"h-4 w-4 text-primary"})}),f?"Quick Tips":"快速提示"]})}),e.jsx(Pe,{children:e.jsxs("ul",{className:"space-y-2 text-sm text-muted-foreground",children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?'Click "Accounts" to view and manage all accounts':"点击左侧「账户管理」可以查看和管理所有账号"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?"Click power icon on account card to switch":"在账号卡片上点击电源图标可以快速切换账号"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?"Tokens auto-refresh 5 minutes before expiry":"Token 会在过期前 5 分钟自动刷新,无需手动操作"]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-primary",children:"•"}),f?'Use "Privacy Mode" to hide sensitive info':"使用「隐私模式」可以隐藏邮箱和账号信息"]})]})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(eo,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:f?"Machine ID":"机器码管理"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:f?"Modify device ID, auto-switch, account binding":"修改设备标识符,切号时自动更换,支持账户绑定"})]})]})})}),e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Cp,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:f?"Groups":"分组管理"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:f?"Batch set groups for selected accounts":"多选账户后可批量设置分组,一键移动账号"})]})]})})}),e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Xl,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:f?"Tags":"标签管理"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:f?"Batch add/remove tags, multi-tag support":"多选账户后可批量添加/移除标签,支持多标签"})]})]})})})]})]})}function kI(){const[n,s]=g.useState("..."),[r,i]=g.useState(!1),[o,d]=g.useState(null),[u,h]=g.useState(!1),{t:f}=Ut(),p=f("common.unknown")==="Unknown";g.useEffect(()=>{window.api.getAppVersion().then(s).catch(()=>s("unknown"))},[]);const y=async()=>{i(!0);try{const T=await window.api.checkForUpdatesManual();d(T),h(!0)}catch(T){d({hasUpdate:!1,error:T instanceof Error?T.message:"Check update failed"}),h(!0)}finally{i(!1)}},b=T=>{T&&window.api.openExternal(T)},v=T=>T<1024?`${T} B`:T<1024*1024?`${(T/1024).toFixed(1)} KB`:`${(T/(1024*1024)).toFixed(1)} MB`,N=[{icon:aM,title:p?"Account router":"Router tai khoan",body:p?"Rotates requests across healthy Kiro accounts by model, quota, and runtime state.":"Xoay request qua cac tai khoan Kiro con khoe theo model, quota va trang thai runtime."},{icon:ii,title:p?"Client API keys":"Key cho client",body:p?"Creates OpenAI-compatible keys for OpenClaw, Aira, Codex, and other dev tools.":"Tao key tuong thich OpenAI cho OpenClaw, Aira, Codex va cac cong cu dev."},{icon:hM,title:"Backend runtime",body:p?"Keeps the proxy service alive from the backend/CLI instead of relying on a browser tab.":"Giu API proxy chay bang backend/CLI thay vi phu thuoc vao tab trinh duyet."},{icon:Ki,title:p?"Localhost or tunnel":"Localhost hoac tunnel",body:p?"Runs local-first and exposes the dashboard publicly only when a tunnel is enabled.":"Uu tien localhost va chi public dashboard khi bat tunnel."}],j=[{icon:$N,label:"OpenClaw / Aira",detail:p?"One client endpoint":"Mot endpoint client"},{icon:Ds,label:oa,detail:"Key, model, quota router"},{icon:Vn,label:p?"Kiro accounts":"Tai khoan Kiro",detail:"Health, quota, profile ARN"}];return e.jsxs("div",{className:"flex-1 overflow-auto p-4 space-y-4 md:p-6 md:space-y-6",children:[e.jsx("div",{className:"page-hero overflow-hidden p-5 md:p-8",children:e.jsxs("div",{className:"relative grid gap-6 lg:grid-cols-[minmax(0,1.15fr)_minmax(320px,0.85fr)] lg:items-center",children:[e.jsxs("div",{className:"min-w-0 space-y-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[e.jsx("img",{src:iw,alt:oa,className:"h-16 w-auto max-w-full shrink-0 md:h-20"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-2xl font-bold text-primary md:text-3xl",children:oa}),e.jsx("p",{className:"mt-1 max-w-2xl text-sm text-muted-foreground md:text-base",children:p?nw:aw}),e.jsxs("p",{className:"mt-2 text-xs text-muted-foreground",children:[p?"Version":"Phien ban"," ",n," · ",tj]})]})]}),e.jsxs("div",{className:"grid gap-2 text-sm text-muted-foreground sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-primary/10 bg-white/45 p-3 dark:bg-white/5",children:[e.jsx("p",{className:"font-semibold text-foreground",children:p?"Web dashboard":"Dashboard web"}),e.jsx("p",{className:"mt-1 text-xs",children:p?"Account control surface":"Noi quan ly tai khoan"})]}),e.jsxs("div",{className:"rounded-xl border border-primary/10 bg-white/45 p-3 dark:bg-white/5",children:[e.jsx("p",{className:"font-semibold text-foreground",children:"CLI runtime"}),e.jsx("p",{className:"mt-1 text-xs",children:p?"Setup and tunnel control":"Setup va tunnel"})]}),e.jsxs("div",{className:"rounded-xl border border-primary/10 bg-white/45 p-3 dark:bg-white/5",children:[e.jsx("p",{className:"font-semibold text-foreground",children:"OpenClaw"}),e.jsx("p",{className:"mt-1 text-xs",children:"provider: krouter"})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",onClick:y,disabled:r,children:[e.jsx(Mt,{className:me("h-4 w-4",r&&"animate-spin")}),r?p?"Checking...":"Dang kiem tra...":p?"Check updates":"Kiem tra cap nhat"]}),e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>b(Pf),children:[e.jsx(jf,{className:"h-4 w-4"}),"GitHub",e.jsx(Xs,{className:"h-3 w-3"})]})]})]}),e.jsxs("div",{className:"relative min-h-[260px] rounded-2xl border border-primary/10 bg-white/55 p-5 shadow-inner dark:bg-white/5",children:[e.jsx("div",{className:"absolute right-5 top-5 rounded-full bg-primary/10 p-3",children:e.jsx("img",{src:Ac,alt:oa,className:"h-12 w-12"})}),e.jsx("div",{className:"flex h-full flex-col justify-end gap-4 pt-20",children:j.map((T,S)=>{const k=T.icon;return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-xl bg-primary text-primary-foreground shadow-sm",children:e.jsx(k,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1 rounded-xl border border-primary/10 bg-background/70 px-3 py-2",children:[e.jsx("p",{className:"truncate text-sm font-semibold",children:T.label}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:T.detail})]}),S<j.length-1&&e.jsx(wp,{className:"hidden h-4 w-4 text-primary md:block"})]},T.label)})})]})]})}),u&&o&&e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>h(!1)}),e.jsx("div",{className:"relative z-10 max-h-[80vh] w-full max-w-md overflow-y-auto rounded-xl bg-card p-6 shadow-xl",children:o.hasUpdate?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-success/10 p-2",children:e.jsx(Ns,{className:"h-6 w-6 text-success"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:p?"New version available":"Co ban moi"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[o.currentVersion," -> ",o.latestVersion]})]})]}),o.releaseName&&e.jsxs("div",{className:"rounded-lg bg-muted/50 p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:o.releaseName}),o.publishedAt&&e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(o.publishedAt).toLocaleDateString(p?"en-US":"vi-VN")})]}),o.releaseNotes&&e.jsx("div",{className:"max-h-32 overflow-y-auto whitespace-pre-wrap rounded-lg bg-muted/30 p-3 text-sm text-muted-foreground",children:o.releaseNotes}),o.assets&&o.assets.length>0&&e.jsx("div",{className:"space-y-1",children:o.assets.slice(0,6).map(T=>e.jsxs("div",{className:"flex items-center justify-between rounded bg-muted/30 px-2 py-1 text-xs",children:[e.jsx("span",{className:"truncate",children:T.name}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:v(T.size)})]},T.downloadUrl))}),e.jsxs(D,{className:"w-full gap-2",onClick:()=>b(o.releaseUrl),children:[e.jsx(Xs,{className:"h-4 w-4"}),p?"Open release page":"Mo trang phat hanh"]})]}):o.error?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-red-500/10 p-2",children:e.jsx(ln,{className:"h-6 w-6 text-red-500"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:p?"Check failed":"Kiem tra loi"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:o.error})]})]}),e.jsx(D,{variant:"outline",className:"w-full",onClick:y,children:p?"Retry":"Thu lai"})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-full bg-success/10 p-2",children:e.jsx(Bn,{className:"h-6 w-6 text-success"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:p?"Up to date":"Dang la ban moi nhat"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:p?`Version ${o.currentVersion}`:`Phien ban ${o.currentVersion}`})]})]})})})]}),e.jsx("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4",children:N.map(T=>{const S=T.icon;return e.jsx(De,{className:"hover-lift",children:e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(S,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-semibold",children:T.title}),e.jsx("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:T.body})]})]})})},T.title)})}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 xl:grid-cols-[1.05fr_0.95fr]",children:[e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(Hi,{className:"h-4 w-4 text-primary"})}),p?"What Krouter is for":"Krouter dung de lam gi"]})}),e.jsxs(Pe,{className:"space-y-3 text-sm leading-relaxed text-muted-foreground",children:[e.jsx("p",{children:p?"Krouter is the control plane for a Kiro-based AI coding setup: it keeps account state visible, exposes one compatible API endpoint, and routes each request to a usable account.":"Krouter la control plane cho workflow AI coding dung Kiro: hien thi trang thai tai khoan, mo mot API endpoint tuong thich va dieu huong moi request den tai khoan dang dung duoc."}),e.jsx("p",{children:p?"The web dashboard handles operations. The backend service and CLI keep proxy, tunnel, API keys, and client imports running outside the browser.":"Dashboard web xu ly thao tac quan ly. Backend service va CLI giu API proxy, tunnel, API key va import client chay doc lap voi trinh duyet."})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(kM,{className:"h-4 w-4 text-primary"})}),p?"Runtime commands":"Lenh runtime"]})}),e.jsx(Pe,{children:e.jsx("div",{className:"grid gap-2 text-xs",children:["krouter setup","krouter status","krouter tunnel start","krouter openclaw import"].map(T=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-muted/40 px-3 py-2 font-mono",children:[e.jsx(U3,{className:"h-3.5 w-3.5 text-primary"}),e.jsx("span",{children:T})]},T))})})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx($A,{className:"h-4 w-4 text-primary"})}),p?"Client integration":"Ket noi client"]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid gap-3 text-sm md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl bg-muted/30 p-3",children:[e.jsx("p",{className:"font-semibold",children:"Endpoint"}),e.jsx("p",{className:"mt-1 break-all font-mono text-xs text-muted-foreground",children:"http://localhost:5580/v1"})]}),e.jsxs("div",{className:"rounded-xl bg-muted/30 p-3",children:[e.jsx("p",{className:"font-semibold",children:"API key"}),e.jsx("p",{className:"mt-1 font-mono text-xs text-muted-foreground",children:"sk-..."})]}),e.jsxs("div",{className:"rounded-xl bg-muted/30 p-3",children:[e.jsx("p",{className:"font-semibold",children:"OpenClaw"}),e.jsx("p",{className:"mt-1 font-mono text-xs text-muted-foreground",children:"provider: krouter"})]})]})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"flex items-center gap-3 text-base",children:[e.jsx("div",{className:"rounded-lg bg-primary/10 p-2",children:e.jsx(jf,{className:"h-4 w-4 text-primary"})}),p?"Project":"Du an"]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium",children:tj}),e.jsx("p",{className:"break-all text-sm text-muted-foreground",children:Pf})]}),e.jsxs(D,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>b(Pf),children:[e.jsx(jf,{className:"h-4 w-4"}),"GitHub",e.jsx(Xs,{className:"h-3 w-3"})]})]})})]})]})}const SI=[{name:"蓝色系",themes:[{id:"default",name:"天空蓝",color:"#3b82f6"},{id:"indigo",name:"靖蓝",color:"#6366f1"},{id:"cyan",name:"清新青",color:"#06b6d4"},{id:"sky",name:"晴空蓝",color:"#0ea5e9"},{id:"teal",name:"水鸭蓝",color:"#14b8a6"}]},{name:"紫红系",themes:[{id:"purple",name:"优雅紫",color:"#a855f7"},{id:"violet",name:"紫罗兰",color:"#8b5cf6"},{id:"fuchsia",name:"洋红",color:"#d946ef"},{id:"pink",name:"粉红",color:"#ec4899"},{id:"rose",name:"玑瑰红",color:"#f43f5e"}]},{name:"暖色系",themes:[{id:"red",name:"热情红",color:"#ef4444"},{id:"orange",name:"活力橙",color:"#f97316"},{id:"amber",name:"琥珀金",color:"#f59e0b"},{id:"yellow",name:"明黄",color:"#eab308"}]},{name:"绿色系",themes:[{id:"emerald",name:"翠绿",color:"#10b981"},{id:"green",name:"草绿",color:"#22c55e"},{id:"lime",name:"青柠",color:"#84cc16"}]},{name:"中性色",themes:[{id:"slate",name:"石板灰",color:"#64748b"},{id:"zinc",name:"锌灰",color:"#71717a"},{id:"stone",name:"暖灰",color:"#78716c"},{id:"neutral",name:"中性灰",color:"#737373"}]},{name:"奢华配色",themes:[{id:"gold",name:"奢华金",color:"#C9A227"},{id:"navy",name:"海军蓝",color:"#1E40AF"},{id:"wine",name:"酒红",color:"#9F1239"},{id:"champagne",name:"香槟",color:"#B89968"}]},{name:"莫兰迪",themes:[{id:"dustyblue",name:"烟雾蓝",color:"#64748B"},{id:"terracotta",name:"陶土橙",color:"#B45434"},{id:"sage",name:"鼠尾草",color:"#6B8E5A"},{id:"mauve",name:"烟紫",color:"#8E7CC3"}]},{name:"自然深色",themes:[{id:"coral",name:"珊瑚粉",color:"#F87171"},{id:"forest",name:"森林绿",color:"#166534"},{id:"ocean",name:"深海青",color:"#155E75"}]}],CI=[{name:"Blue",themes:[{id:"default",name:"Sky Blue",color:"#3b82f6"},{id:"indigo",name:"Indigo",color:"#6366f1"},{id:"cyan",name:"Cyan",color:"#06b6d4"},{id:"sky",name:"Sky",color:"#0ea5e9"},{id:"teal",name:"Teal",color:"#14b8a6"}]},{name:"Purple",themes:[{id:"purple",name:"Purple",color:"#a855f7"},{id:"violet",name:"Violet",color:"#8b5cf6"},{id:"fuchsia",name:"Fuchsia",color:"#d946ef"},{id:"pink",name:"Pink",color:"#ec4899"},{id:"rose",name:"Rose",color:"#f43f5e"}]},{name:"Warm",themes:[{id:"red",name:"Red",color:"#ef4444"},{id:"orange",name:"Orange",color:"#f97316"},{id:"amber",name:"Amber",color:"#f59e0b"},{id:"yellow",name:"Yellow",color:"#eab308"}]},{name:"Green",themes:[{id:"emerald",name:"Emerald",color:"#10b981"},{id:"green",name:"Green",color:"#22c55e"},{id:"lime",name:"Lime",color:"#84cc16"}]},{name:"Neutral",themes:[{id:"slate",name:"Slate",color:"#64748b"},{id:"zinc",name:"Zinc",color:"#71717a"},{id:"stone",name:"Stone",color:"#78716c"},{id:"neutral",name:"Neutral",color:"#737373"}]},{name:"Luxury",themes:[{id:"gold",name:"Gold",color:"#C9A227"},{id:"navy",name:"Navy",color:"#1E40AF"},{id:"wine",name:"Wine",color:"#9F1239"},{id:"champagne",name:"Champagne",color:"#B89968"}]},{name:"Morandi",themes:[{id:"dustyblue",name:"Dusty Blue",color:"#64748B"},{id:"terracotta",name:"Terracotta",color:"#B45434"},{id:"sage",name:"Sage",color:"#6B8E5A"},{id:"mauve",name:"Mauve",color:"#8E7CC3"}]},{name:"Natural",themes:[{id:"coral",name:"Coral",color:"#F87171"},{id:"forest",name:"Forest",color:"#166534"},{id:"ocean",name:"Ocean",color:"#155E75"}]}];function TI(){const{privacyMode:n,setPrivacyMode:s,usagePrecision:r,setUsagePrecision:i,autoRefreshEnabled:o,autoRefreshInterval:d,autoRefreshConcurrency:u,autoRefreshSyncInfo:h,proactiveRenewalEnabled:f,proactiveRenewalLeadMinutes:p,setProactiveRenewalEnabled:y,setAutoRefresh:b,setAutoRefreshConcurrency:v,setAutoRefreshSyncInfo:N,checkAndRefreshExpiringTokens:j,proxyEnabled:T,proxyUrl:S,setProxy:k,autoSwitchEnabled:R,autoSwitchThreshold:I,autoSwitchInterval:M,setAutoSwitch:G,batchImportConcurrency:W,setBatchImportConcurrency:U,loginPrivateMode:q,setLoginPrivateMode:V,switchTarget:le,setSwitchTarget:B,theme:be,darkMode:K,setTheme:se,setDarkMode:te,language:Y,setLanguage:P,accounts:F,importFromExportData:fe}=vt(),{t:pe}=Ut(),C=pe("common.unknown")==="Unknown",[z,X]=g.useState(!1),[re,xe]=g.useState(!1),[Oe,Ee]=g.useState(S),[Qe,_e]=g.useState(!1),[st,oe]=g.useState(!1),[ue,ae]=g.useState({enabled:!0,closeAction:"ask",showNotifications:!0,minimizeOnStart:!1}),[L,we]=g.useState(!0),[Ue,Lt]=g.useState(""),[xt,Qt]=g.useState(!0),[ft,Et]=g.useState(""),[Ge,gt]=g.useState(!1);g.useEffect(()=>{(async()=>{try{const He=await window.api.getShowWindowShortcut();Lt(He)}catch(He){console.error("Failed to load shortcut:",He)}finally{Qt(!1)}})()},[]);const Ze=async je=>{Lt(je),Et("");try{const He=await window.api.setShowWindowShortcut(je);He.success||Et(He.error||"Failed to set shortcut")}catch(He){Et(String(He))}},J=je=>{if(!Ge)return;je.preventDefault();const He=[];je.ctrlKey&&He.push("Ctrl"),je.metaKey&&He.push("Command"),je.altKey&&He.push("Alt"),je.shiftKey&&He.push("Shift");const Tt=je.key;if(!["Control","Meta","Alt","Shift"].includes(Tt)){const H=Tt.length===1?Tt.toUpperCase():Tt;He.push(H);const Se=He.join("+");Ze(Se),gt(!1)}},[Ne,et]=g.useState("rest"),[qe,Je]=g.useState(!0);g.useEffect(()=>{(async()=>{try{const He=await window.api.getUsageApiType();et(He)}catch(He){console.error("Failed to load usage API type:",He)}finally{Je(!1)}})()},[]);const Kt=async je=>{et(je);try{await window.api.setUsageApiType(je)}catch(He){console.error("Failed to save usage API type:",He)}},[Ye,qt]=g.useState(!1),[Jt,Ct]=g.useState(!0);g.useEffect(()=>{(async()=>{try{const He=await window.api.getUseKProxyForApi();qt(He)}catch(He){console.error("Failed to load K-Proxy settings:",He)}finally{Ct(!1)}})()},[]);const O=async je=>{qt(je);try{await window.api.setUseKProxyForApi(je)}catch(He){console.error("Failed to save K-Proxy settings:",He)}};g.useEffect(()=>{(async()=>{try{const He=await window.api.getTraySettings();ae(He)}catch(He){console.error("Failed to load tray settings:",He)}finally{we(!1)}})()},[]);const ne=async(je,He)=>{const Tt={...ue,[je]:He};ae(Tt);try{await window.api.saveTraySettings({[je]:He})}catch(H){console.error("Failed to save tray settings:",H)}},ze=async()=>{oe(!0);try{await j()}finally{oe(!1)}},_=C?CI:SI,ce=()=>{X(!0)},Ce=async()=>{xe(!0);try{const je=await window.api.importFromFile();if(je&&je.format==="json"){const He=JSON.parse(je.content),Tt=fe(He);alert(`导入完成:成功 ${Tt.success} 个,失败 ${Tt.failed} 个`)}else je&&alert("设置页面仅支持 JSON 格式导入,请使用账号管理页面导入 CSV/TXT")}catch(je){alert(`导入失败: ${je instanceof Error?je.message:"未知错误"}`)}finally{xe(!1)}},Ve=()=>{confirm("确定要清除所有账号数据吗?此操作不可恢复!")&&confirm("再次确认:这将删除所有账号、分组和标签数据!")&&(Array.from(F.keys()).forEach(je=>{vt.getState().removeAccount(je)}),alert("所有数据已清除"))};return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary shadow-lg shadow-primary/25",children:e.jsx(Ap,{className:"h-6 w-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:pe("settings.title")}),e.jsx("p",{className:"text-muted-foreground",children:pe("settings.title")==="Settings"?"Configure app features":"配置应用的各项功能"})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),"语言 / Language"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"显示语言 / Display Language"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"选择界面显示语言 / Select interface language"})]}),e.jsxs("select",{className:"w-[160px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:Y,onChange:je=>P(je.target.value),children:[e.jsx("option",{value:"auto",children:"🌐 自动 (Auto)"}),e.jsx("option",{value:"zh",children:"🇨🇳 简体中文"}),e.jsx("option",{value:"en",children:"🇺🇸 English"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsx("p",{children:"• 自动模式会根据系统语言自动选择"}),e.jsx("p",{children:"• Auto mode will follow system language"}),e.jsx("p",{children:"• 支持自定义翻译文件扩展(开发中)"})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(qN,{className:"h-4 w-4 text-primary"})}),C?"Theme":"主题设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Dark Mode":"深色模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Toggle dark/light theme":"切换深色/浅色主题"})]}),e.jsxs(D,{variant:K?"default":"outline",size:"sm",onClick:()=>te(!K),children:[K?e.jsx(VA,{className:"h-4 w-4 mr-2"}):e.jsx(AM,{className:"h-4 w-4 mr-2"}),K?C?"Dark":"深色":C?"Light":"浅色"]})]}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsxs("button",{className:"flex items-center justify-between w-full text-left",onClick:()=>_e(!Qe),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-medium",children:C?"Theme Color":"主题颜色"}),!Qe&&e.jsx("div",{className:"w-5 h-5 rounded-full ring-2 ring-primary ring-offset-1",style:{backgroundColor:_.flatMap(je=>je.themes).find(je=>je.id===be)?.color||"#3b82f6"}})]}),Qe?e.jsx(zi,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(va,{className:"h-4 w-4 text-muted-foreground"})]}),Qe&&e.jsx("div",{className:"space-y-3 mt-3",children:_.map(je=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-muted-foreground w-14 shrink-0",children:je.name}),e.jsx("div",{className:"flex flex-wrap gap-2",children:je.themes.map(He=>e.jsx("button",{className:`group relative w-7 h-7 rounded-full transition-all ${be===He.id?"ring-2 ring-primary ring-offset-2 scale-110":"hover:scale-110 hover:shadow-md"}`,style:{backgroundColor:He.color},onClick:()=>se(He.id),title:He.name,children:e.jsx("span",{className:"absolute -bottom-6 left-1/2 -translate-x-1/2 text-[10px] text-muted-foreground whitespace-nowrap opacity-0 group-hover:opacity-100 transition-opacity bg-popover px-1.5 py-0.5 rounded shadow-sm border pointer-events-none z-10",children:He.name})},He.id))})]},je.name))})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:n?e.jsx(Jl,{className:"h-4 w-4 text-primary"}):e.jsx(Nc,{className:"h-4 w-4 text-primary"})}),C?"Privacy":"隐私设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Privacy Mode":"隐私模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Hide emails and sensitive info":"隐藏邮箱和账号敏感信息"})]}),e.jsxs(D,{variant:n?"default":"outline",size:"sm",onClick:()=>s(!n),children:[n?e.jsx(Jl,{className:"h-4 w-4 mr-2"}):e.jsx(Nc,{className:"h-4 w-4 mr-2"}),n?C?"On":"已开启":C?"Off":"已关闭"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Usage Precision":"使用量精度"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Show decimal places for usage values":"显示使用量的小数精度(如 1.22 而非 1)"})]}),e.jsx(D,{variant:r?"default":"outline",size:"sm",onClick:()=>i(!r),children:r?C?"Decimal":"小数":C?"Integer":"整数"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Switch Target":"切号目标"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Which client to switch account credentials to":"切换账号凭证写入的客户端"})]}),e.jsxs("select",{className:"h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:le,onChange:je=>B(je.target.value),children:[e.jsx("option",{value:"ide",children:"Kiro IDE"}),e.jsx("option",{value:"cli",children:"Kiro CLI"}),e.jsx("option",{value:"both",children:C?"Both (IDE + CLI)":"两者 (IDE + CLI)"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Login Private Mode":"登录隐私模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Open browser in incognito/private mode when logging in":"在线登录时使用浏览器无痕/隐私模式打开"})]}),e.jsxs(D,{variant:q?"default":"outline",size:"sm",onClick:()=>V(!q),children:[e.jsx(KM,{className:"h-4 w-4 mr-2"}),q?C?"On":"已开启":C?"Off":"已关闭"]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Mt,{className:"h-4 w-4 text-primary"})}),C?"Auto Refresh":"自动刷新"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Auto Refresh":"自动刷新"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Auto refresh tokens before expiration":"Token 过期前自动刷新,并同步更新账户信息"})]}),e.jsx(D,{variant:o?"default":"outline",size:"sm",onClick:()=>b(!o),children:o?C?"On":"已开启":C?"Off":"已关闭"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-900 rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-700 dark:text-amber-300",children:C?"About Kiro IDE auto refresh":"关于 Kiro IDE 自动刷新"}),e.jsx("p",{children:C?"• Kiro IDE has its own internal refresh loop (independent of this app). Disabling Auto Refresh here only stops this app from refreshing — it does NOT stop Kiro IDE.":'• Kiro IDE 自带独立的刷新循环,关闭本工具的"自动刷新"不会停止 IDE 自己的刷新。'}),e.jsx("p",{children:C?"• When switching accounts or refreshing tokens here, the new token is synced to ~/.aws/sso/cache/kiro-auth-token.json only for the IDE current active account; other accounts only update the local store.":"• 切号 / 刷新 Token 时,仅当该账号是 Kiro IDE 当前激活账号才会同步到磁盘文件;非激活账号仅更新本工具内部 store。"}),e.jsx("p",{children:C?"• If IDE refreshes the token itself, this app detects the file change and syncs the new token back to its store (bidirectional sync).":"• 当 Kiro IDE 自己 refresh 后,本工具会监听磁盘文件变化并反向同步到 store(双向同步)。"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-3 border-t",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[C?"Proactive Token Renewal for IDE":"IDE 主动续期",e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",C?"Advanced":"进阶",")"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?`Renew IDE's active token ~${p} min before expiry, so Kiro IDE never refreshes by itself (eliminates all race conditions).`:`在 IDE 激活账号的 token 剩 ~${p} 分钟时抢先 refresh,让 Kiro IDE 永远不自己 refresh(彻底消除竞争条件)。`})]}),e.jsx(D,{variant:f?"default":"outline",size:"sm",onClick:async()=>{const je=await y(!f);!je.success&&je.error&&alert((C?"Failed to toggle proactive renewal: ":"切换主动续期失败:")+je.error)},children:f?C?"On":"已开启":C?"Off":"已关闭"})]}),f&&e.jsxs("div",{className:"text-xs text-muted-foreground bg-emerald-50 dark:bg-emerald-950/30 border border-emerald-200 dark:border-emerald-900 rounded-lg p-3 space-y-1",children:[e.jsx("p",{children:C?`• On: a single in-process timer renews token ${p} min before expiry; Kiro IDE keeps seeing fresh tokens (≥${60-p} min remaining) and never invokes OIDC by itself.`:`• 启用后:账号管理器主进程会在 token 剩 ${p} 分钟时自动续期,Kiro IDE 始终看到剩余 ≥ ${60-p} 分钟的 token,永远不会自己调 OIDC。`}),e.jsx("p",{children:C?"• Only the IDE current active account is renewed. Switching accounts re-schedules the timer for the new active account.":"• 仅对 IDE 当前激活账号续期。切号时 timer 会自动重新调度到新账号。"}),e.jsx("p",{children:C?"• If a renewal fails (e.g. server outage), the timer stops; IDE's own refresh loop takes over as fallback.":"• 续期失败时 timer 停止,由 IDE 自己的 refresh loop 接管(双向同步仍生效)。"})]}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",C?"Auto refresh tokens to keep login":"Token 即将过期时自动刷新,保持登录状态"]}),e.jsxs("p",{children:["• ",C?"Update usage and subscription info after refresh":"Token 刷新后自动更新账户用量、订阅等信息"]}),e.jsxs("p",{children:["• ",C?"Check all balances when auto-switch is on":"开启自动换号时,会定期检查所有账户余额"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Check Interval":"检查间隔"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"How often to check account status":"每隔多久检查一次账户状态"})]}),e.jsxs("select",{className:"w-[120px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:d,onChange:je=>b(!0,parseInt(je.target.value)),children:[e.jsx("option",{value:"1",children:C?"1 min":"1 分钟"}),e.jsx("option",{value:"3",children:C?"3 min":"3 分钟"}),e.jsx("option",{value:"5",children:C?"5 min":"5 分钟"}),e.jsx("option",{value:"10",children:C?"10 min":"10 分钟"}),e.jsx("option",{value:"15",children:C?"15 min":"15 分钟"}),e.jsx("option",{value:"20",children:C?"20 min":"20 分钟"}),e.jsx("option",{value:"30",children:C?"30 min":"30 分钟"}),e.jsx("option",{value:"45",children:C?"45 min":"45 分钟"}),e.jsx("option",{value:"60",children:C?"60 min":"60 分钟"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Concurrency":"刷新并发数"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Number of accounts to refresh simultaneously":"同时刷新的账号数量,过大可能卡顿"})]}),e.jsx("input",{type:"number",className:"w-24 h-9 px-3 rounded-lg border bg-background text-sm text-center focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:u,min:1,max:500,onChange:je=>v(parseInt(je.target.value)||50)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Sync Account Info":"同步检测账户信息"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Detect usage, subscription, and ban status":"刷新 Token 时同步检测用量、订阅、封禁状态"})]}),e.jsx(D,{variant:h?"default":"outline",size:"sm",onClick:()=>N(!h),children:h?C?"On":"已开启":C?"Off":"已关闭"})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Manual Trigger":"手动触发"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Manually trigger auto-refresh for debugging":"手动触发一次自动刷新流程(用于调试)"})]}),e.jsx(D,{variant:"outline",size:"sm",onClick:ze,disabled:st,children:st?C?"Refreshing...":"刷新中...":C?"Trigger Now":"立即触发"})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Sp,{className:"h-4 w-4 text-primary"})}),C?"API Settings":"API 设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Usage API Type":"用量查询 API"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Select API type for querying usage limits":"选择查询账户用量的 API 类型"})]}),e.jsxs("select",{className:"w-[180px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:Ne,onChange:je=>Kt(je.target.value),disabled:qe,children:[e.jsx("option",{value:"rest",children:"REST (GetUsageLimits)"}),e.jsx("option",{value:"cbor",children:"CBOR (GetUserUsageAndLimits)"})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",e.jsx("strong",{children:"REST"}),": ",C?"Official Kiro IDE format, recommended":"官方 Kiro IDE 使用的格式,推荐使用"]}),e.jsxs("p",{children:["• ",e.jsx("strong",{children:"CBOR"}),": ",C?"Web portal format, may have different fields":"网页端格式,字段可能有差异"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Use K-Proxy for API":"API 请求走 K-Proxy"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Route API requests through K-Proxy MITM proxy":"API 请求通过 K-Proxy MITM 代理发送"})]}),e.jsx(D,{variant:Ye?"default":"outline",size:"sm",onClick:()=>O(!Ye),disabled:Jt,children:Ye?C?"On":"已开启":C?"Off":"已关闭"})]}),Ye&&e.jsx("div",{className:"text-xs text-amber-500 bg-amber-500/10 rounded-lg p-3",children:C?"⚠️ K-Proxy must be running for this to work":"⚠️ 需要先启动 K-Proxy MITM 代理才能生效"})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),C?"Proxy":"代理设置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Enable Proxy":"启用代理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"All requests through proxy server":"所有网络请求将通过代理服务器"})]}),e.jsx(D,{variant:T?"default":"outline",size:"sm",onClick:()=>k(!T,Oe),children:T?C?"On":"已开启":C?"Off":"已关闭"})]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsx("label",{className:"text-sm font-medium",children:C?"Proxy URL":"代理地址"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",className:"flex-1 h-9 px-3 rounded-lg border bg-background text-sm font-mono focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",placeholder:C?"http://127.0.0.1:7890 or socks5://127.0.0.1:1080":"http://127.0.0.1:7890 或 socks5://127.0.0.1:1080",value:Oe,onChange:je=>Ee(je.target.value)}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>k(T,Oe),disabled:Oe===S,children:C?"Save":"保存"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:C?"Supports HTTP/HTTPS/SOCKS5, format: protocol://host:port":"支持 HTTP/HTTPS/SOCKS5 代理,格式: protocol://host:port"})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(YN,{className:"h-4 w-4 text-primary"})}),C?"Auto Switch":"自动换号"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Enable Auto Switch":"启用自动换号"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Auto switch when balance is low":"余额不足时自动切换到其他可用账号"})]}),e.jsx(D,{variant:R?"default":"outline",size:"sm",onClick:()=>G(!R),children:R?C?"On":"已开启":C?"Off":"已关闭"})]}),R&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Balance Threshold":"余额阈值"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Switch when balance below this":"余额低于此值时自动切换"})]}),e.jsx("input",{type:"number",className:"w-20 h-9 px-3 rounded-lg border bg-background text-sm text-center focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:I,min:0,onChange:je=>G(!0,parseInt(je.target.value)||0)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium flex items-center gap-2",children:[e.jsx(Gn,{className:"h-4 w-4"}),C?"Check Interval":"检查间隔"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"How often to check balance":"每隔多久检查一次余额"})]}),e.jsxs("select",{className:"h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:M,onChange:je=>G(!0,void 0,parseInt(je.target.value)),children:[e.jsx("option",{value:"1",children:C?"1 min":"1 分钟"}),e.jsx("option",{value:"3",children:C?"3 min":"3 分钟"}),e.jsx("option",{value:"5",children:C?"5 min":"5 分钟"}),e.jsx("option",{value:"10",children:C?"10 min":"10 分钟"}),e.jsx("option",{value:"15",children:C?"15 min":"15 分钟"}),e.jsx("option",{value:"30",children:C?"30 min":"30 分钟"})]})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(wA,{className:"h-4 w-4 text-primary"})}),C?"Batch Import":"批量导入"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Concurrency":"并发数"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Too high may cause API rate limiting":"同时验证的账号数量,过大可能导致 API 限流"})]}),e.jsx("input",{type:"number",className:"w-24 h-9 px-3 rounded-lg border bg-background text-sm text-center focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:W,min:1,max:500,onChange:je=>U(parseInt(je.target.value)||100)})]}),e.jsx("p",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-2",children:C?"Recommended: 10-100. Too high may cause failures, too low is slow.":"建议范围: 10-100。设置过大可能导致大量「验证失败」,设置过小则导入速度较慢。"})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Vl,{className:"h-4 w-4 text-primary"})}),C?"System Tray":"系统托盘"]})}),e.jsx(Pe,{className:"space-y-4",children:L?e.jsx("div",{className:"text-sm text-muted-foreground",children:C?"Loading...":"加载中..."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Enable System Tray":"启用系统托盘"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Show icon in system tray":"在系统托盘显示图标"})]}),e.jsx(D,{variant:ue.enabled?"default":"outline",size:"sm",onClick:()=>ne("enabled",!ue.enabled),children:ue.enabled?C?"On":"已开启":C?"Off":"已关闭"})]}),ue.enabled&&e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Close Button Action":"关闭按钮行为"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"What happens when you click X":"点击关闭按钮时的行为"})]}),e.jsxs("select",{className:"w-[140px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary",value:ue.closeAction,onChange:je=>ne("closeAction",je.target.value),children:[e.jsx("option",{value:"ask",children:C?"Ask every time":"每次询问"}),e.jsx("option",{value:"minimize",children:C?"Minimize to tray":"最小化到托盘"}),e.jsx("option",{value:"quit",children:C?"Quit application":"退出程序"})]})]})}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",C?"Double-click tray icon to show window":"双击托盘图标可以显示主窗口"]}),e.jsxs("p",{children:["• ",C?"Right-click tray icon to show menu":"右键托盘图标可以显示菜单"]}),e.jsxs("p",{children:["• ",C?"Tray menu shows current account info and usage":"托盘菜单可以查看当前账户信息和用量"]})]})]})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Ap,{className:"h-4 w-4 text-primary"})}),C?"Keyboard Shortcuts":"快捷键"]})}),e.jsx(Pe,{className:"space-y-4",children:xt?e.jsx("div",{className:"text-sm text-muted-foreground",children:C?"Loading...":"加载中..."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Show Window":"显示主窗口"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Global shortcut to show main window":"全局快捷键唤起主窗口"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",className:`w-[160px] h-9 px-3 rounded-lg border bg-background text-sm focus:outline-none focus:ring-1 focus:ring-primary focus:border-primary text-center ${Ge?"border-primary ring-1 ring-primary animate-pulse":""}`,value:Ge?C?"Press keys...":"请按键...":Ue,onKeyDown:J,onFocus:()=>gt(!0),onBlur:()=>gt(!1),readOnly:!0,placeholder:C?"Click to record":"点击录制"}),Ue&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-9 px-2",onClick:()=>Ze(""),children:e.jsx(Vt,{className:"h-4 w-4"})})]})]}),ft&&e.jsx("p",{className:"text-sm text-destructive",children:ft}),e.jsxs("div",{className:"text-xs text-muted-foreground bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsxs("p",{children:["• ",C?"Click input and press key combination to record":"点击输入框后按下组合键自动录制"]}),e.jsxs("p",{children:["• ",C?"macOS use Command, Windows/Linux use Ctrl":"macOS 使用 Command,Windows/Linux 使用 Ctrl"]}),e.jsxs("p",{children:["• ",C?"Click trash icon to clear shortcut":"点击垃圾桶图标可清除快捷键"]})]})]})})]}),e.jsx(De,{className:"hover-lift bg-primary/5",children:e.jsx(Pe,{className:"py-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(eo,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-sm",children:C?"Machine ID":"机器码管理"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:C?"Device identifier, auto-switch, account binding":"修改设备标识符、切号自动换码、账户机器码绑定等功能"})]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Va,{className:"h-3 w-3"}),e.jsx("span",{children:C?'Set in sidebar "Machine ID"':"请在侧边栏「机器码」中设置"})]})]})})}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Sp,{className:"h-4 w-4 text-primary"})}),C?"Data Management":"数据管理"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Export Data":"导出数据"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Supports JSON, TXT, CSV, Clipboard":"支持 JSON、TXT、CSV、剪贴板等多种格式"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:ce,children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),C?"Export":"导出"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:C?"Import Data":"导入数据"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Import accounts from JSON file":"从 JSON 文件导入账号数据"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:Ce,disabled:re,children:[e.jsx(Fa,{className:"h-4 w-4 mr-2"}),re?C?"Importing...":"导入中...":C?"Import":"导入"]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-destructive",children:C?"Clear All Data":"清除所有数据"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:C?"Delete all accounts, groups and tags":"删除所有账号、分组和标签"})]}),e.jsxs(D,{variant:"destructive",size:"sm",onClick:Ve,children:[e.jsx(Vt,{className:"h-4 w-4 mr-2"}),C?"Clear":"清除"]})]})]})]}),e.jsx(AI,{isEn:C}),e.jsx(sw,{open:z,onClose:()=>X(!1),accounts:Array.from(F.values()),selectedCount:0})]})}function AI({isEn:n}){const s=vt(u=>u.proxyPool),r=vt(u=>u.proxyPoolConfig),i=["kiro-register-config","kiro-register-history","kiro-register-templates","kiro-register-ratelimit-enabled","kiro-register-ratelimit-max","kiro-register-autobackoff","kiro-register-dailyquota-limit","kiro-register-schedule-enabled","kiro-register-schedule-time","kiro-register-mixed-sources","kiro-webhooks","accounts_viewMode","accounts_activeGroupTab","systemLogs_displayLimit","kiro-diagnose-moemail","proxyLogs_timeRange","proxyLogs_displayLimit"],o=()=>{const u={};for(const b of i){const v=localStorage.getItem(b);v!=null&&(u[b]=v)}const h={version:1,type:"krouter-config",exportedAt:Date.now(),proxyPool:Object.fromEntries(s),proxyPoolConfig:r,localStorage:u},f=new Blob([JSON.stringify(h,null,2)],{type:"application/json"}),p=URL.createObjectURL(f),y=document.createElement("a");y.href=p,y.download=`krouter-config-${new Date().toISOString().replace(/[:.]/g,"-")}.json`,y.click(),URL.revokeObjectURL(p)},d=async()=>{const u=await window.api.importFromFile();if(!u||u.format!=="json"){alert(n?"Please select a JSON file":"请选择 JSON 文件");return}try{const h=JSON.parse(u.content);if(h.type!=="krouter-config"&&h.type!=="kiro-account-manager-config"){alert(n?"Not a valid config file":"不是有效的配置文件");return}if(!confirm(n?"This will overwrite proxy pool / webhooks / templates. Continue?":"这将覆盖代理池 / Webhook / 模板等配置,确定继续?"))return;if(h.localStorage&&typeof h.localStorage=="object"){for(const[f,p]of Object.entries(h.localStorage))if(i.includes(f)&&typeof p=="string")try{localStorage.setItem(f,p)}catch{}}h.proxyPool&&typeof h.proxyPool=="object"&&(vt.getState().clearProxyPool(),vt.setState({proxyPool:new Map(Object.entries(h.proxyPool))})),h.proxyPoolConfig&&vt.getState().setProxyPoolConfig(h.proxyPoolConfig),alert(n?"Config imported. Please restart the app to fully apply.":"配置已导入。建议重启应用以完全生效。")}catch(h){alert((n?"Import failed: ":"导入失败: ")+(h instanceof Error?h.message:String(h)))}};return e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(YN,{className:"h-4 w-4 text-primary"})}),n?"Configuration Sync":"配置同步"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:n?"Export all non-sensitive settings (proxy pool, webhooks, templates, rate limits, UI preferences) to a file, for backup or multi-device sync. Does NOT include account tokens or credentials.":'导出所有"非敏感"配置(代理池、Webhook、注册模板、限速、UI 偏好等)到文件,便于备份或多设备同步。不含账号 Token 与凭据。'}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:o,children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),n?"Export Config":"导出配置"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(Fa,{className:"h-4 w-4 mr-2"}),n?"Import Config":"导入配置"]})]})]})]})}function MI(){const{machineIdConfig:n,currentMachineId:s,originalMachineId:r,originalBackupTime:i,accountMachineIds:o,machineIdHistory:d,accounts:u,setMachineIdConfig:h,refreshCurrentMachineId:f,changeMachineId:p,restoreOriginalMachineId:y,clearMachineIdHistory:b,bindMachineIdToAccount:v}=vt(),{t:N}=Ut(),j=N("common.unknown")==="Unknown",[T,S]=g.useState(!1),[k,R]=g.useState(null),[I,M]=g.useState("unknown"),[G,W]=g.useState(""),[U,q]=g.useState(!1),[V,le]=g.useState(!1),[B,be]=g.useState(null),[K,se]=g.useState(""),[te,Y]=g.useState(""),[P,F]=g.useState(null);g.useEffect(()=>{(async()=>{S(!0);try{const Ue=await window.api.machineIdGetOSType();M(Ue);const Lt=await window.api.machineIdCheckAdmin();R(Lt),await f()}catch(Ue){console.error("初始化失败:",Ue)}finally{S(!1)}})()},[f]);const fe=(we,Ue="default")=>{navigator.clipboard.writeText(we),F(Ue),setTimeout(()=>F(null),1500)},pe=async()=>{S(!0);try{await p(),await f()}finally{S(!1)}},C=async()=>{if(G.trim()){S(!0);try{await p(G.trim()),await f(),W("")}finally{S(!1)}}},z=async()=>{S(!0);try{await y(),await f()}finally{S(!1)}},X=async()=>{s&&await window.api.machineIdBackupToFile(s)},re=async()=>{S(!0);try{const we=await window.api.machineIdRestoreFromFile();we.success&&we.machineId&&(await p(we.machineId),await f())}finally{S(!1)}},xe=async()=>{await window.api.machineIdRequestAdminRestart()},Oe=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,we=>{const Ue=Math.random()*16|0;return(we==="x"?Ue:Ue&3|8).toString(16)}),Ee=we=>{be(we),se(o[we]||"")},Qe=we=>{K.trim()&&v(we,K.trim()),be(null),se("")},_e=()=>{be(null),se("")},st=we=>{const Ue=Oe();v(we,Ue),B===we&&se(Ue)},oe=we=>{const{accountMachineIds:Ue}=vt.getState(),Lt={...Ue};delete Lt[we],vt.setState({accountMachineIds:Lt}),vt.getState().saveToStorage()},ue=we=>new Date(we).toLocaleString("zh-CN"),ae=()=>{switch(I){case"windows":return"Windows";case"macos":return"macOS";case"linux":return"Linux";default:return j?"Unknown":"未知"}},L=Object.keys(o).length;return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero",children:[e.jsx("div",{className:"absolute inset-0 bg-grid-white/5"}),e.jsx("div",{className:"absolute top-0 right-0 w-64 h-64 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-3xl -translate-y-1/2 translate-x-1/2"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-48 h-48 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-3xl translate-y-1/2 -translate-x-1/2"}),e.jsxs("div",{className:"relative p-6",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-4 rounded-2xl bg-gradient-to-br from-primary to-primary/80 shadow-lg shadow-primary/25",children:e.jsx(eo,{className:"h-8 w-8 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:j?"Machine ID":"机器码管理"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:j?"Manage device identifier to prevent account bans":"管理设备标识符,防止账号关联和封禁"})]})]}),e.jsxs($e,{variant:"outline",className:"bg-background/80 backdrop-blur-sm",children:[e.jsx(Vl,{className:"h-3 w-3 mr-1"}),ae()]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 mt-6",children:[e.jsx("div",{className:"p-4 rounded-xl bg-background/60 backdrop-blur-sm border border-white/10",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(eo,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:d.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"History":"变更记录"})]})]})}),e.jsx("div",{className:"p-4 rounded-xl bg-background/60 backdrop-blur-sm border border-white/10",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ql,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:L}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Bound Accounts":"已绑定账户"})]})]})}),e.jsx("div",{className:"p-4 rounded-xl bg-background/60 backdrop-blur-sm border border-white/10",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Vn,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:r?j?"Backed":"已备份":j?"None":"未备份"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Original ID":"原始机器码"})]})]})})]})]})]}),k===!1&&e.jsx(De,{className:"border-warning/50 bg-gradient-to-r from-warning/10 to-warning/5 overflow-hidden",children:e.jsx(Pe,{className:"py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-warning/20",children:e.jsx(Rs,{className:"h-5 w-5 text-warning"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-warning",children:j?"Admin Required":"需要管理员权限"}),e.jsx("p",{className:"text-sm text-warning/80",children:j?"Run as administrator to modify machine ID":"修改机器码需要以管理员身份运行应用"})]})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:xe,className:"border-warning/50 hover:bg-warning/10",children:[e.jsx(Vn,{className:"h-4 w-4 mr-1"}),j?"Restart as Admin":"以管理员重启"]})]})})}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(De,{className:"group relative overflow-hidden hover:shadow-lg transition-all duration-300",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/5 to-primary/10 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none"}),e.jsx(at,{className:"pb-3 relative z-10",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Vl,{className:"h-4 w-4 text-primary"})}),j?"Current Machine ID":"当前机器码",s&&s!==r&&e.jsx($e,{className:"ml-auto bg-primary/10 text-primary border-primary/20",children:j?"Modified":"已修改"})]})}),e.jsxs(Pe,{className:"space-y-4 relative z-10",children:[e.jsx("div",{className:"relative group/code",children:e.jsx("div",{className:"p-4 bg-muted rounded-xl font-mono text-sm break-all border border-border text-foreground",children:T?e.jsxs("span",{className:"text-muted-foreground flex items-center gap-2",children:[e.jsx(Mt,{className:"h-4 w-4 animate-spin"}),j?"Loading...":"加载中..."]}):s||e.jsx("span",{className:"text-muted-foreground",children:j?"Unable to get":"无法获取"})})}),d.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(tc,{className:"h-3 w-3"}),j?"Last modified:":"最后修改:"," ",ue(d[d.length-1].timestamp)]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>fe(s,"current"),disabled:!s,className:"flex-1",children:[P==="current"?e.jsx(Pt,{className:"h-4 w-4 mr-1 text-success"}):e.jsx(As,{className:"h-4 w-4 mr-1"}),P==="current"?j?"Copied!":"已复制":j?"Copy":"复制"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:async()=>{S(!0);try{await f()}finally{S(!1)}},disabled:T,className:"flex-1",children:[e.jsx(Mt,{className:me("h-4 w-4 mr-1",T&&"animate-spin")}),j?"Refresh":"刷新"]})]})]})]}),e.jsxs(De,{className:"group relative overflow-hidden hover:shadow-lg transition-all duration-300",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/5 to-primary/10 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none"}),e.jsx(at,{className:"pb-3 relative z-10",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Vn,{className:"h-4 w-4 text-primary"})}),j?"Original Machine ID Backup":"原始机器码备份",r&&e.jsxs($e,{className:"ml-auto bg-primary/10 text-primary border-primary/20",children:[e.jsx(Bn,{className:"h-3 w-3 mr-1"}),j?"Backed Up":"已备份"]})]})}),e.jsx(Pe,{className:"space-y-4 relative z-10",children:r?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"p-4 bg-gradient-to-br from-primary/5 to-primary/10 rounded-xl font-mono text-sm break-all border border-primary/20",children:r}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(Bn,{className:"h-3 w-3 text-primary"}),j?"Backup time:":"备份时间:"," ",i?ue(i):j?"Unknown":"未知"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>fe(r,"original"),className:"flex-1",children:[P==="original"?e.jsx(Pt,{className:"h-4 w-4 mr-1 text-success"}):e.jsx(As,{className:"h-4 w-4 mr-1"}),P==="original"?j?"Copied!":"已复制":j?"Copy":"复制"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:z,disabled:T||s===r,className:"flex-1 border-primary/50 hover:bg-primary/10 hover:text-primary",children:[e.jsx(gr,{className:"h-4 w-4 mr-1"}),j?"Restore":"恢复原始"]})]})]}):e.jsxs("div",{className:"p-6 text-center rounded-xl border-2 border-dashed border-muted",children:[e.jsx(Vn,{className:"h-8 w-8 mx-auto text-muted-foreground/50 mb-2"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:j?"Original ID will be backed up on first change":"首次修改机器码时将自动备份原始值"})]})})]})]}),e.jsxs(De,{className:"overflow-hidden",children:[e.jsx(at,{className:"bg-gradient-to-r from-primary/5 to-primary/10 border-b",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Kn,{className:"h-4 w-4 text-primary"})}),j?"Operations":"机器码操作"]})}),e.jsxs(Pe,{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"group p-5 rounded-xl border-2 border-dashed hover:border-primary/50 hover:bg-primary/5 transition-all space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-primary to-primary/80 text-white",children:e.jsx(Kn,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold",children:j?"Random Generate":"随机生成"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Generate UUID format machine ID":"一键生成 UUID 格式机器码"})]})]}),e.jsxs(D,{onClick:pe,disabled:T,className:"w-full bg-primary hover:bg-primary/90 text-primary-foreground shadow-lg shadow-primary/25",children:[e.jsx(Kn,{className:"h-4 w-4 mr-2"}),j?"Generate & Apply":"随机生成并应用"]})]}),e.jsxs("div",{className:"group p-5 rounded-xl border-2 border-dashed hover:border-primary/50 hover:bg-primary/5 transition-all space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-gradient-to-br from-primary/80 to-primary text-white",children:e.jsx(Nf,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold",children:j?"Custom Input":"自定义输入"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Enter a specific machine ID":"输入指定的机器码"})]})]}),e.jsx("input",{type:"text",placeholder:j?"Enter UUID format machine ID...":"输入 UUID 格式机器码...",value:G,onChange:we=>W(we.target.value),className:"w-full px-4 py-2.5 text-sm border-2 rounded-xl bg-background focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all"}),e.jsx(D,{onClick:C,disabled:T||!G.trim(),variant:"outline",className:"w-full border-2 hover:bg-primary/10 hover:border-primary/50",children:j?"Apply Custom ID":"应用自定义机器码"})]})]}),e.jsxs("div",{className:"flex gap-3 pt-4 border-t",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:X,disabled:!s,className:"flex-1 h-10",children:[e.jsx(Ns,{className:"h-4 w-4 mr-2"}),j?"Export to File":"导出到文件"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:re,disabled:T,className:"flex-1 h-10",children:[e.jsx(Fa,{className:"h-4 w-4 mr-2"}),j?"Import from File":"从文件导入"]})]})]})]}),e.jsxs(De,{className:"overflow-hidden",children:[e.jsx(at,{className:"bg-gradient-to-r from-primary/5 to-primary/10 border-b",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(ql,{className:"h-4 w-4 text-primary"})}),j?"Automation":"自动化设置"]})}),e.jsxs(Pe,{className:"p-0 divide-y",children:[e.jsxs("div",{className:"flex items-center justify-between p-5 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:me("p-2.5 rounded-xl transition-colors",n.autoSwitchOnAccountChange?"bg-primary/10":"bg-muted"),children:e.jsx(Mt,{className:me("h-5 w-5 transition-colors",n.autoSwitchOnAccountChange?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:j?"Auto Change on Switch":"切换账号时自动更换机器码"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Auto generate new ID when switching accounts":"每次切换账号时自动生成并应用新的机器码"})]})]}),e.jsx(D,{variant:n.autoSwitchOnAccountChange?"default":"outline",size:"sm",onClick:()=>h({autoSwitchOnAccountChange:!n.autoSwitchOnAccountChange}),className:me("min-w-[80px]",n.autoSwitchOnAccountChange&&"bg-primary hover:bg-primary/90"),children:n.autoSwitchOnAccountChange?j?"On":"已开启":j?"Off":"已关闭"})]}),e.jsxs("div",{className:"flex items-center justify-between p-5 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:me("p-2.5 rounded-xl transition-colors",n.bindMachineIdToAccount?"bg-primary/10":"bg-muted"),children:e.jsx(ql,{className:me("h-5 w-5 transition-colors",n.bindMachineIdToAccount?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium flex items-center gap-2",children:[j?"Account ID Binding":"账户机器码绑定",L>0&&e.jsx($e,{className:"bg-primary/10 text-primary border-primary/20",children:j?`${L} accounts`:`${L} 个账户`})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Assign unique ID per account, auto-apply on switch":"为每个账户分配唯一的机器码,切换时自动使用"})]})]}),e.jsx(D,{variant:n.bindMachineIdToAccount?"default":"outline",size:"sm",onClick:()=>h({bindMachineIdToAccount:!n.bindMachineIdToAccount}),className:me("min-w-[80px]",n.bindMachineIdToAccount&&"bg-primary hover:bg-primary/90"),children:n.bindMachineIdToAccount?j?"On":"已开启":j?"Off":"已关闭"})]}),n.bindMachineIdToAccount&&e.jsxs("div",{className:"flex items-center justify-between p-5 pl-16 bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:me("p-2 rounded-lg transition-colors",n.useBindedMachineId?"bg-primary/10":"bg-muted"),children:e.jsx(Bn,{className:me("h-4 w-4 transition-colors",n.useBindedMachineId?"text-primary":"text-muted-foreground")})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:j?"Use bound machine ID":"使用绑定的唯一机器码"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"When off, generates new ID on each switch":"关闭时每次切换将随机生成新机器码"})]})]}),e.jsx(D,{variant:n.useBindedMachineId?"default":"outline",size:"sm",onClick:()=>h({useBindedMachineId:!n.useBindedMachineId}),className:me("min-w-[80px]",n.useBindedMachineId&&"bg-primary hover:bg-primary/90"),children:n.useBindedMachineId?j?"On":"已开启":j?"Off":"已关闭"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(De,{className:"group cursor-pointer hover:shadow-lg transition-all duration-300 hover:border-primary/50",onClick:()=>le(!0),children:e.jsx(Pe,{className:"p-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-gradient-to-br from-primary/10 to-primary/5 group-hover:from-primary/20 group-hover:to-primary/10 transition-colors",children:e.jsx(Fn,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-semibold group-hover:text-primary transition-colors",children:j?"Account Machine ID":"账户机器码管理"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"View and manage bound machine IDs":"查看和管理每个账户绑定的机器码"})]}),e.jsx("div",{className:"p-2 rounded-lg bg-muted group-hover:bg-primary/10 transition-colors",children:e.jsx(Nf,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors"})})]})})}),e.jsx(De,{className:"group cursor-pointer hover:shadow-lg transition-all duration-300 hover:border-primary/50",onClick:()=>q(!0),children:e.jsx(Pe,{className:"p-5",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-gradient-to-br from-primary/10 to-primary/5 group-hover:from-primary/20 group-hover:to-primary/10 transition-colors",children:e.jsx(tc,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-semibold group-hover:text-primary transition-colors",children:j?"Change History":"变更历史记录"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?`${d.length} records`:`共 ${d.length} 条历史记录`})]}),e.jsx("div",{className:"p-2 rounded-lg bg-muted group-hover:bg-primary/10 transition-colors",children:e.jsx(tc,{className:"h-4 w-4 text-muted-foreground group-hover:text-primary transition-colors"})})]})})})]}),V&&Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>le(!1)}),e.jsxs("div",{className:"relative bg-background rounded-xl shadow-2xl w-[600px] max-h-[80vh] flex flex-col animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fn,{className:"h-5 w-5"}),e.jsx("h2",{className:"text-lg font-semibold",children:j?"Account Machine ID":"账户机器码管理"}),e.jsxs($e,{variant:"secondary",children:[u.size," ",j?"accounts":"个账户"]})]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>le(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]}),e.jsx("div",{className:"px-4 pt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx(to,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx("input",{type:"text",value:te,onChange:we=>Y(we.target.value),placeholder:j?"Search accounts...":"搜索账户...",className:"w-full pl-9 pr-3 py-2 text-sm bg-muted border-0 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary"}),te&&e.jsx(D,{variant:"ghost",size:"sm",className:"absolute right-1 top-1/2 -translate-y-1/2 h-6 w-6 p-0",onClick:()=>Y(""),children:e.jsx(ns,{className:"h-3 w-3"})})]})}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-2",children:[Array.from(u.values()).filter(we=>{if(!te.trim())return!0;const Ue=te.toLowerCase();return we.email?.toLowerCase().includes(Ue)||we.nickname?.toLowerCase().includes(Ue)||o[we.id]?.toLowerCase().includes(Ue)}).map(we=>{const Ue=o[we.id],Lt=B===we.id;return e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/10 flex items-center justify-center text-primary text-sm font-medium",children:(we.nickname||we.email||"?")[0].toUpperCase()}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"font-medium text-sm truncate max-w-[200px]",children:we.nickname||we.email}),we.nickname&&we.email&&e.jsx("span",{className:"text-xs text-muted-foreground truncate max-w-[200px]",children:we.email})]}),Ue&&e.jsx($e,{variant:"secondary",className:"text-xs bg-success/10 text-success",children:j?"Bound":"已绑定"})]}),e.jsx("div",{className:"flex items-center gap-1",children:Lt?e.jsxs(e.Fragment,{children:[e.jsxs(D,{variant:"default",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>Qe(we.id),children:[e.jsx(Pt,{className:"h-3.5 w-3.5 mr-1"}),j?"Save":"保存"]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:_e,children:j?"Cancel":"取消"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>st(we.id),title:j?"Random":"随机",children:e.jsx(Kn,{className:"h-3.5 w-3.5"})})]}):e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>Ee(we.id),title:j?"Edit":"编辑",children:e.jsx(Nf,{className:"h-3.5 w-3.5"})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>st(we.id),title:j?"Random":"随机",children:e.jsx(Kn,{className:"h-3.5 w-3.5"})}),Ue&&e.jsxs(e.Fragment,{children:[e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>fe(Ue),title:j?"Copy":"复制",children:e.jsx(As,{className:"h-3.5 w-3.5"})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>oe(we.id),title:j?"Delete":"删除",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]})]})})]}),Lt?e.jsx("input",{type:"text",value:K,onChange:xt=>se(xt.target.value),placeholder:j?"Enter UUID format machine ID":"输入 UUID 格式机器码",className:"w-full px-2 py-1.5 text-xs font-mono bg-background border rounded focus:outline-none focus:ring-2 focus:ring-primary",autoFocus:!0}):Ue?e.jsx("div",{className:"flex items-center gap-2 px-2 py-1.5 bg-background rounded border",children:e.jsx("code",{className:"text-xs font-mono flex-1",children:Ue})}):e.jsx("div",{className:"px-2 py-1.5 bg-background/50 rounded border border-dashed text-center",children:e.jsx("span",{className:"text-xs text-muted-foreground",children:j?"Not bound":"未绑定"})})]},we.id)}),u.size===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(Fn,{className:"h-12 w-12 mx-auto text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:j?"No accounts":"暂无账户"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Please add accounts first":"请先添加账户"})]}),u.size>0&&te&&Array.from(u.values()).filter(we=>{const Ue=te.toLowerCase();return we.email?.toLowerCase().includes(Ue)||we.nickname?.toLowerCase().includes(Ue)||o[we.id]?.toLowerCase().includes(Ue)}).length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx(to,{className:"h-10 w-10 mx-auto text-muted-foreground/50 mb-3"}),e.jsx("p",{className:"text-muted-foreground",children:j?"No matches found":"未找到匹配的账户"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Try other keywords":"尝试其他关键词"})]})]}),e.jsx("div",{className:"px-6 py-3 border-t bg-muted/50 text-xs text-muted-foreground",children:j?"💡 Tip: After binding, switching to this account will auto-apply the bound machine ID":"💡 提示:绑定机器码后,切换到该账户时会自动应用对应的机器码"})]})]}),document.body),U&&Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>q(!1)}),e.jsxs("div",{className:"relative bg-background rounded-xl shadow-2xl w-[550px] max-h-[80vh] flex flex-col animate-in fade-in zoom-in-95 duration-200",children:[e.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(tc,{className:"h-5 w-5"}),e.jsx("h2",{className:"text-lg font-semibold",children:j?"Change History":"变更历史"}),e.jsxs($e,{variant:"secondary",children:[d.length," ",j?"records":"条"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d.length>0&&e.jsxs(D,{variant:"ghost",size:"sm",onClick:b,className:"text-destructive hover:text-destructive",children:[e.jsx(Vt,{className:"h-4 w-4 mr-1"}),j?"Clear":"清空"]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>q(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:d.length>0?e.jsx("div",{className:"space-y-2",children:[...d].reverse().map((we,Ue)=>e.jsxs("div",{className:"p-3 bg-muted rounded-lg",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["#",d.length-Ue]}),e.jsxs($e,{variant:"secondary",className:me("text-xs whitespace-nowrap",we.action==="initial"&&"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300",we.action==="manual"&&"bg-purple-100 text-purple-700 dark:bg-purple-900 dark:text-purple-300",we.action==="auto_switch"&&"bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300",we.action==="restore"&&"bg-orange-100 text-orange-700 dark:bg-orange-900 dark:text-orange-300",we.action==="bind"&&"bg-cyan-100 text-cyan-700 dark:bg-cyan-900 dark:text-cyan-300"),children:[we.action==="initial"&&(j?"Init":"初始"),we.action==="manual"&&(j?"Manual":"手动"),we.action==="auto_switch"&&(j?"Auto":"自动"),we.action==="restore"&&(j?"Restore":"恢复"),we.action==="bind"&&(j?"Bind":"绑定")]})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:ue(we.timestamp)})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-background rounded border",children:[e.jsx("code",{className:"text-sm flex-1 font-mono",children:we.machineId}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 shrink-0",onClick:()=>fe(we.machineId),title:j?"Copy":"复制",children:e.jsx(As,{className:"h-3 w-3"})})]}),we.accountId&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:[j?"Account: ":"关联账户: ",u.get(we.accountId)?.nickname||u.get(we.accountId)?.email||we.accountId]})]},we.id))}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx(tc,{className:"h-12 w-12 mx-auto text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:j?"No change records":"暂无变更记录"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Changes will be recorded automatically":"机器码变更后将自动记录"})]})})]})]}),document.body),e.jsx(De,{className:"overflow-hidden bg-gradient-to-br from-muted/50 to-muted/30",children:e.jsx(Pe,{className:"p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"p-2.5 rounded-xl bg-primary/10 shrink-0",children:e.jsx(Vn,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"font-semibold",children:j?"Platform Notes":"平台说明"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-primary/5 border border-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Vl,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:"Windows"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Modifies registry MachineGuid, requires admin":"修改注册表 MachineGuid,需要管理员权限"})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-primary/5 border border-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Vl,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:"macOS"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"App-level override, hardware UUID unchanged":"应用层覆盖方式,原生硬件 UUID 无法修改"})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-primary/5 border border-primary/10",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(Vl,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium text-sm",children:"Linux"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j?"Modifies /etc/machine-id, requires root":"修改 /etc/machine-id,需要 root 权限"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-warning/10 border border-warning/20",children:[e.jsx(Rs,{className:"h-4 w-4 text-warning shrink-0"}),e.jsx("p",{className:"text-xs text-warning",children:j?"Changing machine ID may affect some software licenses, proceed with caution":"修改机器码可能影响部分软件的授权,请谨慎操作"})]})]})]})})})]})}function EI({filename:n,onClose:s,onSaved:r}){const[i,o]=g.useState(""),[d,u]=g.useState(!0),[h,f]=g.useState(!1),[p,y]=g.useState(null),[b,v]=g.useState(!1),{t:N}=Ut(),j=N("common.unknown")==="Unknown";g.useEffect(()=>{T()},[n]);const T=async()=>{u(!0),y(null);try{const I=await window.api.readKiroSteeringFile(n);I.success&&I.content!==void 0?(o(I.content),v(!1)):y(I.error||(j?"Failed to read file":"读取文件失败"))}catch(I){y(j?"Failed to read file":"读取文件失败"),console.error(I)}finally{u(!1)}},S=async()=>{f(!0),y(null);try{const I=await window.api.saveKiroSteeringFile(n,i);I.success?(v(!1),r?.()):y(I.error||(j?"Failed to save file":"保存文件失败"))}catch(I){y(j?"Failed to save file":"保存文件失败"),console.error(I)}finally{f(!1)}},k=()=>{b?confirm(j?"File modified. Close anyway? Unsaved changes will be lost.":"文件已修改,确定要关闭吗?未保存的更改将丢失。")&&s():s()},R=I=>{o(I),v(!0)};return Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:k}),e.jsxs("div",{className:"relative bg-background rounded-lg shadow-xl w-[90vw] max-w-4xl h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"font-semibold",children:j?"Edit Steering File":"编辑 Steering 文件"}),e.jsx("span",{className:"text-sm text-muted-foreground font-mono",children:n}),b&&e.jsxs("span",{className:"text-xs text-warning",children:["● ",j?"Modified":"已修改"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(D,{variant:"ghost",size:"sm",onClick:T,disabled:d,children:e.jsx(Mt,{className:`h-4 w-4 ${d?"animate-spin":""}`})}),e.jsxs(D,{variant:"default",size:"sm",onClick:S,disabled:h||!b,children:[e.jsx(vx,{className:"h-4 w-4 mr-1"}),h?j?"Saving...":"保存中...":j?"Save":"保存"]}),e.jsx(D,{variant:"ghost",size:"sm",onClick:k,children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),p&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm",children:p}),e.jsx("div",{className:"flex-1 p-4 overflow-hidden",children:d?e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(Mt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsx("textarea",{value:i,onChange:I=>R(I.target.value),className:"w-full h-full p-4 font-mono text-sm bg-muted rounded-lg border-0 resize-none focus:outline-none focus:ring-2 focus:ring-primary",placeholder:j?"Edit steering rules here...":"在此编辑 Steering 规则...",spellCheck:!1})}),e.jsx("div",{className:"px-4 py-2 border-t text-xs text-muted-foreground",children:j?"Tip: Steering files use Markdown format to define AI assistant behavior rules":"提示:Steering 文件使用 Markdown 格式,用于定义 AI 助手的行为规则"})]})]}),document.body)}function II({serverName:n,server:s,onClose:r,onSaved:i}){const[o,d]=g.useState(n||""),[u,h]=g.useState(s?.command||""),[f,p]=g.useState(s?.args||[]),[y,b]=g.useState(s?.env?Object.entries(s.env).map(([B,be])=>({key:B,value:be})):[]),[v,N]=g.useState(!1),[j,T]=g.useState(null),[S,k]=g.useState(""),R=!!n,{t:I}=Ut(),M=I("common.unknown")==="Unknown",G=async()=>{if(!o.trim()){T(M?"Please enter server name":"请输入服务器名称");return}if(!u.trim()){T(M?"Please enter command":"请输入命令");return}N(!0),T(null);try{const B={command:u.trim(),args:f.filter(K=>K.trim()),env:y.reduce((K,{key:se,value:te})=>(se.trim()&&(K[se.trim()]=te),K),{})};B.args?.length===0&&delete B.args,Object.keys(B.env||{}).length===0&&delete B.env;const be=await window.api.saveMcpServer(o.trim(),B,R?n:void 0);be.success?(i(),r()):T(be.error||(M?"Save failed":"保存失败"))}catch(B){T(M?"Save failed":"保存失败"),console.error(B)}finally{N(!1)}},W=()=>{S.trim()&&(p([...f,S.trim()]),k(""))},U=B=>{p(f.filter((be,K)=>K!==B))},q=()=>{b([...y,{key:"",value:""}])},V=(B,be,K)=>{const se=[...y];se[B][be]=K,b(se)},le=B=>{b(y.filter((be,K)=>K!==B))};return Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:r}),e.jsxs("div",{className:"relative bg-background rounded-lg shadow-xl w-[90vw] max-w-lg max-h-[80vh] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[e.jsx("h2",{className:"font-semibold",children:R?M?"Edit MCP Server":"编辑 MCP 服务器":M?"Add MCP Server":"添加 MCP 服务器"}),e.jsx(D,{variant:"ghost",size:"sm",onClick:r,children:e.jsx(ns,{className:"h-4 w-4"})})]}),j&&e.jsx("div",{className:"px-4 py-2 bg-destructive/10 text-destructive text-sm",children:j}),e.jsxs("div",{className:"flex-1 p-4 space-y-4 overflow-auto",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Server Name":"服务器名称"}),e.jsx("input",{type:"text",value:o,onChange:B=>d(B.target.value),placeholder:M?"e.g.: fetch, exa, context7":"例如: fetch, exa, context7",className:"w-full px-3 py-2 rounded-md border bg-background text-sm",disabled:R})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Command":"命令"}),e.jsx("input",{type:"text",value:u,onChange:B=>h(B.target.value),placeholder:M?"e.g.: uvx, npx, node":"例如: uvx, npx, node",className:"w-full px-3 py-2 rounded-md border bg-background text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Arguments":"参数"}),e.jsxs("div",{className:"space-y-2",children:[f.map((B,be)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:B}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>U(be),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},be)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:S,onChange:B=>k(B.target.value),placeholder:M?"Add argument":"添加参数",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:B=>B.key==="Enter"&&W()}),e.jsx(D,{variant:"outline",size:"sm",onClick:W,children:e.jsx(Ts,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1",children:M?"Environment Variables":"环境变量"}),e.jsxs("div",{className:"space-y-2",children:[y.map((B,be)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:B.key,onChange:K=>V(be,"key",K.target.value),placeholder:M?"Key":"变量名",className:"w-1/3 px-2 py-1.5 rounded-md border bg-background text-sm"}),e.jsx("input",{type:"text",value:B.value,onChange:K=>V(be,"value",K.target.value),placeholder:M?"Value":"值",className:"flex-1 px-2 py-1.5 rounded-md border bg-background text-sm"}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>le(be),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},be)),e.jsxs(D,{variant:"outline",size:"sm",onClick:q,children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),M?"Add Env Var":"添加环境变量"]})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 px-4 py-3 border-t",children:[e.jsx(D,{variant:"outline",onClick:r,children:M?"Cancel":"取消"}),e.jsxs(D,{onClick:G,disabled:v,children:[e.jsx(vx,{className:"h-4 w-4 mr-1"}),v?M?"Saving...":"保存中...":M?"Save":"保存"]})]})]})]}),document.body)}const RI=["rm -rf *","rm -rf /","rm -rf ~","del /f /s /q *","format","mkfs","dd if=",":(){:|:&};:","chmod -R 777 /","chown -R","> /dev/sda","wget * | sh","curl * | sh","shutdown","reboot","init 0","init 6"],nj={agentAutonomy:"Autopilot",modelSelection:"auto",enableDebugLogs:!1,enableTabAutocomplete:!1,enableCodebaseIndexing:!1,usageSummary:!0,codeReferences:!1,configureMCP:"Enabled",trustedCommands:[],trustedTools:{},commandDenylist:[],ignoreFiles:[],mcpApprovedEnvVars:[],notificationsActionRequired:!0,notificationsFailure:!1,notificationsSuccess:!1,notificationsBilling:!0},DI=[{value:"Autopilot",label:"Autopilot (自动执行)",description:"Agent 自动执行任务"},{value:"Supervised",label:"Supervised (需确认)",description:"每个步骤需要手动确认"}],PI=[{value:"Autopilot",label:"Autopilot (Auto)",description:"Agent executes tasks automatically"},{value:"Supervised",label:"Supervised (Confirm)",description:"Manual confirmation for each step"}],LI=[{value:"Enabled",label:"启用",description:"允许 MCP 服务器连接"},{value:"Disabled",label:"禁用",description:"禁用所有 MCP 功能"}],OI=[{value:"Enabled",label:"Enabled",description:"Allow MCP server connections"},{value:"Disabled",label:"Disabled",description:"Disable all MCP features"}];function zI(){const[n,s]=g.useState(nj),[r,i]=g.useState({mcpServers:{}}),[o,d]=g.useState([]),[u,h]=g.useState(!0),[f,p]=g.useState(!1),[y,b]=g.useState(null),[v,N]=g.useState([]),[j,T]=g.useState(!1),[S,k]=g.useState({agent:!0,mcp:!0,steering:!0,commands:!1}),[R,I]=g.useState(""),[M,G]=g.useState(""),[W,U]=g.useState(""),[q,V]=g.useState(null),[le,B]=g.useState(null),{t:be}=Ut(),K=be("common.unknown")==="Unknown",se=K?PI:DI,te=K?OI:LI;g.useEffect(()=>{P(),Y()},[]);const Y=async()=>{T(!0);try{const ae=await window.api.getKiroAvailableModels();ae.models&&ae.models.length>0&&N(ae.models)}catch(ae){console.error("Failed to load models:",ae)}finally{T(!1)}},P=async()=>{h(!0),b(null);try{const ae=await window.api.getKiroSettings();if(ae.settings){const L=Object.fromEntries(Object.entries(ae.settings).filter(([,we])=>we!==void 0));s({...nj,...L})}ae.mcpConfig&&i(ae.mcpConfig),ae.steeringFiles&&d(ae.steeringFiles)}catch(ae){b(K?"Failed to load Kiro settings":"加载 Kiro 设置失败"),console.error(ae)}finally{h(!1)}},F=async()=>{p(!0),b(null);try{await window.api.saveKiroSettings(n)}catch(ae){b(K?"Failed to save settings":"保存设置失败"),console.error(ae)}finally{p(!1)}},fe=ae=>{k(L=>({...L,[ae]:!L[ae]}))},pe=async()=>{try{await window.api.openKiroSettingsFile()}catch(ae){console.error(ae)}},C=async ae=>{try{await window.api.openKiroMcpConfig(ae)}catch(L){console.error(L)}},z=async()=>{try{await window.api.openKiroSteeringFolder()}catch(ae){console.error(ae)}},X=ae=>{V(ae)},re=async ae=>{try{await window.api.openKiroSteeringFile(ae)}catch(L){console.error(L)}},xe=async()=>{try{(await window.api.createKiroDefaultRules()).success&&await P()}catch(ae){console.error(ae)}},Oe=async ae=>{if(confirm(K?`Delete "${ae}"? This cannot be undone.`:`确定要删除 "${ae}" 吗?此操作无法撤销。`))try{const L=await window.api.deleteKiroSteeringFile(ae);L.success?await P():b(L.error||(K?"Failed to delete file":"删除文件失败"))}catch(L){console.error(L),b(K?"Failed to delete file":"删除文件失败")}},Ee=async ae=>{if(confirm(K?`Delete MCP server "${ae}"?`:`确定要删除 MCP 服务器 "${ae}" 吗?`))try{const L=await window.api.deleteMcpServer(ae);L.success?await P():b(L.error||(K?"Failed to delete server":"删除服务器失败"))}catch(L){console.error(L),b(K?"Failed to delete server":"删除服务器失败")}},Qe=()=>{R.trim()&&(s(ae=>({...ae,trustedCommands:[...ae.trustedCommands,R.trim()]})),I(""))},_e=ae=>{s(L=>({...L,trustedCommands:L.trustedCommands.filter((we,Ue)=>Ue!==ae)}))},st=()=>{W.trim()&&(s(ae=>({...ae,commandDenylist:[...ae.commandDenylist,W.trim()]})),U(""))},oe=()=>{s(ae=>{const L=RI.filter(we=>!ae.commandDenylist.includes(we));return{...ae,commandDenylist:[...ae.commandDenylist,...L]}})},ue=ae=>{s(L=>({...L,commandDenylist:L.commandDenylist.filter((we,Ue)=>Ue!==ae)}))};return u?e.jsx("div",{className:"flex-1 p-6 flex items-center justify-center",children:e.jsx(Mt,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary shadow-lg shadow-primary/25",children:e.jsx(Hi,{className:"h-6 w-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:K?"Kiro Settings":"Kiro 设置"}),e.jsx("p",{className:"text-muted-foreground",children:K?"Manage Kiro IDE config, MCP servers and user rules":"管理 Kiro IDE 的配置、MCP 服务器和用户规则"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:P,className:"bg-background/50 backdrop-blur-sm",children:[e.jsx(Mt,{className:"h-4 w-4 mr-2"}),K?"Refresh":"刷新"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:pe,className:"bg-background/50 backdrop-blur-sm",children:[e.jsx(Xs,{className:"h-4 w-4 mr-2"}),K?"Open File":"打开设置文件"]}),e.jsxs(D,{size:"sm",onClick:F,disabled:f,children:[e.jsx(vx,{className:"h-4 w-4 mr-2"}),f?K?"Saving...":"保存中...":K?"Save":"保存设置"]})]})]})]}),y&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-destructive/10 text-destructive rounded-lg",children:[e.jsx(ln,{className:"h-4 w-4"}),y]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("agent"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Ka,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"Agent Settings":"Agent 设置"})]}),S.agent?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.agent&&e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent Autonomy":"Agent 自主模式"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Determines whether the agent will ask for accept/reject at each checkpoint in the workflow.":"决定 Agent 在工作流的每个检查点是否要求接受/拒绝"})]}),e.jsx(ei,{value:n.agentAutonomy,options:se,onChange:ae=>s(L=>({...L,agentAutonomy:ae})),className:"w-[200px]"})]}),e.jsxs("div",{className:"flex items-center justify-between border-t pt-4",children:[e.jsxs("div",{className:"flex-1 mr-4",children:[e.jsx("p",{className:"font-medium",children:K?"Model Selection":"模型选择"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Select model to use for agent operations.":"选择 Agent 操作使用的模型"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v.length>0?e.jsx(ei,{value:n.modelSelection,options:v.map(ae=>({value:ae.id,label:ae.name||ae.id,description:ae.description})),onChange:ae=>s(L=>({...L,modelSelection:ae})),className:"w-[240px]"}):e.jsx("input",{type:"text",value:n.modelSelection,onChange:ae=>s(L=>({...L,modelSelection:ae.target.value})),placeholder:"claude-haiku-4.5",className:"w-[240px] px-3 py-1.5 rounded-md border bg-background text-sm"}),e.jsx(D,{variant:"ghost",size:"sm",onClick:Y,disabled:j,title:K?"Refresh models":"刷新模型列表",children:e.jsx(Mt,{className:`h-4 w-4 ${j?"animate-spin":""}`})})]})]}),e.jsxs("div",{className:"border-t pt-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable Tab Autocomplete":"Tab 自动补全"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Tab Autocomplete allows Kiro Agent to provide code suggestions in the editor as you type.":"Tab 自动补全允许 Kiro Agent 在输入时提供代码建议"})]}),e.jsx(Pa,{checked:n.enableTabAutocomplete,onChange:ae=>s(L=>({...L,enableTabAutocomplete:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Usage Summary":"使用统计"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Display usage summary and elapsed time for agent executions.":"显示 Agent 执行的用量摘要和耗时"})]}),e.jsx(Pa,{checked:n.usageSummary,onChange:ae=>s(L=>({...L,usageSummary:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Code References: Reference Tracker":"代码引用追踪"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Allow Kiro to generate code with code references. Sometimes code generated by Kiro may be similar to publicly available code.":"允许 Kiro 生成带代码引用的代码。Kiro 生成的代码可能与公开可用代码相似。"})]}),e.jsx(Pa,{checked:n.codeReferences,onChange:ae=>s(L=>({...L,codeReferences:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable Codebase Indexing":"代码库索引"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Enable Repo Indexing (Experimental). This is an experimental feature which does not work with multi-folder workspaces.":"启用仓库索引(实验性)。这是一个实验性功能,不支持多文件夹工作区。"})]}),e.jsx(Pa,{checked:n.enableCodebaseIndexing,onChange:ae=>s(L=>({...L,enableCodebaseIndexing:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable Debug Logs":"调试日志"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Enable Kiro Debug Logs in the Output panel.":"在输出面板启用 Kiro 调试日志"})]}),e.jsx(Pa,{checked:n.enableDebugLogs,onChange:ae=>s(L=>({...L,enableDebugLogs:ae}))})]})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("p",{className:"font-medium mb-3",children:K?"Notifications":"通知设置"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent: Action Required":"Agent: 需要操作"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show desktop notification when the agent requires input, e.g. for a shell command.":"Agent 需要输入时显示桌面通知,如执行 Shell 命令时"})]}),e.jsx(Pa,{checked:n.notificationsActionRequired,onChange:ae=>s(L=>({...L,notificationsActionRequired:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent: Failure":"Agent: 失败"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show desktop notification when the agent encounters an unexpected failure.":"Agent 遇到意外失败时显示桌面通知"})]}),e.jsx(Pa,{checked:n.notificationsFailure,onChange:ae=>s(L=>({...L,notificationsFailure:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Agent: Success":"Agent: 成功"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show desktop notifications when the agent successfully completes a task.":"Agent 成功完成任务时显示桌面通知"})]}),e.jsx(Pa,{checked:n.notificationsSuccess,onChange:ae=>s(L=>({...L,notificationsSuccess:ae}))})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Billing":"账单"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Show in-app notifications for billing and usage events (usage resets, low resources, overages).":"显示账单和用量事件的应用内通知(用量重置、资源不足、超额)"})]}),e.jsx(Pa,{checked:n.notificationsBilling,onChange:ae=>s(L=>({...L,notificationsBilling:ae}))})]})]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("mcp"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Ds,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"MCP Servers":"MCP 服务器"}),e.jsx("span",{className:"px-2 py-0.5 text-xs rounded-full bg-primary/10 text-primary",children:Object.keys(r.mcpServers).length})]}),S.mcp?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.mcp&&e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:K?"Enable MCP":"启用 MCP"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Allow connections to external tools and data sources":"允许连接外部工具和数据源"})]}),e.jsx(ei,{value:n.configureMCP,options:te,onChange:ae=>s(L=>({...L,configureMCP:ae}))})]}),e.jsxs("div",{className:"border-t pt-4",children:[e.jsx("p",{className:"font-medium mb-2",children:K?"Configured MCP Servers":"已配置的 MCP 服务器"}),Object.keys(r.mcpServers).length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"No MCP servers configured":"暂无配置的 MCP 服务器"}):e.jsx("div",{className:"space-y-2",children:Object.entries(r.mcpServers).map(([ae,L])=>e.jsxs("div",{className:"flex items-center justify-between p-2 bg-muted rounded-md",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-sm",children:ae}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:L.command})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>B({name:ae,server:L}),title:K?"Edit":"编辑",children:e.jsx(Ou,{className:"h-4 w-4 text-primary"})}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>Ee(ae),title:K?"Delete":"删除",children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]})]},ae))})]}),e.jsxs("div",{className:"flex gap-2 pt-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>B({}),children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),K?"Add MCP Server":"添加 MCP 服务器"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>C("user"),children:[e.jsx(Vi,{className:"h-4 w-4 mr-2"}),K?"User MCP Config":"用户 MCP 配置"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>C("workspace"),children:[e.jsx(Vi,{className:"h-4 w-4 mr-2"}),K?"Workspace MCP Config":"工作区 MCP 配置"]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("steering"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(xr,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"User Rules (Steering)":"用户规则 (Steering)"}),e.jsxs("span",{className:"px-2 py-0.5 text-xs rounded-full bg-primary/10 text-primary",children:[o.length," ",K?"files":"个文件"]})]}),S.steering?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.steering&&e.jsxs(Pe,{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"Steering files define AI assistant behavior rules and context":"Steering 文件用于定义 AI 助手的行为规则和上下文"}),o.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:K?"No steering files":"暂无 Steering 文件"}):e.jsx("div",{className:"space-y-2",children:o.map((ae,L)=>e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-muted rounded-md",children:[e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-mono flex-1",children:ae}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>X(ae),title:K?"Edit internally":"内部编辑",children:e.jsx(Ou,{className:"h-4 w-4 text-primary"})}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>re(ae),title:K?"Open externally":"外部打开",children:e.jsx(Xs,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx("button",{className:"p-1 hover:bg-background rounded transition-colors",onClick:()=>Oe(ae),title:K?"Delete":"删除",children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},L))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:xe,children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),K?"Create Rules":"创建规则文件"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:z,children:[e.jsx(Vi,{className:"h-4 w-4 mr-2"}),K?"Open Steering Folder":"打开 Steering 目录"]})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2 cursor-pointer hover:bg-muted/30 transition-colors rounded-t-lg",onClick:()=>fe("commands"),children:e.jsxs(rt,{className:"text-base flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(WN,{className:"h-4 w-4 text-primary"})}),e.jsx("span",{children:K?"Command Config":"命令配置"})]}),S.commands?e.jsx(zi,{className:"h-4 w-4"}):e.jsx(va,{className:"h-4 w-4"})]})}),S.commands&&e.jsxs(Pe,{className:"space-y-6",children:[e.jsxs("div",{className:"p-4 rounded-lg bg-muted/50 border border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Vn,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"font-medium",children:K?"Trusted Commands":"信任的命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:K?"These commands will auto-execute without confirmation":"这些命令将自动执行,无需确认"}),e.jsxs("div",{className:"space-y-2",children:[n.trustedCommands.map((ae,L)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:ae}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>_e(L),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},L)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:R,onChange:ae=>I(ae.target.value),placeholder:K?"e.g.: npm *":"如: npm *",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:ae=>ae.key==="Enter"&&Qe()}),e.jsx(D,{variant:"outline",size:"sm",onClick:Qe,children:e.jsx(Ts,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-muted/50 border border-border",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(Ds,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"font-medium",children:K?"Trusted Tools":"信任的工具"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:K?"Tools to auto-accept if requested by the Agent. Each tool name maps to a boolean indicating whether it should be trusted.":"当 Agent 请求使用这些工具时自动批准。每个工具名称对应是否信任的布尔值。"}),e.jsxs("div",{className:"space-y-2",children:[Object.entries(n.trustedTools).map(([ae,L])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:ae}),e.jsx(Pa,{checked:L,onChange:we=>s(Ue=>({...Ue,trustedTools:{...Ue.trustedTools,[ae]:we}}))}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{s(we=>{const Ue={...we.trustedTools};return delete Ue[ae],{...we,trustedTools:Ue}})},children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},ae)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:M,onChange:ae=>G(ae.target.value),placeholder:K?"Tool name":"工具名称",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:ae=>{ae.key==="Enter"&&M.trim()&&(s(L=>({...L,trustedTools:{...L.trustedTools,[M.trim()]:!0}})),G(""))}}),e.jsx(D,{variant:"outline",size:"sm",onClick:()=>{M.trim()&&(s(ae=>({...ae,trustedTools:{...ae.trustedTools,[M.trim()]:!0}})),G(""))},children:e.jsx(Ts,{className:"h-4 w-4"})})]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-destructive/5 border border-destructive/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(ln,{className:"h-4 w-4 text-destructive"}),e.jsx("p",{className:"font-medium text-destructive",children:K?"Blocked Commands":"禁止的命令"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:K?"These commands always require manual confirmation":"这些命令总是需要手动确认"}),e.jsxs("div",{className:"space-y-2",children:[n.commandDenylist.map((ae,L)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1 bg-muted rounded text-sm",children:ae}),e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>ue(L),children:e.jsx(Vt,{className:"h-4 w-4 text-destructive"})})]},L)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:W,onChange:ae=>U(ae.target.value),placeholder:K?"e.g.: rm -rf *":"如: rm -rf *",className:"flex-1 px-3 py-1.5 rounded-md border bg-background text-sm",onKeyDown:ae=>ae.key==="Enter"&&st()}),e.jsx(D,{variant:"outline",size:"sm",onClick:st,children:e.jsx(Ts,{className:"h-4 w-4"})})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:oe,className:"mt-2",children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),K?"Add Default Blocked":"添加默认禁止命令"]})]})]})]})]}),q&&e.jsx(EI,{filename:q,onClose:()=>V(null),onSaved:P}),le&&e.jsx(II,{serverName:le.name,server:le.server,onClose:()=>B(null),onSaved:P})]})}function UI({config:n,setConfig:s,isRunning:r,isEn:i}){const[o,d]=g.useState(!1),[u,h]=g.useState(!1),[f,p]=g.useState(!1),[y,b]=g.useState(null),[v,N]=g.useState([]),[j,T]=g.useState(!1),[S,k]=g.useState(!1),[R,I]=g.useState(!1),M=!!(n.enableMultiAccount&&(n.accountSelectionStrategy||"smart")!=="sticky"),[G,W]=g.useState((n.allowedIPs||[]).join(`
117
117
  `)),[U,q]=g.useState((n.deniedIPs||[]).join(`
118
118
  `));g.useEffect(()=>{W((n.allowedIPs||[]).join(`
119
119
  `)),q((n.deniedIPs||[]).join(`
@@ -122,7 +122,7 @@ email----password----refreshToken----clientId----clientSecret`:`JSON 格式:
122
122
  `),k=new Blob([S],{type:"text/plain"}),R=URL.createObjectURL(k),I=document.createElement("a");I.href=R,I.download=`proxy-logs-${new Date().toISOString().slice(0,10)}.txt`,I.click(),URL.revokeObjectURL(R)},v=r.filter(S=>S.status<400).length,N=r.filter(S=>S.status>=400).length,j=r.reduce((S,k)=>S+(k.credits||0),0),T=r.reduce((S,k)=>S+(k.tokens||0),0);return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[900px] max-h-[80vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsxs(at,{className:"pb-3 border-b sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(rt,{className:"text-lg",children:f?"Request Logs":"请求日志"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:b,disabled:r.length===0,children:[e.jsx(Ns,{className:"h-4 w-4 mr-1"}),f?"Export":"导出"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:d,disabled:r.length===0,children:[e.jsx(Vt,{className:"h-4 w-4 mr-1"}),f?"Clear":"清空"]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 mt-2 text-sm",children:[e.jsxs("span",{children:[f?"Total":"总计",": ",e.jsx($e,{variant:"secondary",children:r.length})]}),e.jsxs("span",{children:[f?"Success":"成功",": ",e.jsx($e,{className:"bg-success/20 text-success",children:v})]}),e.jsxs("span",{children:[f?"Error":"错误",": ",e.jsx($e,{className:"bg-destructive/20 text-destructive",children:N})]}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsxs("span",{children:["Tokens ",f?"Recent":"最近",": ",e.jsx($e,{variant:"outline",children:T.toLocaleString()})]}),e.jsxs("span",{className:"flex items-center gap-1",children:["Tokens ",f?"Total":"总计",": ",e.jsx($e,{variant:"secondary",children:o.toLocaleString()}),h&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:h,title:f?"Reset total":"重置总计",children:e.jsx(gr,{className:"h-3 w-3"})})]}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsxs("span",{children:["Credits ",f?"Recent":"最近",": ",e.jsx($e,{variant:"outline",children:j.toFixed(4)})]}),e.jsxs("span",{className:"flex items-center gap-1",children:["Credits ",f?"Total":"总计",": ",e.jsx($e,{variant:"secondary",children:i.toFixed(4)}),u&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-5 w-5",onClick:u,title:f?"Reset total":"重置总计",children:e.jsx(gr,{className:"h-3 w-3"})})]})]})]}),e.jsx(Pe,{className:"p-0",children:e.jsx("div",{className:"max-h-[calc(80vh-120px)] overflow-y-auto",children:r.length===0?e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:f?"No logs yet":"暂无日志"}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-2 font-medium",children:f?"Time":"时间"}),e.jsx("th",{className:"text-left p-2 font-medium",children:f?"Path":"路径"}),e.jsx("th",{className:"text-left p-2 font-medium",children:f?"Model":"模型"}),e.jsx("th",{className:"text-center p-2 font-medium",children:f?"Status":"状态"}),e.jsx("th",{className:"text-center p-2 font-medium",children:f?"In":"输入"}),e.jsx("th",{className:"text-center p-2 font-medium",children:f?"Out":"输出"}),e.jsx("th",{className:"text-center p-2 font-medium",children:"Cache"}),e.jsx("th",{className:"text-right p-2 font-medium",children:"Credits"}),e.jsx("th",{className:"text-right p-2 font-medium",children:f?"Time":"耗时"})]})}),e.jsx("tbody",{className:"font-mono",children:r.map((S,k)=>e.jsxs("tr",{className:"border-b border-muted/30 hover:bg-muted/30",children:[e.jsx("td",{className:"p-2 text-muted-foreground whitespace-nowrap",children:S.time}),e.jsx("td",{className:"p-2 truncate max-w-[200px]",title:S.path,children:S.path}),e.jsx("td",{className:"p-2 truncate max-w-[150px] text-muted-foreground",title:S.model,children:S.model?S.model.replace("anthropic.","").replace("-v1:0",""):"-"}),e.jsx("td",{className:"p-2 text-center relative",children:S.status>=400&&S.error?e.jsxs("div",{className:"relative inline-block",children:[e.jsxs($e,{className:"bg-destructive/20 text-destructive cursor-pointer hover:bg-destructive/30 transition-colors",onClick:()=>y(p===k?null:k),children:[e.jsx(ln,{className:"h-3 w-3 mr-1"}),S.status]}),p===k&&e.jsxs("div",{className:"absolute z-50 top-full left-1/2 -translate-x-1/2 mt-2 w-80 bg-background border border-destructive/30 rounded-lg shadow-xl p-3 text-left",children:[e.jsx("div",{className:"absolute -top-2 left-1/2 -translate-x-1/2 w-3 h-3 bg-background border-l border-t border-destructive/30 rotate-45"}),e.jsxs("div",{className:"text-xs font-sans",children:[e.jsxs("div",{className:"font-medium text-destructive mb-2 flex items-center gap-1",children:[e.jsx(ln,{className:"h-3 w-3"}),f?"Error Details":"错误详情"]}),e.jsx("pre",{className:"whitespace-pre-wrap break-all bg-destructive/10 p-2 rounded text-destructive text-xs max-h-40 overflow-y-auto",children:S.error})]})]})]}):e.jsx($e,{className:S.status>=400?"bg-destructive/20 text-destructive":"bg-success/20 text-success",children:S.status})}),e.jsx("td",{className:"p-2 text-center text-muted-foreground",children:S.inputTokens?S.inputTokens.toLocaleString():"-"}),e.jsx("td",{className:"p-2 text-center text-muted-foreground",children:S.outputTokens?S.outputTokens.toLocaleString():"-"}),e.jsx("td",{className:"p-2 text-center text-success",children:S.cacheReadTokens?S.cacheReadTokens.toLocaleString():"-"}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:S.credits?S.credits.toFixed(6):"-"}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:S.responseTime?`${(S.responseTime/1e3).toFixed(1)}s`:"-"})]},k))})]})})})]})]})}function Ol({value:n,options:s,onChange:r,placeholder:i,className:o}){const[d,u]=g.useState(!1),h=g.useRef(null),f=s.find(p=>p.value===n);return g.useEffect(()=>{const p=y=>{h.current&&!h.current.contains(y.target)&&u(!1)};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[]),e.jsxs("div",{ref:h,className:`relative ${o||""}`,children:[e.jsxs("button",{type:"button",onClick:()=>u(!d),className:"relative h-8 px-2 pr-7 rounded-lg border border-border bg-background/50 text-xs cursor-pointer hover:border-primary/50 focus:border-primary focus:outline-none transition-all flex items-center gap-1.5",children:[f?.icon,e.jsx("span",{className:"flex-1 text-left truncate",children:f?.label||i}),e.jsx(va,{className:`w-3.5 h-3.5 absolute right-1.5 top-1/2 -translate-y-1/2 text-muted-foreground transition-transform ${d?"rotate-180":""}`})]}),d&&e.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-full py-1 rounded-lg border border-border bg-popover shadow-lg z-50 animate-in fade-in-0 zoom-in-95",children:s.map(p=>e.jsxs("button",{type:"button",onClick:()=>{r(p.value),u(!1)},className:`w-full px-2.5 py-1.5 text-xs text-left flex items-center gap-1.5 hover:bg-accent transition-colors ${p.value===n?"bg-accent text-accent-foreground":""}`,children:[p.icon,e.jsx("span",{children:p.label}),p.value===n&&e.jsx("svg",{className:"w-4 h-4 ml-auto text-primary",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})]},p.value))})]})}function BI({open:n,onOpenChange:s}){const{t:r}=Ut(),i=r("common.unknown")==="Unknown",[o,d]=g.useState([]),[u,h]=g.useState(!1),[f,p]=g.useState(""),[y,b]=g.useState("all"),[v,N]=g.useState("all"),[j,T]=g.useState(!0),[S,k]=g.useState(0),[R,I]=g.useState(new Set),M=g.useRef(0),[G,W]=g.useState(()=>localStorage.getItem("proxyLogs_timeRange")||"all"),[U,q]=g.useState(()=>localStorage.getItem("proxyLogs_displayLimit")||"all"),V=g.useRef(null),le=g.useRef(null),B=g.useCallback(async()=>{try{const xe=await window.api.proxyGetLogs();d(xe)}catch(xe){console.error("Failed to load logs:",xe)}},[]);g.useEffect(()=>(n&&(h(!0),B().finally(()=>h(!1)),le.current=setInterval(()=>{B().then(()=>{!j&&o.length>M.current&&k(xe=>xe+(o.length-M.current)),M.current=o.length})},1500)),()=>{le.current&&(clearInterval(le.current),le.current=null)}),[n,B,j,o.length]);const be=g.useCallback(()=>{const xe=V.current;if(!xe)return;const Oe=xe.scrollHeight-xe.scrollTop-xe.clientHeight<40;T(Oe),Oe&&k(0)},[]),K=()=>{V.current&&(V.current.scrollTop=V.current.scrollHeight,T(!0),k(0))};g.useEffect(()=>{localStorage.setItem("proxyLogs_timeRange",G)},[G]),g.useEffect(()=>{localStorage.setItem("proxyLogs_displayLimit",U)},[U]);const se=async()=>{try{await window.api.proxyClearLogs(),d([])}catch(xe){console.error("Failed to clear logs:",xe)}},te=()=>{const xe=o.map(_e=>{const st=_e.data?` | ${JSON.stringify(_e.data)}`:"";return`[${_e.timestamp}] [${_e.level}] [${_e.category}] ${_e.message}${st}`}).join(`
123
123
  `),Oe=new Blob([xe],{type:"text/plain"}),Ee=URL.createObjectURL(Oe),Qe=document.createElement("a");Qe.href=Ee,Qe.download=`proxy-logs-${new Date().toISOString().replace(/[:.]/g,"-")}.log`,Qe.click(),URL.revokeObjectURL(Ee)},Y=xe=>{const Oe=xe.data?`
124
124
  Data: ${JSON.stringify(xe.data,null,2)}`:"",Ee=`[${xe.timestamp}] [${xe.level}] [${xe.category}]
125
- ${xe.message}${Oe}`;navigator.clipboard.writeText(Ee)},P=xe=>{const Oe=new Set(R);Oe.has(xe)?Oe.delete(xe):Oe.add(xe),I(Oe)},F=g.useMemo(()=>Array.from(new Set(o.map(xe=>xe.category))).sort(),[o]),fe=xe=>{switch(xe){case"1h":return 36e5;case"6h":return 6*36e5;case"12h":return 12*36e5;case"1d":return 864e5;case"3d":return 3*864e5;case"7d":return 7*864e5;case"30d":return 30*864e5;case"180d":return 180*864e5;case"1y":return 365*864e5;default:return 0}},pe=g.useMemo(()=>{const xe=Date.now(),Oe=fe(G),Ee=f.toLowerCase();let Qe=o.filter(_e=>{if(Oe>0){const st=new Date(_e.timestamp).getTime();if(xe-st>Oe)return!1}if(y!=="all"&&_e.level!==y||v!=="all"&&_e.category!==v)return!1;if(Ee){if(_e.message.toLowerCase().includes(Ee)||_e.category.toLowerCase().includes(Ee))return!0;if(_e.data)try{return JSON.stringify(_e.data).toLowerCase().includes(Ee)}catch{return!1}return!1}return!0});if(U!=="all"){const _e=parseInt(U);_e>0&&(Qe=Qe.slice(-_e))}return Qe},[o,G,y,v,f,U]),C=lo({count:pe.length,getScrollElement:()=>V.current,estimateSize:xe=>R.has(xe)?120:32,overscan:20});g.useEffect(()=>{j&&pe.length>0&&C.scrollToIndex(pe.length-1,{align:"end"})},[pe.length,j,C]);const z=xe=>{switch(xe){case"ERROR":return"bg-destructive/20 text-destructive border-destructive/30";case"WARN":return"bg-warning/20 text-warning border-warning/30";case"INFO":return"bg-primary/20 text-primary border-primary/30";case"DEBUG":return"bg-muted text-muted-foreground border-muted";default:return"bg-muted text-muted-foreground border-muted"}},X=xe=>{switch(xe){case"ERROR":return"bg-destructive/5 hover:bg-destructive/10";case"WARN":return"bg-warning/5 hover:bg-warning/10";case"INFO":return"hover:bg-primary/5";case"DEBUG":return"hover:bg-muted/50";default:return"hover:bg-muted/50"}},re=xe=>{try{if(!xe)return"-";const Oe=new Date(xe);if(isNaN(Oe.getTime()))return xe||"-";const Ee=Oe.getFullYear(),Qe=(Oe.getMonth()+1).toString().padStart(2,"0"),_e=Oe.getDate().toString().padStart(2,"0"),st=Oe.getHours().toString().padStart(2,"0"),oe=Oe.getMinutes().toString().padStart(2,"0"),ue=Oe.getSeconds().toString().padStart(2,"0"),ae=Oe.getMilliseconds().toString().padStart(3,"0");return`${Ee}-${Qe}-${_e} ${st}:${oe}:${ue}.${ae}`}catch{return xe||"-"}};return n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>s(!1),children:e.jsxs("div",{className:"glass-card-strong rounded-2xl shadow-2xl max-w-[90vw] w-[1200px] h-[80vh] flex flex-col overflow-hidden animate-in zoom-in-95 duration-200",onClick:xe=>xe.stopPropagation(),children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-5 py-4 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),e.jsx("h2",{className:"text-lg font-semibold",children:i?"Proxy Detailed Logs":"反代详细日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ol,{value:G,onChange:W,className:"min-w-[70px]",options:[{value:"all",label:i?"All Time":"全部时间"},{value:"1h",label:i?"1 Hour":"1小时"},{value:"6h",label:i?"6 Hours":"6小时"},{value:"12h",label:i?"12 Hours":"12小时"},{value:"1d",label:i?"1 Day":"1天"},{value:"3d",label:i?"3 Days":"3天"},{value:"7d",label:i?"7 Days":"7天"},{value:"30d",label:i?"30 Days":"30天"},{value:"180d",label:i?"180 Days":"180天"},{value:"1y",label:i?"1 Year":"1年"}]}),e.jsx(Ol,{value:U,onChange:q,className:"min-w-[70px]",options:[{value:"all",label:i?"All":"全部"},{value:"5000",label:"5000"},{value:"10000",label:i?"10K":"1万"},{value:"50000",label:i?"50K":"5万"},{value:"100000",label:i?"100K":"10万"},{value:"200000",label:i?"200K":"20万"},{value:"500000",label:i?"500K":"50万"},{value:"1000000",label:i?"1M":"100万"}]}),e.jsxs($e,{variant:"secondary",className:"font-mono",children:[pe.length," / ",o.length," ",i?"entries":"条"]}),e.jsx(D,{variant:"ghost",size:"icon",className:"rounded-full hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2.5 border-b border-border",children:[e.jsxs("div",{className:"relative flex-1 min-w-[100px]",children:[e.jsx(to,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),e.jsx(it,{placeholder:i?"Search logs...":"搜索日志内容...",value:f,onChange:xe=>p(xe.target.value),className:"pl-8 pr-8 h-8 text-xs bg-background/50 border-border focus:border-primary"}),f&&e.jsx(D,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 w-7 h-7 rounded-full",onClick:()=>p(""),children:e.jsx(ns,{className:"w-3.5 h-3.5"})})]}),e.jsx(Ol,{value:y,onChange:b,options:[{value:"all",label:i?"All":"全部",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-gradient-to-r from-destructive via-warning to-primary"})},{value:"ERROR",label:"ERR",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-destructive"})},{value:"WARN",label:"WARN",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-warning"})},{value:"INFO",label:"INFO",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-primary"})},{value:"DEBUG",label:"DBG",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-gray-400"})}]}),e.jsx(Ol,{value:v,onChange:N,className:"min-w-[100px]",options:[{value:"all",label:i?"All":"全部",icon:e.jsx("svg",{className:"w-3 h-3 text-primary",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})},...F.map(xe=>({value:xe,label:xe,icon:e.jsx("svg",{className:"w-3 h-3 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z"})})}))]}),e.jsx("div",{className:"h-5 w-px bg-border flex-shrink-0"}),e.jsx(Ol,{value:U,onChange:q,className:"min-w-[60px]",options:[{value:"all",label:i?"All":"全部"},{value:"5000",label:"5K"},{value:"10000",label:"10K"},{value:"50000",label:"50K"},{value:"100000",label:"100K"}]}),e.jsx(Ol,{value:G,onChange:W,className:"min-w-[60px]",options:[{value:"all",label:i?"All":"全部"},{value:"1h",label:"1h"},{value:"6h",label:"6h"},{value:"1d",label:"1d"},{value:"7d",label:"7d"}]}),e.jsx("div",{className:"h-5 w-px bg-border flex-shrink-0"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:B,disabled:u,children:e.jsx(Mt,{className:`w-3.5 h-3.5 ${u?"animate-spin":""}`})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:te,disabled:o.length===0,children:e.jsx(Ns,{className:"w-3.5 h-3.5"})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-destructive",onClick:se,disabled:o.length===0,children:e.jsx(Vt,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[e.jsx("div",{ref:V,className:"h-full overflow-y-auto font-mono text-xs",onScroll:be,children:pe.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground gap-2",children:[e.jsx(px,{className:"h-8 w-8 opacity-20"}),e.jsx("span",{className:"text-sm",children:o.length===0?i?"No logs yet":"暂无日志记录":i?"No matching logs":"没有匹配的日志"})]}):e.jsx("div",{style:{height:C.getTotalSize(),width:"100%",position:"relative"},children:C.getVirtualItems().map(xe=>{const Oe=xe.index,Ee=pe[Oe],Qe=R.has(Oe),_e=Ee.data!==void 0&&Ee.data!==null;return e.jsxs("div",{"data-index":Oe,ref:C.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${xe.start}px)`},className:`group rounded-lg px-3 py-1.5 transition-colors ${X(Ee.level)}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground whitespace-nowrap flex-shrink-0 tabular-nums text-[10px]",children:re(Ee.timestamp)}),e.jsx($e,{variant:"outline",className:`text-[9px] px-1 py-0 flex-shrink-0 font-semibold ${z(Ee.level)}`,children:Ee.level}),e.jsx("span",{className:"text-primary/80 flex-shrink-0 font-medium text-[10px]",children:Ee.category}),e.jsx("span",{className:"flex-1 break-all text-foreground/90 text-[11px]",children:Ee.message}),e.jsxs("div",{className:"flex-shrink-0 opacity-0 group-hover:opacity-100 flex items-center gap-0.5 transition-opacity",children:[_e&&e.jsx(D,{variant:"ghost",size:"icon",className:"w-5 h-5 rounded-full",onClick:()=>P(Oe),children:Qe?e.jsx(zi,{className:"w-3 h-3"}):e.jsx(va,{className:"w-3 h-3"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"w-5 h-5 rounded-full",onClick:()=>Y(Ee),children:e.jsx(As,{className:"w-3 h-3"})})]})]}),Qe&&_e&&e.jsx("pre",{className:"mt-1.5 ml-20 p-2 rounded-md bg-muted/50 border border-border text-primary overflow-x-auto text-[10px] leading-4",children:JSON.stringify(Ee.data,null,2)})]},xe.key)})})}),!j&&e.jsxs("button",{className:"absolute bottom-3 right-3 flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-primary text-primary-foreground text-xs font-medium shadow-lg hover:bg-primary/90 transition-all",onClick:K,children:[e.jsx(VN,{className:"h-3.5 w-3.5"}),S>0?e.jsx(e.Fragment,{children:i?`${S} new`:`${S} 条新`}):e.jsx(e.Fragment,{children:i?"Bottom":"底部"})]})]}),e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-4 py-1.5 border-t border-border text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:[i?"Showing":"显示"," ",pe.length.toLocaleString()," / ",o.length.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(UN,{className:`h-3 w-3 ${j?"text-success":"text-muted-foreground/40"}`}),e.jsx("span",{children:j?i?"Following":"跟随中":i?"Scrolled up":"已暂停跟随"})]})]})]})}):null}function _I({open:n,onOpenChange:s,isEn:r,onOpenModelMapping:i,mappingCount:o=0}){const[d,u]=g.useState([]),[h,f]=g.useState(!1),[p,y]=g.useState(!1),[b,v]=g.useState(null),[N,j]=g.useState(()=>localStorage.getItem("models_dialog_ip_tip_dismissed")!=="1"),T=()=>{localStorage.setItem("models_dialog_ip_tip_dismissed","1"),j(!1)},S=async()=>{f(!0),v(null);try{const R=await window.api.proxyGetModels();R.success?(u(R.models),y(R.fromCache||!1)):v(R.error||"Failed to fetch models")}catch(R){v(R instanceof Error?R.message:"Unknown error")}finally{f(!1)}};if(g.useEffect(()=>{n&&S()},[n]),!n)return null;const k=R=>R==null?"-":R>=1e6?`${(R/1e6).toFixed(1)}M`:R>=1e3?`${(R/1e3).toFixed(0)}K`:R.toString();return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[850px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsx(at,{className:"pb-4 border-b sticky top-0 z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-xl flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(ai,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold",children:r?"Available Models":"可用模型"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs($e,{className:"bg-primary/10 text-primary border-primary/20 font-semibold",children:[d.length," ",r?"models":"个模型"]}),p&&e.jsxs($e,{variant:"secondary",className:"text-xs bg-warning/10 text-warning border-0",children:[e.jsx(Hi,{className:"h-3 w-3 mr-1"}),r?"Cached":"缓存"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsxs(D,{variant:"outline",size:"sm",onClick:i,className:"rounded-lg",children:[e.jsx(Kn,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-1.5",children:r?"Mapping":"映射"}),o>0&&e.jsx($e,{className:"ml-1.5 h-5 px-1.5 bg-primary/20 text-primary text-xs",children:o})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:S,disabled:h,className:"rounded-lg",children:[h?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Mt,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-1.5",children:r?"Refresh":"刷新"})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-5 w-5"})})]})]})}),e.jsxs(Pe,{className:"p-4",children:[N&&e.jsx("div",{className:"mb-3 rounded-xl border border-warning/30 bg-gradient-to-r from-warning/10 to-warning/5 p-3.5 relative",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"shrink-0 p-1.5 rounded-lg bg-warning/20",children:e.jsx(Rs,{className:"h-4 w-4 text-warning"})}),e.jsxs("div",{className:"flex-1 min-w-0 pr-6",children:[e.jsxs("p",{className:"text-sm font-semibold text-warning mb-1.5 flex items-center gap-1.5",children:[e.jsx(ri,{className:"h-3.5 w-3.5"}),r?"Pro/Pro Max subscription but missing advanced models?":"订阅 Pro/Pro Max 但看不到高级模型?"]}),e.jsx("p",{className:"text-xs text-warning/90 leading-relaxed mb-1",children:r?"This is likely caused by regional restrictions on China-mainland IPs. Try the following:":"这通常是国内 IP 被限制导致的。请尝试以下方案:"}),e.jsxs("ul",{className:"text-xs text-warning/90 space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:r?"Enable VPN/proxy (system-level or app-level)":"开启 VPN / 代理(系统级或应用级均可)"}),e.jsx("li",{children:r?"Switch to high-quality outbound IP (US/EU residential preferred)":"切换到优质外网 IP(推荐美国 / 欧洲住宅 IP)"}),e.jsx("li",{children:r?"Click Refresh after IP change to reload models":"IP 切换后点击右上角「刷新」重新加载模型"})]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-7 w-7 hover:bg-warning/20 text-warning",onClick:T,title:r?"Don't show again":"不再显示",children:e.jsx(ns,{className:"h-4 w-4"})})]})}),e.jsx("div",{className:"max-h-[calc(85vh-140px)] overflow-y-auto pr-2",children:h&&d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-primary/10 mb-4",children:e.jsx(bt,{className:"h-8 w-8 animate-spin text-primary"})}),e.jsx("p",{className:"font-medium",children:r?"Loading models...":"加载模型中..."})]}):b?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-destructive/10 mb-4",children:e.jsx(ns,{className:"h-8 w-8 text-destructive"})}),e.jsx("p",{className:"text-destructive font-medium",children:b}),e.jsx("p",{className:"text-sm mt-2",children:r?"Make sure proxy is running and has synced accounts":"请确保代理服务已启动且已同步账号"})]}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-muted mb-4",children:e.jsx(ai,{className:"h-8 w-8"})}),e.jsx("p",{className:"font-medium",children:r?"No models available":"暂无可用模型"})]}):e.jsx("div",{className:"grid grid-cols-2 gap-3",children:d.map((R,I)=>e.jsxs("div",{className:me("group p-3 rounded-xl border hover:shadow-md hover:border-primary/30 transition-all duration-200",I===0?"border-primary/40 bg-primary/10":"bg-background"),children:[e.jsxs("div",{className:"flex items-start gap-2 mb-2",children:[e.jsx("div",{className:me("w-2 h-2 rounded-full mt-1.5 shrink-0",I===0?"bg-primary":"bg-muted-foreground/30")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("code",{className:"text-sm font-bold text-foreground",children:R.id}),R.name&&R.name!==R.id&&e.jsx("p",{className:"text-[11px] text-primary/70 font-medium truncate",children:R.name})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground line-clamp-2 mb-2 pl-4",children:R.description||(r?"No description":"无描述")}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[R.inputTypes?.includes("TEXT")&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-blue-500/10 text-blue-600 dark:text-blue-400 border-0",children:e.jsx(xr,{className:"h-3 w-3"})}),R.inputTypes?.includes("IMAGE")&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-purple-500/10 text-purple-600 dark:text-purple-400 border-0",children:e.jsx(FN,{className:"h-3 w-3"})})]}),R.supportsThinking&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-0",title:R.thinkingEfforts?.join(", "),children:e.jsx(g3,{className:"h-3 w-3"})}),R.supportsPromptCaching&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-cyan-500/10 text-cyan-600 dark:text-cyan-400 border-0",children:e.jsx(Sp,{className:"h-3 w-3"})}),R.rateMultiplier!==void 0&&e.jsxs($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-amber-500/10 text-amber-600 dark:text-amber-400 border-0",children:[e.jsx(Ds,{className:"h-3 w-3 mr-0.5"}),R.rateMultiplier,"x ",R.rateUnit||"credit"]})]}),e.jsxs("div",{className:"flex items-center gap-1 text-[11px] font-mono text-muted-foreground",children:[e.jsx(HN,{className:"h-3 w-3"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:k(R.maxInputTokens)}),e.jsx("span",{children:"/"}),e.jsx("span",{className:"text-orange-600 dark:text-orange-400",children:k(R.maxOutputTokens)})]})]})]},R.id))})})]})]})]})}function VI({open:n,onOpenChange:s,isEn:r,mappings:i,onMappingsChange:o,apiKeys:d,availableModels:u}){const[h,f]=g.useState(i),[p,y]=g.useState(null),[b,v]=g.useState(!1);g.useEffect(()=>{n&&f(i)},[n]);const N=()=>`mapping_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,j=()=>{const B={id:N(),name:r?"New Rule":"新规则",enabled:!0,type:"replace",sourceModel:"",targetModels:[""],priority:h.length,apiKeyIds:[]};f([...h,B]),y(B.id)},T=(B,be)=>{f(h.map(K=>K.id===B?{...K,...be}:K))},S=B=>{f(h.filter(be=>be.id!==B)),p===B&&y(null)},k=(B,be)=>{const K=h.findIndex(Y=>Y.id===B);if(be==="up"&&K===0||be==="down"&&K===h.length-1)return;const se=[...h],te=be==="up"?K-1:K+1;[se[K],se[te]]=[se[te],se[K]],se.forEach((Y,P)=>Y.priority=P),f(se)},R=B=>{const be=h.find(K=>K.id===B);be&&T(B,{targetModels:[...be.targetModels,""],weights:be.weights?[...be.weights,1]:void 0})},I=(B,be,K)=>{const se=h.find(te=>te.id===B);if(se){const te=[...se.targetModels];te[be]=K,T(B,{targetModels:te})}},M=(B,be)=>{const K=h.find(se=>se.id===B);if(K&&K.targetModels.length>1){const se=K.targetModels.filter((Y,P)=>P!==be),te=K.weights?K.weights.filter((Y,P)=>P!==be):void 0;T(B,{targetModels:se,weights:te})}},G=(B,be,K)=>{const se=h.find(te=>te.id===B);if(se){const te=se.weights?[...se.weights]:se.targetModels.map(()=>1);te[be]=K,T(B,{weights:te})}},W=(B,be)=>{const K=h.find(se=>se.id===B);if(K){const se=K.apiKeyIds||[],te=se.includes(be)?se.filter(Y=>Y!==be):[...se,be];T(B,{apiKeyIds:te})}},U=async()=>{v(!0);try{o(h),s(!1)}finally{v(!1)}},q=B=>{switch(B){case"replace":return e.jsx(wp,{className:"h-4 w-4"});case"alias":return e.jsx(Xl,{className:"h-4 w-4"});case"loadbalance":return e.jsx(Kn,{className:"h-4 w-4"});default:return e.jsx(Ka,{className:"h-4 w-4"})}},V=B=>{switch(B){case"replace":return r?"Replace":"替换";case"alias":return r?"Alias":"别名";case"loadbalance":return r?"Load Balance":"负载均衡";default:return B}},le=B=>{switch(B){case"replace":return"bg-blue-500/10 text-blue-600 dark:text-blue-400";case"alias":return"bg-purple-500/10 text-purple-600 dark:text-purple-400";case"loadbalance":return"bg-green-500/10 text-green-600 dark:text-green-400";default:return"bg-muted"}};return n?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[900px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsx(at,{className:"pb-4 border-b sticky top-0 z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-xl flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(Kn,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold",children:r?"Model Mapping":"模型映射"}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs($e,{className:"bg-primary/10 text-primary border-primary/20 font-semibold",children:[h.length," ",r?"rules":"条规则"]})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:j,className:"rounded-lg",children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),r?"Add Rule":"添加规则"]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-5 w-5"})})]})]})}),e.jsxs(Pe,{className:"p-4",children:[e.jsx("div",{className:"max-h-[calc(85vh-180px)] overflow-y-auto pr-2 space-y-3",children:h.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-muted mb-4",children:e.jsx(Kn,{className:"h-8 w-8"})}),e.jsx("p",{className:"font-medium",children:r?"No mapping rules":"暂无映射规则"}),e.jsx("p",{className:"text-sm mt-1",children:r?'Click "Add Rule" to create one':'点击"添加规则"创建新规则'})]}):h.map((B,be)=>e.jsxs("div",{className:me("border rounded-xl overflow-hidden transition-all",B.enabled?"bg-background":"bg-muted/30 opacity-60",p===B.id?"ring-2 ring-primary/30":""),children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 cursor-pointer hover:bg-muted/30",onClick:()=>y(p===B.id?null:B.id),children:[e.jsx(hA,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("div",{onClick:K=>K.stopPropagation(),children:e.jsx(is,{checked:B.enabled,onCheckedChange:K=>{T(B.id,{enabled:K})}})}),e.jsxs($e,{className:me("px-2 py-0.5",le(B.type)),children:[q(B.type),e.jsx("span",{className:"ml-1",children:V(B.type)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium truncate",children:B.name}),e.jsx("span",{className:"text-muted-foreground mx-2",children:":"}),e.jsx("code",{className:"text-sm bg-muted px-1.5 py-0.5 rounded",children:B.sourceModel||"..."}),e.jsx(wp,{className:"inline h-4 w-4 mx-2 text-muted-foreground"}),e.jsx("code",{className:"text-sm bg-muted px-1.5 py-0.5 rounded",children:B.targetModels.filter(K=>K).join(", ")||"..."})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:K=>{K.stopPropagation(),k(B.id,"up")},disabled:be===0,children:e.jsx(zi,{className:"h-4 w-4"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:K=>{K.stopPropagation(),k(B.id,"down")},disabled:be===h.length-1,children:e.jsx(va,{className:"h-4 w-4"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7 hover:bg-destructive/10 hover:text-destructive",onClick:K=>{K.stopPropagation(),S(B.id)},children:e.jsx(Vt,{className:"h-4 w-4"})})]})]}),p===B.id&&e.jsxs("div",{className:"border-t p-4 space-y-4 bg-muted/10",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:r?"Rule Name":"规则名称"}),e.jsx(it,{value:B.name,onChange:K=>T(B.id,{name:K.target.value}),placeholder:r?"Enter rule name":"输入规则名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:r?"Mapping Type":"映射类型"}),e.jsxs("select",{className:"w-full h-10 px-3 py-2 text-sm rounded-xl border border-input bg-background ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2",value:B.type,onChange:K=>T(B.id,{type:K.target.value}),children:[e.jsx("option",{value:"replace",children:r?"Replace - Direct model replacement":"替换 - 直接替换模型"}),e.jsx("option",{value:"alias",children:r?"Alias - Create model alias":"别名 - 创建模型别名"}),e.jsx("option",{value:"loadbalance",children:r?"Load Balance - Random selection":"负载均衡 - 随机选择"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:r?"Source Model":"源模型"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:r?"The model name in user request (e.g., gpt-4, claude-*, my-alias). Supports * wildcard.":"用户请求时使用的模型名(如 gpt-4, claude-*, my-alias)。支持 * 通配符。"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(it,{value:B.sourceModel,onChange:K=>T(B.id,{sourceModel:K.target.value}),placeholder:r?"e.g., claude-*, gpt-4, my-alias":"例如: claude-*, gpt-4, my-alias",className:"flex-1"}),u.length>0&&e.jsxs("select",{className:"h-10 px-3 text-sm rounded-xl border border-input bg-background",value:"",onChange:K=>{K.target.value&&T(B.id,{sourceModel:K.target.value})},children:[e.jsx("option",{value:"",children:r?"Select model":"选择模型"}),u.map(K=>e.jsx("option",{value:K.id,children:K.id},K.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:r?"Target Models":"目标模型"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:r?"The actual Kiro model to call. Select from the dropdown for official models.":"实际调用的 Kiro 模型。从下拉框选择官方模型。"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>R(B.id),className:"h-7 text-xs",children:[e.jsx(Ts,{className:"h-3 w-3 mr-1"}),r?"Add":"添加"]})]}),e.jsx("div",{className:"space-y-2",children:B.targetModels.map((K,se)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{value:K,onChange:te=>I(B.id,se,te.target.value),placeholder:r?"Target model name":"目标模型名",className:"flex-1"}),u.length>0&&e.jsxs("select",{className:"h-10 px-3 text-sm rounded-xl border border-input bg-background",value:"",onChange:te=>{te.target.value&&I(B.id,se,te.target.value)},children:[e.jsx("option",{value:"",children:r?"Select":"选择"}),u.map(te=>e.jsx("option",{value:te.id,children:te.id},te.id))]}),B.type==="loadbalance"&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Fe,{className:"text-xs whitespace-nowrap",children:r?"Weight":"权重"}),e.jsx(it,{type:"number",min:1,value:B.weights?.[se]??1,onChange:te=>G(B.id,se,parseInt(te.target.value)||1),className:"w-16"})]}),B.targetModels.length>1&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10 hover:text-destructive",onClick:()=>M(B.id,se),children:e.jsx(Vt,{className:"h-4 w-4"})})]},se))})]}),d.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:r?"Apply to API Keys (empty = all keys)":"适用 API Key(空 = 所有 Key)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(K=>e.jsx($e,{variant:B.apiKeyIds?.includes(K.id)?"default":"outline",className:"cursor-pointer hover:bg-primary/20",onClick:()=>W(B.id,K.id),children:K.name},K.id))})]})]})]},B.id))}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4 border-t mt-4",children:[e.jsx(D,{variant:"outline",onClick:()=>s(!1),children:r?"Cancel":"取消"}),e.jsxs(D,{onClick:U,disabled:b,children:[b&&e.jsx(bt,{className:"h-4 w-4 mr-2 animate-spin"}),r?"Save":"保存"]})]})]})]})]}):null}function KI({open:n,onOpenChange:s,accounts:r,selectedAccountId:i,onSelect:o,isEn:d}){const[u,h]=g.useState(""),f=g.useMemo(()=>Array.from(r.values()),[r]),p=g.useMemo(()=>{if(!u.trim())return f;const S=u.toLowerCase();return f.filter(k=>k.email?.toLowerCase().includes(S)||k.id.toLowerCase().includes(S)||k.subscription?.title?.toLowerCase().includes(S))},[f,u]),y=S=>{o(S),s(!1)},b=S=>{const k=S.usage;return k?k.limit>0?Math.min(100,k.current/k.limit*100):Math.min(100,Math.max(0,(k.percentUsed||0)*100)):0},v=S=>{const k=S.usage;return k?`${k.current.toFixed(1)} / ${k.limit}`:"-"},N=S=>{if(!S)return"bg-gray-500 text-white";const k=S.toUpperCase();return k.includes("PRO+")||k.includes("PRO_PLUS")||k.includes("PROPLUS")?"bg-purple-500 text-white":k.includes("POWER")?"bg-amber-500 text-white":k.includes("PRO")?"bg-blue-500 text-white":"bg-gray-500 text-white"},j=S=>{const k=S.lastError?.toLowerCase();return k?k.includes("accountsuspendedexception")||k.includes("account suspended")||k.includes("temporarily_suspended")||k.includes("temporarily suspended")||k.includes("user id is")&&k.includes("suspended")||k.includes("账户已封禁")||k.includes("已封禁")||/\b423\b/.test(k)?!0:(k.includes("fetch failed")||k.includes("network")||k.includes("token expired")||k.includes("token 过期")||k.includes("刷新失败")||k.includes("unauthorizedexception"),!1):!1},T=S=>{if(j(S))return{icon:e.jsx(jc,{className:"h-3.5 w-3.5"}),text:d?"Banned":"已封禁",color:"bg-destructive/10 text-destructive"};switch(S.status){case"error":return{icon:e.jsx(ln,{className:"h-3.5 w-3.5"}),text:d?"Error":"错误",color:"bg-destructive/10 text-destructive"};case"expired":return{icon:e.jsx(jc,{className:"h-3.5 w-3.5"}),text:d?"Expired":"已过期",color:"bg-warning/10 text-warning"};case"refreshing":return{icon:e.jsx(Ds,{className:"h-3.5 w-3.5"}),text:d?"Refreshing":"刷新中",color:"bg-warning/10 text-warning"};case"active":return null;default:return null}};return n?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[600px] max-h-[80vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsxs(at,{className:"pb-3 border-b sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(rt,{className:"text-lg",children:d?"Select Account":"选择账号"}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx(to,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(it,{placeholder:d?"Search by email, ID or subscription...":"搜索邮箱、ID 或订阅类型...",value:u,onChange:S=>h(S.target.value),className:"pl-9"})]})]}),e.jsxs(Pe,{className:"p-0 overflow-y-auto max-h-[60vh]",children:[e.jsx("div",{className:`p-4 border-b cursor-pointer transition-colors hover:bg-accent/50 ${i?"":"bg-primary/5 border-l-2 border-l-primary"}`,onClick:()=>y(void 0),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Ds,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:d?"First Available":"第一个可用账号"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:d?"Automatically use the first available account":"自动使用第一个可用的账号"})]})]}),!i&&e.jsx(Pt,{className:"h-5 w-5 text-primary"})]})}),p.length===0?e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:u?d?"No accounts found":"未找到匹配的账号":d?"No accounts available":"暂无可用账号"}):p.map(S=>{const k=i===S.id,R=b(S),I=v(S),M=T(S),G=j(S),W=S.status==="error"||S.status==="expired"||G;return e.jsx("div",{className:`p-4 border-b cursor-pointer transition-colors hover:bg-accent/50 ${k?"bg-primary/5 border-l-2 border-l-primary":""} ${W?"opacity-60":""}`,onClick:()=>y(S.id),children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 ${W?"bg-destructive/10":"bg-primary/10"}`,children:W?e.jsx(ln,{className:"h-5 w-5 text-destructive"}):e.jsx(Ep,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(gx,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"font-medium truncate",children:S.email||S.id.substring(0,12)+"..."}),M&&e.jsxs($e,{className:`text-xs ${M.color}`,children:[M.icon,e.jsx("span",{className:"ml-1",children:M.text})]})]}),S.lastError&&e.jsx("div",{className:"text-xs text-destructive mt-1 truncate",children:S.lastError}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsxs($e,{className:`text-xs ${N(S.subscription?.title)}`,children:[e.jsx($a,{className:"h-3 w-3 mr-1"}),S.subscription?.title||"Unknown"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[d?"Usage":"使用量",": ",I]})]}),e.jsx("div",{className:"mt-2 w-full bg-muted rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:`h-full transition-all ${R>80?"bg-destructive":R>50?"bg-warning":"bg-success"}`,style:{width:`${R}%`}})}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1.5 font-mono",children:["ID: ",S.id.substring(0,20),"..."]})]})]}),k&&e.jsx(Pt,{className:"h-5 w-5 text-primary flex-shrink-0 mt-2"})]})},S.id)})]})]})]}):null}function HI({open:n,onOpenChange:s,apiKey:r}){const{t:i}=Ut(),o=i("common.unknown")==="Unknown",[d,u]=g.useState("history"),h=N=>new Date(N).toLocaleString(),f=N=>N.replace("anthropic.","").replace("-v1:0",""),p=g.useMemo(()=>r?.usage.daily?Object.entries(r.usage.daily).sort((j,T)=>T[0].localeCompare(j[0])).slice(0,7).reverse().map(([j,T])=>({date:j.slice(5),...T})):[],[r?.usage.daily]),y=g.useMemo(()=>r?.usage.byModel?Object.entries(r.usage.byModel).map(([N,j])=>({model:f(N),...j})).sort((N,j)=>j.requests-N.requests):[],[r?.usage.byModel]),b=g.useMemo(()=>Math.max(...p.map(N=>N.credits),.001),[p]),v=g.useMemo(()=>Math.max(...y.map(N=>N.requests),1),[y]);return!n||!r?null:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[900px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsxs(at,{className:"pb-3 border-b sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-lg flex items-center gap-2",children:[e.jsx(Lu,{className:"h-5 w-5 text-primary"}),o?"Usage Details":"用量详情"," - ",r.name]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-4 mt-4",children:[e.jsxs("div",{className:"bg-primary/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Total Requests":"总请求数"}),e.jsx("div",{className:"text-xl font-bold text-primary",children:r.usage.totalRequests.toLocaleString()})]}),e.jsxs("div",{className:"bg-success/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Total Credits":"总 Credits"}),e.jsx("div",{className:"text-xl font-bold text-success",children:r.usage.totalCredits.toFixed(4)})]}),e.jsxs("div",{className:"bg-primary/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Input Tokens":"输入 Tokens"}),e.jsx("div",{className:"text-xl font-bold text-primary",children:r.usage.totalInputTokens.toLocaleString()})]}),e.jsxs("div",{className:"bg-[var(--gradient-to)]/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Output Tokens":"输出 Tokens"}),e.jsx("div",{className:"text-xl font-bold text-[var(--gradient-to)]",children:r.usage.totalOutputTokens.toLocaleString()})]})]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsxs(D,{variant:d==="history"?"default":"outline",size:"sm",onClick:()=>u("history"),children:[e.jsx(Gn,{className:"h-4 w-4 mr-1"}),o?"History":"历史记录"]}),e.jsxs(D,{variant:d==="model"?"default":"outline",size:"sm",onClick:()=>u("model"),children:[e.jsx(ai,{className:"h-4 w-4 mr-1"}),o?"By Model":"按模型"]}),e.jsxs(D,{variant:d==="daily"?"default":"outline",size:"sm",onClick:()=>u("daily"),children:[e.jsx(QN,{className:"h-4 w-4 mr-1"}),o?"Daily Stats":"每日统计"]})]})]}),e.jsxs(Pe,{className:"p-4 max-h-[calc(85vh-280px)] overflow-y-auto",children:[d==="history"&&e.jsx("div",{children:r.usageHistory&&r.usageHistory.length>0?e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Time":"时间"}),e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Model":"模型"}),e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Path":"路径"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"In":"输入"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Out":"输出"}),e.jsx("th",{className:"text-right p-2 font-medium",children:"Credits"})]})}),e.jsx("tbody",{className:"font-mono",children:r.usageHistory.map((N,j)=>e.jsxs("tr",{className:"border-b border-muted/30 hover:bg-muted/30",children:[e.jsx("td",{className:"p-2 text-muted-foreground whitespace-nowrap text-xs",children:h(N.timestamp)}),e.jsx("td",{className:"p-2 truncate max-w-[150px]",title:N.model,children:f(N.model)}),e.jsx("td",{className:"p-2 truncate max-w-[120px] text-muted-foreground",title:N.path,children:N.path}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:N.inputTokens.toLocaleString()}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:N.outputTokens.toLocaleString()}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:N.credits.toFixed(6)})]},j))})]}):e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:o?"No usage history yet":"暂无用量记录"})}),d==="model"&&e.jsx("div",{className:"space-y-4",children:y.length>0?y.map((N,j)=>e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[e.jsx(ai,{className:"h-4 w-4 text-primary"}),N.model]}),e.jsxs($e,{variant:"secondary",children:[N.requests," ",o?"requests":"次请求"]})]}),e.jsx("div",{className:"h-2 bg-muted rounded-full overflow-hidden mb-3",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${N.requests/v*100}%`}})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:["Credits",":"]}),e.jsx("span",{className:"ml-2 font-mono",children:N.credits.toFixed(4)})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[o?"Input":"输入",":"]}),e.jsx("span",{className:"ml-2 font-mono",children:N.inputTokens.toLocaleString()})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[o?"Output":"输出",":"]}),e.jsx("span",{className:"ml-2 font-mono",children:N.outputTokens.toLocaleString()})]})]})]},j)):e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:o?"No model statistics yet":"暂无模型统计"})}),d==="daily"&&e.jsx("div",{className:"space-y-4",children:p.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4",children:[e.jsxs("div",{className:"text-sm font-medium mb-4 flex items-center gap-2",children:[e.jsx(B3,{className:"h-4 w-4 text-primary"}),o?"Daily Credits (Last 7 Days)":"每日 Credits(最近7天)"]}),e.jsx("div",{className:"flex items-end gap-2 h-32",children:p.map((N,j)=>e.jsxs("div",{className:"flex-1 flex flex-col items-center",children:[e.jsx("div",{className:"w-full bg-primary rounded-t transition-all hover:bg-primary/80",style:{height:`${N.credits/b*100}%`,minHeight:"4px"},title:`${N.credits.toFixed(4)} credits`}),e.jsx("div",{className:"text-xs text-muted-foreground mt-2",children:N.date})]},j))})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Date":"日期"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Requests":"请求数"}),e.jsx("th",{className:"text-right p-2 font-medium",children:"Credits"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Input":"输入"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Output":"输出"})]})}),e.jsx("tbody",{className:"font-mono",children:Object.entries(r.usage.daily).sort((N,j)=>j[0].localeCompare(N[0])).slice(0,30).map(([N,j],T)=>e.jsxs("tr",{className:"border-b border-muted/30 hover:bg-muted/30",children:[e.jsx("td",{className:"p-2",children:N}),e.jsx("td",{className:"p-2 text-right",children:j.requests}),e.jsx("td",{className:"p-2 text-right",children:j.credits.toFixed(4)}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:j.inputTokens.toLocaleString()}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:j.outputTokens.toLocaleString()})]},T))})]})]}):e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:o?"No daily statistics yet":"暂无每日统计"})})]})]})]})}function FI(){const{language:n}=vt(),s=n==="en",[r,i]=g.useState([]),[o,d]=g.useState(!0),[u,h]=g.useState(""),[f,p]=g.useState("sk"),[y,b]=g.useState(""),[v,N]=g.useState(null),[j,T]=g.useState(new Set),[S,k]=g.useState(null),[R,I]=g.useState(!1),M=g.useCallback(async()=>{try{const se=await window.api.proxyGetApiKeys();se.success&&i(se.apiKeys)}catch(se){console.error("Failed to load API keys:",se)}finally{d(!1)}},[]);g.useEffect(()=>{M()},[M]);const G=async()=>{if(u.trim())try{const se=y?parseFloat(y):void 0,te=await window.api.proxyAddApiKey({name:u.trim(),format:f,creditsLimit:se&&se>0?se:void 0});te.success&&te.apiKey&&(i(Y=>[...Y,te.apiKey]),h(""),b(""))}catch(se){console.error("Failed to add API key:",se)}},W=async se=>{if(confirm(s?"Delete this API key?":"确定删除此 API Key?"))try{(await window.api.proxyDeleteApiKey(se)).success&&(i(Y=>Y.filter(P=>P.id!==se)),S===se&&k(null))}catch(te){console.error("Failed to delete API key:",te)}},U=async(se,te)=>{try{(await window.api.proxyUpdateApiKey(se,{enabled:te})).success&&i(P=>P.map(F=>F.id===se?{...F,enabled:te}:F))}catch(Y){console.error("Failed to toggle API key:",Y)}},q=async se=>{if(confirm(s?"Reset usage statistics?":"确定重置用量统计?"))try{(await window.api.proxyResetApiKeyUsage(se)).success&&i(Y=>Y.map(P=>P.id===se?{...P,usage:{totalRequests:0,totalCredits:0,totalInputTokens:0,totalOutputTokens:0,daily:{}}}:P))}catch(te){console.error("Failed to reset usage:",te)}},V=(se,te)=>{navigator.clipboard.writeText(te),N(se),setTimeout(()=>N(null),2e3)},le=se=>{T(te=>{const Y=new Set(te);return Y.has(se)?Y.delete(se):Y.add(se),Y})},B=se=>{const te=new Date(se);return`${te.toLocaleDateString()} ${te.toLocaleTimeString()}`},be=se=>se.substring(0,8)+"..."+se.substring(se.length-4),K=r.find(se=>se.id===S);return o?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(Mt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Dc,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"API Keys":"API 密钥"})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[r.length," ",s?"keys":"个"]})]}),e.jsx(Gl,{children:s?"Manage API keys for authentication":"管理用于身份验证的 API 密钥"})]}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(it,{placeholder:s?"Key name...":"密钥名称...",value:u,onChange:se=>h(se.target.value),onKeyDown:se=>se.key==="Enter"&&G(),className:"flex-1"}),e.jsx(ei,{value:f,options:[{value:"sk",label:"sk-xxx"},{value:"simple",label:"PROXY_KEY"},{value:"token",label:"KEY:TOKEN"}],onChange:se=>p(se),className:"w-[120px]"}),e.jsxs(D,{onClick:G,disabled:!u.trim(),children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),s?"Add":"添加"]})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(it,{type:"number",placeholder:s?"Credits limit (optional)":"Credits 额度限制(可选)",value:y,onChange:se=>b(se.target.value),className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:s?"0 = unlimited":"0 = 无限制"})]})]}),r.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:s?"No API keys yet":"暂无 API 密钥"}):e.jsx("div",{className:"space-y-2",children:r.map(se=>e.jsxs("div",{className:me("flex items-center gap-3 p-3 rounded-lg border transition-colors cursor-pointer",S===se.id?"bg-primary/5 border-primary":"hover:bg-muted/50",!se.enabled&&"opacity-50"),onClick:()=>k(S===se.id?null:se.id),children:[e.jsx("div",{onClick:te=>te.stopPropagation(),children:e.jsx(is,{checked:se.enabled,onCheckedChange:te=>U(se.id,te)})}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[e.jsx("div",{className:"font-medium truncate",children:se.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("code",{className:"bg-muted px-1 rounded",children:j.has(se.id)?se.key:be(se.key)}),e.jsx("button",{className:"hover:text-foreground",onClick:te=>{te.stopPropagation(),le(se.id)},children:j.has(se.id)?e.jsx(Jl,{className:"h-3 w-3"}):e.jsx(Nc,{className:"h-3 w-3"})}),e.jsx("button",{className:"hover:text-foreground",onClick:te=>{te.stopPropagation(),V(se.id,se.key)},children:v===se.id?e.jsx(Pt,{className:"h-3 w-3 text-success"}):e.jsx(As,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"text-right text-xs text-muted-foreground",children:[e.jsxs("div",{children:[se.usage.totalRequests," ",s?"requests":"请求"]}),e.jsxs("div",{className:me(se.creditsLimit&&se.usage.totalCredits>=se.creditsLimit&&"text-destructive font-medium"),children:[se.usage.totalCredits.toFixed(2),se.creditsLimit?`/${se.creditsLimit}`:""," credits"]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:te=>{te.stopPropagation(),W(se.id)},children:e.jsx(Vt,{className:"h-4 w-4"})})]},se.id))})]})]}),K&&e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Lu,{className:"h-5 w-5 text-primary"}),e.jsxs(rt,{className:"text-lg",children:[s?"Usage Details":"用量详情",": ",K.name]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>I(!0),children:[e.jsx(Xs,{className:"h-3 w-3 mr-1"}),s?"View Details":"查看详情"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>q(K.id),children:[e.jsx(Mt,{className:"h-3 w-3 mr-1"}),s?"Reset Usage":"重置用量"]})]})]})}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(yx,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:s?"Total Requests":"总请求数"})]}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalRequests})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(Ds,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:s?"Total Credits":"总 Credits"})]}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalCredits.toFixed(2)})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:e.jsx("span",{className:"text-xs",children:s?"Input Tokens":"输入 Tokens"})}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalInputTokens.toLocaleString()})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:e.jsx("span",{className:"text-xs",children:s?"Output Tokens":"输出 Tokens"})}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalOutputTokens.toLocaleString()})]})]}),e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s?"Credits Limit:":"Credits 额度限制:"}),e.jsx(it,{type:"number",placeholder:s?"Unlimited":"无限制",value:K.creditsLimit||"",onChange:async se=>{const te=se.target.value?parseFloat(se.target.value):null;(await window.api.proxyUpdateApiKey(K.id,{creditsLimit:te&&te>0?te:null})).success&&i(P=>P.map(F=>F.id===K.id?{...F,creditsLimit:te&&te>0?te:void 0}:F))},className:"w-32 h-8"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"(0 = unlimited)":"(0 = 无限制)"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gn,{className:"h-3 w-3"}),e.jsxs("span",{children:[s?"Created:":"创建时间:"," ",B(K.createdAt)]})]}),K.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gn,{className:"h-3 w-3"}),e.jsxs("span",{children:[s?"Last used:":"最后使用:"," ",B(K.lastUsedAt)]})]})]})]})]})]}),e.jsx(HI,{open:R,onOpenChange:I,apiKey:K||null})]})}const GI={claudeCode:"Claude Code",opencode:"OpenCode",codex:"Codex CLI",gemini:"Gemini CLI",hermes:"Hermes",openclaw:"OpenClaw"},Uu=["claude-sonnet-4.5","claude-sonnet-4","claude-opus-4.8","claude-opus-4.7","claude-opus-4.5","claude-haiku-4.5"],qI=[{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Claude Sonnet 4.5",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Claude Sonnet 4",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-opus-4.8",name:"Claude Opus 4.8",description:"Power account model",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-opus-4.7",name:"Claude Opus 4.7",description:"Power account model",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Power account model",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Claude Haiku 4.5",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3}];function ss(n){return n.trim().toLowerCase().replace(/^(claude-(?:sonnet|haiku|opus)-\d+)-(\d+)(.*)$/u,"$1.$2$3")}function aj(n){const s=new Map;for(const r of[...n,...qI]){if(!r.id?.trim())continue;const i=ss(r.id);s.has(i)||s.set(i,r)}return Array.from(s.values()).sort((r,i)=>{const o=Uu.findIndex(u=>ss(u)===ss(r.id)),d=Uu.findIndex(u=>ss(u)===ss(i.id));return o!==-1||d!==-1?(o===-1?99:o)-(d===-1?99:d):ss(r.id)==="auto"?1:ss(i.id)==="auto"?-1:r.id.localeCompare(i.id)})}function rj(n,s){const r=ss(s),i=n.find(o=>ss(o.id)===r);if(r&&r!=="auto"&&i)return i.id;for(const o of Uu){const d=n.find(u=>ss(u.id)===ss(o));if(d)return d.id}return n.find(o=>ss(o.id)!=="auto")?.id||n[0]?.id||""}function Of(n,s){const r=new Map(n.map(u=>[ss(u.id),u.id])),i=s.map(u=>r.get(ss(u))).filter(u=>!!(u&&ss(u)!=="auto"));if(i.length>0)return Array.from(new Set(i));const o=Uu.map(u=>r.get(ss(u))).filter(u=>!!(u&&ss(u)!=="auto"));if(o.length>0)return Array.from(new Set(o));const d=n.find(u=>ss(u.id)!=="auto")?.id;return d?[d]:[]}function XI({open:n,onOpenChange:s,isEn:r}){const i=vt(oe=>oe.accounts),o=vt(oe=>oe.activeAccountId),[d,u]=g.useState([]),[h,f]=g.useState(""),[p,y]=g.useState([]),[b,v]=g.useState(["openclaw"]),[N,j]=g.useState(!1),[T,S]=g.useState(!1),[k,R]=g.useState(!1),[I,M]=g.useState(!1),[G,W]=g.useState(null),[U,q]=g.useState([]),[V,le]=g.useState(""),[,B]=g.useState([]),[be,K]=g.useState(null),[se,te]=g.useState(!1),Y=g.useMemo(()=>[{id:"claudeCode",name:"Claude Code",description:r?"Writes ANTHROPIC_BASE_URL, API key and default model":"Ghi ANTHROPIC_BASE_URL, API key và model mặc định",icon:$N},{id:"opencode",name:"OpenCode",description:r?"Adds Kiro provider and model metadata to opencode.json":"Thêm provider Kiro và metadata model vào opencode.json",icon:O3},{id:"codex",name:"Codex CLI",description:r?"Adds Kiro OpenAI Responses provider":"Thêm provider Kiro dùng OpenAI Responses",icon:WN},{id:"gemini",name:"Gemini CLI",description:r?"Writes .env and settings.json for Gemini v1beta":"Ghi .env và settings.json cho Gemini v1beta",icon:Hi},{id:"hermes",name:"Hermes",description:r?"Adds Kiro provider to config.yaml":"Thêm provider Kiro vào config.yaml",icon:qM},{id:"openclaw",name:"OpenClaw",description:r?"Adds Kiro provider to openclaw.json":"Thêm provider Kiro vào openclaw.json",icon:Ka}],[r]),P=d.find(oe=>oe.id===h),F=g.useMemo(()=>new Set(p.map(ss)),[p]),fe=b.length===1&&b[0]==="openclaw",pe=oe=>oe.length<=14?oe:`${oe.slice(0,8)}...${oe.slice(-4)}`,C=oe=>oe.find(ue=>ue.name==="OpenClaw - Kiro API Proxy")||oe.find(ue=>ue.enabled!==!1)||oe[0]||null,z=g.useCallback(async()=>{j(!0),W(null),q([]);try{const oe=await window.api.proxyGetModels();if(oe.success&&oe.models.length>0){const L=aj(oe.models);u(L),f(we=>rj(L,we)),y(we=>Of(L,we));return}const ue=o?i.get(o):void 0,ae=ue?.status==="active"&&ue.credentials?.accessToken?ue:Array.from(i.values()).find(L=>L.status==="active"&&L.credentials?.accessToken);if(ae){const L=await window.api.accountGetModels(ae.credentials.accessToken,ae.credentials.region||"us-east-1",ae.profileArn,ae.machineId,ae.credentials.provider||ae.idp,ae.credentials.authMethod,ae.id);if(L.success&&L.models.length>0){const we=aj(L.models);u(we),f(Ue=>rj(we,Ue)),y(Ue=>Of(we,Ue));return}}u([]),f(""),y([]),W(r?"No models were loaded. Please check whether the account is active and try reloading.":"Chưa tải được model. Hãy kiểm tra tài khoản đang active rồi tải lại.")}catch(oe){u([]),f(""),y([]),W(oe instanceof Error?oe.message:r?"Failed to load models":"Tải model thất bại")}finally{j(!1)}},[i,o,r]),X=g.useCallback(async()=>{S(!0);try{const oe=await window.api.proxyGetApiKeys();if(oe.success){const ue=oe.apiKeys||[];B(ue),K(C(ue))}}catch(oe){console.error("[ClientConfig] Failed to load API keys:",oe)}finally{S(!1)}},[]);if(g.useEffect(()=>{n&&(z(),X())},[n,z,X]),!n)return null;const re=oe=>{q([]),v(ue=>ue.includes(oe)?ue.filter(ae=>ae!==oe):[...ue,oe])},xe=oe=>{q([]),y(ue=>{const ae=ss(oe),L=ue.some(Ue=>ss(Ue)===ae),we=L?ue.filter(Ue=>ss(Ue)!==ae):[...ue,oe];return!L&&we.length===1&&f(oe),L&&ss(h)===ae&&f(we[0]||""),we})},Oe=()=>{q([]),y(Of(d,[]))},Ee=()=>{q([]),y(h?[h]:[])},Qe=async()=>{be?.key&&(await navigator.clipboard.writeText(be.key),te(!0),setTimeout(()=>te(!1),1600))},_e=async()=>{R(!0),W(null);try{const oe=await window.api.proxyAddApiKey({name:"OpenClaw - Kiro API Proxy",format:"sk"});if(!oe.success||!oe.apiKey){W(oe.error||(r?"Failed to create API key":"Tạo API key thất bại"));return}B(ue=>[oe.apiKey,...ue]),K(oe.apiKey)}catch(oe){W(oe instanceof Error?oe.message:r?"Failed to create API key":"Tạo API key thất bại")}finally{R(!1)}},st=async()=>{if(!h){W(r?"Please select a model":"Hãy chọn model");return}if(b.length===0){W(r?"Please select at least one client":"Hãy chọn ít nhất một client");return}if(p.length===0){W(r?"Please select at least one model to add":"Hãy chọn ít nhất một model để thêm");return}M(!0),W(null),q([]);try{const oe=new Set(p.map(ss));oe.add(ss(h));const ue=d.filter(we=>oe.has(ss(we.id)));!ue.some(we=>ss(we.id)===ss(h))&&P&&ue.unshift(P);const ae=await window.api.proxyConfigureClients({clients:b,modelId:h,modelName:P?.name,models:ue.map(we=>({id:we.id,name:we.name,inputTypes:we.inputTypes,maxInputTokens:we.maxInputTokens,maxOutputTokens:we.maxOutputTokens}))});le(ae.openaiBaseUrl||ae.proxyOrigin);const L=ae.apiKey;L&&(K(L),B(we=>we.some(Ue=>Ue.id&&Ue.id===L.id)?we.map(Ue=>Ue.id===L.id?{...Ue,...L}:Ue):[L,...we])),q(ae.results),ae.success||W(ae.error||(r?"Some clients failed to configure":"Một số client cấu hình thất bại"))}catch(oe){W(oe instanceof Error?oe.message:r?"Failed to configure clients":"Cấu hình client thất bại")}finally{M(!1)}};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[780px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsx(at,{className:"pb-4 border-b sticky top-0 z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-xl flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(Ka,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold",children:r?"One-Click Client Configuration":"Cấu hình client một chạm"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs($e,{className:"bg-primary/10 text-primary border-primary/20 font-semibold",children:[b.length," ",r?"selected":"đã chọn"]}),V&&e.jsx($e,{variant:"secondary",className:"text-xs border-0",children:V})]})]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-5 w-5"})})]})}),e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"max-h-[calc(85vh-140px)] overflow-y-auto pr-2 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border bg-background p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ii,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium",children:r?"Kiro API Proxy key":"Key Kiro API Proxy"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:_e,disabled:k,children:[k?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(ii,{className:"h-4 w-4"}),r?"Create key":"Tạo key"]})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/40 px-3 py-2 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 text-xs break-all",children:T?r?"Loading key...":"Đang tải key...":be?.key?pe(be.key):r?"No key yet. Import will create one automatically.":"Chưa có key. Khi import hệ thống sẽ tự tạo."}),be?.key&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:Qe,title:r?"Copy key":"Sao chép key",children:se?e.jsx(Pt,{className:"h-3.5 w-3.5 text-success"}):e.jsx(As,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:r?"The server stores this key and OpenClaw uses it to call the Kiro API proxy quota pool.":"Server sẽ lưu key này để OpenClaw gọi qua Kiro API proxy và dùng quota xoay tài khoản."})]}),e.jsxs("div",{className:"rounded-xl border bg-background p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ai,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium",children:"Model"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:z,disabled:N,children:[N?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(J3,{className:"h-4 w-4"}),r?"Reload":"Tải lại"]})]}),N?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-2",children:[e.jsx(bt,{className:"h-4 w-4 animate-spin"}),r?"Loading models...":"Đang tải model..."]}):d.length>0?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ei,{value:h,options:d.map(oe=>({value:oe.id,label:oe.id,description:oe.name&&oe.name!==oe.id?oe.name:oe.description})),onChange:oe=>{f(oe),y(ue=>ue.some(ae=>ss(ae)===ss(oe))?ue:[...ue,oe]),q([])},placeholder:r?"Select model":"Chọn model"}),P&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[e.jsx($e,{variant:"secondary",className:"border-0",children:P.name||P.id}),P.inputTypes?.map(oe=>e.jsx($e,{variant:"secondary",className:"border-0",children:oe},oe))]}),e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{className:"bg-primary/10 text-primary border-primary/20",children:p.length}),e.jsx("span",{className:"text-sm font-medium",children:r?"Models to add":"Model sẽ thêm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{type:"button",variant:"outline",size:"sm",onClick:Oe,children:[e.jsx(Pt,{className:"h-3.5 w-3.5"}),r?"Recommended":"Đề xuất"]}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:Ee,children:r?"Only primary":"Chỉ primary"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-56 overflow-y-auto pr-1",children:d.filter(oe=>ss(oe.id)!=="auto").map(oe=>{const ue=F.has(ss(oe.id));return e.jsxs("button",{type:"button",onClick:()=>xe(oe.id),className:me("flex items-start gap-2 rounded-lg border px-3 py-2 text-left text-xs transition-colors",ue?"border-primary/50 bg-primary/10":"border-border bg-background hover:border-primary/40"),children:[e.jsx("span",{className:me("mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border",ue?"border-primary bg-primary text-primary-foreground":"border-muted-foreground/40"),children:ue&&e.jsx(Pt,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate font-semibold",children:oe.id}),oe.name&&oe.name!==oe.id&&e.jsx("span",{className:"block truncate text-muted-foreground",children:oe.name})]})]},oe.id)})})]})]}):e.jsx("div",{className:"text-sm text-muted-foreground py-2",children:r?"No models loaded":"Chưa có model"})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Y.map(oe=>{const ue=oe.icon,ae=b.includes(oe.id);return e.jsxs("button",{type:"button",onClick:()=>re(oe.id),className:me("text-left rounded-xl border p-4 transition-all hover:border-primary/50 hover:bg-primary/5",ae?"border-primary/50 bg-primary/10 shadow-sm":"bg-background"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ue,{className:"h-5 w-5 text-primary"})}),e.jsx("div",{className:me("h-5 w-5 rounded-full border flex items-center justify-center",ae?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/40"),children:ae&&e.jsx(Pt,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"font-semibold text-sm mb-1",children:oe.name}),e.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed",children:oe.description})]},oe.id)})}),e.jsxs("div",{className:"rounded-xl border border-warning/30 bg-warning/10 p-3 flex items-start gap-2 text-sm text-warning",children:[e.jsx(ln,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("div",{children:r?"Existing client files are merged and backed up before writing.":"File client hiện có sẽ được merge và tạo backup trước khi ghi."})]}),G&&e.jsxs("div",{className:"rounded-xl border border-destructive/30 bg-destructive/10 p-3 flex items-start gap-2 text-sm text-destructive",children:[e.jsx(ln,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("div",{children:G})]}),U.length>0&&e.jsxs("div",{className:"space-y-2",children:[V&&e.jsxs("div",{className:"rounded-xl border border-primary/20 bg-primary/5 p-3 text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:"Base URL:"})," ",e.jsx("code",{children:V})]}),e.jsx("div",{children:r?"In OpenClaw, use /models and choose the krouter provider.":"Trong OpenClaw, gõ /models rồi chọn provider krouter."})]}),U.map(oe=>e.jsxs("div",{className:me("rounded-xl border p-3 text-sm",oe.success?"border-success/30 bg-success/10":"border-destructive/30 bg-destructive/10"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsx("span",{className:"font-semibold",children:GI[oe.client]}),e.jsx($e,{className:oe.success?"bg-success/15 text-success border-success/20":"bg-destructive/15 text-destructive border-destructive/20",children:oe.success?r?"Configured":"Đã cấu hình":r?"Failed":"Thất bại"})]}),oe.error?e.jsx("div",{className:"text-xs text-destructive",children:oe.error}):e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[oe.paths.map(ue=>e.jsx("div",{className:"font-mono break-all",children:ue},ue)),oe.backupPaths.length>0&&e.jsxs("div",{children:[r?"Backups created":"Backup đã tạo",": ",oe.backupPaths.length]})]})]},oe.client))]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(D,{variant:"outline",onClick:()=>s(!1),disabled:I,children:r?"Close":"Đóng"}),e.jsxs(D,{onClick:st,disabled:N||I||!h||p.length===0||b.length===0,children:[I?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Pt,{className:"h-4 w-4"}),I?r?"Configuring...":"Đang cấu hình...":fe?r?"Import to OpenClaw":"Import vào OpenClaw":r?"Apply Configuration":"Áp dụng cấu hình"]})]})]})})]})]})}const YI=5e3;function zl(n){return n>=1e9?`${(n/1e9).toFixed(1)}B`:n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e5?`${(n/1e3).toFixed(0)}K`:n.toLocaleString()}let Nu=[],Ip=null,ij=!1;function WI(){ij||(ij=!0,window.api.onProxyResponse(n=>{const s=new Date,r=s.getFullYear(),i=(s.getMonth()+1).toString().padStart(2,"0"),o=s.getDate().toString().padStart(2,"0"),d=s.getHours().toString().padStart(2,"0"),u=s.getMinutes().toString().padStart(2,"0"),h=s.getSeconds().toString().padStart(2,"0"),f=s.getMilliseconds().toString().padStart(3,"0");Nu=[{time:`${r}-${i}-${o} ${d}:${u}:${h}.${f}`,path:n.path,model:n.model,status:n.status,tokens:n.tokens,inputTokens:n.inputTokens,outputTokens:n.outputTokens,cacheReadTokens:n.cacheReadTokens,reasoningTokens:n.reasoningTokens,credits:n.credits,responseTime:n.responseTime,error:n.error},...Nu.slice(0,99)],Ip?.(Nu)}))}function QI(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",[r,i]=g.useState(!1),[o,d]=g.useState({enabled:!1,port:5580,host:"127.0.0.1",enableMultiAccount:!0,logRequests:!0,clientDrivenToolExecution:!0,accountSelectionStrategy:"round-robin",sessionAffinityEnabled:!1}),[u,h]=g.useState(null),[f,p]=g.useState(null),[y,b]=g.useState(0),[v,N]=g.useState(0),[j,T]=g.useState(!1),[S,k]=g.useState(null),[R,I]=g.useState(Nu),[M,G]=g.useState(!1),[W,U]=g.useState(!1),[q,V]=g.useState(!1),[le,B]=g.useState(!1),[be,K]=g.useState(!1),[se,te]=g.useState(!1),[Y,P]=g.useState(!1),[F,fe]=g.useState(!1),[pe,C]=g.useState(!1),[z,X]=g.useState([]),[re,xe]=g.useState(!1),[Oe,Ee]=g.useState(!1),[Qe,_e]=g.useState(!1),[st,oe]=g.useState("sk"),[ue,ae]=g.useState(!1),[L,we]=g.useState(!1),[Ue,Lt]=g.useState(null),[xt,Qt]=g.useState(""),[ft,Et]=g.useState(!1),[Ge,gt]=g.useState(!1),Ze=vt(H=>H.accounts),J=vt(H=>H.groups),Ne=g.useCallback(()=>{const H=Xe=>{const Nt="abcdefghijklmnopqrstuvwxyz0123456789";return Array.from({length:Xe},()=>Nt[Math.floor(Math.random()*Nt.length)]).join("")};let Se;switch(st){case"sk":Se=`sk-${H(48)}`;break;case"simple":Se=`PROXY_KEY_${H(32).toUpperCase()}`;break;case"token":Se=`PROXY_KEY:${H(32)}`;break;default:Se=`sk-${H(48)}`}d(Xe=>({...Xe,apiKey:Se})),window.api.proxyUpdateConfig({apiKey:Se}),_e(!0),we(!0),setTimeout(()=>we(!1),1500)},[st]),et=g.useCallback(()=>{o.apiKey&&(navigator.clipboard.writeText(o.apiKey),ae(!0),setTimeout(()=>ae(!1),1500))},[o.apiKey]),qe=g.useCallback(async()=>{try{const H=await window.api.proxyGetStatus();if(i(H.running),H.config){const Xe=H.config;Xe.selectedAccountIds&&Xe.selectedAccountIds.length>0&&(Xe.selectedAccountId=Xe.selectedAccountIds[0]);const Nt=Xe.clientDrivenToolExecution!==!1;d({...Xe,clientDrivenToolExecution:Nt})}H.stats&&h(H.stats),H.sessionStats&&p(H.sessionStats);const Se=await window.api.proxyGetAccounts();b(Se.accounts.length),N(Se.availableCount)}catch(H){console.error("Failed to fetch proxy status:",H)}},[]),Je=g.useCallback(async()=>{if(typeof window.api.dashboardTunnelGetStatus=="function")try{const H=await window.api.dashboardTunnelGetStatus();Lt(H),Qt(Se=>Se||H.localUrl||"")}catch(H){console.error("Failed to fetch dashboard tunnel status:",H)}},[]),Kt=async()=>{if(typeof window.api.dashboardTunnelStart=="function"){Et(!0),k(null);try{const H=await window.api.dashboardTunnelStart({localUrl:xt.trim()||void 0});Lt(H.status),Qt(H.status.localUrl),H.success||k(H.error||H.status.error||"Không bật được Dashboard Tunnel")}catch(H){k(H instanceof Error?H.message:String(H))}finally{Et(!1)}}},Ye=async()=>{if(typeof window.api.dashboardTunnelStop=="function"){Et(!0),k(null);try{const H=await window.api.dashboardTunnelStop();Lt(H.status),H.success||k(H.error||H.status.error||"Không tắt được Dashboard Tunnel")}catch(H){k(H instanceof Error?H.message:String(H))}finally{Et(!1)}}},qt=g.useCallback(()=>{Ue?.publicUrl&&(navigator.clipboard.writeText(Ue.publicUrl),gt(!0),setTimeout(()=>gt(!1),1500))},[Ue?.publicUrl]),Jt=g.useCallback(async()=>{try{const H=await window.api.proxyGetModels();H.success&&H.models&&X(H.models.map(Se=>({id:Se.id,name:Se.name||Se.id})))}catch{}},[]),Ct=g.useCallback(async H=>{G(!0),V(!1);try{const Se=H?.mode??o.multiAccountSelectionMode??"all",Xe=H?.groupIds??o.multiAccountGroupIds??[];let Nt=Array.from(Ze.values()).filter(Bt=>Bt.status==="active"&&Bt.credentials?.accessToken);if(o.enableMultiAccount&&Se==="groups"){const Bt=new Set(Xe);Nt=Nt.filter(qn=>qn.groupId?Bt.has(qn.groupId):Bt.has("__ungrouped__"))}const nt=Nt.map(Bt=>({id:Bt.id,email:Bt.email,accessToken:Bt.credentials.accessToken,refreshToken:Bt.credentials?.refreshToken,profileArn:Bt.profileArn,expiresAt:Bt.credentials?.expiresAt,machineId:Bt.machineId,clientId:Bt.credentials?.clientId,clientSecret:Bt.credentials?.clientSecret,region:Bt.credentials?.region||"us-east-1",authMethod:Bt.credentials?.authMethod,provider:Bt.credentials?.provider||Bt.idp,groupId:Bt.groupId})),$t=await window.api.proxySyncAccounts(nt);$t.success&&(b($t.accountCount||0),await qe(),V(!0),setTimeout(()=>V(!1),2e3))}catch(Se){console.error("Failed to sync accounts:",Se)}finally{G(!1)}},[Ze,qe,o.enableMultiAccount,o.multiAccountSelectionMode,o.multiAccountGroupIds]),O=async()=>{k(null);try{await Ct();const H=await window.api.proxyStart({port:o.port,host:o.host,apiKey:o.apiKey,enableMultiAccount:o.enableMultiAccount,enabled:!0,autoStart:o.autoStart,accountSelectionStrategy:o.enableMultiAccount?o.accountSelectionStrategy||"round-robin":o.accountSelectionStrategy,sessionAffinityEnabled:o.enableMultiAccount&&(o.accountSelectionStrategy||"round-robin")!=="sticky"?!1:o.sessionAffinityEnabled,logRequests:o.logRequests,clientDrivenToolExecution:o.clientDrivenToolExecution!==!1,disableTools:o.disableTools});H.success?(i(!0),d(Se=>({...Se,enabled:!0})),await qe()):k(H.error||(s?"Failed to start":"Khởi động thất bại"))}catch(H){k(H.message)}},ne=async()=>{k(null);try{const H=await window.api.proxyStop();H.success?(i(!1),d(Se=>({...Se,enabled:!1})),h(null)):k(H.error||(s?"Failed to stop":"Dừng thất bại"))}catch(H){k(H.message)}},ze=()=>{const Se=`http://${o.host==="0.0.0.0"?"localhost":o.host}:${o.port}`;navigator.clipboard.writeText(Se),T(!0),setTimeout(()=>T(!1),2e3)},_=async()=>{U(!0),B(!1);try{const H=await window.api.proxyRefreshModels();H.success?(await Jt(),B(!0),setTimeout(()=>B(!1),2e3)):k(H.error||(s?"Failed to refresh models":"Làm mới model thất bại"))}catch(H){k(H.message)}finally{U(!1)}};g.useEffect(()=>{window.api.proxyLoadLogs().then(H=>{H.success&&H.logs.length>0&&I(H.logs)})},[]),g.useEffect(()=>{Je();const H=setInterval(()=>void Je(),5e3);return()=>clearInterval(H)},[Je]),g.useEffect(()=>{if(R.length===0)return;const H=setTimeout(()=>{window.api.proxySaveLogs(R)},2e3);return()=>clearTimeout(H)},[R]),g.useEffect(()=>{qe(),Jt();const H=window.api.onProxyRequest(nt=>{console.log("[Proxy] Request:",nt)});WI(),Ip=I;const Se=window.api.onProxyResponse(()=>{qe()}),Xe=window.api.onProxyError(nt=>{console.error("[Proxy] Error:",nt),k(nt)}),Nt=window.api.onProxyStatusChange(nt=>{i(nt.running),nt.running&&d($t=>({...$t,port:nt.port}))});return()=>{H(),Se(),Xe(),Nt(),Ip=null}},[qe,Jt]),g.useEffect(()=>{const H=()=>{document.hidden||qe()};document.addEventListener("visibilitychange",H);const Se=setInterval(H,YI);return()=>{document.removeEventListener("visibilitychange",H),clearInterval(Se)}},[qe]);const ce=g.useRef(Ct);g.useEffect(()=>{ce.current=Ct},[Ct]);const Ce=g.useMemo(()=>Array.from(Ze.values()).filter(H=>H.status==="active"&&H.credentials?.accessToken).map(H=>`${H.id}:${H.groupId||""}`).sort().join("|"),[Ze]),Ve=g.useRef(!1);g.useEffect(()=>{if(!r)return;if(!Ve.current){Ve.current=!0;return}const H=setTimeout(()=>{ce.current()},600);return()=>clearTimeout(H)},[Ce,r]);const[je,He]=g.useState(0);g.useEffect(()=>{if(!r||!u){He(0);return}He(Math.floor((Date.now()-u.startTime)/1e3));const H=setInterval(()=>{He(Math.floor((Date.now()-u.startTime)/1e3))},1e3);return()=>clearInterval(H)},[r,u]);const Tt=H=>{const Se=Math.floor(H/3600),Xe=Math.floor(H%3600/60),Nt=H%60;return`${Se}h ${Xe}m ${Nt}s`};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(De,{className:"hover-lift relative z-10",children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Sc,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(rt,{className:"text-lg text-primary",children:"Kiro API Proxy"}),e.jsx(Gl,{children:s?"Provides OpenAI and Claude compatible API endpoints":"Cung cấp endpoint tương thích OpenAI và Claude"})]})]}),e.jsxs($e,{variant:r?"default":"secondary",className:r?"bg-success text-white flex items-center gap-1.5 pr-2.5":"bg-muted text-muted-foreground flex items-center gap-1.5 pr-2.5",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[r&&e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-white opacity-75"}),e.jsx("span",{className:r?"relative inline-flex rounded-full h-2 w-2 bg-white":"relative inline-flex rounded-full h-2 w-2 bg-muted-foreground"})]}),r?s?"Running":"Đang chạy":s?"Stopped":"Đã dừng"]})]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsxs(D,{onClick:ne,variant:"destructive",className:"gap-2",children:[e.jsx(Cn,{className:"h-4 w-4"}),s?"Stop Service":"Tắt dịch vụ"]}):e.jsxs(D,{onClick:O,className:"gap-2",children:[e.jsx(Ba,{className:"h-4 w-4"}),s?"Start Service":"Bật dịch vụ"]}),e.jsxs(D,{onClick:()=>void Ct(),variant:"outline",className:"gap-2",disabled:!r||M,children:[M?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):q?e.jsx(Pt,{className:"h-4 w-4 text-success"}):e.jsx(Mt,{className:"h-4 w-4"}),M?s?"Syncing...":"Đang đồng bộ...":q?s?"Synced!":"Đã đồng bộ":s?"Sync Accounts":"Đồng bộ tài khoản"]}),e.jsxs(D,{onClick:_,variant:"outline",className:"gap-2",disabled:!r||W,children:[W?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):le?e.jsx(Pt,{className:"h-4 w-4 text-success"}):e.jsx(Mt,{className:"h-4 w-4"}),W?s?"Refreshing...":"Đang làm mới...":le?s?"Refreshed!":"Đã làm mới":s?"Refresh Models":"Làm mới model"]}),e.jsxs(D,{onClick:()=>P(!0),variant:"outline",className:"gap-2",disabled:!r,children:[e.jsx(ai,{className:"h-4 w-4"}),s?"View Models":"Xem model"]}),e.jsxs(D,{onClick:()=>fe(!0),variant:"outline",className:"gap-2",children:[e.jsx(Ka,{className:"h-4 w-4"}),s?"Configure Clients":"Cấu hình client"]})]}),S&&e.jsxs("div",{className:"flex items-center gap-2 text-destructive text-sm",children:[e.jsx(ln,{className:"h-4 w-4"}),S]}),r&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"min-w-[80px]",children:s?"Address:":"Địa chỉ:"}),e.jsxs("code",{className:"flex-1 px-3 py-2 bg-muted rounded text-sm",children:["http://",o.host==="0.0.0.0"?"localhost":o.host,":",o.port]}),e.jsx(D,{variant:"outline",size:"icon",onClick:ze,children:j?e.jsx(Pt,{className:"h-4 w-4"}):e.jsx(As,{className:"h-4 w-4"})})]}),o.host==="0.0.0.0"&&e.jsx("p",{className:"text-xs text-muted-foreground pl-[88px]",children:s?`LAN devices use http://<this-machine-IP>:${o.port}`:`Thiết bị khác dùng http://<IP-máy-này>:${o.port}`})]}),e.jsxs("div",{className:"rounded-lg border bg-background/70 p-3 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:s?"Dashboard Tunnel":"Tunnel dashboard"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Expose the dashboard with Cloudflare Quick Tunnel. Login is still required.":"Mở dashboard bằng Cloudflare Quick Tunnel. Người dùng vẫn phải đăng nhập."})]})]}),e.jsx($e,{variant:Ue?.running?"default":"secondary",className:Ue?.running?"bg-success text-white":"",children:Ue?.running?s?"Online":"Đang bật":s?"Off":"Đang tắt"})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-2 items-end",children:[e.jsxs("div",{className:"col-span-8 space-y-1.5",children:[e.jsx(Fe,{htmlFor:"tunnelTarget",className:"text-xs",children:s?"Local dashboard target":"Đích dashboard nội bộ"}),e.jsx(it,{id:"tunnelTarget",value:xt,onChange:H=>Qt(H.target.value),placeholder:s?"Example: http://127.0.0.1 or http://127.0.0.1:4010":"Ví dụ: http://127.0.0.1 hoặc http://127.0.0.1:4010",disabled:Ue?.running||ft,className:"h-9"})]}),e.jsx("div",{className:"col-span-4 flex gap-2",children:Ue?.running?e.jsxs(D,{onClick:Ye,variant:"outline",className:"gap-2 flex-1",disabled:ft,children:[ft?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Cn,{className:"h-4 w-4"}),s?"Stop Tunnel":"Tắt tunnel"]}):e.jsxs(D,{onClick:Kt,variant:"outline",className:"gap-2 flex-1",disabled:ft,children:[ft?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Ba,{className:"h-4 w-4"}),s?"Start Tunnel":"Bật tunnel"]})})]}),Ue?.publicUrl&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded text-sm truncate",children:Ue.publicUrl}),e.jsx(D,{variant:"outline",size:"icon",onClick:qt,title:s?"Copy tunnel URL":"Sao chép link tunnel",children:Ge?e.jsx(Pt,{className:"h-4 w-4"}):e.jsx(As,{className:"h-4 w-4"})}),e.jsx(D,{variant:"outline",size:"icon",onClick:()=>window.api.openExternal(Ue.publicUrl),title:s?"Open tunnel":"Mở tunnel",children:e.jsx(Xs,{className:"h-4 w-4"})})]}),Ue?.error&&e.jsx("div",{className:"text-xs text-destructive",children:Ue.error}),Ue&&!Ue.running&&!Ue.error&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s?`Binary: ${Ue.binary}. Set CLOUDFLARED_BIN if cloudflared is not in PATH.`:`File chạy: ${Ue.binary}. Nếu cloudflared không có trong PATH, đặt CLOUDFLARED_BIN.`})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-3",children:[e.jsxs("div",{className:"col-span-2 space-y-1.5",children:[e.jsx(Fe,{htmlFor:"port",className:"text-xs",children:s?"Port":"Cổng"}),e.jsx(it,{id:"port",type:"number",value:o.port,onChange:H=>{const Se=parseInt(H.target.value)||5580;d(Xe=>({...Xe,port:Se})),window.api.proxyUpdateConfig({port:Se})},disabled:r,className:"h-9"})]}),e.jsxs("div",{className:"col-span-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Fe,{htmlFor:"host",className:"text-xs",title:o.host==="0.0.0.0"?s?"LAN access enabled. Set an API Key and allow port through firewall.":"Đang cho phép truy cập ngoài máy; nên đặt API Key và mở cổng firewall":s?"Loopback only. Toggle Public for LAN access.":"Chỉ chạy nội bộ; bật Public để thiết bị khác truy cập",children:s?"Host":"Địa chỉ nghe"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(is,{id:"publicAccess",checked:o.host==="0.0.0.0",onCheckedChange:async H=>{const Se=H?"0.0.0.0":"127.0.0.1";if(d(Xe=>({...Xe,host:Se})),await window.api.proxyUpdateConfig({host:Se}),r)try{await window.api.proxyStop(),await new Promise(Xe=>setTimeout(Xe,200)),await window.api.proxyStart()}catch(Xe){console.error("[Proxy] Failed to restart after host change:",Xe),k(Xe instanceof Error?Xe.message:String(Xe))}},className:"scale-75"}),e.jsx(Fe,{htmlFor:"publicAccess",className:"text-[10px] cursor-pointer",children:"Public"})]})]}),e.jsx(it,{id:"host",value:o.host,onChange:H=>{const Se=H.target.value;d(Xe=>({...Xe,host:Se})),window.api.proxyUpdateConfig({host:Se})},disabled:r,className:`h-9 ${o.host==="0.0.0.0"?"border-warning/50":""}`})]}),e.jsxs("div",{className:"col-span-7 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Fe,{htmlFor:"apiKey",className:"text-xs",title:s?"When set, requests must provide this key in Authorization or X-Api-Key header":"Khi đặt key, request phải gửi qua header Authorization hoặc X-Api-Key",children:s?"API Key (Optional)":"API Key (tùy chọn)"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ei,{value:st,options:[{value:"sk",label:"sk-xxx"},{value:"simple",label:"PROXY_KEY"},{value:"token",label:"KEY:TOKEN"}],onChange:H=>oe(H),className:"w-[120px] h-7 text-xs [&>button]:h-7 [&>button]:py-0 [&>button]:px-2.5"}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:Ne,disabled:r,title:s?"Generate":"Tạo ngẫu nhiên",children:L?e.jsx(Pt,{className:"h-3.5 w-3.5 text-success"}):e.jsx(G3,{className:"h-3.5 w-3.5"})}),o.apiKey&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:et,title:s?"Copy":"Sao chép",children:ue?e.jsx(Pt,{className:"h-3.5 w-3.5 text-success"}):e.jsx(As,{className:"h-3.5 w-3.5"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>Ee(!0),title:s?"Manage Multiple API Keys":"Quản lý nhiều API Key",children:e.jsx(Ka,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(it,{id:"apiKey",type:Qe?"text":"password",placeholder:s?"Leave empty to skip auth":"Để trống để bỏ xác thực",value:o.apiKey||"",onChange:H=>{const Se=H.target.value||void 0;d(Xe=>({...Xe,apiKey:Se})),window.api.proxyUpdateConfig({apiKey:Se})},disabled:r,className:"pr-9 h-9"}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-2.5 hover:bg-transparent",onClick:()=>_e(!Qe),title:Qe?s?"Hide":"Ẩn":s?"Show":"Hiện",children:Qe?e.jsx(Jl,{className:"h-3.5 w-3.5"}):e.jsx(Nc,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-x-4 gap-y-3 items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"autoStart",checked:o.autoStart||!1,onCheckedChange:async H=>{const Se=H?{autoStart:!0,enabled:!0}:{autoStart:!1,enabled:r};d(Nt=>({...Nt,...Se}));const Xe=await window.api.proxyUpdateConfig(Se);Xe.success||k(Xe.error||(s?"Failed to update auto start":"Không lưu được tự khởi động")),await qe()}}),e.jsx(Fe,{htmlFor:"autoStart",className:"text-sm cursor-pointer",children:s?"Auto Start":"Tự khởi động"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"multiAccount",checked:o.enableMultiAccount,onCheckedChange:H=>{const Se=H?{enableMultiAccount:!0,accountSelectionStrategy:"round-robin",sessionAffinityEnabled:!1}:{enableMultiAccount:!1};d(Xe=>({...Xe,...Se})),window.api.proxyUpdateConfig(Se)},disabled:r}),e.jsx(Fe,{htmlFor:"multiAccount",className:"text-sm cursor-pointer",children:s?"Multi-Account":"Nhiều tài khoản"})]}),o.enableMultiAccount&&e.jsxs("div",{className:"col-span-2 flex items-center gap-2",children:[e.jsxs(Fe,{className:"text-sm shrink-0",children:[s?"Strategy":"Chiến lược",":"]}),e.jsx("div",{className:"flex gap-1 bg-muted/30 rounded-lg p-0.5",children:["round-robin","least-used","sticky"].map(H=>{const Se=(o.accountSelectionStrategy||"round-robin")===H,Xe=H==="round-robin"?"Round-Robin":H==="least-used"?"Least-Used":"Sticky",Nt=H==="round-robin"?"Xoay vòng":H==="least-used"?"Ít dùng nhất":"Bám phiên";return e.jsx("button",{type:"button",disabled:r,className:`px-3 py-1 rounded-md text-xs font-medium transition-all ${Se?"bg-primary text-primary-foreground shadow-sm":"text-muted-foreground hover:text-foreground hover:bg-muted/50"} disabled:opacity-50 disabled:cursor-not-allowed`,onClick:()=>{const nt=H!=="sticky"?{accountSelectionStrategy:H,sessionAffinityEnabled:!1}:{accountSelectionStrategy:H};d($t=>({...$t,...nt})),window.api.proxyUpdateConfig(nt)},children:s?Xe:Nt},H)})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:(()=>{const H=o.accountSelectionStrategy||"round-robin";return H==="least-used"?s?"Pick the account with the fewest successful requests":"Chọn tài khoản có số request thành công thấp nhất":H==="sticky"?s?"Stay on success account until failure (preserves prompt cache)":"Giữ tài khoản đang thành công cho tới khi lỗi":s?"Each request rotates to next account (load balanced)":"Mỗi request chuyển sang tài khoản kế tiếp để cân bằng tải"})()})]}),o.enableMultiAccount&&(()=>{const H=o.multiAccountSelectionMode||"all",Se=new Set(o.multiAccountGroupIds||[]),Xe=Array.from(J.values()).sort((Ot,ws)=>(Ot.order??0)-(ws.order??0)),Nt=Array.from(Ze.values()).filter(Ot=>Ot.status==="active"&&Ot.credentials?.accessToken),nt=Nt.filter(Ot=>!Ot.groupId).length,$t=new Map;for(const Ot of Nt)Ot.groupId&&$t.set(Ot.groupId,($t.get(Ot.groupId)||0)+1);const Bt=H==="all"?Nt.length:Nt.filter(Ot=>Ot.groupId?Se.has(Ot.groupId):Se.has("__ungrouped__")).length,qn=Ot=>{const ws=new Set(Se);ws.has(Ot)?ws.delete(Ot):ws.add(Ot);const Hs=Array.from(ws);d(Z=>({...Z,multiAccountGroupIds:Hs})),window.api.proxyUpdateConfig({multiAccountGroupIds:Hs}),Ct({mode:"groups",groupIds:Hs})};return e.jsxs("div",{className:"col-span-2 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(Fe,{className:"text-sm shrink-0",children:[s?"Scope":"Phạm vi",":"]}),e.jsx("div",{className:"flex gap-1 bg-muted/30 rounded-lg p-0.5",children:["all","groups"].map(Ot=>{const ws=H===Ot,Hs=Ot==="all"?s?"All Accounts":"Tất cả tài khoản":s?"Specific Groups":"Nhóm đã chọn";return e.jsx("button",{type:"button",disabled:r,className:`px-3 py-1 rounded-md text-xs font-medium transition-all ${ws?"bg-primary text-primary-foreground shadow-sm":"text-muted-foreground hover:text-foreground hover:bg-muted/50"} disabled:opacity-50 disabled:cursor-not-allowed`,onClick:()=>{d(Z=>({...Z,multiAccountSelectionMode:Ot})),window.api.proxyUpdateConfig({multiAccountSelectionMode:Ot}),Ct({mode:Ot,groupIds:Array.from(Se)})},children:Hs},Ot)})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:H==="all"?s?`${Bt} active accounts`:`${Bt} tài khoản hoạt động`:s?`${Bt} accounts in selected groups`:`${Bt} tài khoản trong nhóm đã chọn`})]}),H==="groups"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pl-[60px]",children:[e.jsxs("button",{type:"button",disabled:r,onClick:()=>qn("__ungrouped__"),className:`flex items-center gap-1 px-2 h-7 rounded-md text-xs font-medium border transition-all ${Se.has("__ungrouped__")?"bg-muted text-foreground border-muted-foreground/30":"bg-background text-muted-foreground border-border hover:text-foreground hover:border-primary/40"} disabled:opacity-50 disabled:cursor-not-allowed`,children:[Se.has("__ungrouped__")&&e.jsx(Pt,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Ungrouped":"Chưa nhóm"}),e.jsxs("span",{className:"text-[10px] opacity-70",children:["(",nt,")"]})]}),Xe.map(Ot=>{const ws=Se.has(Ot.id),Hs=$t.get(Ot.id)||0;return e.jsxs("button",{type:"button",disabled:r,onClick:()=>qn(Ot.id),className:`flex items-center gap-1 px-2 h-7 rounded-md text-xs font-medium border transition-all ${ws?"text-foreground":"bg-background text-muted-foreground border-border hover:text-foreground hover:border-primary/40"} disabled:opacity-50 disabled:cursor-not-allowed`,style:ws?{backgroundColor:(Ot.color||"#888")+"22",borderColor:(Ot.color||"#888")+"66"}:void 0,children:[ws&&e.jsx(Pt,{className:"h-3 w-3",style:{color:Ot.color||void 0}}),e.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:Ot.color||"#888"}}),e.jsx("span",{children:Ot.name}),e.jsxs("span",{className:"text-[10px] opacity-70",children:["(",Hs,")"]})]},Ot.id)}),Xe.length===0&&e.jsx("span",{className:"text-xs text-muted-foreground italic",children:s?"No groups defined yet. Create groups in Account Manager first.":"Chưa có nhóm nào. Hãy tạo nhóm trong trang Tài khoản trước."})]})]})})(),!o.enableMultiAccount&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-2",children:e.jsxs(D,{variant:"outline",className:"w-full justify-start",onClick:()=>xe(!0),disabled:r,children:[e.jsx(Rv,{className:"h-4 w-4 mr-2"}),o.selectedAccountId?(()=>{const H=Ze.get(o.selectedAccountId);return H?H.email||H.id.substring(0,12)+"...":s?"First Available":"Tài khoản khả dụng đầu tiên"})():s?"First Available":"Tài khoản khả dụng đầu tiên"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"autoSwitchOnQuotaExhausted",checked:o.autoSwitchOnQuotaExhausted||!1,onCheckedChange:H=>{d(Se=>({...Se,autoSwitchOnQuotaExhausted:H})),window.api.proxyUpdateConfig({autoSwitchOnQuotaExhausted:H})},disabled:r}),e.jsx(Fe,{htmlFor:"autoSwitchOnQuotaExhausted",className:"text-sm cursor-pointer truncate",title:s?"Auto-switch on quota exhausted":"Tự chuyển khi tài khoản hết hạn mức",children:s?"Auto-switch":"Tự chuyển"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"logRequests",checked:o.logRequests,onCheckedChange:H=>{d(Se=>({...Se,logRequests:H})),window.api.proxyUpdateConfig({logRequests:H})}}),e.jsx(Fe,{htmlFor:"logRequests",className:"text-sm cursor-pointer",children:s?"Log Requests":"Ghi log request"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"logStreamEvents",checked:o.logStreamEvents||!1,onCheckedChange:H=>{d(Se=>({...Se,logStreamEvents:H})),window.api.proxyUpdateConfig({logStreamEvents:H})}}),e.jsx(Fe,{htmlFor:"logStreamEvents",className:"text-sm cursor-pointer",children:s?"Stream Events":"Sự kiện stream"})]})]}),e.jsxs("div",{className:"border-t border-border pt-3 overflow-visible",children:[e.jsxs("h4",{className:"text-xs font-medium mb-2 text-muted-foreground uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(Ka,{className:"h-3.5 w-3.5"}),s?"Advanced Settings":"Cài đặt nâng cao"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-x-3 gap-y-3 items-start overflow-visible",children:[e.jsxs("div",{className:"space-y-1.5 relative z-20",children:[e.jsx(Fe,{htmlFor:"preferredEndpoint",className:"text-xs",children:s?"Preferred Endpoint":"Endpoint ưu tiên"}),e.jsx(ei,{value:o.preferredEndpoint||"",options:[{value:"",label:s?"Auto Select":"Tự chọn",description:s?"Auto select based on availability":"Tự chọn endpoint theo khả dụng"},{value:"codewhisperer",label:"CodeWhisperer",description:s?"IDE mode endpoint":"Endpoint chế độ IDE"},{value:"amazonq",label:"AmazonQ",description:s?"IDE mode (q.amazonaws.com)":"Chế độ IDE (q.amazonaws.com)"},{value:"amazonq-cli",label:"AmazonQ CLI",description:s?"CLI mode (SendMessageStreaming)":"Chế độ CLI (SendMessageStreaming)"}],onChange:H=>{const Se=H||void 0;d(Xe=>({...Xe,preferredEndpoint:Se})),window.api.proxyUpdateConfig({preferredEndpoint:Se})},placeholder:s?"Select endpoint":"Chọn endpoint"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"maxRetries",className:"text-xs",children:s?"Max Retries":"Số lần thử lại tối đa"}),e.jsx(it,{id:"maxRetries",type:"number",min:0,max:10,value:o.maxRetries||3,onChange:H=>{const Se=parseInt(H.target.value)||3;d(Xe=>({...Xe,maxRetries:Se})),window.api.proxyUpdateConfig({maxRetries:Se})},disabled:r,className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"payloadSizeLimit",className:"text-xs",title:s?"When payload exceeds this limit, oldest tool results will be truncated. Default 1536KB (1.5MB).":"Khi payload vượt giới hạn này, kết quả tool cũ nhất sẽ bị cắt. Mặc định 1536KB (1.5MB).",children:"Payload (KB)"}),e.jsx(it,{id:"payloadSizeLimit",type:"number",min:256,max:10240,step:128,value:o.payloadSizeLimitKB||1536,onChange:H=>{const Se=parseInt(H.target.value)||1536;d(Xe=>({...Xe,payloadSizeLimitKB:Se})),window.api.proxyUpdateConfig({payloadSizeLimitKB:Se})},disabled:r,className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"clientDrivenToolExecution",className:"text-xs",title:s?"Recommended for OpenCode and Claude Code. Disable only when the proxy should fabricate tool results.":"Khuyến nghị cho OpenCode và Claude Code. Chỉ tắt khi muốn proxy tự tạo kết quả tool.",children:s?"Tool Execution":"Thực thi tool"}),e.jsxs("div",{className:"flex items-center justify-between h-9 px-3 rounded-md border border-input bg-transparent",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Client-driven":"Client xử lý"}),e.jsx(is,{id:"clientDrivenToolExecution",checked:o.clientDrivenToolExecution!==!1,onCheckedChange:H=>{d(Se=>({...Se,clientDrivenToolExecution:H})),window.api.proxyUpdateConfig({clientDrivenToolExecution:H})},disabled:r,className:"scale-90"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"disableTools",className:"text-xs",title:s?"When enabled, the proxy strips all tool definitions from requests.":"Khi bật, proxy sẽ loại bỏ toàn bộ định nghĩa tool khỏi request, phù hợp chat thuần.",children:s?"Disable Tools":"Tắt gọi tool"}),e.jsxs("div",{className:"flex items-center justify-between h-9 px-3 rounded-md border border-input bg-transparent",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"No tool calls":"Không gọi tool"}),e.jsx(is,{id:"disableTools",checked:o.disableTools||!1,onCheckedChange:H=>{d(Se=>({...Se,disableTools:H})),window.api.proxyUpdateConfig({disableTools:H})},disabled:r,className:"scale-90"})]})]}),e.jsxs("div",{className:"col-span-3 space-y-1.5",children:[e.jsx(Fe,{htmlFor:"tokenBufferReserve",className:"text-xs",title:s?"When enabled, reserves N tokens below context window for trim (e.g. 200K → trim at 180K). When disabled, never trims.":"Khi bật, chừa N token dưới context window để làm ngưỡng cắt (ví dụ 200K -> cắt ở 180K). Khi tắt sẽ không cắt lịch sử.",children:s?"Token Buffer Reserve (auto-trim history)":"Dự phòng token (tự cắt lịch sử)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between h-9 px-3 rounded-md border border-input bg-transparent w-[160px] flex-shrink-0",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Auto-trim":"Bật tự cắt"}),e.jsx(is,{id:"enableTokenBufferReserve",checked:o.enableTokenBufferReserve||!1,onCheckedChange:H=>{d(Se=>({...Se,enableTokenBufferReserve:H})),window.api.proxyUpdateConfig({enableTokenBufferReserve:H})},disabled:r,className:"scale-90"})]}),e.jsx(it,{id:"tokenBufferReserve",type:"number",min:5e3,max:15e4,step:1e3,value:o.tokenBufferReserve||2e4,onChange:H=>{const Se=parseInt(H.target.value)||2e4;d(Xe=>({...Xe,tokenBufferReserve:Se})),window.api.proxyUpdateConfig({tokenBufferReserve:Se})},disabled:r||!o.enableTokenBufferReserve,placeholder:s?"Reserve tokens (default 20000)":"Số token dự phòng (mặc định 20000)",className:"h-9 flex-1"})]})]})]})]})]})]}),e.jsx(UI,{config:o,setConfig:d,isRunning:r,isEn:s}),r&&e.jsxs("div",{className:"grid grid-cols-6 gap-3",children:[e.jsx(De,{className:"hover-lift bg-gradient-to-br from-blue-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Fn,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Pool":"Pool tài khoản"})]}),e.jsxs("div",{className:"text-xl font-bold text-foreground",children:[v,"/",y]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-purple-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Total":"Tổng request"})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-4 w-4 text-muted-foreground hover:text-destructive",onClick:async()=>{await window.api.proxyResetRequestStats();const H=await window.api.proxyGetStatus();H.stats&&h(H.stats),H.sessionStats&&p(H.sessionStats)},title:s?"Reset Statistics":"Đặt lại thống kê",children:e.jsx(gr,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-xl font-bold text-foreground",children:u?.totalRequests||0})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-green-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Pt,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Total S/F":"Tổng thành công/lỗi"})]}),e.jsxs("div",{className:"text-xl font-bold",children:[e.jsx("span",{className:"text-success",children:u?.successRequests||0}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-destructive",children:u?.failedRequests||0})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-cyan-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ds,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Session":"Phiên này"})]}),e.jsx("div",{className:"text-xl font-bold text-foreground",children:f?.totalRequests||0})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-orange-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Session S/F":"Phiên thành công/lỗi"})]}),e.jsxs("div",{className:"text-xl font-bold",children:[e.jsx("span",{className:"text-success",children:f?.successRequests||0}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-destructive",children:f?.failedRequests||0})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-primary/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Gn,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Uptime":"Thời gian chạy"})]}),e.jsx("div",{className:"text-xl font-bold text-primary whitespace-nowrap",children:Tt(je)})]})})]}),r&&u&&e.jsxs("div",{className:"grid grid-cols-6 gap-3",children:[e.jsx(De,{className:"hover-lift bg-gradient-to-br from-indigo-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Total Tokens":"Tổng token"})]}),e.jsx("div",{className:"text-xl font-bold text-indigo-500",title:((u.inputTokens||0)+(u.outputTokens||0)).toLocaleString(),children:zl((u.inputTokens||0)+(u.outputTokens||0))})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-blue-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Input / Output":"Đầu vào / Đầu ra"})]}),e.jsxs("div",{className:"text-sm font-bold",children:[e.jsx("span",{className:"text-blue-500",title:(u.inputTokens||0).toLocaleString(),children:zl(u.inputTokens||0)}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-purple-500",title:(u.outputTokens||0).toLocaleString(),children:zl(u.outputTokens||0)})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-emerald-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(ai,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Cache Hit":"Cache hit"}),(()=>{const H=u.cacheReadTokens||0,Se=H+(u.cacheWriteTokens||0),Xe=Se>0?H/Se*100:0;return Xe>0?e.jsxs($e,{variant:"secondary",className:"ml-1 text-[10px] px-1 py-0",children:[Xe.toFixed(0),"%"]}):null})()]}),e.jsxs("div",{className:"text-sm font-bold",children:[e.jsx("span",{className:"text-emerald-500",title:`${s?"Cache Read":"Đọc cache"}: ${(u.cacheReadTokens||0).toLocaleString()}`,children:zl(u.cacheReadTokens||0)}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-amber-500",title:`${s?"Cache Write":"Ghi cache"}: ${(u.cacheWriteTokens||0).toLocaleString()}`,children:zl(u.cacheWriteTokens||0)})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-violet-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ds,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Reasoning":"Token suy luận"})]}),e.jsx("div",{className:"text-xl font-bold text-violet-500",title:(u.reasoningTokens||0).toLocaleString(),children:zl(u.reasoningTokens||0)})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-green-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Rv,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Success Rate":"Tỷ lệ thành công"})]}),e.jsx("div",{className:"text-xl font-bold text-success",children:u.totalRequests>0?`${(u.successRequests/u.totalRequests*100).toFixed(1)}%`:"-"})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-amber-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Sc,{className:"h-3 w-3"}),e.jsx("span",{children:"Credits"})]}),e.jsx("div",{className:"text-xl font-bold text-amber-500",children:(u.totalCredits||0).toFixed(4)})]})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),s?"API Endpoints":"Endpoint API"]})}),e.jsxs(Pe,{className:"space-y-1.5 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/chat/completions"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"OpenAI Compatible":"Tương thích OpenAI"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/responses"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"OpenAI Responses"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/messages"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Claude Compatible":"Tương thích Claude"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/anthropic/v1/messages"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Claude Code"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/messages/count_tokens"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Token Count":"Đếm token"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/models"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Model List":"Danh sách model"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1beta/models/*:generateContent"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Gemini Compatible":"Tương thích Gemini"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1beta/models"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Gemini Models":"Model Gemini"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/health"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Health Check":"Kiểm tra health"})]}),e.jsxs("div",{className:"border-t pt-2 mt-2 space-y-1.5",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:s?"Admin API (Requires API Key)":"Admin API (cần API Key)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/admin/stats"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Detailed Stats":"Thống kê chi tiết"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/admin/accounts"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Account List":"Danh sách tài khoản"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/admin/logs"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Request Logs":"Log request"})]})]})]})]}),R.length>0&&e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Ks,{className:"h-4 w-4 text-primary"})}),s?"Recent Requests":"Request gần đây"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{variant:"secondary",className:"text-xs",children:R.length}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>K(!0),children:[e.jsx(xr,{className:"h-3 w-3 mr-1"}),s?"View All":"Xem tất cả"]}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>te(!0),children:[e.jsx(Ks,{className:"h-3 w-3 mr-1"}),s?"Detailed Logs":"Log chi tiết"]})]})]})}),e.jsx(Pe,{className:"pt-2",children:e.jsx("div",{className:"max-h-[150px] overflow-y-auto text-xs font-mono space-y-0.5",children:R.slice(0,5).map((H,Se)=>e.jsxs("div",{className:"grid gap-2 py-1 px-2 rounded hover:bg-muted/50 items-center",style:{gridTemplateColumns:"2fr 1fr 1.2fr 0.5fr 0.8fr 0.8fr 0.8fr 0.8fr 0.6fr"},children:[e.jsx("span",{className:"text-muted-foreground whitespace-nowrap text-left",children:H.time}),e.jsx("span",{className:"truncate text-left",title:H.path,children:H.path}),e.jsx("span",{className:"truncate text-left text-muted-foreground",title:H.model,children:H.model?H.model.replace("anthropic.","").replace("-v1:0",""):"-"}),e.jsx("span",{className:`text-center ${H.status>=400?"text-destructive":"text-success"}`,children:H.status}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.inputTokens?H.inputTokens.toLocaleString():"-"}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.outputTokens?H.outputTokens.toLocaleString():"-"}),e.jsx("span",{className:"text-success text-right",children:H.cacheReadTokens?H.cacheReadTokens.toLocaleString():"-"}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.credits?H.credits.toFixed(4):"-"}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.responseTime?`${(H.responseTime/1e3).toFixed(1)}s`:"-"})]},Se))})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Ds,{className:"h-4 w-4 text-primary"})}),s?"Supported Features":"Tính năng hỗ trợ"]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Auto Token Refresh":"Tự làm mới token"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Request Retry":"Tự thử lại request"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Multi-Account Rotation":"Xoay tua nhiều tài khoản"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"IDC/Social Auth":"Xác thực IDC/Social"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Agentic Mode Detection":"Nhận diện chế độ agentic"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Thinking Mode Support":"Hỗ trợ thinking mode"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Image Processing":"Xử lý hình ảnh"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Usage Statistics":"Thống kê sử dụng"})]})]})})]}),e.jsx($I,{open:be,onOpenChange:K,logs:R,totalCredits:u?.totalCredits||0,totalTokens:(u?.inputTokens||0)+(u?.outputTokens||0),onClearLogs:()=>{I([]),window.api.proxySaveLogs([])},onResetCredits:async()=>{await window.api.proxyResetCredits(),qe()},onResetTokens:async()=>{await window.api.proxyResetTokens(),qe()},isEn:s}),e.jsx(BI,{open:se,onOpenChange:te}),e.jsx(_I,{open:Y,onOpenChange:P,isEn:s,onOpenModelMapping:async()=>{try{const H=await window.api.proxyGetModels();H.success&&H.models&&X(H.models.map(Se=>({id:Se.id,name:Se.name||Se.id})))}catch{}P(!1),C(!0)},mappingCount:o.modelMappings?.length||0}),e.jsx(XI,{open:F,onOpenChange:fe,isEn:s}),e.jsx(VI,{open:pe,onOpenChange:C,isEn:s,mappings:o.modelMappings||[],onMappingsChange:H=>{d(Se=>({...Se,modelMappings:H})),window.api.proxyUpdateConfig({modelMappings:H})},apiKeys:(o.apiKeys||[]).map(H=>({id:H.id,name:H.name})),availableModels:z}),e.jsx(KI,{open:re,onOpenChange:xe,accounts:Ze,selectedAccountId:o.selectedAccountId,onSelect:H=>{d(Se=>({...Se,selectedAccountId:H})),window.api.proxyUpdateConfig({selectedAccountIds:H?[H]:[]})},isEn:s}),Oe&&Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>Ee(!1)}),e.jsxs("div",{className:"relative bg-background rounded-lg shadow-lg w-[800px] max-h-[80vh] overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s?"API Key Management":"Quản lý API Key"}),e.jsx(D,{variant:"ghost",size:"icon",onClick:()=>Ee(!1),children:"✕"})]}),e.jsx(FI,{})]})]}),document.body)]})}function ZI(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown";return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary shadow-lg shadow-primary/25",children:e.jsx(Sc,{className:"h-6 w-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:s?"API Proxy Service":"API 反代服务"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Provide OpenAI and Claude compatible API endpoints with multi-account rotation":"提供 OpenAI 和 Claude 兼容的 API 端点,支持多账号轮询"})]})]})]}),e.jsx(QI,{})]})}let wu=[],Rp=null,lj=!1;function JI(){lj||(lj=!0,window.api.onKproxyRequest(n=>{wu=[{timestamp:n.timestamp,host:n.host,method:n.method,path:n.path,isMitm:n.isMitm,deviceIdReplaced:n.deviceIdReplaced},...wu].slice(0,50),Rp?.(wu)}))}function eR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",[r,i]=g.useState(!1),[o,d]=g.useState(!1),[u,h]=g.useState(!1),[f,p]=g.useState({enabled:!1,port:8899,host:"127.0.0.1",mitmDomains:["amazonaws.com","amazon.com"],autoStart:!1,logRequests:!0}),[y,b]=g.useState(null),[v,N]=g.useState(null),[j,T]=g.useState(null),[S,k]=g.useState(!1),[R,I]=g.useState(!1),[M,G]=g.useState(wu),[W,U]=g.useState(null),q=g.useCallback(async()=>{try{const P=await window.api.kproxyCheckCaCertInstalled();U(P.installed)}catch{U(null)}},[]),V=g.useCallback(async()=>{if(!(o||u)){h(!0),T(null);try{const P=await window.api.kproxyInit();if(P.success){d(!0),P.caInfo&&N(P.caInfo);const F=await window.api.kproxyGetStatus();F.config&&p(F.config),F.stats&&b(F.stats),i(F.running)}else T(P.error||"Failed to initialize K-Proxy")}catch(P){T(P instanceof Error?P.message:"Init failed")}finally{h(!1)}}},[o,u]);g.useEffect(()=>{V(),q()},[V,q]),g.useEffect(()=>{JI(),Rp=G;const P=window.api.onKproxyStatusChange(fe=>{i(fe.running)}),F=window.api.onKproxyError(fe=>{T(fe)});return()=>{P(),F(),Rp=null}},[]);const le=async()=>{T(null);try{if(r){const F=await window.api.kproxyStop();F.success||T(F.error||"Failed to stop")}else{const F=await window.api.kproxyStart(f);F.success||T(F.error||"Failed to start")}const P=await window.api.kproxyGetStatus();i(P.running),P.stats&&b(P.stats)}catch(P){T(P instanceof Error?P.message:"Operation failed")}},B=async P=>{const F={...f,...P};p(F);try{await window.api.kproxyUpdateConfig(P)}catch(fe){console.error("Failed to update config:",fe)}},be=async()=>{try{const P=await window.api.kproxyGenerateDeviceId();P.success&&P.deviceId&&(await B({deviceId:P.deviceId}),await window.api.kproxySetDeviceId(P.deviceId))}catch(P){T(P instanceof Error?P.message:"Failed to generate device ID")}},K=()=>{const P=`${f.host}:${f.port}`;navigator.clipboard.writeText(P),k(!0),setTimeout(()=>k(!1),2e3)},se=()=>{f.deviceId&&(navigator.clipboard.writeText(f.deviceId),I(!0),setTimeout(()=>I(!1),2e3))},te=async()=>{try{const P=await window.api.kproxyExportCaCert();P.success||T(P.error||"Export failed")}catch(P){T(P instanceof Error?P.message:"Export failed")}},Y=P=>new Date(P).toLocaleTimeString();return o?e.jsxs("div",{className:"space-y-4",children:[j&&e.jsxs("div",{className:"bg-destructive/10 text-destructive px-4 py-2 rounded-md flex items-center gap-2",children:[e.jsx(ln,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:j}),e.jsx(D,{variant:"ghost",size:"sm",className:"ml-auto h-6 px-2",onClick:()=>T(null),children:"✕"})]}),e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:"K-Proxy MITM"}),e.jsx($e,{variant:r?"default":"secondary",className:me("ml-2",r&&"bg-green-500 hover:bg-green-600"),children:r?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-white opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-white"})]}),s?"Running":"运行中"]}):s?"Stopped":"已停止"})]}),e.jsx(D,{onClick:le,variant:r?"destructive":"default",size:"sm",children:r?e.jsxs(e.Fragment,{children:[e.jsx(Cn,{className:"h-4 w-4 mr-1"}),s?"Stop":"停止"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ba,{className:"h-4 w-4 mr-1"}),s?"Start":"启动"]})})]}),e.jsx(Gl,{children:s?"MITM proxy for replacing Machine ID in Kiro requests":"MITM 代理,用于替换 Kiro 请求中的 Machine ID"})]}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Sc,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s?"Proxy:":"代理地址:"}),e.jsxs("code",{className:"bg-muted px-2 py-1 rounded text-sm font-mono",children:[f.host,":",f.port]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:K,children:S?e.jsx(Pt,{className:"h-3 w-3 text-green-500"}):e.jsx(As,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:s?"Port":"端口"}),e.jsx(it,{type:"number",value:f.port,onChange:P=>B({port:parseInt(P.target.value)||8899}),disabled:r,className:"h-8"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:s?"Host":"监听地址"}),e.jsx(it,{value:f.host,onChange:P=>B({host:P.target.value}),disabled:r,className:"h-8"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Fe,{children:s?"Log Requests":"记录请求日志"})]}),e.jsx(is,{checked:f.logRequests,onCheckedChange:P=>B({logRequests:P})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ba,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Fe,{children:s?"Auto Start":"自动启动"})]}),e.jsx(is,{checked:f.autoStart,onCheckedChange:P=>B({autoStart:P})})]})]})]}),e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(eo,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"Device ID":"设备 ID"})]}),e.jsx(Gl,{children:s?"Machine ID to replace in requests (64 hex characters)":"替换请求中的 Machine ID(64位十六进制)"})]}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{value:f.deviceId||"",onChange:P=>{B({deviceId:P.target.value}),P.target.value.length===64&&window.api.kproxySetDeviceId(P.target.value)},placeholder:s?"Enter or generate device ID":"输入或生成设备 ID",className:"font-mono text-xs h-8"}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-8",onClick:be,children:[e.jsx(Dc,{className:"h-3 w-3 mr-1"}),s?"Generate":"生成"]}),f.deviceId&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 px-2",onClick:se,children:R?e.jsx(Pt,{className:"h-3 w-3 text-green-500"}):e.jsx(As,{className:"h-3 w-3"})})]}),f.deviceId&&e.jsx("p",{className:"text-xs text-muted-foreground",children:f.deviceId.length===64?s?"✓ Valid device ID format":"✓ 设备 ID 格式正确":s?`⚠ Invalid length: ${f.deviceId.length}/64`:`⚠ 长度不正确: ${f.deviceId.length}/64`})]})]}),e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"CA Certificate":"CA 证书"})]}),e.jsxs("div",{className:"flex gap-2",children:[W===!1?e.jsx(D,{variant:"default",size:"sm",onClick:async()=>{try{const P=await window.api.kproxyInstallCaCert();P.success?(U(!0),alert(P.message||(s?"Certificate installed":"证书已安装"))):alert(P.error||(s?"Failed to install":"安装失败"))}catch(P){alert(P instanceof Error?P.message:String(P))}},children:s?"Install":"安装"}):W===!0?e.jsx(D,{variant:"destructive",size:"sm",onClick:async()=>{try{const P=await window.api.kproxyUninstallCaCert();P.success?(U(!1),alert(P.message||(s?"Certificate uninstalled":"证书已卸载"))):alert(P.error||(s?"Failed to uninstall":"卸载失败"))}catch(P){alert(P instanceof Error?P.message:String(P))}},children:s?"Uninstall":"卸载"}):e.jsx(D,{variant:"outline",size:"sm",disabled:!0,children:s?"Checking...":"检测中..."}),e.jsxs(D,{variant:"outline",size:"sm",onClick:te,children:[e.jsx(Ns,{className:"h-3 w-3 mr-1"}),s?"Export":"导出"]})]})]}),e.jsx(Gl,{children:s?"Install this certificate to trust K-Proxy MITM":"安装此证书以信任 K-Proxy MITM 代理"})]}),v&&e.jsxs(Pe,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s?"Fingerprint:":"指纹:"}),e.jsx("code",{className:"bg-muted px-2 py-0.5 rounded text-xs font-mono truncate max-w-[300px]",children:v.fingerprint})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s?"Valid:":"有效期:"}),e.jsxs("span",{className:"text-xs",children:[new Date(v.validFrom).toLocaleDateString()," - ",new Date(v.validTo).toLocaleDateString()]})]})]})]}),y&&e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"Statistics":"统计"})]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid grid-cols-4 gap-4 text-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold",children:y.totalRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Total":"总请求"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-blue-500",children:y.mitmRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"MITM"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-green-500",children:y.modifiedRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Modified":"已修改"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-gray-500",children:y.bypassRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Bypass":"透传"})]})]})})]}),M.length>0&&e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ri,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"Recent Requests":"最近请求"})]})}),e.jsx(Pe,{children:e.jsx("div",{className:"space-y-1 max-h-48 overflow-y-auto",children:M.slice(0,10).map((P,F)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1 border-b last:border-0",children:[e.jsx("span",{className:"text-muted-foreground w-16",children:Y(P.timestamp)}),e.jsx($e,{variant:P.isMitm?"default":"secondary",className:"text-[10px] px-1 py-0",children:P.isMitm?"MITM":"PASS"}),P.deviceIdReplaced&&e.jsx($e,{variant:"outline",className:"text-[10px] px-1 py-0 text-green-600 border-green-600",children:"ID"}),e.jsx("span",{className:"font-mono truncate flex-1",children:P.host})]},F))})})]}),e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsx(rt,{className:"text-lg",children:s?"Usage Guide":"使用说明"})}),e.jsxs(Pe,{className:"text-sm text-muted-foreground space-y-2",children:[e.jsxs("p",{children:["1. ",s?"Export and install the CA certificate to your system trust store":"导出并安装 CA 证书到系统信任存储"]}),e.jsxs("p",{children:["2. ",s?"Set your system/application proxy to":"设置系统/应用代理为"," ",e.jsxs("code",{className:"bg-muted px-1 rounded",children:[f.host,":",f.port]})]}),e.jsxs("p",{children:["3. ",s?"Generate or enter a device ID to use for requests":"生成或输入用于请求的设备 ID"]}),e.jsxs("p",{children:["4. ",s?"Start the proxy and use Kiro IDE normally":"启动代理后正常使用 Kiro IDE"]})]})]})]}):u||!j?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-4",children:[e.jsx(bt,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Initializing K-Proxy...":"正在初始化 K-Proxy..."})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-4",children:[e.jsx(ln,{className:"h-8 w-8 text-destructive"}),e.jsx("p",{className:"text-destructive",children:j}),e.jsxs(D,{onClick:V,children:[e.jsx(Mt,{className:"h-4 w-4 mr-2"}),s?"Retry":"重试"]})]})}function tR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown";return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-purple-500/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-purple-500/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-purple-500 shadow-lg shadow-purple-500/25",children:e.jsx(Vn,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-purple-600 dark:text-purple-400",children:"K-Proxy MITM"}),e.jsx("p",{className:"text-muted-foreground",children:s?"MITM proxy for Machine ID replacement, reduces ban risk":"MITM 代理,替换 Machine ID,降低封禁风险"})]})]})]}),e.jsx(eR,{})]})}const sR=[{value:"round_robin",label:"轮询",labelEn:"Round Robin",desc:"依次使用每个代理",descEn:"Use each proxy in sequence"},{value:"random",label:"随机",labelEn:"Random",desc:"随机挑选",descEn:"Pick randomly"},{value:"least_used",label:"最少使用",labelEn:"Least Used",desc:"使用次数少的优先",descEn:"Prefer proxies used less"},{value:"fastest",label:"最快优先",labelEn:"Fastest",desc:"按延迟升序",descEn:"Sort by latency asc"}];function nR({diag:n,isEn:s}){if(!n.success||!n.diagnose)return e.jsxs("div",{className:"mt-2 text-[11px] rounded-md bg-red-500/10 border border-red-500/30 text-red-700 dark:text-red-400 px-2 py-1.5",children:[s?"Diagnose failed: ":"诊断失败:",n.error||"unknown error"]});const r=n.diagnose,i=({ok:o,label:d,rt:u,err:h})=>e.jsxs("div",{className:"flex items-start gap-2 text-[11px]",children:[e.jsx("span",{className:me("mt-0.5 inline-flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-bold",o?"bg-green-500/20 text-green-600 dark:text-green-400":"bg-red-500/20 text-red-600 dark:text-red-400"),children:o?"✓":"✗"}),e.jsxs("span",{className:"flex-1",children:[e.jsx("span",{className:"text-foreground",children:d}),u!==void 0&&e.jsxs("span",{className:"ml-1 text-muted-foreground font-mono",children:[u,"ms"]}),h&&e.jsx("div",{className:"mt-0.5 text-red-600 dark:text-red-400 break-all",children:h})]})]});return e.jsxs("div",{className:"mt-2 space-y-1.5 rounded-md border border-border bg-card/50 px-3 py-2",children:[e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono truncate",children:["target: ",n.targetUrl.replace(/:([^:@/]+)@/,":***@")]}),e.jsx(i,{ok:r.upstreamReachable,label:s?"A) Upstream TCP reachable":"A) 上游中转 TCP 可达",rt:r.upstreamRtMs,err:r.upstreamError}),e.jsx(i,{ok:r.targetReachable,label:s?"B) Via upstream → target proxy entry":"B) 经上游 → 目标代理入口",rt:r.targetRtMs,err:r.targetError}),e.jsx(i,{ok:r.endToEndOk===!0,label:s?`C) End-to-end CONNECT (status ${r.targetStatus??"?"} ${r.targetStatusText??""})`.trim():`C) 端到端 CONNECT(状态 ${r.targetStatus??"?"} ${r.targetStatusText??""})`.trim(),rt:r.endToEndRtMs,err:r.endToEndError}),r.targetBodySnippet&&e.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground font-mono break-all",children:["body: ",r.targetBodySnippet.slice(0,160)]})]})}function aR(n){const s={total:n.length,enabled:0,alive:0,slow:0,dead:0,untested:0,testing:0,totalUsed:0,totalFailed:0,totalSuccess:0,successRate:null,avgLatencyMs:null,topUsed:[]};let r=0,i=0;for(const o of n)o.enabled&&s.enabled++,o.status==="alive"?s.alive++:o.status==="slow"?s.slow++:o.status==="dead"?s.dead++:o.status==="untested"?s.untested++:o.status==="testing"&&s.testing++,s.totalUsed+=o.usedCount,s.totalFailed+=o.failCount,o.latencyMs&&(o.status==="alive"||o.status==="slow")&&(r+=o.latencyMs,i++);return s.totalSuccess=Math.max(0,s.totalUsed-s.totalFailed),s.successRate=s.totalUsed>0?s.totalSuccess/s.totalUsed:null,s.avgLatencyMs=i>0?Math.round(r/i):null,s.topUsed=n.slice().filter(o=>o.usedCount>0).sort((o,d)=>d.usedCount-o.usedCount).slice(0,5).map(o=>{const d=Math.max(0,o.usedCount-o.failCount);return{id:o.id,label:o.label||`${o.protocol}://${o.host}:${o.port}`,used:o.usedCount,failed:o.failCount,success:d,rate:o.usedCount>0?d/o.usedCount:null,status:o.status}}),s}function Ul({label:n,value:s,sub:r,tone:i}){const o=i==="green"?"text-green-600 dark:text-green-400":i==="amber"?"text-amber-600 dark:text-amber-400":i==="red"?"text-red-600 dark:text-red-400":i==="blue"?"text-blue-600 dark:text-blue-400":"text-foreground";return e.jsxs("div",{className:"rounded-lg border border-border bg-card/50 px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("div",{className:me("mt-0.5 text-lg font-semibold tabular-nums",o),children:s}),r!==void 0&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:r})]})}function rR({stats:n,isEn:s}){if(n.total===0)return null;const r=n.total>0?(n.alive+n.slow)/n.total:0,i=n.successRate!==null?Math.round(n.successRate*100):null,o=i===null?"default":i>=80?"green":i>=50?"amber":"red",d=n.total===0?"default":r>=.7?"green":r>=.3?"amber":"red";return e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ks,{className:"h-4 w-4 text-primary"}),s?"Pool Health Dashboard":"代理池健康看板"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2",children:[e.jsx(Ul,{label:s?"Total / Enabled":"总数 / 已启用",value:e.jsxs(e.Fragment,{children:[n.total,e.jsxs("span",{className:"text-muted-foreground text-base",children:[" / ",n.enabled]})]})}),e.jsx(Ul,{label:s?"Availability":"可用率",value:`${Math.round(r*100)}%`,sub:`${n.alive+n.slow} ${s?"alive":"可用"}`,tone:d}),e.jsx(Ul,{label:s?"Success Rate":"成功率",value:i!==null?`${i}%`:"—",sub:`${n.totalSuccess} / ${n.totalUsed}`,tone:o}),e.jsx(Ul,{label:s?"Avg Latency":"平均延迟",value:n.avgLatencyMs!==null?`${n.avgLatencyMs}ms`:"—",tone:"blue"}),e.jsx(Ul,{label:s?"Dead":"失效",value:n.dead,tone:n.dead>0?"red":"default"}),e.jsx(Ul,{label:s?"Untested":"未测试",value:n.untested+n.testing,tone:n.untested>0?"amber":"default"})]}),n.topUsed.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs text-muted-foreground",children:s?`Top ${n.topUsed.length} most used proxies`:`承担量 Top ${n.topUsed.length}`}),e.jsx("div",{className:"space-y-1.5",children:n.topUsed.map(u=>{const h=u.rate!==null?Math.round(u.rate*100):null,f=u.rate!==null?u.rate*100:0,p=h===null?"bg-muted-foreground/30":h>=80?"bg-green-500":h>=50?"bg-amber-500":"bg-red-500";return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(lw,{status:u.status}),e.jsx("span",{className:"font-mono text-[11px] truncate",children:u.label})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:[u.success,"/",u.used,h!==null&&e.jsxs("span",{className:"ml-1.5 font-medium text-foreground",children:[h,"%"]})]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:me("h-full transition-all",p),style:{width:`${f}%`}})})]},u.id)})})]})]})]})}function lw({status:n,latency:s}){const r={untested:{color:"bg-muted text-muted-foreground",label:"未测试",labelEn:"Untested"},testing:{color:"bg-blue-500/15 text-blue-600 dark:text-blue-400",label:"测试中",labelEn:"Testing"},alive:{color:"bg-green-500/15 text-green-600 dark:text-green-400",label:"可用",labelEn:"Alive"},slow:{color:"bg-amber-500/15 text-amber-600 dark:text-amber-400",label:"较慢",labelEn:"Slow"},dead:{color:"bg-red-500/15 text-red-600 dark:text-red-400",label:"失效",labelEn:"Dead"}}[n];return e.jsxs("span",{className:me("inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-medium",r.color),children:[n==="testing"&&e.jsx(bt,{className:"h-3 w-3 animate-spin"}),n==="alive"&&e.jsx(an,{className:"h-3 w-3"}),n==="slow"&&e.jsx(Ks,{className:"h-3 w-3"}),n==="dead"&&e.jsx(fs,{className:"h-3 w-3"}),e.jsx("span",{children:r.label}),s!==void 0&&(n==="alive"||n==="slow")&&e.jsxs("span",{className:"font-mono opacity-70",children:[s,"ms"]})]})}function iR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",{proxyPool:r,proxyPoolConfig:i,addProxy:o,importProxies:d,removeProxy:u,removeProxies:h,toggleProxyEnabled:f,updateProxy:p,validateProxy:y,validateProxiesBatch:b,clearProxyPool:v,setProxyPoolConfig:N,accounts:j,accountProxyBindings:T,unbindAccountFromProxy:S,clearAccountProxyBindings:k,autoDistributeAccountsToProxies:R}=vt(),[I,M]=g.useState(""),[G,W]=g.useState(""),[U,q]=g.useState(!1),[V,le]=g.useState(new Set),[B,be]=g.useState(""),[K,se]=g.useState("all"),[te,Y]=g.useState("all"),[P,F]=g.useState("all"),[fe,pe]=g.useState("all"),[C,z]=g.useState("all"),[X,re]=g.useState(!1),[xe,Oe]=g.useState(!1),[Ee,Qe]=g.useState(10),[_e,st]=g.useState(5),[oe,ue]=g.useState(!1),[ae,L]=g.useState(!1),[we,Ue]=g.useState(null),Lt=g.useCallback(async()=>{const O=i.upstreamProxy?.trim();if(!O)return;const ne=Array.from(r.values()),ze=ne.find(_=>_.enabled)||ne[0];if(ze){L(!0),Ue(null);try{const _=await window.api.proxyPoolDiagnoseChain({targetUrl:ze.url,upstreamProxy:O});Ue({targetUrl:ze.url,..._})}catch(_){Ue({targetUrl:ze.url,success:!1,error:_ instanceof Error?_.message:String(_)})}finally{L(!1)}}},[r,i.upstreamProxy]),xt=g.useMemo(()=>Array.from(r.values()),[r]),Qt=g.useMemo(()=>aR(xt),[xt]),ft=g.useMemo(()=>{const ne=Array.from(j.values()).filter(Ve=>Ve.status==="active").length,ze=Object.keys(T).filter(Ve=>j.has(Ve)).length,_=xt.filter(Ve=>Ve.enabled&&Ve.status!=="dead"),ce={};for(const[Ve,je]of Object.entries(T))j.has(Ve)&&(ce[je]=(ce[je]||0)+1);const Ce=Object.entries(ce).filter(([,Ve])=>Ve>10).map(([Ve,je])=>({pid:Ve,count:je,proxy:r.get(Ve)}));return{totalActive:ne,boundCount:ze,unboundCount:ne-ze,aliveProxyCount:_.length,perProxy:ce,overloadedProxies:Ce}},[j,T,xt,r]),Et=g.useRef(0);g.useEffect(()=>{const O=i.autoValidateIntervalMin;if(!O||O<=0)return;const ze=setInterval(()=>{const _=Date.now();if(_-Et.current<O*6e4)return;const ce=Array.from(r.values()).filter(Ce=>Ce.enabled).map(Ce=>Ce.id);ce.length!==0&&(Et.current=_,console.log(`[ProxyPool] Auto-validate ${ce.length} proxies`),b(ce,i.autoValidateConcurrency||5))},6e4);return()=>clearInterval(ze)},[i.autoValidateIntervalMin,i.autoValidateConcurrency,r,b]);const Ge=g.useCallback(O=>{if(ft.aliveProxyCount===0){alert(s?"No alive proxies. Validate proxies first.":"没有可用代理,请先验活代理");return}const ne=Array.from(j.values()).filter(_=>_.status==="active").map(_=>_.id);if(ne.length===0){alert(s?"No active accounts.":"没有可用账号");return}const ze=R({accountsPerProxy:_e,onlyUnbound:O,accountIds:ne});alert(s?`Distributed ${ze.distributed} accounts, skipped ${ze.skipped}`:`已分配 ${ze.distributed} 个账号,跳过 ${ze.skipped}`)},[j,_e,R,ft.aliveProxyCount,s]),gt=g.useMemo(()=>{let O=0,ne=0,ze=0,_=0,ce=0;for(const Ce of xt)Ce.enabled&&ce++,Ce.status==="alive"?O++:Ce.status==="dead"?ne++:Ce.status==="slow"?ze++:Ce.status==="untested"&&_++;return{total:xt.length,alive:O,dead:ne,slow:ze,untested:_,enabled:ce}},[xt]),Ze=g.useMemo(()=>{const O=Date.now(),ne=3600*1e3,ze=24*ne;return xt.filter(_=>{if(K!=="all"&&_.status!==K||te!=="all"&&_.protocol!==te||P==="enabled"&&!_.enabled||P==="disabled"&&_.enabled)return!1;if(fe!=="all"){const ce=_.latencyMs;if(fe==="unknown"){if(typeof ce=="number")return!1}else{if(typeof ce!="number")return!1;if(fe==="fast"&&ce>=200||fe==="medium"&&(ce<200||ce>=1e3)||fe==="slow"&&ce<1e3)return!1}}if(C!=="all")if(C==="never"){if(_.lastTestedAt)return!1}else if(_.lastTestedAt){const ce=O-_.lastTestedAt;if(C==="1h"&&ce>ne||C==="1d"&&ce>ze||C==="7d"&&ce>7*ze)return!1}else return!1;if(B){const ce=B.toLowerCase().trim();if(![_.host,String(_.port),_.protocol,_.username||"",_.label||"",_.lastBoundEmail||"",_.url||"",(_.tags||[]).join(" "),_.source||""].join(" ").toLowerCase().includes(ce))return!1}return!0})},[xt,B,K,te,P,fe,C]),J=g.useMemo(()=>{let O=0;return te!=="all"&&O++,P!=="all"&&O++,fe!=="all"&&O++,C!=="all"&&O++,O},[te,P,fe,C]),Ne=g.useCallback(()=>{Y("all"),F("all"),pe("all"),z("all")},[]),et=g.useCallback(()=>{if(!I.trim())return;o(I.trim())?M(""):alert(s?"Invalid proxy URL or duplicate":"代理 URL 无效或重复")},[I,o,s]),qe=g.useCallback(()=>{if(!G.trim())return;const O=d(G);alert(s?`Imported: added ${O.added}, skipped ${O.skipped}, failed ${O.failed}`:`导入完成:新增 ${O.added},跳过 ${O.skipped},失败 ${O.failed}`),W(""),q(!1)},[G,d,s]),Je=g.useCallback(async()=>{const O=Ze.map(ne=>ne.id);if(O.length!==0){Oe(!0);try{await b(O,Ee)}finally{Oe(!1)}}},[Ze,b,Ee]),Kt=g.useCallback(async()=>{const O=Array.from(V);if(O.length!==0){Oe(!0);try{await b(O,Ee)}finally{Oe(!1)}}},[V,b,Ee]),Ye=g.useCallback(()=>{V.size!==0&&confirm(s?`Delete ${V.size} proxies?`:`确定删除 ${V.size} 个代理?`)&&(h(Array.from(V)),le(new Set))},[V,h,s]),qt=g.useCallback(()=>{const O=xt.filter(ne=>ne.status==="dead").map(ne=>ne.id);O.length!==0&&confirm(s?`Remove ${O.length} dead proxies?`:`确定移除 ${O.length} 个失效代理?`)&&h(O)},[xt,h,s]),Jt=O=>{le(ne=>{const ze=new Set(ne);return ze.has(O)?ze.delete(O):ze.add(O),ze})},Ct=()=>{V.size===Ze.length&&Ze.length>0?le(new Set):le(new Set(Ze.map(O=>O.id)))};return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-cyan-500/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-cyan-500/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-cyan-500 shadow-lg shadow-cyan-500/25",children:e.jsx(Ki,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-cyan-600 dark:text-cyan-400",children:s?"Proxy Pool":"代理池"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Proxy routing for registration tasks. Use only for legitimate network configuration; it does not bypass provider risk controls.":"注册任务的代理路由配置。仅用于合规网络配置,不能绕过服务商风控。"})]})]})]}),e.jsx(rR,{stats:Qt,isEn:s}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ka,{className:"h-4 w-4 text-primary"}),s?"Pool Configuration":"池配置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(is,{checked:i.enabled,onCheckedChange:O=>N({enabled:O})}),e.jsxs("div",{children:[e.jsx(Fe,{className:"cursor-pointer text-sm",children:s?"Enable proxy pool for registration":"为注册流程启用代理池"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s?"When enabled, each registration task picks an available proxy by the strategy below.":"开启后,每个注册任务会按下方策略自动选取一个可用代理"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-xs",children:s?"Selection Strategy":"调度策略"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:sR.map(O=>e.jsx("button",{type:"button",onClick:()=>N({strategy:O.value}),className:me("px-3 py-1.5 rounded-md border text-xs transition-colors",i.strategy===O.value?"border-primary bg-primary/10 text-primary font-medium":"border-border hover:border-primary/50"),title:s?O.descEn:O.desc,children:s?O.labelEn:O.label},O.value))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{checked:i.autoDisableDead,onCheckedChange:O=>N({autoDisableDead:O})}),e.jsx(Fe,{className:"text-xs cursor-pointer",children:s?"Auto-disable on failure":"失败自动停用"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Failure threshold":"失败阈值"}),e.jsx(it,{type:"number",min:1,max:20,value:i.failureThreshold,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=1&&N({failureThreshold:ne})},className:"h-8 text-xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"IP Detection Endpoint":"IP 检测端点"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("select",{value:kf.find(O=>O.url===i.testUrl)?.id||"_custom",onChange:O=>{const ne=kf.find(ze=>ze.id===O.target.value);ne&&N({testUrl:ne.url})},className:"h-8 text-xs rounded-lg border border-foreground/15 bg-[var(--glass-bg)] backdrop-blur-md px-2 flex-shrink-0",children:[kf.map(O=>e.jsx("option",{value:O.id,children:O.label},O.id)),e.jsx("option",{value:"_custom",children:s?"Custom...":"自定义..."})]}),e.jsx(it,{value:i.testUrl,onChange:O=>N({testUrl:O.target.value}),placeholder:"https://api.ipify.org?format=json",className:"h-8 text-xs font-mono flex-1"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Fe,{className:"text-xs flex items-center gap-1",children:[e.jsx(Gn,{className:"h-3 w-3"}),s?"Auto-validate interval (min, 0=off)":"定时自动验活(分钟,0=关闭)"]}),e.jsx(it,{type:"number",min:0,max:1440,value:i.autoValidateIntervalMin,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=0&&N({autoValidateIntervalMin:ne})},className:"h-8 text-xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Auto-validate concurrency":"验活并发"}),e.jsx(it,{type:"number",min:1,max:50,value:i.autoValidateConcurrency,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=1&&N({autoValidateConcurrency:ne})},disabled:i.autoValidateIntervalMin===0,className:"h-8 text-xs"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Upstream relay proxy (proxy chaining)":"上游中转代理(代理链)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{value:i.upstreamProxy||"",onChange:O=>N({upstreamProxy:O.target.value}),placeholder:s?"e.g. socks5://127.0.0.1:7890 (empty = off)":"如 socks5://127.0.0.1:7890(留空=不启用)",className:"h-8 text-xs font-mono flex-1"}),e.jsxs(D,{size:"sm",variant:"outline",className:"h-8 px-3 text-xs whitespace-nowrap",disabled:!i.upstreamProxy?.trim()||r.size===0||ae,onClick:()=>void Lt(),title:s?"Diagnose proxy chain (locates failure layer)":"诊断代理链(定位失败在哪一层)",children:[ae?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(jx,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1",children:s?"Diagnose":"诊断"})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:s?"When set, traffic chains: local → relay → target proxy → site. Use only to satisfy your proxy provider routing or allowlist requirements. Supports http/socks5.":"填写后链路为:本机 → 上游中转 → 目标代理 → 目标站点。仅用于满足代理服务商的路由或白名单要求。支持 http/socks5。"}),we&&e.jsx(nR,{diag:we,isEn:s})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ts,{className:"h-4 w-4 text-primary"}),s?"Add Proxies":"添加代理"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(it,{value:I,onChange:O=>M(O.target.value),onKeyDown:O=>O.key==="Enter"&&et(),placeholder:s?"http://user:pass@host:port or host:port or socks5://...":"http://user:pass@host:port 或 host:port 或 socks5://...",className:"font-mono text-xs"}),e.jsxs(D,{onClick:et,disabled:!I.trim(),children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),s?"Add":"添加"]}),e.jsxs(D,{variant:"outline",onClick:()=>q(!U),children:[e.jsx(Fa,{className:"h-4 w-4 mr-1"}),s?"Bulk":"批量"]})]}),U&&e.jsxs("div",{className:"space-y-2 p-3 bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Fe,{className:"text-xs",children:s?"One proxy per line. Supports: http(s)://host:port, user:pass@host:port, host:port:user:pass, socks5://...":"每行一个代理。支持格式: http(s)://host:port、user:pass@host:port、host:port:user:pass、socks5://..."}),e.jsx("textarea",{value:G,onChange:O=>W(O.target.value),rows:5,className:"w-full px-3 py-2 bg-background border rounded-lg text-xs font-mono resize-none",placeholder:`http://127.0.0.1:7890
125
+ ${xe.message}${Oe}`;navigator.clipboard.writeText(Ee)},P=xe=>{const Oe=new Set(R);Oe.has(xe)?Oe.delete(xe):Oe.add(xe),I(Oe)},F=g.useMemo(()=>Array.from(new Set(o.map(xe=>xe.category))).sort(),[o]),fe=xe=>{switch(xe){case"1h":return 36e5;case"6h":return 6*36e5;case"12h":return 12*36e5;case"1d":return 864e5;case"3d":return 3*864e5;case"7d":return 7*864e5;case"30d":return 30*864e5;case"180d":return 180*864e5;case"1y":return 365*864e5;default:return 0}},pe=g.useMemo(()=>{const xe=Date.now(),Oe=fe(G),Ee=f.toLowerCase();let Qe=o.filter(_e=>{if(Oe>0){const st=new Date(_e.timestamp).getTime();if(xe-st>Oe)return!1}if(y!=="all"&&_e.level!==y||v!=="all"&&_e.category!==v)return!1;if(Ee){if(_e.message.toLowerCase().includes(Ee)||_e.category.toLowerCase().includes(Ee))return!0;if(_e.data)try{return JSON.stringify(_e.data).toLowerCase().includes(Ee)}catch{return!1}return!1}return!0});if(U!=="all"){const _e=parseInt(U);_e>0&&(Qe=Qe.slice(-_e))}return Qe},[o,G,y,v,f,U]),C=lo({count:pe.length,getScrollElement:()=>V.current,estimateSize:xe=>R.has(xe)?120:32,overscan:20});g.useEffect(()=>{j&&pe.length>0&&C.scrollToIndex(pe.length-1,{align:"end"})},[pe.length,j,C]);const z=xe=>{switch(xe){case"ERROR":return"bg-destructive/20 text-destructive border-destructive/30";case"WARN":return"bg-warning/20 text-warning border-warning/30";case"INFO":return"bg-primary/20 text-primary border-primary/30";case"DEBUG":return"bg-muted text-muted-foreground border-muted";default:return"bg-muted text-muted-foreground border-muted"}},X=xe=>{switch(xe){case"ERROR":return"bg-destructive/5 hover:bg-destructive/10";case"WARN":return"bg-warning/5 hover:bg-warning/10";case"INFO":return"hover:bg-primary/5";case"DEBUG":return"hover:bg-muted/50";default:return"hover:bg-muted/50"}},re=xe=>{try{if(!xe)return"-";const Oe=new Date(xe);if(isNaN(Oe.getTime()))return xe||"-";const Ee=Oe.getFullYear(),Qe=(Oe.getMonth()+1).toString().padStart(2,"0"),_e=Oe.getDate().toString().padStart(2,"0"),st=Oe.getHours().toString().padStart(2,"0"),oe=Oe.getMinutes().toString().padStart(2,"0"),ue=Oe.getSeconds().toString().padStart(2,"0"),ae=Oe.getMilliseconds().toString().padStart(3,"0");return`${Ee}-${Qe}-${_e} ${st}:${oe}:${ue}.${ae}`}catch{return xe||"-"}};return n?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:()=>s(!1),children:e.jsxs("div",{className:"glass-card-strong rounded-2xl shadow-2xl max-w-[90vw] w-[1200px] h-[80vh] flex flex-col overflow-hidden animate-in zoom-in-95 duration-200",onClick:xe=>xe.stopPropagation(),children:[e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-5 py-4 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx("svg",{className:"w-5 h-5 text-primary",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})})}),e.jsx("h2",{className:"text-lg font-semibold",children:i?"Proxy Detailed Logs":"反代详细日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ol,{value:G,onChange:W,className:"min-w-[70px]",options:[{value:"all",label:i?"All Time":"全部时间"},{value:"1h",label:i?"1 Hour":"1小时"},{value:"6h",label:i?"6 Hours":"6小时"},{value:"12h",label:i?"12 Hours":"12小时"},{value:"1d",label:i?"1 Day":"1天"},{value:"3d",label:i?"3 Days":"3天"},{value:"7d",label:i?"7 Days":"7天"},{value:"30d",label:i?"30 Days":"30天"},{value:"180d",label:i?"180 Days":"180天"},{value:"1y",label:i?"1 Year":"1年"}]}),e.jsx(Ol,{value:U,onChange:q,className:"min-w-[70px]",options:[{value:"all",label:i?"All":"全部"},{value:"5000",label:"5000"},{value:"10000",label:i?"10K":"1万"},{value:"50000",label:i?"50K":"5万"},{value:"100000",label:i?"100K":"10万"},{value:"200000",label:i?"200K":"20万"},{value:"500000",label:i?"500K":"50万"},{value:"1000000",label:i?"1M":"100万"}]}),e.jsxs($e,{variant:"secondary",className:"font-mono",children:[pe.length," / ",o.length," ",i?"entries":"条"]}),e.jsx(D,{variant:"ghost",size:"icon",className:"rounded-full hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex-shrink-0 flex items-center gap-2 px-4 py-2.5 border-b border-border",children:[e.jsxs("div",{className:"relative flex-1 min-w-[100px]",children:[e.jsx(to,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground"}),e.jsx(it,{placeholder:i?"Search logs...":"搜索日志内容...",value:f,onChange:xe=>p(xe.target.value),className:"pl-8 pr-8 h-8 text-xs bg-background/50 border-border focus:border-primary"}),f&&e.jsx(D,{variant:"ghost",size:"icon",className:"absolute right-1 top-1/2 -translate-y-1/2 w-7 h-7 rounded-full",onClick:()=>p(""),children:e.jsx(ns,{className:"w-3.5 h-3.5"})})]}),e.jsx(Ol,{value:y,onChange:b,options:[{value:"all",label:i?"All":"全部",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-gradient-to-r from-destructive via-warning to-primary"})},{value:"ERROR",label:"ERR",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-destructive"})},{value:"WARN",label:"WARN",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-warning"})},{value:"INFO",label:"INFO",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-primary"})},{value:"DEBUG",label:"DBG",icon:e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-gray-400"})}]}),e.jsx(Ol,{value:v,onChange:N,className:"min-w-[100px]",options:[{value:"all",label:i?"All":"全部",icon:e.jsx("svg",{className:"w-3 h-3 text-primary",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16M4 18h16"})})},...F.map(xe=>({value:xe,label:xe,icon:e.jsx("svg",{className:"w-3 h-3 text-muted-foreground",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A2 2 0 013 12V7a4 4 0 014-4z"})})}))]}),e.jsx("div",{className:"h-5 w-px bg-border flex-shrink-0"}),e.jsx(Ol,{value:U,onChange:q,className:"min-w-[60px]",options:[{value:"all",label:i?"All":"全部"},{value:"5000",label:"5K"},{value:"10000",label:"10K"},{value:"50000",label:"50K"},{value:"100000",label:"100K"}]}),e.jsx(Ol,{value:G,onChange:W,className:"min-w-[60px]",options:[{value:"all",label:i?"All":"全部"},{value:"1h",label:"1h"},{value:"6h",label:"6h"},{value:"1d",label:"1d"},{value:"7d",label:"7d"}]}),e.jsx("div",{className:"h-5 w-px bg-border flex-shrink-0"}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:B,disabled:u,children:e.jsx(Mt,{className:`w-3.5 h-3.5 ${u?"animate-spin":""}`})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",onClick:te,disabled:o.length===0,children:e.jsx(Ns,{className:"w-3.5 h-3.5"})}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-destructive",onClick:se,disabled:o.length===0,children:e.jsx(Vt,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex-1 overflow-hidden relative",children:[e.jsx("div",{ref:V,className:"h-full overflow-y-auto font-mono text-xs",onScroll:be,children:pe.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground gap-2",children:[e.jsx(px,{className:"h-8 w-8 opacity-20"}),e.jsx("span",{className:"text-sm",children:o.length===0?i?"No logs yet":"暂无日志记录":i?"No matching logs":"没有匹配的日志"})]}):e.jsx("div",{style:{height:C.getTotalSize(),width:"100%",position:"relative"},children:C.getVirtualItems().map(xe=>{const Oe=xe.index,Ee=pe[Oe],Qe=R.has(Oe),_e=Ee.data!==void 0&&Ee.data!==null;return e.jsxs("div",{"data-index":Oe,ref:C.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${xe.start}px)`},className:`group rounded-lg px-3 py-1.5 transition-colors ${X(Ee.level)}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-muted-foreground whitespace-nowrap flex-shrink-0 tabular-nums text-[10px]",children:re(Ee.timestamp)}),e.jsx($e,{variant:"outline",className:`text-[9px] px-1 py-0 flex-shrink-0 font-semibold ${z(Ee.level)}`,children:Ee.level}),e.jsx("span",{className:"text-primary/80 flex-shrink-0 font-medium text-[10px]",children:Ee.category}),e.jsx("span",{className:"flex-1 break-all text-foreground/90 text-[11px]",children:Ee.message}),e.jsxs("div",{className:"flex-shrink-0 opacity-0 group-hover:opacity-100 flex items-center gap-0.5 transition-opacity",children:[_e&&e.jsx(D,{variant:"ghost",size:"icon",className:"w-5 h-5 rounded-full",onClick:()=>P(Oe),children:Qe?e.jsx(zi,{className:"w-3 h-3"}):e.jsx(va,{className:"w-3 h-3"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"w-5 h-5 rounded-full",onClick:()=>Y(Ee),children:e.jsx(As,{className:"w-3 h-3"})})]})]}),Qe&&_e&&e.jsx("pre",{className:"mt-1.5 ml-20 p-2 rounded-md bg-muted/50 border border-border text-primary overflow-x-auto text-[10px] leading-4",children:JSON.stringify(Ee.data,null,2)})]},xe.key)})})}),!j&&e.jsxs("button",{className:"absolute bottom-3 right-3 flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-primary text-primary-foreground text-xs font-medium shadow-lg hover:bg-primary/90 transition-all",onClick:K,children:[e.jsx(VN,{className:"h-3.5 w-3.5"}),S>0?e.jsx(e.Fragment,{children:i?`${S} new`:`${S} 条新`}):e.jsx(e.Fragment,{children:i?"Bottom":"底部"})]})]}),e.jsxs("div",{className:"flex-shrink-0 flex items-center justify-between px-4 py-1.5 border-t border-border text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:[i?"Showing":"显示"," ",pe.length.toLocaleString()," / ",o.length.toLocaleString()]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(UN,{className:`h-3 w-3 ${j?"text-success":"text-muted-foreground/40"}`}),e.jsx("span",{children:j?i?"Following":"跟随中":i?"Scrolled up":"已暂停跟随"})]})]})]})}):null}function _I({open:n,onOpenChange:s,isEn:r,onOpenModelMapping:i,mappingCount:o=0}){const[d,u]=g.useState([]),[h,f]=g.useState(!1),[p,y]=g.useState(!1),[b,v]=g.useState(null),[N,j]=g.useState(()=>localStorage.getItem("models_dialog_ip_tip_dismissed")!=="1"),T=()=>{localStorage.setItem("models_dialog_ip_tip_dismissed","1"),j(!1)},S=async()=>{f(!0),v(null);try{const R=await window.api.proxyGetModels();R.success?(u(R.models),y(R.fromCache||!1)):v(R.error||"Failed to fetch models")}catch(R){v(R instanceof Error?R.message:"Unknown error")}finally{f(!1)}};if(g.useEffect(()=>{n&&S()},[n]),!n)return null;const k=R=>R==null?"-":R>=1e6?`${(R/1e6).toFixed(1)}M`:R>=1e3?`${(R/1e3).toFixed(0)}K`:R.toString();return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[850px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsx(at,{className:"pb-4 border-b sticky top-0 z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-xl flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(ai,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold",children:r?"Available Models":"可用模型"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs($e,{className:"bg-primary/10 text-primary border-primary/20 font-semibold",children:[d.length," ",r?"models":"个模型"]}),p&&e.jsxs($e,{variant:"secondary",className:"text-xs bg-warning/10 text-warning border-0",children:[e.jsx(Hi,{className:"h-3 w-3 mr-1"}),r?"Cached":"缓存"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsxs(D,{variant:"outline",size:"sm",onClick:i,className:"rounded-lg",children:[e.jsx(Kn,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-1.5",children:r?"Mapping":"映射"}),o>0&&e.jsx($e,{className:"ml-1.5 h-5 px-1.5 bg-primary/20 text-primary text-xs",children:o})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:S,disabled:h,className:"rounded-lg",children:[h?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Mt,{className:"h-4 w-4"}),e.jsx("span",{className:"ml-1.5",children:r?"Refresh":"刷新"})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-5 w-5"})})]})]})}),e.jsxs(Pe,{className:"p-4",children:[N&&e.jsx("div",{className:"mb-3 rounded-xl border border-warning/30 bg-gradient-to-r from-warning/10 to-warning/5 p-3.5 relative",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"shrink-0 p-1.5 rounded-lg bg-warning/20",children:e.jsx(Rs,{className:"h-4 w-4 text-warning"})}),e.jsxs("div",{className:"flex-1 min-w-0 pr-6",children:[e.jsxs("p",{className:"text-sm font-semibold text-warning mb-1.5 flex items-center gap-1.5",children:[e.jsx(ri,{className:"h-3.5 w-3.5"}),r?"Pro/Pro Max subscription but missing advanced models?":"订阅 Pro/Pro Max 但看不到高级模型?"]}),e.jsx("p",{className:"text-xs text-warning/90 leading-relaxed mb-1",children:r?"This is likely caused by regional restrictions on China-mainland IPs. Try the following:":"这通常是国内 IP 被限制导致的。请尝试以下方案:"}),e.jsxs("ul",{className:"text-xs text-warning/90 space-y-0.5 list-disc list-inside",children:[e.jsx("li",{children:r?"Enable VPN/proxy (system-level or app-level)":"开启 VPN / 代理(系统级或应用级均可)"}),e.jsx("li",{children:r?"Switch to high-quality outbound IP (US/EU residential preferred)":"切换到优质外网 IP(推荐美国 / 欧洲住宅 IP)"}),e.jsx("li",{children:r?"Click Refresh after IP change to reload models":"IP 切换后点击右上角「刷新」重新加载模型"})]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"absolute top-2 right-2 h-7 w-7 hover:bg-warning/20 text-warning",onClick:T,title:r?"Don't show again":"不再显示",children:e.jsx(ns,{className:"h-4 w-4"})})]})}),e.jsx("div",{className:"max-h-[calc(85vh-140px)] overflow-y-auto pr-2",children:h&&d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-primary/10 mb-4",children:e.jsx(bt,{className:"h-8 w-8 animate-spin text-primary"})}),e.jsx("p",{className:"font-medium",children:r?"Loading models...":"加载模型中..."})]}):b?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-destructive/10 mb-4",children:e.jsx(ns,{className:"h-8 w-8 text-destructive"})}),e.jsx("p",{className:"text-destructive font-medium",children:b}),e.jsx("p",{className:"text-sm mt-2",children:r?"Make sure proxy is running and has synced accounts":"请确保代理服务已启动且已同步账号"})]}):d.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-muted mb-4",children:e.jsx(ai,{className:"h-8 w-8"})}),e.jsx("p",{className:"font-medium",children:r?"No models available":"暂无可用模型"})]}):e.jsx("div",{className:"grid grid-cols-2 gap-3",children:d.map((R,I)=>e.jsxs("div",{className:me("group p-3 rounded-xl border hover:shadow-md hover:border-primary/30 transition-all duration-200",I===0?"border-primary/40 bg-primary/10":"bg-background"),children:[e.jsxs("div",{className:"flex items-start gap-2 mb-2",children:[e.jsx("div",{className:me("w-2 h-2 rounded-full mt-1.5 shrink-0",I===0?"bg-primary":"bg-muted-foreground/30")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("code",{className:"text-sm font-bold text-foreground",children:R.id}),R.name&&R.name!==R.id&&e.jsx("p",{className:"text-[11px] text-primary/70 font-medium truncate",children:R.name})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground line-clamp-2 mb-2 pl-4",children:R.description||(r?"No description":"无描述")}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[R.inputTypes?.includes("TEXT")&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-blue-500/10 text-blue-600 dark:text-blue-400 border-0",children:e.jsx(xr,{className:"h-3 w-3"})}),R.inputTypes?.includes("IMAGE")&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-purple-500/10 text-purple-600 dark:text-purple-400 border-0",children:e.jsx(FN,{className:"h-3 w-3"})})]}),R.supportsThinking&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-0",title:R.thinkingEfforts?.join(", "),children:e.jsx(g3,{className:"h-3 w-3"})}),R.supportsPromptCaching&&e.jsx($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-cyan-500/10 text-cyan-600 dark:text-cyan-400 border-0",children:e.jsx(Sp,{className:"h-3 w-3"})}),R.rateMultiplier!==void 0&&e.jsxs($e,{variant:"secondary",className:"text-[10px] px-1.5 h-5 bg-amber-500/10 text-amber-600 dark:text-amber-400 border-0",children:[e.jsx(Ds,{className:"h-3 w-3 mr-0.5"}),R.rateMultiplier,"x ",R.rateUnit||"credit"]})]}),e.jsxs("div",{className:"flex items-center gap-1 text-[11px] font-mono text-muted-foreground",children:[e.jsx(HN,{className:"h-3 w-3"}),e.jsx("span",{className:"text-green-600 dark:text-green-400",children:k(R.maxInputTokens)}),e.jsx("span",{children:"/"}),e.jsx("span",{className:"text-orange-600 dark:text-orange-400",children:k(R.maxOutputTokens)})]})]})]},R.id))})})]})]})]})}function VI({open:n,onOpenChange:s,isEn:r,mappings:i,onMappingsChange:o,apiKeys:d,availableModels:u}){const[h,f]=g.useState(i),[p,y]=g.useState(null),[b,v]=g.useState(!1);g.useEffect(()=>{n&&f(i)},[n]);const N=()=>`mapping_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,j=()=>{const B={id:N(),name:r?"New Rule":"新规则",enabled:!0,type:"replace",sourceModel:"",targetModels:[""],priority:h.length,apiKeyIds:[]};f([...h,B]),y(B.id)},T=(B,be)=>{f(h.map(K=>K.id===B?{...K,...be}:K))},S=B=>{f(h.filter(be=>be.id!==B)),p===B&&y(null)},k=(B,be)=>{const K=h.findIndex(Y=>Y.id===B);if(be==="up"&&K===0||be==="down"&&K===h.length-1)return;const se=[...h],te=be==="up"?K-1:K+1;[se[K],se[te]]=[se[te],se[K]],se.forEach((Y,P)=>Y.priority=P),f(se)},R=B=>{const be=h.find(K=>K.id===B);be&&T(B,{targetModels:[...be.targetModels,""],weights:be.weights?[...be.weights,1]:void 0})},I=(B,be,K)=>{const se=h.find(te=>te.id===B);if(se){const te=[...se.targetModels];te[be]=K,T(B,{targetModels:te})}},M=(B,be)=>{const K=h.find(se=>se.id===B);if(K&&K.targetModels.length>1){const se=K.targetModels.filter((Y,P)=>P!==be),te=K.weights?K.weights.filter((Y,P)=>P!==be):void 0;T(B,{targetModels:se,weights:te})}},G=(B,be,K)=>{const se=h.find(te=>te.id===B);if(se){const te=se.weights?[...se.weights]:se.targetModels.map(()=>1);te[be]=K,T(B,{weights:te})}},W=(B,be)=>{const K=h.find(se=>se.id===B);if(K){const se=K.apiKeyIds||[],te=se.includes(be)?se.filter(Y=>Y!==be):[...se,be];T(B,{apiKeyIds:te})}},U=async()=>{v(!0);try{o(h),s(!1)}finally{v(!1)}},q=B=>{switch(B){case"replace":return e.jsx(wp,{className:"h-4 w-4"});case"alias":return e.jsx(Xl,{className:"h-4 w-4"});case"loadbalance":return e.jsx(Kn,{className:"h-4 w-4"});default:return e.jsx(Ka,{className:"h-4 w-4"})}},V=B=>{switch(B){case"replace":return r?"Replace":"替换";case"alias":return r?"Alias":"别名";case"loadbalance":return r?"Load Balance":"负载均衡";default:return B}},le=B=>{switch(B){case"replace":return"bg-blue-500/10 text-blue-600 dark:text-blue-400";case"alias":return"bg-purple-500/10 text-purple-600 dark:text-purple-400";case"loadbalance":return"bg-green-500/10 text-green-600 dark:text-green-400";default:return"bg-muted"}};return n?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[900px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsx(at,{className:"pb-4 border-b sticky top-0 z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-xl flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(Kn,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold",children:r?"Model Mapping":"模型映射"}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs($e,{className:"bg-primary/10 text-primary border-primary/20 font-semibold",children:[h.length," ",r?"rules":"条规则"]})})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:j,className:"rounded-lg",children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),r?"Add Rule":"添加规则"]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-5 w-5"})})]})]})}),e.jsxs(Pe,{className:"p-4",children:[e.jsx("div",{className:"max-h-[calc(85vh-180px)] overflow-y-auto pr-2 space-y-3",children:h.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-muted-foreground",children:[e.jsx("div",{className:"p-4 rounded-full bg-muted mb-4",children:e.jsx(Kn,{className:"h-8 w-8"})}),e.jsx("p",{className:"font-medium",children:r?"No mapping rules":"暂无映射规则"}),e.jsx("p",{className:"text-sm mt-1",children:r?'Click "Add Rule" to create one':'点击"添加规则"创建新规则'})]}):h.map((B,be)=>e.jsxs("div",{className:me("border rounded-xl overflow-hidden transition-all",B.enabled?"bg-background":"bg-muted/30 opacity-60",p===B.id?"ring-2 ring-primary/30":""),children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 cursor-pointer hover:bg-muted/30",onClick:()=>y(p===B.id?null:B.id),children:[e.jsx(hA,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("div",{onClick:K=>K.stopPropagation(),children:e.jsx(is,{checked:B.enabled,onCheckedChange:K=>{T(B.id,{enabled:K})}})}),e.jsxs($e,{className:me("px-2 py-0.5",le(B.type)),children:[q(B.type),e.jsx("span",{className:"ml-1",children:V(B.type)})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"font-medium truncate",children:B.name}),e.jsx("span",{className:"text-muted-foreground mx-2",children:":"}),e.jsx("code",{className:"text-sm bg-muted px-1.5 py-0.5 rounded",children:B.sourceModel||"..."}),e.jsx(wp,{className:"inline h-4 w-4 mx-2 text-muted-foreground"}),e.jsx("code",{className:"text-sm bg-muted px-1.5 py-0.5 rounded",children:B.targetModels.filter(K=>K).join(", ")||"..."})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:K=>{K.stopPropagation(),k(B.id,"up")},disabled:be===0,children:e.jsx(zi,{className:"h-4 w-4"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:K=>{K.stopPropagation(),k(B.id,"down")},disabled:be===h.length-1,children:e.jsx(va,{className:"h-4 w-4"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7 hover:bg-destructive/10 hover:text-destructive",onClick:K=>{K.stopPropagation(),S(B.id)},children:e.jsx(Vt,{className:"h-4 w-4"})})]})]}),p===B.id&&e.jsxs("div",{className:"border-t p-4 space-y-4 bg-muted/10",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:r?"Rule Name":"规则名称"}),e.jsx(it,{value:B.name,onChange:K=>T(B.id,{name:K.target.value}),placeholder:r?"Enter rule name":"输入规则名称"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:r?"Mapping Type":"映射类型"}),e.jsxs("select",{className:"w-full h-10 px-3 py-2 text-sm rounded-xl border border-input bg-background ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2",value:B.type,onChange:K=>T(B.id,{type:K.target.value}),children:[e.jsx("option",{value:"replace",children:r?"Replace - Direct model replacement":"替换 - 直接替换模型"}),e.jsx("option",{value:"alias",children:r?"Alias - Create model alias":"别名 - 创建模型别名"}),e.jsx("option",{value:"loadbalance",children:r?"Load Balance - Random selection":"负载均衡 - 随机选择"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:r?"Source Model":"源模型"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:r?"The model name in user request (e.g., gpt-4, claude-*, my-alias). Supports * wildcard.":"用户请求时使用的模型名(如 gpt-4, claude-*, my-alias)。支持 * 通配符。"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(it,{value:B.sourceModel,onChange:K=>T(B.id,{sourceModel:K.target.value}),placeholder:r?"e.g., claude-*, gpt-4, my-alias":"例如: claude-*, gpt-4, my-alias",className:"flex-1"}),u.length>0&&e.jsxs("select",{className:"h-10 px-3 text-sm rounded-xl border border-input bg-background",value:"",onChange:K=>{K.target.value&&T(B.id,{sourceModel:K.target.value})},children:[e.jsx("option",{value:"",children:r?"Select model":"选择模型"}),u.map(K=>e.jsx("option",{value:K.id,children:K.id},K.id))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(Fe,{children:r?"Target Models":"目标模型"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:r?"The actual Kiro model to call. Select from the dropdown for official models.":"实际调用的 Kiro 模型。从下拉框选择官方模型。"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>R(B.id),className:"h-7 text-xs",children:[e.jsx(Ts,{className:"h-3 w-3 mr-1"}),r?"Add":"添加"]})]}),e.jsx("div",{className:"space-y-2",children:B.targetModels.map((K,se)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{value:K,onChange:te=>I(B.id,se,te.target.value),placeholder:r?"Target model name":"目标模型名",className:"flex-1"}),u.length>0&&e.jsxs("select",{className:"h-10 px-3 text-sm rounded-xl border border-input bg-background",value:"",onChange:te=>{te.target.value&&I(B.id,se,te.target.value)},children:[e.jsx("option",{value:"",children:r?"Select":"选择"}),u.map(te=>e.jsx("option",{value:te.id,children:te.id},te.id))]}),B.type==="loadbalance"&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Fe,{className:"text-xs whitespace-nowrap",children:r?"Weight":"权重"}),e.jsx(it,{type:"number",min:1,value:B.weights?.[se]??1,onChange:te=>G(B.id,se,parseInt(te.target.value)||1),className:"w-16"})]}),B.targetModels.length>1&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 hover:bg-destructive/10 hover:text-destructive",onClick:()=>M(B.id,se),children:e.jsx(Vt,{className:"h-4 w-4"})})]},se))})]}),d.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:r?"Apply to API Keys (empty = all keys)":"适用 API Key(空 = 所有 Key)"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:d.map(K=>e.jsx($e,{variant:B.apiKeyIds?.includes(K.id)?"default":"outline",className:"cursor-pointer hover:bg-primary/20",onClick:()=>W(B.id,K.id),children:K.name},K.id))})]})]})]},B.id))}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4 border-t mt-4",children:[e.jsx(D,{variant:"outline",onClick:()=>s(!1),children:r?"Cancel":"取消"}),e.jsxs(D,{onClick:U,disabled:b,children:[b&&e.jsx(bt,{className:"h-4 w-4 mr-2 animate-spin"}),r?"Save":"保存"]})]})]})]})]}):null}function KI({open:n,onOpenChange:s,accounts:r,selectedAccountId:i,onSelect:o,isEn:d}){const[u,h]=g.useState(""),f=g.useMemo(()=>Array.from(r.values()),[r]),p=g.useMemo(()=>{if(!u.trim())return f;const S=u.toLowerCase();return f.filter(k=>k.email?.toLowerCase().includes(S)||k.id.toLowerCase().includes(S)||k.subscription?.title?.toLowerCase().includes(S))},[f,u]),y=S=>{o(S),s(!1)},b=S=>{const k=S.usage;return k?k.limit>0?Math.min(100,k.current/k.limit*100):Math.min(100,Math.max(0,(k.percentUsed||0)*100)):0},v=S=>{const k=S.usage;return k?`${k.current.toFixed(1)} / ${k.limit}`:"-"},N=S=>{if(!S)return"bg-gray-500 text-white";const k=S.toUpperCase();return k.includes("PRO+")||k.includes("PRO_PLUS")||k.includes("PROPLUS")?"bg-purple-500 text-white":k.includes("POWER")?"bg-amber-500 text-white":k.includes("PRO")?"bg-blue-500 text-white":"bg-gray-500 text-white"},j=S=>{const k=S.lastError?.toLowerCase();return k?k.includes("accountsuspendedexception")||k.includes("account suspended")||k.includes("temporarily_suspended")||k.includes("temporarily suspended")||k.includes("user id is")&&k.includes("suspended")||k.includes("账户已封禁")||k.includes("已封禁")||/\b423\b/.test(k)?!0:(k.includes("fetch failed")||k.includes("network")||k.includes("token expired")||k.includes("token 过期")||k.includes("刷新失败")||k.includes("unauthorizedexception"),!1):!1},T=S=>{if(j(S))return{icon:e.jsx(jc,{className:"h-3.5 w-3.5"}),text:d?"Banned":"已封禁",color:"bg-destructive/10 text-destructive"};switch(S.status){case"error":return{icon:e.jsx(ln,{className:"h-3.5 w-3.5"}),text:d?"Error":"错误",color:"bg-destructive/10 text-destructive"};case"expired":return{icon:e.jsx(jc,{className:"h-3.5 w-3.5"}),text:d?"Expired":"已过期",color:"bg-warning/10 text-warning"};case"refreshing":return{icon:e.jsx(Ds,{className:"h-3.5 w-3.5"}),text:d?"Refreshing":"刷新中",color:"bg-warning/10 text-warning"};case"active":return null;default:return null}};return n?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[600px] max-h-[80vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsxs(at,{className:"pb-3 border-b sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(rt,{className:"text-lg",children:d?"Select Account":"选择账号"}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"relative mt-3",children:[e.jsx(to,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(it,{placeholder:d?"Search by email, ID or subscription...":"搜索邮箱、ID 或订阅类型...",value:u,onChange:S=>h(S.target.value),className:"pl-9"})]})]}),e.jsxs(Pe,{className:"p-0 overflow-y-auto max-h-[60vh]",children:[e.jsx("div",{className:`p-4 border-b cursor-pointer transition-colors hover:bg-accent/50 ${i?"":"bg-primary/5 border-l-2 border-l-primary"}`,onClick:()=>y(void 0),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-muted flex items-center justify-center",children:e.jsx(Ds,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:d?"First Available":"第一个可用账号"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:d?"Automatically use the first available account":"自动使用第一个可用的账号"})]})]}),!i&&e.jsx(Pt,{className:"h-5 w-5 text-primary"})]})}),p.length===0?e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:u?d?"No accounts found":"未找到匹配的账号":d?"No accounts available":"暂无可用账号"}):p.map(S=>{const k=i===S.id,R=b(S),I=v(S),M=T(S),G=j(S),W=S.status==="error"||S.status==="expired"||G;return e.jsx("div",{className:`p-4 border-b cursor-pointer transition-colors hover:bg-accent/50 ${k?"bg-primary/5 border-l-2 border-l-primary":""} ${W?"opacity-60":""}`,onClick:()=>y(S.id),children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3 flex-1 min-w-0",children:[e.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center flex-shrink-0 ${W?"bg-destructive/10":"bg-primary/10"}`,children:W?e.jsx(ln,{className:"h-5 w-5 text-destructive"}):e.jsx(Ep,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(gx,{className:"h-3.5 w-3.5 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"font-medium truncate",children:S.email||S.id.substring(0,12)+"..."}),M&&e.jsxs($e,{className:`text-xs ${M.color}`,children:[M.icon,e.jsx("span",{className:"ml-1",children:M.text})]})]}),S.lastError&&e.jsx("div",{className:"text-xs text-destructive mt-1 truncate",children:S.lastError}),e.jsxs("div",{className:"flex items-center gap-3 mt-2",children:[e.jsxs($e,{className:`text-xs ${N(S.subscription?.title)}`,children:[e.jsx($a,{className:"h-3 w-3 mr-1"}),S.subscription?.title||"Unknown"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[d?"Usage":"使用量",": ",I]})]}),e.jsx("div",{className:"mt-2 w-full bg-muted rounded-full h-1.5 overflow-hidden",children:e.jsx("div",{className:`h-full transition-all ${R>80?"bg-destructive":R>50?"bg-warning":"bg-success"}`,style:{width:`${R}%`}})}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1.5 font-mono",children:["ID: ",S.id.substring(0,20),"..."]})]})]}),k&&e.jsx(Pt,{className:"h-5 w-5 text-primary flex-shrink-0 mt-2"})]})},S.id)})]})]})]}):null}function HI({open:n,onOpenChange:s,apiKey:r}){const{t:i}=Ut(),o=i("common.unknown")==="Unknown",[d,u]=g.useState("history"),h=N=>new Date(N).toLocaleString(),f=N=>N.replace("anthropic.","").replace("-v1:0",""),p=g.useMemo(()=>r?.usage.daily?Object.entries(r.usage.daily).sort((j,T)=>T[0].localeCompare(j[0])).slice(0,7).reverse().map(([j,T])=>({date:j.slice(5),...T})):[],[r?.usage.daily]),y=g.useMemo(()=>r?.usage.byModel?Object.entries(r.usage.byModel).map(([N,j])=>({model:f(N),...j})).sort((N,j)=>j.requests-N.requests):[],[r?.usage.byModel]),b=g.useMemo(()=>Math.max(...p.map(N=>N.credits),.001),[p]),v=g.useMemo(()=>Math.max(...y.map(N=>N.requests),1),[y]);return!n||!r?null:e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[900px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsxs(at,{className:"pb-3 border-b sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-lg flex items-center gap-2",children:[e.jsx(Lu,{className:"h-5 w-5 text-primary"}),o?"Usage Details":"用量详情"," - ",r.name]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-4 mt-4",children:[e.jsxs("div",{className:"bg-primary/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Total Requests":"总请求数"}),e.jsx("div",{className:"text-xl font-bold text-primary",children:r.usage.totalRequests.toLocaleString()})]}),e.jsxs("div",{className:"bg-success/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Total Credits":"总 Credits"}),e.jsx("div",{className:"text-xl font-bold text-success",children:r.usage.totalCredits.toFixed(4)})]}),e.jsxs("div",{className:"bg-primary/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Input Tokens":"输入 Tokens"}),e.jsx("div",{className:"text-xl font-bold text-primary",children:r.usage.totalInputTokens.toLocaleString()})]}),e.jsxs("div",{className:"bg-[var(--gradient-to)]/10 rounded-lg p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:o?"Output Tokens":"输出 Tokens"}),e.jsx("div",{className:"text-xl font-bold text-[var(--gradient-to)]",children:r.usage.totalOutputTokens.toLocaleString()})]})]}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsxs(D,{variant:d==="history"?"default":"outline",size:"sm",onClick:()=>u("history"),children:[e.jsx(Gn,{className:"h-4 w-4 mr-1"}),o?"History":"历史记录"]}),e.jsxs(D,{variant:d==="model"?"default":"outline",size:"sm",onClick:()=>u("model"),children:[e.jsx(ai,{className:"h-4 w-4 mr-1"}),o?"By Model":"按模型"]}),e.jsxs(D,{variant:d==="daily"?"default":"outline",size:"sm",onClick:()=>u("daily"),children:[e.jsx(QN,{className:"h-4 w-4 mr-1"}),o?"Daily Stats":"每日统计"]})]})]}),e.jsxs(Pe,{className:"p-4 max-h-[calc(85vh-280px)] overflow-y-auto",children:[d==="history"&&e.jsx("div",{children:r.usageHistory&&r.usageHistory.length>0?e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Time":"时间"}),e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Model":"模型"}),e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Path":"路径"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"In":"输入"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Out":"输出"}),e.jsx("th",{className:"text-right p-2 font-medium",children:"Credits"})]})}),e.jsx("tbody",{className:"font-mono",children:r.usageHistory.map((N,j)=>e.jsxs("tr",{className:"border-b border-muted/30 hover:bg-muted/30",children:[e.jsx("td",{className:"p-2 text-muted-foreground whitespace-nowrap text-xs",children:h(N.timestamp)}),e.jsx("td",{className:"p-2 truncate max-w-[150px]",title:N.model,children:f(N.model)}),e.jsx("td",{className:"p-2 truncate max-w-[120px] text-muted-foreground",title:N.path,children:N.path}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:N.inputTokens.toLocaleString()}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:N.outputTokens.toLocaleString()}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:N.credits.toFixed(6)})]},j))})]}):e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:o?"No usage history yet":"暂无用量记录"})}),d==="model"&&e.jsx("div",{className:"space-y-4",children:y.length>0?y.map((N,j)=>e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"font-medium flex items-center gap-2",children:[e.jsx(ai,{className:"h-4 w-4 text-primary"}),N.model]}),e.jsxs($e,{variant:"secondary",children:[N.requests," ",o?"requests":"次请求"]})]}),e.jsx("div",{className:"h-2 bg-muted rounded-full overflow-hidden mb-3",children:e.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${N.requests/v*100}%`}})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 text-sm",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:["Credits",":"]}),e.jsx("span",{className:"ml-2 font-mono",children:N.credits.toFixed(4)})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[o?"Input":"输入",":"]}),e.jsx("span",{className:"ml-2 font-mono",children:N.inputTokens.toLocaleString()})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-muted-foreground",children:[o?"Output":"输出",":"]}),e.jsx("span",{className:"ml-2 font-mono",children:N.outputTokens.toLocaleString()})]})]})]},j)):e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:o?"No model statistics yet":"暂无模型统计"})}),d==="daily"&&e.jsx("div",{className:"space-y-4",children:p.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4",children:[e.jsxs("div",{className:"text-sm font-medium mb-4 flex items-center gap-2",children:[e.jsx(B3,{className:"h-4 w-4 text-primary"}),o?"Daily Credits (Last 7 Days)":"每日 Credits(最近7天)"]}),e.jsx("div",{className:"flex items-end gap-2 h-32",children:p.map((N,j)=>e.jsxs("div",{className:"flex-1 flex flex-col items-center",children:[e.jsx("div",{className:"w-full bg-primary rounded-t transition-all hover:bg-primary/80",style:{height:`${N.credits/b*100}%`,minHeight:"4px"},title:`${N.credits.toFixed(4)} credits`}),e.jsx("div",{className:"text-xs text-muted-foreground mt-2",children:N.date})]},j))})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left p-2 font-medium",children:o?"Date":"日期"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Requests":"请求数"}),e.jsx("th",{className:"text-right p-2 font-medium",children:"Credits"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Input":"输入"}),e.jsx("th",{className:"text-right p-2 font-medium",children:o?"Output":"输出"})]})}),e.jsx("tbody",{className:"font-mono",children:Object.entries(r.usage.daily).sort((N,j)=>j[0].localeCompare(N[0])).slice(0,30).map(([N,j],T)=>e.jsxs("tr",{className:"border-b border-muted/30 hover:bg-muted/30",children:[e.jsx("td",{className:"p-2",children:N}),e.jsx("td",{className:"p-2 text-right",children:j.requests}),e.jsx("td",{className:"p-2 text-right",children:j.credits.toFixed(4)}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:j.inputTokens.toLocaleString()}),e.jsx("td",{className:"p-2 text-right text-muted-foreground",children:j.outputTokens.toLocaleString()})]},T))})]})]}):e.jsx("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:o?"No daily statistics yet":"暂无每日统计"})})]})]})]})}function FI(){const{language:n}=vt(),s=n==="en",[r,i]=g.useState([]),[o,d]=g.useState(!0),[u,h]=g.useState(""),[f,p]=g.useState("sk"),[y,b]=g.useState(""),[v,N]=g.useState(null),[j,T]=g.useState(new Set),[S,k]=g.useState(null),[R,I]=g.useState(!1),M=g.useCallback(async()=>{try{const se=await window.api.proxyGetApiKeys();se.success&&i(se.apiKeys)}catch(se){console.error("Failed to load API keys:",se)}finally{d(!1)}},[]);g.useEffect(()=>{M()},[M]);const G=async()=>{if(u.trim())try{const se=y?parseFloat(y):void 0,te=await window.api.proxyAddApiKey({name:u.trim(),format:f,creditsLimit:se&&se>0?se:void 0});te.success&&te.apiKey&&(i(Y=>[...Y,te.apiKey]),h(""),b(""))}catch(se){console.error("Failed to add API key:",se)}},W=async se=>{if(confirm(s?"Delete this API key?":"确定删除此 API Key?"))try{(await window.api.proxyDeleteApiKey(se)).success&&(i(Y=>Y.filter(P=>P.id!==se)),S===se&&k(null))}catch(te){console.error("Failed to delete API key:",te)}},U=async(se,te)=>{try{(await window.api.proxyUpdateApiKey(se,{enabled:te})).success&&i(P=>P.map(F=>F.id===se?{...F,enabled:te}:F))}catch(Y){console.error("Failed to toggle API key:",Y)}},q=async se=>{if(confirm(s?"Reset usage statistics?":"确定重置用量统计?"))try{(await window.api.proxyResetApiKeyUsage(se)).success&&i(Y=>Y.map(P=>P.id===se?{...P,usage:{totalRequests:0,totalCredits:0,totalInputTokens:0,totalOutputTokens:0,daily:{}}}:P))}catch(te){console.error("Failed to reset usage:",te)}},V=(se,te)=>{navigator.clipboard.writeText(te),N(se),setTimeout(()=>N(null),2e3)},le=se=>{T(te=>{const Y=new Set(te);return Y.has(se)?Y.delete(se):Y.add(se),Y})},B=se=>{const te=new Date(se);return`${te.toLocaleDateString()} ${te.toLocaleTimeString()}`},be=se=>se.substring(0,8)+"..."+se.substring(se.length-4),K=r.find(se=>se.id===S);return o?e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx(Mt,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Dc,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"API Keys":"API 密钥"})]}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[r.length," ",s?"keys":"个"]})]}),e.jsx(Gl,{children:s?"Manage API keys for authentication":"管理用于身份验证的 API 密钥"})]}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(it,{placeholder:s?"Key name...":"密钥名称...",value:u,onChange:se=>h(se.target.value),onKeyDown:se=>se.key==="Enter"&&G(),className:"flex-1"}),e.jsx(ei,{value:f,options:[{value:"sk",label:"sk-xxx"},{value:"simple",label:"PROXY_KEY"},{value:"token",label:"KEY:TOKEN"}],onChange:se=>p(se),className:"w-[120px]"}),e.jsxs(D,{onClick:G,disabled:!u.trim(),children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),s?"Add":"添加"]})]}),e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(it,{type:"number",placeholder:s?"Credits limit (optional)":"Credits 额度限制(可选)",value:y,onChange:se=>b(se.target.value),className:"flex-1"}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:s?"0 = unlimited":"0 = 无限制"})]})]}),r.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:s?"No API keys yet":"暂无 API 密钥"}):e.jsx("div",{className:"space-y-2",children:r.map(se=>e.jsxs("div",{className:me("flex items-center gap-3 p-3 rounded-lg border transition-colors cursor-pointer",S===se.id?"bg-primary/5 border-primary":"hover:bg-muted/50",!se.enabled&&"opacity-50"),onClick:()=>k(S===se.id?null:se.id),children:[e.jsx("div",{onClick:te=>te.stopPropagation(),children:e.jsx(is,{checked:se.enabled,onCheckedChange:te=>U(se.id,te)})}),e.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden",children:[e.jsx("div",{className:"font-medium truncate",children:se.name}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("code",{className:"bg-muted px-1 rounded",children:j.has(se.id)?se.key:be(se.key)}),e.jsx("button",{className:"hover:text-foreground",onClick:te=>{te.stopPropagation(),le(se.id)},children:j.has(se.id)?e.jsx(Jl,{className:"h-3 w-3"}):e.jsx(Nc,{className:"h-3 w-3"})}),e.jsx("button",{className:"hover:text-foreground",onClick:te=>{te.stopPropagation(),V(se.id,se.key)},children:v===se.id?e.jsx(Pt,{className:"h-3 w-3 text-success"}):e.jsx(As,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"text-right text-xs text-muted-foreground",children:[e.jsxs("div",{children:[se.usage.totalRequests," ",s?"requests":"请求"]}),e.jsxs("div",{className:me(se.creditsLimit&&se.usage.totalCredits>=se.creditsLimit&&"text-destructive font-medium"),children:[se.usage.totalCredits.toFixed(2),se.creditsLimit?`/${se.creditsLimit}`:""," credits"]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive",onClick:te=>{te.stopPropagation(),W(se.id)},children:e.jsx(Vt,{className:"h-4 w-4"})})]},se.id))})]})]}),K&&e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Lu,{className:"h-5 w-5 text-primary"}),e.jsxs(rt,{className:"text-lg",children:[s?"Usage Details":"用量详情",": ",K.name]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>I(!0),children:[e.jsx(Xs,{className:"h-3 w-3 mr-1"}),s?"View Details":"查看详情"]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:()=>q(K.id),children:[e.jsx(Mt,{className:"h-3 w-3 mr-1"}),s?"Reset Usage":"重置用量"]})]})]})}),e.jsxs(Pe,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(yx,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:s?"Total Requests":"总请求数"})]}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalRequests})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(Ds,{className:"h-4 w-4"}),e.jsx("span",{className:"text-xs",children:s?"Total Credits":"总 Credits"})]}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalCredits.toFixed(2)})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:e.jsx("span",{className:"text-xs",children:s?"Input Tokens":"输入 Tokens"})}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalInputTokens.toLocaleString()})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:e.jsx("span",{className:"text-xs",children:s?"Output Tokens":"输出 Tokens"})}),e.jsx("div",{className:"text-2xl font-bold",children:K.usage.totalOutputTokens.toLocaleString()})]})]}),e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s?"Credits Limit:":"Credits 额度限制:"}),e.jsx(it,{type:"number",placeholder:s?"Unlimited":"无限制",value:K.creditsLimit||"",onChange:async se=>{const te=se.target.value?parseFloat(se.target.value):null;(await window.api.proxyUpdateApiKey(K.id,{creditsLimit:te&&te>0?te:null})).success&&i(P=>P.map(F=>F.id===K.id?{...F,creditsLimit:te&&te>0?te:void 0}:F))},className:"w-32 h-8"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"(0 = unlimited)":"(0 = 无限制)"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gn,{className:"h-3 w-3"}),e.jsxs("span",{children:[s?"Created:":"创建时间:"," ",B(K.createdAt)]})]}),K.lastUsedAt&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Gn,{className:"h-3 w-3"}),e.jsxs("span",{children:[s?"Last used:":"最后使用:"," ",B(K.lastUsedAt)]})]})]})]})]})]}),e.jsx(HI,{open:R,onOpenChange:I,apiKey:K||null})]})}const GI={claudeCode:"Claude Code",opencode:"OpenCode",codex:"Codex CLI",gemini:"Gemini CLI",hermes:"Hermes",openclaw:"OpenClaw"},Uu=["claude-sonnet-4.5","claude-sonnet-4","claude-opus-4.8","claude-opus-4.7","claude-opus-4.5","claude-haiku-4.5"],qI=[{id:"claude-sonnet-4.5",name:"Claude Sonnet 4.5",description:"Claude Sonnet 4.5",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-sonnet-4",name:"Claude Sonnet 4",description:"Claude Sonnet 4",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-opus-4.8",name:"Claude Opus 4.8",description:"Power account model",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-opus-4.7",name:"Claude Opus 4.7",description:"Power account model",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-opus-4.5",name:"Claude Opus 4.5",description:"Power account model",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3},{id:"claude-haiku-4.5",name:"Claude Haiku 4.5",description:"Claude Haiku 4.5",inputTypes:["TEXT","IMAGE"],maxInputTokens:2e5,maxOutputTokens:64e3}];function ss(n){return n.trim().toLowerCase().replace(/^(claude-(?:sonnet|haiku|opus)-\d+)-(\d+)(.*)$/u,"$1.$2$3")}function aj(n){const s=new Map;for(const r of[...n,...qI]){if(!r.id?.trim())continue;const i=ss(r.id);s.has(i)||s.set(i,r)}return Array.from(s.values()).sort((r,i)=>{const o=Uu.findIndex(u=>ss(u)===ss(r.id)),d=Uu.findIndex(u=>ss(u)===ss(i.id));return o!==-1||d!==-1?(o===-1?99:o)-(d===-1?99:d):ss(r.id)==="auto"?1:ss(i.id)==="auto"?-1:r.id.localeCompare(i.id)})}function rj(n,s){const r=ss(s),i=n.find(o=>ss(o.id)===r);if(r&&r!=="auto"&&i)return i.id;for(const o of Uu){const d=n.find(u=>ss(u.id)===ss(o));if(d)return d.id}return n.find(o=>ss(o.id)!=="auto")?.id||n[0]?.id||""}function Of(n,s){const r=new Map(n.map(u=>[ss(u.id),u.id])),i=s.map(u=>r.get(ss(u))).filter(u=>!!(u&&ss(u)!=="auto"));if(i.length>0)return Array.from(new Set(i));const o=Uu.map(u=>r.get(ss(u))).filter(u=>!!(u&&ss(u)!=="auto"));if(o.length>0)return Array.from(new Set(o));const d=n.find(u=>ss(u.id)!=="auto")?.id;return d?[d]:[]}function XI({open:n,onOpenChange:s,isEn:r}){const i=vt(oe=>oe.accounts),o=vt(oe=>oe.activeAccountId),[d,u]=g.useState([]),[h,f]=g.useState(""),[p,y]=g.useState([]),[b,v]=g.useState(["openclaw"]),[N,j]=g.useState(!1),[T,S]=g.useState(!1),[k,R]=g.useState(!1),[I,M]=g.useState(!1),[G,W]=g.useState(null),[U,q]=g.useState([]),[V,le]=g.useState(""),[,B]=g.useState([]),[be,K]=g.useState(null),[se,te]=g.useState(!1),Y=g.useMemo(()=>[{id:"claudeCode",name:"Claude Code",description:r?"Writes ANTHROPIC_BASE_URL, API key and default model":"Ghi ANTHROPIC_BASE_URL, API key và model mặc định",icon:$N},{id:"opencode",name:"OpenCode",description:r?"Adds Kiro provider and model metadata to opencode.json":"Thêm provider Kiro và metadata model vào opencode.json",icon:O3},{id:"codex",name:"Codex CLI",description:r?"Adds Kiro OpenAI Responses provider":"Thêm provider Kiro dùng OpenAI Responses",icon:WN},{id:"gemini",name:"Gemini CLI",description:r?"Writes .env and settings.json for Gemini v1beta":"Ghi .env và settings.json cho Gemini v1beta",icon:Hi},{id:"hermes",name:"Hermes",description:r?"Adds Kiro provider to config.yaml":"Thêm provider Kiro vào config.yaml",icon:qM},{id:"openclaw",name:"OpenClaw",description:r?"Adds Kiro provider to openclaw.json":"Thêm provider Kiro vào openclaw.json",icon:Ka}],[r]),P=d.find(oe=>oe.id===h),F=g.useMemo(()=>new Set(p.map(ss)),[p]),fe=b.length===1&&b[0]==="openclaw",pe=oe=>oe.length<=14?oe:`${oe.slice(0,8)}...${oe.slice(-4)}`,C=oe=>oe.find(ue=>ue.name==="OpenClaw - Kiro API Proxy")||oe.find(ue=>ue.enabled!==!1)||oe[0]||null,z=g.useCallback(async()=>{j(!0),W(null),q([]);try{const oe=await window.api.proxyGetModels();if(oe.success&&oe.models.length>0){const L=aj(oe.models);u(L),f(we=>rj(L,we)),y(we=>Of(L,we));return}const ue=o?i.get(o):void 0,ae=ue?.status==="active"&&ue.credentials?.accessToken?ue:Array.from(i.values()).find(L=>L.status==="active"&&L.credentials?.accessToken);if(ae){const L=await window.api.accountGetModels(ae.credentials.accessToken,ae.credentials.region||"us-east-1",ae.profileArn,ae.machineId,ae.credentials.provider||ae.idp,ae.credentials.authMethod,ae.id);if(L.success&&L.models.length>0){const we=aj(L.models);u(we),f(Ue=>rj(we,Ue)),y(Ue=>Of(we,Ue));return}}u([]),f(""),y([]),W(r?"No models were loaded. Please check whether the account is active and try reloading.":"Chưa tải được model. Hãy kiểm tra tài khoản đang active rồi tải lại.")}catch(oe){u([]),f(""),y([]),W(oe instanceof Error?oe.message:r?"Failed to load models":"Tải model thất bại")}finally{j(!1)}},[i,o,r]),X=g.useCallback(async()=>{S(!0);try{const oe=await window.api.proxyGetApiKeys();if(oe.success){const ue=oe.apiKeys||[];B(ue),K(C(ue))}}catch(oe){console.error("[ClientConfig] Failed to load API keys:",oe)}finally{S(!1)}},[]);if(g.useEffect(()=>{n&&(z(),X())},[n,z,X]),!n)return null;const re=oe=>{q([]),v(ue=>ue.includes(oe)?ue.filter(ae=>ae!==oe):[...ue,oe])},xe=oe=>{q([]),y(ue=>{const ae=ss(oe),L=ue.some(Ue=>ss(Ue)===ae),we=L?ue.filter(Ue=>ss(Ue)!==ae):[...ue,oe];return!L&&we.length===1&&f(oe),L&&ss(h)===ae&&f(we[0]||""),we})},Oe=()=>{q([]),y(Of(d,[]))},Ee=()=>{q([]),y(h?[h]:[])},Qe=async()=>{be?.key&&(await navigator.clipboard.writeText(be.key),te(!0),setTimeout(()=>te(!1),1600))},_e=async()=>{R(!0),W(null);try{const oe=await window.api.proxyAddApiKey({name:"OpenClaw - Kiro API Proxy",format:"sk"});if(!oe.success||!oe.apiKey){W(oe.error||(r?"Failed to create API key":"Tạo API key thất bại"));return}B(ue=>[oe.apiKey,...ue]),K(oe.apiKey)}catch(oe){W(oe instanceof Error?oe.message:r?"Failed to create API key":"Tạo API key thất bại")}finally{R(!1)}},st=async()=>{if(!h){W(r?"Please select a model":"Hãy chọn model");return}if(b.length===0){W(r?"Please select at least one client":"Hãy chọn ít nhất một client");return}if(p.length===0){W(r?"Please select at least one model to add":"Hãy chọn ít nhất một model để thêm");return}M(!0),W(null),q([]);try{const oe=new Set(p.map(ss));oe.add(ss(h));const ue=d.filter(we=>oe.has(ss(we.id)));!ue.some(we=>ss(we.id)===ss(h))&&P&&ue.unshift(P);const ae=await window.api.proxyConfigureClients({clients:b,modelId:h,modelName:P?.name,models:ue.map(we=>({id:we.id,name:we.name,inputTypes:we.inputTypes,maxInputTokens:we.maxInputTokens,maxOutputTokens:we.maxOutputTokens}))});le(ae.openaiBaseUrl||ae.proxyOrigin);const L=ae.apiKey;L&&(K(L),B(we=>we.some(Ue=>Ue.id&&Ue.id===L.id)?we.map(Ue=>Ue.id===L.id?{...Ue,...L}:Ue):[L,...we])),q(ae.results),ae.success||W(ae.error||(r?"Some clients failed to configure":"Một số client cấu hình thất bại"))}catch(oe){W(oe instanceof Error?oe.message:r?"Failed to configure clients":"Cấu hình client thất bại")}finally{M(!1)}};return e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>s(!1)}),e.jsxs(De,{className:"relative w-[780px] max-h-[85vh] shadow-2xl border-0 overflow-hidden animate-in fade-in zoom-in-95 duration-200 glass-card-strong",children:[e.jsx(at,{className:"pb-4 border-b sticky top-0 z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-xl flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-primary/10",children:e.jsx(Ka,{className:"h-6 w-6 text-primary"})}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold",children:r?"One-Click Client Configuration":"Cấu hình client một chạm"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs($e,{className:"bg-primary/10 text-primary border-primary/20 font-semibold",children:[b.length," ",r?"selected":"đã chọn"]}),V&&e.jsx($e,{variant:"secondary",className:"text-xs border-0",children:V})]})]})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-9 w-9 rounded-lg hover:bg-red-500 hover:text-white transition-colors",onClick:()=>s(!1),children:e.jsx(ns,{className:"h-5 w-5"})})]})}),e.jsx(Pe,{className:"p-4",children:e.jsxs("div",{className:"max-h-[calc(85vh-140px)] overflow-y-auto pr-2 space-y-4",children:[e.jsxs("div",{className:"rounded-xl border bg-background p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ii,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium",children:r?"Kiro API Proxy key":"Key Kiro API Proxy"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:_e,disabled:k,children:[k?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(ii,{className:"h-4 w-4"}),r?"Create key":"Tạo key"]})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/40 px-3 py-2 flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 text-xs break-all",children:T?r?"Loading key...":"Đang tải key...":be?.key?pe(be.key):r?"No key yet. Import will create one automatically.":"Chưa có key. Khi import hệ thống sẽ tự tạo."}),be?.key&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:Qe,title:r?"Copy key":"Sao chép key",children:se?e.jsx(Pt,{className:"h-3.5 w-3.5 text-success"}):e.jsx(As,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:r?"The server stores this key and OpenClaw uses it to call the Kiro API proxy quota pool.":"Server sẽ lưu key này để OpenClaw gọi qua Kiro API proxy và dùng quota xoay tài khoản."})]}),e.jsxs("div",{className:"rounded-xl border bg-background p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ai,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-medium",children:"Model"})]}),e.jsxs(D,{variant:"outline",size:"sm",onClick:z,disabled:N,children:[N?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(J3,{className:"h-4 w-4"}),r?"Reload":"Tải lại"]})]}),N?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-2",children:[e.jsx(bt,{className:"h-4 w-4 animate-spin"}),r?"Loading models...":"Đang tải model..."]}):d.length>0?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ei,{value:h,options:d.map(oe=>({value:oe.id,label:oe.id,description:oe.name&&oe.name!==oe.id?oe.name:oe.description})),onChange:oe=>{f(oe),y(ue=>ue.some(ae=>ss(ae)===ss(oe))?ue:[...ue,oe]),q([])},placeholder:r?"Select model":"Chọn model"}),P&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[e.jsx($e,{variant:"secondary",className:"border-0",children:P.name||P.id}),P.inputTypes?.map(oe=>e.jsx($e,{variant:"secondary",className:"border-0",children:oe},oe))]}),e.jsxs("div",{className:"rounded-lg border bg-muted/20 p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{className:"bg-primary/10 text-primary border-primary/20",children:p.length}),e.jsx("span",{className:"text-sm font-medium",children:r?"Models to add":"Model sẽ thêm"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(D,{type:"button",variant:"outline",size:"sm",onClick:Oe,children:[e.jsx(Pt,{className:"h-3.5 w-3.5"}),r?"Recommended":"Đề xuất"]}),e.jsx(D,{type:"button",variant:"ghost",size:"sm",onClick:Ee,children:r?"Only primary":"Chỉ primary"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2 max-h-56 overflow-y-auto pr-1",children:d.filter(oe=>ss(oe.id)!=="auto").map(oe=>{const ue=F.has(ss(oe.id));return e.jsxs("button",{type:"button",onClick:()=>xe(oe.id),className:me("flex items-start gap-2 rounded-lg border px-3 py-2 text-left text-xs transition-colors",ue?"border-primary/50 bg-primary/10":"border-border bg-background hover:border-primary/40"),children:[e.jsx("span",{className:me("mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border",ue?"border-primary bg-primary text-primary-foreground":"border-muted-foreground/40"),children:ue&&e.jsx(Pt,{className:"h-3 w-3"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate font-semibold",children:oe.id}),oe.name&&oe.name!==oe.id&&e.jsx("span",{className:"block truncate text-muted-foreground",children:oe.name})]})]},oe.id)})})]})]}):e.jsx("div",{className:"text-sm text-muted-foreground py-2",children:r?"No models loaded":"Chưa có model"})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Y.map(oe=>{const ue=oe.icon,ae=b.includes(oe.id);return e.jsxs("button",{type:"button",onClick:()=>re(oe.id),className:me("text-left rounded-xl border p-4 transition-all hover:border-primary/50 hover:bg-primary/5",ae?"border-primary/50 bg-primary/10 shadow-sm":"bg-background"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(ue,{className:"h-5 w-5 text-primary"})}),e.jsx("div",{className:me("h-5 w-5 rounded-full border flex items-center justify-center",ae?"bg-primary border-primary text-primary-foreground":"border-muted-foreground/40"),children:ae&&e.jsx(Pt,{className:"h-3.5 w-3.5"})})]}),e.jsx("div",{className:"font-semibold text-sm mb-1",children:oe.name}),e.jsx("div",{className:"text-xs text-muted-foreground leading-relaxed",children:oe.description})]},oe.id)})}),e.jsxs("div",{className:"rounded-xl border border-warning/30 bg-warning/10 p-3 flex items-start gap-2 text-sm text-warning",children:[e.jsx(ln,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("div",{children:r?"Existing client files are merged and backed up before writing.":"File client hiện có sẽ được merge và tạo backup trước khi ghi."})]}),G&&e.jsxs("div",{className:"rounded-xl border border-destructive/30 bg-destructive/10 p-3 flex items-start gap-2 text-sm text-destructive",children:[e.jsx(ln,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("div",{children:G})]}),U.length>0&&e.jsxs("div",{className:"space-y-2",children:[V&&e.jsxs("div",{className:"rounded-xl border border-primary/20 bg-primary/5 p-3 text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:"Base URL:"})," ",e.jsx("code",{children:V})]}),e.jsx("div",{children:r?"In OpenClaw, use /models and choose the krouter provider.":"Trong OpenClaw, gõ /models rồi chọn provider krouter."})]}),U.map(oe=>e.jsxs("div",{className:me("rounded-xl border p-3 text-sm",oe.success?"border-success/30 bg-success/10":"border-destructive/30 bg-destructive/10"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[e.jsx("span",{className:"font-semibold",children:GI[oe.client]}),e.jsx($e,{className:oe.success?"bg-success/15 text-success border-success/20":"bg-destructive/15 text-destructive border-destructive/20",children:oe.success?r?"Configured":"Đã cấu hình":r?"Failed":"Thất bại"})]}),oe.error?e.jsx("div",{className:"text-xs text-destructive",children:oe.error}):e.jsxs("div",{className:"space-y-1 text-xs text-muted-foreground",children:[oe.paths.map(ue=>e.jsx("div",{className:"font-mono break-all",children:ue},ue)),oe.backupPaths.length>0&&e.jsxs("div",{children:[r?"Backups created":"Backup đã tạo",": ",oe.backupPaths.length]})]})]},oe.client))]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(D,{variant:"outline",onClick:()=>s(!1),disabled:I,children:r?"Close":"Đóng"}),e.jsxs(D,{onClick:st,disabled:N||I||!h||p.length===0||b.length===0,children:[I?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Pt,{className:"h-4 w-4"}),I?r?"Configuring...":"Đang cấu hình...":fe?r?"Import to OpenClaw":"Import vào OpenClaw":r?"Apply Configuration":"Áp dụng cấu hình"]})]})]})})]})]})}const YI=5e3;function zl(n){return n>=1e9?`${(n/1e9).toFixed(1)}B`:n>=1e6?`${(n/1e6).toFixed(1)}M`:n>=1e5?`${(n/1e3).toFixed(0)}K`:n.toLocaleString()}let Nu=[],Ip=null,ij=!1;function WI(){ij||(ij=!0,window.api.onProxyResponse(n=>{const s=new Date,r=s.getFullYear(),i=(s.getMonth()+1).toString().padStart(2,"0"),o=s.getDate().toString().padStart(2,"0"),d=s.getHours().toString().padStart(2,"0"),u=s.getMinutes().toString().padStart(2,"0"),h=s.getSeconds().toString().padStart(2,"0"),f=s.getMilliseconds().toString().padStart(3,"0");Nu=[{time:`${r}-${i}-${o} ${d}:${u}:${h}.${f}`,path:n.path,model:n.model,status:n.status,tokens:n.tokens,inputTokens:n.inputTokens,outputTokens:n.outputTokens,cacheReadTokens:n.cacheReadTokens,reasoningTokens:n.reasoningTokens,credits:n.credits,responseTime:n.responseTime,error:n.error},...Nu.slice(0,99)],Ip?.(Nu)}))}function QI(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",[r,i]=g.useState(!1),[o,d]=g.useState({enabled:!1,port:5580,host:"127.0.0.1",enableMultiAccount:!0,logRequests:!0,clientDrivenToolExecution:!0,accountSelectionStrategy:"smart",sessionAffinityEnabled:!1}),[u,h]=g.useState(null),[f,p]=g.useState(null),[y,b]=g.useState(0),[v,N]=g.useState(0),[j,T]=g.useState(!1),[S,k]=g.useState(null),[R,I]=g.useState(Nu),[M,G]=g.useState(!1),[W,U]=g.useState(!1),[q,V]=g.useState(!1),[le,B]=g.useState(!1),[be,K]=g.useState(!1),[se,te]=g.useState(!1),[Y,P]=g.useState(!1),[F,fe]=g.useState(!1),[pe,C]=g.useState(!1),[z,X]=g.useState([]),[re,xe]=g.useState(!1),[Oe,Ee]=g.useState(!1),[Qe,_e]=g.useState(!1),[st,oe]=g.useState("sk"),[ue,ae]=g.useState(!1),[L,we]=g.useState(!1),[Ue,Lt]=g.useState(null),[xt,Qt]=g.useState(""),[ft,Et]=g.useState(!1),[Ge,gt]=g.useState(!1),Ze=vt(H=>H.accounts),J=vt(H=>H.groups),Ne=g.useCallback(()=>{const H=Xe=>{const Nt="abcdefghijklmnopqrstuvwxyz0123456789";return Array.from({length:Xe},()=>Nt[Math.floor(Math.random()*Nt.length)]).join("")};let Se;switch(st){case"sk":Se=`sk-${H(48)}`;break;case"simple":Se=`PROXY_KEY_${H(32).toUpperCase()}`;break;case"token":Se=`PROXY_KEY:${H(32)}`;break;default:Se=`sk-${H(48)}`}d(Xe=>({...Xe,apiKey:Se})),window.api.proxyUpdateConfig({apiKey:Se}),_e(!0),we(!0),setTimeout(()=>we(!1),1500)},[st]),et=g.useCallback(()=>{o.apiKey&&(navigator.clipboard.writeText(o.apiKey),ae(!0),setTimeout(()=>ae(!1),1500))},[o.apiKey]),qe=g.useCallback(async()=>{try{const H=await window.api.proxyGetStatus();if(i(H.running),H.config){const Xe=H.config;Xe.selectedAccountIds&&Xe.selectedAccountIds.length>0&&(Xe.selectedAccountId=Xe.selectedAccountIds[0]);const Nt=Xe.clientDrivenToolExecution!==!1;d({...Xe,clientDrivenToolExecution:Nt})}H.stats&&h(H.stats),H.sessionStats&&p(H.sessionStats);const Se=await window.api.proxyGetAccounts();b(Se.accounts.length),N(Se.availableCount)}catch(H){console.error("Failed to fetch proxy status:",H)}},[]),Je=g.useCallback(async()=>{if(typeof window.api.dashboardTunnelGetStatus=="function")try{const H=await window.api.dashboardTunnelGetStatus();Lt(H),Qt(Se=>Se||H.localUrl||"")}catch(H){console.error("Failed to fetch dashboard tunnel status:",H)}},[]),Kt=async()=>{if(typeof window.api.dashboardTunnelStart=="function"){Et(!0),k(null);try{const H=await window.api.dashboardTunnelStart({localUrl:xt.trim()||void 0});Lt(H.status),Qt(H.status.localUrl),H.success||k(H.error||H.status.error||"Không bật được Dashboard Tunnel")}catch(H){k(H instanceof Error?H.message:String(H))}finally{Et(!1)}}},Ye=async()=>{if(typeof window.api.dashboardTunnelStop=="function"){Et(!0),k(null);try{const H=await window.api.dashboardTunnelStop();Lt(H.status),H.success||k(H.error||H.status.error||"Không tắt được Dashboard Tunnel")}catch(H){k(H instanceof Error?H.message:String(H))}finally{Et(!1)}}},qt=g.useCallback(()=>{Ue?.publicUrl&&(navigator.clipboard.writeText(Ue.publicUrl),gt(!0),setTimeout(()=>gt(!1),1500))},[Ue?.publicUrl]),Jt=g.useCallback(async()=>{try{const H=await window.api.proxyGetModels();H.success&&H.models&&X(H.models.map(Se=>({id:Se.id,name:Se.name||Se.id})))}catch{}},[]),Ct=g.useCallback(async H=>{G(!0),V(!1);try{const Se=H?.mode??o.multiAccountSelectionMode??"all",Xe=H?.groupIds??o.multiAccountGroupIds??[];let Nt=Array.from(Ze.values()).filter(Bt=>Bt.status==="active"&&Bt.credentials?.accessToken);if(o.enableMultiAccount&&Se==="groups"){const Bt=new Set(Xe);Nt=Nt.filter(qn=>qn.groupId?Bt.has(qn.groupId):Bt.has("__ungrouped__"))}const nt=Nt.map(Bt=>({id:Bt.id,email:Bt.email,accessToken:Bt.credentials.accessToken,refreshToken:Bt.credentials?.refreshToken,profileArn:Bt.profileArn,expiresAt:Bt.credentials?.expiresAt,machineId:Bt.machineId,clientId:Bt.credentials?.clientId,clientSecret:Bt.credentials?.clientSecret,region:Bt.credentials?.region||"us-east-1",authMethod:Bt.credentials?.authMethod,provider:Bt.credentials?.provider||Bt.idp,groupId:Bt.groupId})),$t=await window.api.proxySyncAccounts(nt);$t.success&&(b($t.accountCount||0),await qe(),V(!0),setTimeout(()=>V(!1),2e3))}catch(Se){console.error("Failed to sync accounts:",Se)}finally{G(!1)}},[Ze,qe,o.enableMultiAccount,o.multiAccountSelectionMode,o.multiAccountGroupIds]),O=async()=>{k(null);try{await Ct();const H=await window.api.proxyStart({port:o.port,host:o.host,apiKey:o.apiKey,enableMultiAccount:o.enableMultiAccount,enabled:!0,autoStart:o.autoStart,accountSelectionStrategy:o.enableMultiAccount?o.accountSelectionStrategy||"smart":o.accountSelectionStrategy,sessionAffinityEnabled:o.enableMultiAccount&&(o.accountSelectionStrategy||"smart")!=="sticky"?!1:o.sessionAffinityEnabled,logRequests:o.logRequests,clientDrivenToolExecution:o.clientDrivenToolExecution!==!1,disableTools:o.disableTools});H.success?(i(!0),d(Se=>({...Se,enabled:!0})),await qe()):k(H.error||(s?"Failed to start":"Khởi động thất bại"))}catch(H){k(H.message)}},ne=async()=>{k(null);try{const H=await window.api.proxyStop();H.success?(i(!1),d(Se=>({...Se,enabled:!1})),h(null)):k(H.error||(s?"Failed to stop":"Dừng thất bại"))}catch(H){k(H.message)}},ze=()=>{const Se=`http://${o.host==="0.0.0.0"?"localhost":o.host}:${o.port}`;navigator.clipboard.writeText(Se),T(!0),setTimeout(()=>T(!1),2e3)},_=async()=>{U(!0),B(!1);try{const H=await window.api.proxyRefreshModels();H.success?(await Jt(),B(!0),setTimeout(()=>B(!1),2e3)):k(H.error||(s?"Failed to refresh models":"Làm mới model thất bại"))}catch(H){k(H.message)}finally{U(!1)}};g.useEffect(()=>{window.api.proxyLoadLogs().then(H=>{H.success&&H.logs.length>0&&I(H.logs)})},[]),g.useEffect(()=>{Je();const H=setInterval(()=>void Je(),5e3);return()=>clearInterval(H)},[Je]),g.useEffect(()=>{if(R.length===0)return;const H=setTimeout(()=>{window.api.proxySaveLogs(R)},2e3);return()=>clearTimeout(H)},[R]),g.useEffect(()=>{qe(),Jt();const H=window.api.onProxyRequest(nt=>{console.log("[Proxy] Request:",nt)});WI(),Ip=I;const Se=window.api.onProxyResponse(()=>{qe()}),Xe=window.api.onProxyError(nt=>{console.error("[Proxy] Error:",nt),k(nt)}),Nt=window.api.onProxyStatusChange(nt=>{i(nt.running),nt.running&&d($t=>({...$t,port:nt.port}))});return()=>{H(),Se(),Xe(),Nt(),Ip=null}},[qe,Jt]),g.useEffect(()=>{const H=()=>{document.hidden||qe()};document.addEventListener("visibilitychange",H);const Se=setInterval(H,YI);return()=>{document.removeEventListener("visibilitychange",H),clearInterval(Se)}},[qe]);const ce=g.useRef(Ct);g.useEffect(()=>{ce.current=Ct},[Ct]);const Ce=g.useMemo(()=>Array.from(Ze.values()).filter(H=>H.status==="active"&&H.credentials?.accessToken).map(H=>`${H.id}:${H.groupId||""}`).sort().join("|"),[Ze]),Ve=g.useRef(!1);g.useEffect(()=>{if(!r)return;if(!Ve.current){Ve.current=!0;return}const H=setTimeout(()=>{ce.current()},600);return()=>clearTimeout(H)},[Ce,r]);const[je,He]=g.useState(0);g.useEffect(()=>{if(!r||!u){He(0);return}He(Math.floor((Date.now()-u.startTime)/1e3));const H=setInterval(()=>{He(Math.floor((Date.now()-u.startTime)/1e3))},1e3);return()=>clearInterval(H)},[r,u]);const Tt=H=>{const Se=Math.floor(H/3600),Xe=Math.floor(H%3600/60),Nt=H%60;return`${Se}h ${Xe}m ${Nt}s`};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(De,{className:"hover-lift relative z-10",children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-primary/10",children:e.jsx(Sc,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx(rt,{className:"text-lg text-primary",children:"Kiro API Proxy"}),e.jsx(Gl,{children:s?"Provides OpenAI and Claude compatible API endpoints":"Cung cấp endpoint tương thích OpenAI và Claude"})]})]}),e.jsxs($e,{variant:r?"default":"secondary",className:r?"bg-success text-white flex items-center gap-1.5 pr-2.5":"bg-muted text-muted-foreground flex items-center gap-1.5 pr-2.5",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[r&&e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-white opacity-75"}),e.jsx("span",{className:r?"relative inline-flex rounded-full h-2 w-2 bg-white":"relative inline-flex rounded-full h-2 w-2 bg-muted-foreground"})]}),r?s?"Running":"Đang chạy":s?"Stopped":"Đã dừng"]})]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[r?e.jsxs(D,{onClick:ne,variant:"destructive",className:"gap-2",children:[e.jsx(Cn,{className:"h-4 w-4"}),s?"Stop Service":"Tắt dịch vụ"]}):e.jsxs(D,{onClick:O,className:"gap-2",children:[e.jsx(Ba,{className:"h-4 w-4"}),s?"Start Service":"Bật dịch vụ"]}),e.jsxs(D,{onClick:()=>void Ct(),variant:"outline",className:"gap-2",disabled:!r||M,children:[M?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):q?e.jsx(Pt,{className:"h-4 w-4 text-success"}):e.jsx(Mt,{className:"h-4 w-4"}),M?s?"Syncing...":"Đang đồng bộ...":q?s?"Synced!":"Đã đồng bộ":s?"Sync Accounts":"Đồng bộ tài khoản"]}),e.jsxs(D,{onClick:_,variant:"outline",className:"gap-2",disabled:!r||W,children:[W?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):le?e.jsx(Pt,{className:"h-4 w-4 text-success"}):e.jsx(Mt,{className:"h-4 w-4"}),W?s?"Refreshing...":"Đang làm mới...":le?s?"Refreshed!":"Đã làm mới":s?"Refresh Models":"Làm mới model"]}),e.jsxs(D,{onClick:()=>P(!0),variant:"outline",className:"gap-2",disabled:!r,children:[e.jsx(ai,{className:"h-4 w-4"}),s?"View Models":"Xem model"]}),e.jsxs(D,{onClick:()=>fe(!0),variant:"outline",className:"gap-2",children:[e.jsx(Ka,{className:"h-4 w-4"}),s?"Configure Clients":"Cấu hình client"]})]}),S&&e.jsxs("div",{className:"flex items-center gap-2 text-destructive text-sm",children:[e.jsx(ln,{className:"h-4 w-4"}),S]}),r&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"min-w-[80px]",children:s?"Address:":"Địa chỉ:"}),e.jsxs("code",{className:"flex-1 px-3 py-2 bg-muted rounded text-sm",children:["http://",o.host==="0.0.0.0"?"localhost":o.host,":",o.port]}),e.jsx(D,{variant:"outline",size:"icon",onClick:ze,children:j?e.jsx(Pt,{className:"h-4 w-4"}):e.jsx(As,{className:"h-4 w-4"})})]}),o.host==="0.0.0.0"&&e.jsx("p",{className:"text-xs text-muted-foreground pl-[88px]",children:s?`LAN devices use http://<this-machine-IP>:${o.port}`:`Thiết bị khác dùng http://<IP-máy-này>:${o.port}`})]}),e.jsxs("div",{className:"rounded-lg border bg-background/70 p-3 space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-semibold",children:s?"Dashboard Tunnel":"Tunnel dashboard"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Expose the dashboard with Cloudflare Quick Tunnel. Login is still required.":"Mở dashboard bằng Cloudflare Quick Tunnel. Người dùng vẫn phải đăng nhập."})]})]}),e.jsx($e,{variant:Ue?.running?"default":"secondary",className:Ue?.running?"bg-success text-white":"",children:Ue?.running?s?"Online":"Đang bật":s?"Off":"Đang tắt"})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-2 items-end",children:[e.jsxs("div",{className:"col-span-8 space-y-1.5",children:[e.jsx(Fe,{htmlFor:"tunnelTarget",className:"text-xs",children:s?"Local dashboard target":"Đích dashboard nội bộ"}),e.jsx(it,{id:"tunnelTarget",value:xt,onChange:H=>Qt(H.target.value),placeholder:s?"Example: http://127.0.0.1 or http://127.0.0.1:4010":"Ví dụ: http://127.0.0.1 hoặc http://127.0.0.1:4010",disabled:Ue?.running||ft,className:"h-9"})]}),e.jsx("div",{className:"col-span-4 flex gap-2",children:Ue?.running?e.jsxs(D,{onClick:Ye,variant:"outline",className:"gap-2 flex-1",disabled:ft,children:[ft?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Cn,{className:"h-4 w-4"}),s?"Stop Tunnel":"Tắt tunnel"]}):e.jsxs(D,{onClick:Kt,variant:"outline",className:"gap-2 flex-1",disabled:ft,children:[ft?e.jsx(bt,{className:"h-4 w-4 animate-spin"}):e.jsx(Ba,{className:"h-4 w-4"}),s?"Start Tunnel":"Bật tunnel"]})})]}),Ue?.publicUrl&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"flex-1 px-3 py-2 bg-muted rounded text-sm truncate",children:Ue.publicUrl}),e.jsx(D,{variant:"outline",size:"icon",onClick:qt,title:s?"Copy tunnel URL":"Sao chép link tunnel",children:Ge?e.jsx(Pt,{className:"h-4 w-4"}):e.jsx(As,{className:"h-4 w-4"})}),e.jsx(D,{variant:"outline",size:"icon",onClick:()=>window.api.openExternal(Ue.publicUrl),title:s?"Open tunnel":"Mở tunnel",children:e.jsx(Xs,{className:"h-4 w-4"})})]}),Ue?.error&&e.jsx("div",{className:"text-xs text-destructive",children:Ue.error}),Ue&&!Ue.running&&!Ue.error&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s?`Binary: ${Ue.binary}. Set CLOUDFLARED_BIN if cloudflared is not in PATH.`:`File chạy: ${Ue.binary}. Nếu cloudflared không có trong PATH, đặt CLOUDFLARED_BIN.`})]}),e.jsxs("div",{className:"grid grid-cols-12 gap-3",children:[e.jsxs("div",{className:"col-span-2 space-y-1.5",children:[e.jsx(Fe,{htmlFor:"port",className:"text-xs",children:s?"Port":"Cổng"}),e.jsx(it,{id:"port",type:"number",value:o.port,onChange:H=>{const Se=parseInt(H.target.value)||5580;d(Xe=>({...Xe,port:Se})),window.api.proxyUpdateConfig({port:Se})},disabled:r,className:"h-9"})]}),e.jsxs("div",{className:"col-span-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Fe,{htmlFor:"host",className:"text-xs",title:o.host==="0.0.0.0"?s?"LAN access enabled. Set an API Key and allow port through firewall.":"Đang cho phép truy cập ngoài máy; nên đặt API Key và mở cổng firewall":s?"Loopback only. Toggle Public for LAN access.":"Chỉ chạy nội bộ; bật Public để thiết bị khác truy cập",children:s?"Host":"Địa chỉ nghe"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(is,{id:"publicAccess",checked:o.host==="0.0.0.0",onCheckedChange:async H=>{const Se=H?"0.0.0.0":"127.0.0.1";if(d(Xe=>({...Xe,host:Se})),await window.api.proxyUpdateConfig({host:Se}),r)try{await window.api.proxyStop(),await new Promise(Xe=>setTimeout(Xe,200)),await window.api.proxyStart()}catch(Xe){console.error("[Proxy] Failed to restart after host change:",Xe),k(Xe instanceof Error?Xe.message:String(Xe))}},className:"scale-75"}),e.jsx(Fe,{htmlFor:"publicAccess",className:"text-[10px] cursor-pointer",children:"Public"})]})]}),e.jsx(it,{id:"host",value:o.host,onChange:H=>{const Se=H.target.value;d(Xe=>({...Xe,host:Se})),window.api.proxyUpdateConfig({host:Se})},disabled:r,className:`h-9 ${o.host==="0.0.0.0"?"border-warning/50":""}`})]}),e.jsxs("div",{className:"col-span-7 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Fe,{htmlFor:"apiKey",className:"text-xs",title:s?"When set, requests must provide this key in Authorization or X-Api-Key header":"Khi đặt key, request phải gửi qua header Authorization hoặc X-Api-Key",children:s?"API Key (Optional)":"API Key (tùy chọn)"}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(ei,{value:st,options:[{value:"sk",label:"sk-xxx"},{value:"simple",label:"PROXY_KEY"},{value:"token",label:"KEY:TOKEN"}],onChange:H=>oe(H),className:"w-[120px] h-7 text-xs [&>button]:h-7 [&>button]:py-0 [&>button]:px-2.5"}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:Ne,disabled:r,title:s?"Generate":"Tạo ngẫu nhiên",children:L?e.jsx(Pt,{className:"h-3.5 w-3.5 text-success"}):e.jsx(G3,{className:"h-3.5 w-3.5"})}),o.apiKey&&e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:et,title:s?"Copy":"Sao chép",children:ue?e.jsx(Pt,{className:"h-3.5 w-3.5 text-success"}):e.jsx(As,{className:"h-3.5 w-3.5"})}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>Ee(!0),title:s?"Manage Multiple API Keys":"Quản lý nhiều API Key",children:e.jsx(Ka,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(it,{id:"apiKey",type:Qe?"text":"password",placeholder:s?"Leave empty to skip auth":"Để trống để bỏ xác thực",value:o.apiKey||"",onChange:H=>{const Se=H.target.value||void 0;d(Xe=>({...Xe,apiKey:Se})),window.api.proxyUpdateConfig({apiKey:Se})},disabled:r,className:"pr-9 h-9"}),e.jsx(D,{type:"button",variant:"ghost",size:"icon",className:"absolute right-0 top-0 h-full px-2.5 hover:bg-transparent",onClick:()=>_e(!Qe),title:Qe?s?"Hide":"Ẩn":s?"Show":"Hiện",children:Qe?e.jsx(Jl,{className:"h-3.5 w-3.5"}):e.jsx(Nc,{className:"h-3.5 w-3.5"})})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-x-4 gap-y-3 items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"autoStart",checked:o.autoStart||!1,onCheckedChange:async H=>{const Se=H?{autoStart:!0,enabled:!0}:{autoStart:!1,enabled:r};d(Nt=>({...Nt,...Se}));const Xe=await window.api.proxyUpdateConfig(Se);Xe.success||k(Xe.error||(s?"Failed to update auto start":"Không lưu được tự khởi động")),await qe()}}),e.jsx(Fe,{htmlFor:"autoStart",className:"text-sm cursor-pointer",children:s?"Auto Start":"Tự khởi động"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"multiAccount",checked:o.enableMultiAccount,onCheckedChange:H=>{const Se=H?{enableMultiAccount:!0,accountSelectionStrategy:"smart",sessionAffinityEnabled:!1}:{enableMultiAccount:!1};d(Xe=>({...Xe,...Se})),window.api.proxyUpdateConfig(Se)},disabled:r}),e.jsx(Fe,{htmlFor:"multiAccount",className:"text-sm cursor-pointer",children:s?"Multi-Account":"Nhiều tài khoản"})]}),o.enableMultiAccount&&e.jsxs("div",{className:"col-span-2 flex items-center gap-2",children:[e.jsxs(Fe,{className:"text-sm shrink-0",children:[s?"Strategy":"Chiến lược",":"]}),e.jsx("div",{className:"flex gap-1 bg-muted/30 rounded-lg p-0.5",children:["smart","round-robin","least-used","sticky"].map(H=>{const Se=(o.accountSelectionStrategy||"smart")===H,Xe=H==="smart"?"Smart":H==="round-robin"?"Round-Robin":H==="least-used"?"Least-Used":"Sticky",Nt=H==="smart"?"Thông minh":H==="round-robin"?"Xoay vòng":H==="least-used"?"Ít dùng nhất":"Bám phiên";return e.jsx("button",{type:"button",disabled:r,className:`px-3 py-1 rounded-md text-xs font-medium transition-all ${Se?"bg-primary text-primary-foreground shadow-sm":"text-muted-foreground hover:text-foreground hover:bg-muted/50"} disabled:opacity-50 disabled:cursor-not-allowed`,onClick:()=>{const nt=H!=="sticky"?{accountSelectionStrategy:H,sessionAffinityEnabled:!1}:{accountSelectionStrategy:H};d($t=>({...$t,...nt})),window.api.proxyUpdateConfig(nt)},children:s?Xe:Nt},H)})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:(()=>{const H=o.accountSelectionStrategy||"smart";return H==="smart"?s?"Score quota, errors, latency and token freshness before each request":"Chấm điểm quota, lỗi, độ trễ và token trước mỗi request":H==="least-used"?s?"Pick the account with the fewest successful requests":"Chọn tài khoản có số request thành công thấp nhất":H==="sticky"?s?"Stay on success account until failure (preserves prompt cache)":"Giữ tài khoản đang thành công cho tới khi lỗi":s?"Each request rotates to next account (load balanced)":"Mỗi request chuyển sang tài khoản kế tiếp để cân bằng tải"})()})]}),o.enableMultiAccount&&(()=>{const H=o.multiAccountSelectionMode||"all",Se=new Set(o.multiAccountGroupIds||[]),Xe=Array.from(J.values()).sort((Ot,ws)=>(Ot.order??0)-(ws.order??0)),Nt=Array.from(Ze.values()).filter(Ot=>Ot.status==="active"&&Ot.credentials?.accessToken),nt=Nt.filter(Ot=>!Ot.groupId).length,$t=new Map;for(const Ot of Nt)Ot.groupId&&$t.set(Ot.groupId,($t.get(Ot.groupId)||0)+1);const Bt=H==="all"?Nt.length:Nt.filter(Ot=>Ot.groupId?Se.has(Ot.groupId):Se.has("__ungrouped__")).length,qn=Ot=>{const ws=new Set(Se);ws.has(Ot)?ws.delete(Ot):ws.add(Ot);const Hs=Array.from(ws);d(Z=>({...Z,multiAccountGroupIds:Hs})),window.api.proxyUpdateConfig({multiAccountGroupIds:Hs}),Ct({mode:"groups",groupIds:Hs})};return e.jsxs("div",{className:"col-span-2 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(Fe,{className:"text-sm shrink-0",children:[s?"Scope":"Phạm vi",":"]}),e.jsx("div",{className:"flex gap-1 bg-muted/30 rounded-lg p-0.5",children:["all","groups"].map(Ot=>{const ws=H===Ot,Hs=Ot==="all"?s?"All Accounts":"Tất cả tài khoản":s?"Specific Groups":"Nhóm đã chọn";return e.jsx("button",{type:"button",disabled:r,className:`px-3 py-1 rounded-md text-xs font-medium transition-all ${ws?"bg-primary text-primary-foreground shadow-sm":"text-muted-foreground hover:text-foreground hover:bg-muted/50"} disabled:opacity-50 disabled:cursor-not-allowed`,onClick:()=>{d(Z=>({...Z,multiAccountSelectionMode:Ot})),window.api.proxyUpdateConfig({multiAccountSelectionMode:Ot}),Ct({mode:Ot,groupIds:Array.from(Se)})},children:Hs},Ot)})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:H==="all"?s?`${Bt} active accounts`:`${Bt} tài khoản hoạt động`:s?`${Bt} accounts in selected groups`:`${Bt} tài khoản trong nhóm đã chọn`})]}),H==="groups"&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 pl-[60px]",children:[e.jsxs("button",{type:"button",disabled:r,onClick:()=>qn("__ungrouped__"),className:`flex items-center gap-1 px-2 h-7 rounded-md text-xs font-medium border transition-all ${Se.has("__ungrouped__")?"bg-muted text-foreground border-muted-foreground/30":"bg-background text-muted-foreground border-border hover:text-foreground hover:border-primary/40"} disabled:opacity-50 disabled:cursor-not-allowed`,children:[Se.has("__ungrouped__")&&e.jsx(Pt,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Ungrouped":"Chưa nhóm"}),e.jsxs("span",{className:"text-[10px] opacity-70",children:["(",nt,")"]})]}),Xe.map(Ot=>{const ws=Se.has(Ot.id),Hs=$t.get(Ot.id)||0;return e.jsxs("button",{type:"button",disabled:r,onClick:()=>qn(Ot.id),className:`flex items-center gap-1 px-2 h-7 rounded-md text-xs font-medium border transition-all ${ws?"text-foreground":"bg-background text-muted-foreground border-border hover:text-foreground hover:border-primary/40"} disabled:opacity-50 disabled:cursor-not-allowed`,style:ws?{backgroundColor:(Ot.color||"#888")+"22",borderColor:(Ot.color||"#888")+"66"}:void 0,children:[ws&&e.jsx(Pt,{className:"h-3 w-3",style:{color:Ot.color||void 0}}),e.jsx("span",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:Ot.color||"#888"}}),e.jsx("span",{children:Ot.name}),e.jsxs("span",{className:"text-[10px] opacity-70",children:["(",Hs,")"]})]},Ot.id)}),Xe.length===0&&e.jsx("span",{className:"text-xs text-muted-foreground italic",children:s?"No groups defined yet. Create groups in Account Manager first.":"Chưa có nhóm nào. Hãy tạo nhóm trong trang Tài khoản trước."})]})]})})(),!o.enableMultiAccount&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"col-span-2",children:e.jsxs(D,{variant:"outline",className:"w-full justify-start",onClick:()=>xe(!0),disabled:r,children:[e.jsx(Rv,{className:"h-4 w-4 mr-2"}),o.selectedAccountId?(()=>{const H=Ze.get(o.selectedAccountId);return H?H.email||H.id.substring(0,12)+"...":s?"First Available":"Tài khoản khả dụng đầu tiên"})():s?"First Available":"Tài khoản khả dụng đầu tiên"]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"autoSwitchOnQuotaExhausted",checked:o.autoSwitchOnQuotaExhausted||!1,onCheckedChange:H=>{d(Se=>({...Se,autoSwitchOnQuotaExhausted:H})),window.api.proxyUpdateConfig({autoSwitchOnQuotaExhausted:H})},disabled:r}),e.jsx(Fe,{htmlFor:"autoSwitchOnQuotaExhausted",className:"text-sm cursor-pointer truncate",title:s?"Auto-switch on quota exhausted":"Tự chuyển khi tài khoản hết hạn mức",children:s?"Auto-switch":"Tự chuyển"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"logRequests",checked:o.logRequests,onCheckedChange:H=>{d(Se=>({...Se,logRequests:H})),window.api.proxyUpdateConfig({logRequests:H})}}),e.jsx(Fe,{htmlFor:"logRequests",className:"text-sm cursor-pointer",children:s?"Log Requests":"Ghi log request"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{id:"logStreamEvents",checked:o.logStreamEvents||!1,onCheckedChange:H=>{d(Se=>({...Se,logStreamEvents:H})),window.api.proxyUpdateConfig({logStreamEvents:H})}}),e.jsx(Fe,{htmlFor:"logStreamEvents",className:"text-sm cursor-pointer",children:s?"Stream Events":"Sự kiện stream"})]})]}),e.jsxs("div",{className:"border-t border-border pt-3 overflow-visible",children:[e.jsxs("h4",{className:"text-xs font-medium mb-2 text-muted-foreground uppercase tracking-wider flex items-center gap-1.5",children:[e.jsx(Ka,{className:"h-3.5 w-3.5"}),s?"Advanced Settings":"Cài đặt nâng cao"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-x-3 gap-y-3 items-start overflow-visible",children:[e.jsxs("div",{className:"space-y-1.5 relative z-20",children:[e.jsx(Fe,{htmlFor:"preferredEndpoint",className:"text-xs",children:s?"Preferred Endpoint":"Endpoint ưu tiên"}),e.jsx(ei,{value:o.preferredEndpoint||"",options:[{value:"",label:s?"Auto Select":"Tự chọn",description:s?"Auto select based on availability":"Tự chọn endpoint theo khả dụng"},{value:"codewhisperer",label:"CodeWhisperer",description:s?"IDE mode endpoint":"Endpoint chế độ IDE"},{value:"amazonq",label:"AmazonQ",description:s?"IDE mode (q.amazonaws.com)":"Chế độ IDE (q.amazonaws.com)"},{value:"amazonq-cli",label:"AmazonQ CLI",description:s?"CLI mode (SendMessageStreaming)":"Chế độ CLI (SendMessageStreaming)"}],onChange:H=>{const Se=H||void 0;d(Xe=>({...Xe,preferredEndpoint:Se})),window.api.proxyUpdateConfig({preferredEndpoint:Se})},placeholder:s?"Select endpoint":"Chọn endpoint"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"maxRetries",className:"text-xs",children:s?"Max Retries":"Số lần thử lại tối đa"}),e.jsx(it,{id:"maxRetries",type:"number",min:0,max:10,value:o.maxRetries||3,onChange:H=>{const Se=parseInt(H.target.value)||3;d(Xe=>({...Xe,maxRetries:Se})),window.api.proxyUpdateConfig({maxRetries:Se})},disabled:r,className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"payloadSizeLimit",className:"text-xs",title:s?"When payload exceeds this limit, oldest tool results will be truncated. Default 1536KB (1.5MB).":"Khi payload vượt giới hạn này, kết quả tool cũ nhất sẽ bị cắt. Mặc định 1536KB (1.5MB).",children:"Payload (KB)"}),e.jsx(it,{id:"payloadSizeLimit",type:"number",min:256,max:10240,step:128,value:o.payloadSizeLimitKB||1536,onChange:H=>{const Se=parseInt(H.target.value)||1536;d(Xe=>({...Xe,payloadSizeLimitKB:Se})),window.api.proxyUpdateConfig({payloadSizeLimitKB:Se})},disabled:r,className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"clientDrivenToolExecution",className:"text-xs",title:s?"Recommended for OpenCode and Claude Code. Disable only when the proxy should fabricate tool results.":"Khuyến nghị cho OpenCode và Claude Code. Chỉ tắt khi muốn proxy tự tạo kết quả tool.",children:s?"Tool Execution":"Thực thi tool"}),e.jsxs("div",{className:"flex items-center justify-between h-9 px-3 rounded-md border border-input bg-transparent",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Client-driven":"Client xử lý"}),e.jsx(is,{id:"clientDrivenToolExecution",checked:o.clientDrivenToolExecution!==!1,onCheckedChange:H=>{d(Se=>({...Se,clientDrivenToolExecution:H})),window.api.proxyUpdateConfig({clientDrivenToolExecution:H})},disabled:r,className:"scale-90"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(Fe,{htmlFor:"disableTools",className:"text-xs",title:s?"When enabled, the proxy strips all tool definitions from requests.":"Khi bật, proxy sẽ loại bỏ toàn bộ định nghĩa tool khỏi request, phù hợp chat thuần.",children:s?"Disable Tools":"Tắt gọi tool"}),e.jsxs("div",{className:"flex items-center justify-between h-9 px-3 rounded-md border border-input bg-transparent",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"No tool calls":"Không gọi tool"}),e.jsx(is,{id:"disableTools",checked:o.disableTools||!1,onCheckedChange:H=>{d(Se=>({...Se,disableTools:H})),window.api.proxyUpdateConfig({disableTools:H})},disabled:r,className:"scale-90"})]})]}),e.jsxs("div",{className:"col-span-3 space-y-1.5",children:[e.jsx(Fe,{htmlFor:"tokenBufferReserve",className:"text-xs",title:s?"When enabled, reserves N tokens below context window for trim (e.g. 200K → trim at 180K). When disabled, never trims.":"Khi bật, chừa N token dưới context window để làm ngưỡng cắt (ví dụ 200K -> cắt ở 180K). Khi tắt sẽ không cắt lịch sử.",children:s?"Token Buffer Reserve (auto-trim history)":"Dự phòng token (tự cắt lịch sử)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between h-9 px-3 rounded-md border border-input bg-transparent w-[160px] flex-shrink-0",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Auto-trim":"Bật tự cắt"}),e.jsx(is,{id:"enableTokenBufferReserve",checked:o.enableTokenBufferReserve||!1,onCheckedChange:H=>{d(Se=>({...Se,enableTokenBufferReserve:H})),window.api.proxyUpdateConfig({enableTokenBufferReserve:H})},disabled:r,className:"scale-90"})]}),e.jsx(it,{id:"tokenBufferReserve",type:"number",min:5e3,max:15e4,step:1e3,value:o.tokenBufferReserve||2e4,onChange:H=>{const Se=parseInt(H.target.value)||2e4;d(Xe=>({...Xe,tokenBufferReserve:Se})),window.api.proxyUpdateConfig({tokenBufferReserve:Se})},disabled:r||!o.enableTokenBufferReserve,placeholder:s?"Reserve tokens (default 20000)":"Số token dự phòng (mặc định 20000)",className:"h-9 flex-1"})]})]})]})]})]})]}),e.jsx(UI,{config:o,setConfig:d,isRunning:r,isEn:s}),r&&e.jsxs("div",{className:"grid grid-cols-6 gap-3",children:[e.jsx(De,{className:"hover-lift bg-gradient-to-br from-blue-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Fn,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Pool":"Pool tài khoản"})]}),e.jsxs("div",{className:"text-xl font-bold text-foreground",children:[v,"/",y]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-purple-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Total":"Tổng request"})]}),e.jsx(D,{variant:"ghost",size:"icon",className:"h-4 w-4 text-muted-foreground hover:text-destructive",onClick:async()=>{await window.api.proxyResetRequestStats();const H=await window.api.proxyGetStatus();H.stats&&h(H.stats),H.sessionStats&&p(H.sessionStats)},title:s?"Reset Statistics":"Đặt lại thống kê",children:e.jsx(gr,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"text-xl font-bold text-foreground",children:u?.totalRequests||0})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-green-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Pt,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Total S/F":"Tổng thành công/lỗi"})]}),e.jsxs("div",{className:"text-xl font-bold",children:[e.jsx("span",{className:"text-success",children:u?.successRequests||0}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-destructive",children:u?.failedRequests||0})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-cyan-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ds,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Session":"Phiên này"})]}),e.jsx("div",{className:"text-xl font-bold text-foreground",children:f?.totalRequests||0})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-orange-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Session S/F":"Phiên thành công/lỗi"})]}),e.jsxs("div",{className:"text-xl font-bold",children:[e.jsx("span",{className:"text-success",children:f?.successRequests||0}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-destructive",children:f?.failedRequests||0})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-primary/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Gn,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Uptime":"Thời gian chạy"})]}),e.jsx("div",{className:"text-xl font-bold text-primary whitespace-nowrap",children:Tt(je)})]})})]}),r&&u&&e.jsxs("div",{className:"grid grid-cols-6 gap-3",children:[e.jsx(De,{className:"hover-lift bg-gradient-to-br from-indigo-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Total Tokens":"Tổng token"})]}),e.jsx("div",{className:"text-xl font-bold text-indigo-500",title:((u.inputTokens||0)+(u.outputTokens||0)).toLocaleString(),children:zl((u.inputTokens||0)+(u.outputTokens||0))})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-blue-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ks,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Input / Output":"Đầu vào / Đầu ra"})]}),e.jsxs("div",{className:"text-sm font-bold",children:[e.jsx("span",{className:"text-blue-500",title:(u.inputTokens||0).toLocaleString(),children:zl(u.inputTokens||0)}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-purple-500",title:(u.outputTokens||0).toLocaleString(),children:zl(u.outputTokens||0)})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-emerald-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(ai,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Cache Hit":"Cache hit"}),(()=>{const H=u.cacheReadTokens||0,Se=H+(u.cacheWriteTokens||0),Xe=Se>0?H/Se*100:0;return Xe>0?e.jsxs($e,{variant:"secondary",className:"ml-1 text-[10px] px-1 py-0",children:[Xe.toFixed(0),"%"]}):null})()]}),e.jsxs("div",{className:"text-sm font-bold",children:[e.jsx("span",{className:"text-emerald-500",title:`${s?"Cache Read":"Đọc cache"}: ${(u.cacheReadTokens||0).toLocaleString()}`,children:zl(u.cacheReadTokens||0)}),e.jsx("span",{className:"text-muted-foreground mx-1",children:"/"}),e.jsx("span",{className:"text-amber-500",title:`${s?"Cache Write":"Ghi cache"}: ${(u.cacheWriteTokens||0).toLocaleString()}`,children:zl(u.cacheWriteTokens||0)})]})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-violet-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Ds,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Reasoning":"Token suy luận"})]}),e.jsx("div",{className:"text-xl font-bold text-violet-500",title:(u.reasoningTokens||0).toLocaleString(),children:zl(u.reasoningTokens||0)})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-green-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Rv,{className:"h-3 w-3"}),e.jsx("span",{children:s?"Success Rate":"Tỷ lệ thành công"})]}),e.jsx("div",{className:"text-xl font-bold text-success",children:u.totalRequests>0?`${(u.successRequests/u.totalRequests*100).toFixed(1)}%`:"-"})]})}),e.jsx(De,{className:"hover-lift bg-gradient-to-br from-amber-500/5 to-transparent",children:e.jsxs(Pe,{className:"pt-3 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground mb-1",children:[e.jsx(Sc,{className:"h-3 w-3"}),e.jsx("span",{children:"Credits"})]}),e.jsx("div",{className:"text-xl font-bold text-amber-500",children:(u.totalCredits||0).toFixed(4)})]})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(ri,{className:"h-4 w-4 text-primary"})}),s?"API Endpoints":"Endpoint API"]})}),e.jsxs(Pe,{className:"space-y-1.5 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/chat/completions"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"OpenAI Compatible":"Tương thích OpenAI"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/responses"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"OpenAI Responses"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/messages"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Claude Compatible":"Tương thích Claude"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/anthropic/v1/messages"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Claude Code"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/messages/count_tokens"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Token Count":"Đếm token"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1/models"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Model List":"Danh sách model"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-orange-500 w-11 flex-shrink-0 font-mono",children:"POST"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1beta/models/*:generateContent"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Gemini Compatible":"Tương thích Gemini"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/v1beta/models"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Gemini Models":"Model Gemini"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/health"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Health Check":"Kiểm tra health"})]}),e.jsxs("div",{className:"border-t pt-2 mt-2 space-y-1.5",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:s?"Admin API (Requires API Key)":"Admin API (cần API Key)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/admin/stats"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Detailed Stats":"Thống kê chi tiết"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/admin/accounts"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Account List":"Danh sách tài khoản"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500 w-11 flex-shrink-0 font-mono",children:"GET"}),e.jsx("code",{className:"text-muted-foreground flex-1 font-mono",children:"/admin/logs"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Request Logs":"Log request"})]})]})]})]}),R.length>0&&e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Ks,{className:"h-4 w-4 text-primary"})}),s?"Recent Requests":"Request gần đây"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{variant:"secondary",className:"text-xs",children:R.length}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>K(!0),children:[e.jsx(xr,{className:"h-3 w-3 mr-1"}),s?"View All":"Xem tất cả"]}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>te(!0),children:[e.jsx(Ks,{className:"h-3 w-3 mr-1"}),s?"Detailed Logs":"Log chi tiết"]})]})]})}),e.jsx(Pe,{className:"pt-2",children:e.jsx("div",{className:"max-h-[150px] overflow-y-auto text-xs font-mono space-y-0.5",children:R.slice(0,5).map((H,Se)=>e.jsxs("div",{className:"grid gap-2 py-1 px-2 rounded hover:bg-muted/50 items-center",style:{gridTemplateColumns:"2fr 1fr 1.2fr 0.5fr 0.8fr 0.8fr 0.8fr 0.8fr 0.6fr"},children:[e.jsx("span",{className:"text-muted-foreground whitespace-nowrap text-left",children:H.time}),e.jsx("span",{className:"truncate text-left",title:H.path,children:H.path}),e.jsx("span",{className:"truncate text-left text-muted-foreground",title:H.model,children:H.model?H.model.replace("anthropic.","").replace("-v1:0",""):"-"}),e.jsx("span",{className:`text-center ${H.status>=400?"text-destructive":"text-success"}`,children:H.status}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.inputTokens?H.inputTokens.toLocaleString():"-"}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.outputTokens?H.outputTokens.toLocaleString():"-"}),e.jsx("span",{className:"text-success text-right",children:H.cacheReadTokens?H.cacheReadTokens.toLocaleString():"-"}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.credits?H.credits.toFixed(4):"-"}),e.jsx("span",{className:"text-muted-foreground text-right",children:H.responseTime?`${(H.responseTime/1e3).toFixed(1)}s`:"-"})]},Se))})})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded-lg bg-primary/10",children:e.jsx(Ds,{className:"h-4 w-4 text-primary"})}),s?"Supported Features":"Tính năng hỗ trợ"]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Auto Token Refresh":"Tự làm mới token"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Request Retry":"Tự thử lại request"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Multi-Account Rotation":"Xoay tua nhiều tài khoản"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"IDC/Social Auth":"Xác thực IDC/Social"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Agentic Mode Detection":"Nhận diện chế độ agentic"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Thinking Mode Support":"Hỗ trợ thinking mode"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Image Processing":"Xử lý hình ảnh"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-primary",children:"✓"}),e.jsx("span",{className:"text-foreground",children:s?"Usage Statistics":"Thống kê sử dụng"})]})]})})]}),e.jsx($I,{open:be,onOpenChange:K,logs:R,totalCredits:u?.totalCredits||0,totalTokens:(u?.inputTokens||0)+(u?.outputTokens||0),onClearLogs:()=>{I([]),window.api.proxySaveLogs([])},onResetCredits:async()=>{await window.api.proxyResetCredits(),qe()},onResetTokens:async()=>{await window.api.proxyResetTokens(),qe()},isEn:s}),e.jsx(BI,{open:se,onOpenChange:te}),e.jsx(_I,{open:Y,onOpenChange:P,isEn:s,onOpenModelMapping:async()=>{try{const H=await window.api.proxyGetModels();H.success&&H.models&&X(H.models.map(Se=>({id:Se.id,name:Se.name||Se.id})))}catch{}P(!1),C(!0)},mappingCount:o.modelMappings?.length||0}),e.jsx(XI,{open:F,onOpenChange:fe,isEn:s}),e.jsx(VI,{open:pe,onOpenChange:C,isEn:s,mappings:o.modelMappings||[],onMappingsChange:H=>{d(Se=>({...Se,modelMappings:H})),window.api.proxyUpdateConfig({modelMappings:H})},apiKeys:(o.apiKeys||[]).map(H=>({id:H.id,name:H.name})),availableModels:z}),e.jsx(KI,{open:re,onOpenChange:xe,accounts:Ze,selectedAccountId:o.selectedAccountId,onSelect:H=>{d(Se=>({...Se,selectedAccountId:H})),window.api.proxyUpdateConfig({selectedAccountIds:H?[H]:[]})},isEn:s}),Oe&&Tn.createPortal(e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50",onClick:()=>Ee(!1)}),e.jsxs("div",{className:"relative bg-background rounded-lg shadow-lg w-[800px] max-h-[80vh] overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold",children:s?"API Key Management":"Quản lý API Key"}),e.jsx(D,{variant:"ghost",size:"icon",onClick:()=>Ee(!1),children:"✕"})]}),e.jsx(FI,{})]})]}),document.body)]})}function ZI(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown";return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-primary/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-primary shadow-lg shadow-primary/25",children:e.jsx(Sc,{className:"h-6 w-6 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-primary",children:s?"API Proxy Service":"API 反代服务"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Provide OpenAI and Claude compatible API endpoints with multi-account rotation":"提供 OpenAI 和 Claude 兼容的 API 端点,支持多账号轮询"})]})]})]}),e.jsx(QI,{})]})}let wu=[],Rp=null,lj=!1;function JI(){lj||(lj=!0,window.api.onKproxyRequest(n=>{wu=[{timestamp:n.timestamp,host:n.host,method:n.method,path:n.path,isMitm:n.isMitm,deviceIdReplaced:n.deviceIdReplaced},...wu].slice(0,50),Rp?.(wu)}))}function eR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",[r,i]=g.useState(!1),[o,d]=g.useState(!1),[u,h]=g.useState(!1),[f,p]=g.useState({enabled:!1,port:8899,host:"127.0.0.1",mitmDomains:["amazonaws.com","amazon.com"],autoStart:!1,logRequests:!0}),[y,b]=g.useState(null),[v,N]=g.useState(null),[j,T]=g.useState(null),[S,k]=g.useState(!1),[R,I]=g.useState(!1),[M,G]=g.useState(wu),[W,U]=g.useState(null),q=g.useCallback(async()=>{try{const P=await window.api.kproxyCheckCaCertInstalled();U(P.installed)}catch{U(null)}},[]),V=g.useCallback(async()=>{if(!(o||u)){h(!0),T(null);try{const P=await window.api.kproxyInit();if(P.success){d(!0),P.caInfo&&N(P.caInfo);const F=await window.api.kproxyGetStatus();F.config&&p(F.config),F.stats&&b(F.stats),i(F.running)}else T(P.error||"Failed to initialize K-Proxy")}catch(P){T(P instanceof Error?P.message:"Init failed")}finally{h(!1)}}},[o,u]);g.useEffect(()=>{V(),q()},[V,q]),g.useEffect(()=>{JI(),Rp=G;const P=window.api.onKproxyStatusChange(fe=>{i(fe.running)}),F=window.api.onKproxyError(fe=>{T(fe)});return()=>{P(),F(),Rp=null}},[]);const le=async()=>{T(null);try{if(r){const F=await window.api.kproxyStop();F.success||T(F.error||"Failed to stop")}else{const F=await window.api.kproxyStart(f);F.success||T(F.error||"Failed to start")}const P=await window.api.kproxyGetStatus();i(P.running),P.stats&&b(P.stats)}catch(P){T(P instanceof Error?P.message:"Operation failed")}},B=async P=>{const F={...f,...P};p(F);try{await window.api.kproxyUpdateConfig(P)}catch(fe){console.error("Failed to update config:",fe)}},be=async()=>{try{const P=await window.api.kproxyGenerateDeviceId();P.success&&P.deviceId&&(await B({deviceId:P.deviceId}),await window.api.kproxySetDeviceId(P.deviceId))}catch(P){T(P instanceof Error?P.message:"Failed to generate device ID")}},K=()=>{const P=`${f.host}:${f.port}`;navigator.clipboard.writeText(P),k(!0),setTimeout(()=>k(!1),2e3)},se=()=>{f.deviceId&&(navigator.clipboard.writeText(f.deviceId),I(!0),setTimeout(()=>I(!1),2e3))},te=async()=>{try{const P=await window.api.kproxyExportCaCert();P.success||T(P.error||"Export failed")}catch(P){T(P instanceof Error?P.message:"Export failed")}},Y=P=>new Date(P).toLocaleTimeString();return o?e.jsxs("div",{className:"space-y-4",children:[j&&e.jsxs("div",{className:"bg-destructive/10 text-destructive px-4 py-2 rounded-md flex items-center gap-2",children:[e.jsx(ln,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:j}),e.jsx(D,{variant:"ghost",size:"sm",className:"ml-auto h-6 px-2",onClick:()=>T(null),children:"✕"})]}),e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:"K-Proxy MITM"}),e.jsx($e,{variant:r?"default":"secondary",className:me("ml-2",r&&"bg-green-500 hover:bg-green-600"),children:r?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-white opacity-75"}),e.jsx("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-white"})]}),s?"Running":"运行中"]}):s?"Stopped":"已停止"})]}),e.jsx(D,{onClick:le,variant:r?"destructive":"default",size:"sm",children:r?e.jsxs(e.Fragment,{children:[e.jsx(Cn,{className:"h-4 w-4 mr-1"}),s?"Stop":"停止"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ba,{className:"h-4 w-4 mr-1"}),s?"Start":"启动"]})})]}),e.jsx(Gl,{children:s?"MITM proxy for replacing Machine ID in Kiro requests":"MITM 代理,用于替换 Kiro 请求中的 Machine ID"})]}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Sc,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:s?"Proxy:":"代理地址:"}),e.jsxs("code",{className:"bg-muted px-2 py-1 rounded text-sm font-mono",children:[f.host,":",f.port]}),e.jsx(D,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:K,children:S?e.jsx(Pt,{className:"h-3 w-3 text-green-500"}):e.jsx(As,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:s?"Port":"端口"}),e.jsx(it,{type:"number",value:f.port,onChange:P=>B({port:parseInt(P.target.value)||8899}),disabled:r,className:"h-8"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{children:s?"Host":"监听地址"}),e.jsx(it,{value:f.host,onChange:P=>B({host:P.target.value}),disabled:r,className:"h-8"})]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xr,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Fe,{children:s?"Log Requests":"记录请求日志"})]}),e.jsx(is,{checked:f.logRequests,onCheckedChange:P=>B({logRequests:P})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ba,{className:"h-4 w-4 text-muted-foreground"}),e.jsx(Fe,{children:s?"Auto Start":"自动启动"})]}),e.jsx(is,{checked:f.autoStart,onCheckedChange:P=>B({autoStart:P})})]})]})]}),e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(eo,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"Device ID":"设备 ID"})]}),e.jsx(Gl,{children:s?"Machine ID to replace in requests (64 hex characters)":"替换请求中的 Machine ID(64位十六进制)"})]}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{value:f.deviceId||"",onChange:P=>{B({deviceId:P.target.value}),P.target.value.length===64&&window.api.kproxySetDeviceId(P.target.value)},placeholder:s?"Enter or generate device ID":"输入或生成设备 ID",className:"font-mono text-xs h-8"}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-8",onClick:be,children:[e.jsx(Dc,{className:"h-3 w-3 mr-1"}),s?"Generate":"生成"]}),f.deviceId&&e.jsx(D,{variant:"ghost",size:"sm",className:"h-8 px-2",onClick:se,children:R?e.jsx(Pt,{className:"h-3 w-3 text-green-500"}):e.jsx(As,{className:"h-3 w-3"})})]}),f.deviceId&&e.jsx("p",{className:"text-xs text-muted-foreground",children:f.deviceId.length===64?s?"✓ Valid device ID format":"✓ 设备 ID 格式正确":s?`⚠ Invalid length: ${f.deviceId.length}/64`:`⚠ 长度不正确: ${f.deviceId.length}/64`})]})]}),e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Vn,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"CA Certificate":"CA 证书"})]}),e.jsxs("div",{className:"flex gap-2",children:[W===!1?e.jsx(D,{variant:"default",size:"sm",onClick:async()=>{try{const P=await window.api.kproxyInstallCaCert();P.success?(U(!0),alert(P.message||(s?"Certificate installed":"证书已安装"))):alert(P.error||(s?"Failed to install":"安装失败"))}catch(P){alert(P instanceof Error?P.message:String(P))}},children:s?"Install":"安装"}):W===!0?e.jsx(D,{variant:"destructive",size:"sm",onClick:async()=>{try{const P=await window.api.kproxyUninstallCaCert();P.success?(U(!1),alert(P.message||(s?"Certificate uninstalled":"证书已卸载"))):alert(P.error||(s?"Failed to uninstall":"卸载失败"))}catch(P){alert(P instanceof Error?P.message:String(P))}},children:s?"Uninstall":"卸载"}):e.jsx(D,{variant:"outline",size:"sm",disabled:!0,children:s?"Checking...":"检测中..."}),e.jsxs(D,{variant:"outline",size:"sm",onClick:te,children:[e.jsx(Ns,{className:"h-3 w-3 mr-1"}),s?"Export":"导出"]})]})]}),e.jsx(Gl,{children:s?"Install this certificate to trust K-Proxy MITM":"安装此证书以信任 K-Proxy MITM 代理"})]}),v&&e.jsxs(Pe,{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s?"Fingerprint:":"指纹:"}),e.jsx("code",{className:"bg-muted px-2 py-0.5 rounded text-xs font-mono truncate max-w-[300px]",children:v.fingerprint})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-muted-foreground",children:s?"Valid:":"有效期:"}),e.jsxs("span",{className:"text-xs",children:[new Date(v.validFrom).toLocaleDateString()," - ",new Date(v.validTo).toLocaleDateString()]})]})]})]}),y&&e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"Statistics":"统计"})]})}),e.jsx(Pe,{children:e.jsxs("div",{className:"grid grid-cols-4 gap-4 text-center",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold",children:y.totalRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Total":"总请求"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-blue-500",children:y.mitmRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"MITM"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-green-500",children:y.modifiedRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Modified":"已修改"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-gray-500",children:y.bypassRequests}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s?"Bypass":"透传"})]})]})})]}),M.length>0&&e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ri,{className:"h-5 w-5 text-primary"}),e.jsx(rt,{className:"text-lg",children:s?"Recent Requests":"最近请求"})]})}),e.jsx(Pe,{children:e.jsx("div",{className:"space-y-1 max-h-48 overflow-y-auto",children:M.slice(0,10).map((P,F)=>e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1 border-b last:border-0",children:[e.jsx("span",{className:"text-muted-foreground w-16",children:Y(P.timestamp)}),e.jsx($e,{variant:P.isMitm?"default":"secondary",className:"text-[10px] px-1 py-0",children:P.isMitm?"MITM":"PASS"}),P.deviceIdReplaced&&e.jsx($e,{variant:"outline",className:"text-[10px] px-1 py-0 text-green-600 border-green-600",children:"ID"}),e.jsx("span",{className:"font-mono truncate flex-1",children:P.host})]},F))})})]}),e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsx(rt,{className:"text-lg",children:s?"Usage Guide":"使用说明"})}),e.jsxs(Pe,{className:"text-sm text-muted-foreground space-y-2",children:[e.jsxs("p",{children:["1. ",s?"Export and install the CA certificate to your system trust store":"导出并安装 CA 证书到系统信任存储"]}),e.jsxs("p",{children:["2. ",s?"Set your system/application proxy to":"设置系统/应用代理为"," ",e.jsxs("code",{className:"bg-muted px-1 rounded",children:[f.host,":",f.port]})]}),e.jsxs("p",{children:["3. ",s?"Generate or enter a device ID to use for requests":"生成或输入用于请求的设备 ID"]}),e.jsxs("p",{children:["4. ",s?"Start the proxy and use Kiro IDE normally":"启动代理后正常使用 Kiro IDE"]})]})]})]}):u||!j?e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-4",children:[e.jsx(bt,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Initializing K-Proxy...":"正在初始化 K-Proxy..."})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-64 gap-4",children:[e.jsx(ln,{className:"h-8 w-8 text-destructive"}),e.jsx("p",{className:"text-destructive",children:j}),e.jsxs(D,{onClick:V,children:[e.jsx(Mt,{className:"h-4 w-4 mr-2"}),s?"Retry":"重试"]})]})}function tR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown";return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-purple-500/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-purple-500/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-purple-500 shadow-lg shadow-purple-500/25",children:e.jsx(Vn,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-purple-600 dark:text-purple-400",children:"K-Proxy MITM"}),e.jsx("p",{className:"text-muted-foreground",children:s?"MITM proxy for Machine ID replacement, reduces ban risk":"MITM 代理,替换 Machine ID,降低封禁风险"})]})]})]}),e.jsx(eR,{})]})}const sR=[{value:"round_robin",label:"轮询",labelEn:"Round Robin",desc:"依次使用每个代理",descEn:"Use each proxy in sequence"},{value:"random",label:"随机",labelEn:"Random",desc:"随机挑选",descEn:"Pick randomly"},{value:"least_used",label:"最少使用",labelEn:"Least Used",desc:"使用次数少的优先",descEn:"Prefer proxies used less"},{value:"fastest",label:"最快优先",labelEn:"Fastest",desc:"按延迟升序",descEn:"Sort by latency asc"}];function nR({diag:n,isEn:s}){if(!n.success||!n.diagnose)return e.jsxs("div",{className:"mt-2 text-[11px] rounded-md bg-red-500/10 border border-red-500/30 text-red-700 dark:text-red-400 px-2 py-1.5",children:[s?"Diagnose failed: ":"诊断失败:",n.error||"unknown error"]});const r=n.diagnose,i=({ok:o,label:d,rt:u,err:h})=>e.jsxs("div",{className:"flex items-start gap-2 text-[11px]",children:[e.jsx("span",{className:me("mt-0.5 inline-flex items-center justify-center w-4 h-4 rounded-full text-[10px] font-bold",o?"bg-green-500/20 text-green-600 dark:text-green-400":"bg-red-500/20 text-red-600 dark:text-red-400"),children:o?"✓":"✗"}),e.jsxs("span",{className:"flex-1",children:[e.jsx("span",{className:"text-foreground",children:d}),u!==void 0&&e.jsxs("span",{className:"ml-1 text-muted-foreground font-mono",children:[u,"ms"]}),h&&e.jsx("div",{className:"mt-0.5 text-red-600 dark:text-red-400 break-all",children:h})]})]});return e.jsxs("div",{className:"mt-2 space-y-1.5 rounded-md border border-border bg-card/50 px-3 py-2",children:[e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono truncate",children:["target: ",n.targetUrl.replace(/:([^:@/]+)@/,":***@")]}),e.jsx(i,{ok:r.upstreamReachable,label:s?"A) Upstream TCP reachable":"A) 上游中转 TCP 可达",rt:r.upstreamRtMs,err:r.upstreamError}),e.jsx(i,{ok:r.targetReachable,label:s?"B) Via upstream → target proxy entry":"B) 经上游 → 目标代理入口",rt:r.targetRtMs,err:r.targetError}),e.jsx(i,{ok:r.endToEndOk===!0,label:s?`C) End-to-end CONNECT (status ${r.targetStatus??"?"} ${r.targetStatusText??""})`.trim():`C) 端到端 CONNECT(状态 ${r.targetStatus??"?"} ${r.targetStatusText??""})`.trim(),rt:r.endToEndRtMs,err:r.endToEndError}),r.targetBodySnippet&&e.jsxs("div",{className:"mt-1 text-[10px] text-muted-foreground font-mono break-all",children:["body: ",r.targetBodySnippet.slice(0,160)]})]})}function aR(n){const s={total:n.length,enabled:0,alive:0,slow:0,dead:0,untested:0,testing:0,totalUsed:0,totalFailed:0,totalSuccess:0,successRate:null,avgLatencyMs:null,topUsed:[]};let r=0,i=0;for(const o of n)o.enabled&&s.enabled++,o.status==="alive"?s.alive++:o.status==="slow"?s.slow++:o.status==="dead"?s.dead++:o.status==="untested"?s.untested++:o.status==="testing"&&s.testing++,s.totalUsed+=o.usedCount,s.totalFailed+=o.failCount,o.latencyMs&&(o.status==="alive"||o.status==="slow")&&(r+=o.latencyMs,i++);return s.totalSuccess=Math.max(0,s.totalUsed-s.totalFailed),s.successRate=s.totalUsed>0?s.totalSuccess/s.totalUsed:null,s.avgLatencyMs=i>0?Math.round(r/i):null,s.topUsed=n.slice().filter(o=>o.usedCount>0).sort((o,d)=>d.usedCount-o.usedCount).slice(0,5).map(o=>{const d=Math.max(0,o.usedCount-o.failCount);return{id:o.id,label:o.label||`${o.protocol}://${o.host}:${o.port}`,used:o.usedCount,failed:o.failCount,success:d,rate:o.usedCount>0?d/o.usedCount:null,status:o.status}}),s}function Ul({label:n,value:s,sub:r,tone:i}){const o=i==="green"?"text-green-600 dark:text-green-400":i==="amber"?"text-amber-600 dark:text-amber-400":i==="red"?"text-red-600 dark:text-red-400":i==="blue"?"text-blue-600 dark:text-blue-400":"text-foreground";return e.jsxs("div",{className:"rounded-lg border border-border bg-card/50 px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wide text-muted-foreground",children:n}),e.jsx("div",{className:me("mt-0.5 text-lg font-semibold tabular-nums",o),children:s}),r!==void 0&&e.jsx("div",{className:"text-[11px] text-muted-foreground",children:r})]})}function rR({stats:n,isEn:s}){if(n.total===0)return null;const r=n.total>0?(n.alive+n.slow)/n.total:0,i=n.successRate!==null?Math.round(n.successRate*100):null,o=i===null?"default":i>=80?"green":i>=50?"amber":"red",d=n.total===0?"default":r>=.7?"green":r>=.3?"amber":"red";return e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ks,{className:"h-4 w-4 text-primary"}),s?"Pool Health Dashboard":"代理池健康看板"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2",children:[e.jsx(Ul,{label:s?"Total / Enabled":"总数 / 已启用",value:e.jsxs(e.Fragment,{children:[n.total,e.jsxs("span",{className:"text-muted-foreground text-base",children:[" / ",n.enabled]})]})}),e.jsx(Ul,{label:s?"Availability":"可用率",value:`${Math.round(r*100)}%`,sub:`${n.alive+n.slow} ${s?"alive":"可用"}`,tone:d}),e.jsx(Ul,{label:s?"Success Rate":"成功率",value:i!==null?`${i}%`:"—",sub:`${n.totalSuccess} / ${n.totalUsed}`,tone:o}),e.jsx(Ul,{label:s?"Avg Latency":"平均延迟",value:n.avgLatencyMs!==null?`${n.avgLatencyMs}ms`:"—",tone:"blue"}),e.jsx(Ul,{label:s?"Dead":"失效",value:n.dead,tone:n.dead>0?"red":"default"}),e.jsx(Ul,{label:s?"Untested":"未测试",value:n.untested+n.testing,tone:n.untested>0?"amber":"default"})]}),n.topUsed.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs text-muted-foreground",children:s?`Top ${n.topUsed.length} most used proxies`:`承担量 Top ${n.topUsed.length}`}),e.jsx("div",{className:"space-y-1.5",children:n.topUsed.map(u=>{const h=u.rate!==null?Math.round(u.rate*100):null,f=u.rate!==null?u.rate*100:0,p=h===null?"bg-muted-foreground/30":h>=80?"bg-green-500":h>=50?"bg-amber-500":"bg-red-500";return e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(lw,{status:u.status}),e.jsx("span",{className:"font-mono text-[11px] truncate",children:u.label})]}),e.jsxs("div",{className:"shrink-0 text-[11px] tabular-nums text-muted-foreground",children:[u.success,"/",u.used,h!==null&&e.jsxs("span",{className:"ml-1.5 font-medium text-foreground",children:[h,"%"]})]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:me("h-full transition-all",p),style:{width:`${f}%`}})})]},u.id)})})]})]})]})}function lw({status:n,latency:s}){const r={untested:{color:"bg-muted text-muted-foreground",label:"未测试",labelEn:"Untested"},testing:{color:"bg-blue-500/15 text-blue-600 dark:text-blue-400",label:"测试中",labelEn:"Testing"},alive:{color:"bg-green-500/15 text-green-600 dark:text-green-400",label:"可用",labelEn:"Alive"},slow:{color:"bg-amber-500/15 text-amber-600 dark:text-amber-400",label:"较慢",labelEn:"Slow"},dead:{color:"bg-red-500/15 text-red-600 dark:text-red-400",label:"失效",labelEn:"Dead"}}[n];return e.jsxs("span",{className:me("inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-medium",r.color),children:[n==="testing"&&e.jsx(bt,{className:"h-3 w-3 animate-spin"}),n==="alive"&&e.jsx(an,{className:"h-3 w-3"}),n==="slow"&&e.jsx(Ks,{className:"h-3 w-3"}),n==="dead"&&e.jsx(fs,{className:"h-3 w-3"}),e.jsx("span",{children:r.label}),s!==void 0&&(n==="alive"||n==="slow")&&e.jsxs("span",{className:"font-mono opacity-70",children:[s,"ms"]})]})}function iR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",{proxyPool:r,proxyPoolConfig:i,addProxy:o,importProxies:d,removeProxy:u,removeProxies:h,toggleProxyEnabled:f,updateProxy:p,validateProxy:y,validateProxiesBatch:b,clearProxyPool:v,setProxyPoolConfig:N,accounts:j,accountProxyBindings:T,unbindAccountFromProxy:S,clearAccountProxyBindings:k,autoDistributeAccountsToProxies:R}=vt(),[I,M]=g.useState(""),[G,W]=g.useState(""),[U,q]=g.useState(!1),[V,le]=g.useState(new Set),[B,be]=g.useState(""),[K,se]=g.useState("all"),[te,Y]=g.useState("all"),[P,F]=g.useState("all"),[fe,pe]=g.useState("all"),[C,z]=g.useState("all"),[X,re]=g.useState(!1),[xe,Oe]=g.useState(!1),[Ee,Qe]=g.useState(10),[_e,st]=g.useState(5),[oe,ue]=g.useState(!1),[ae,L]=g.useState(!1),[we,Ue]=g.useState(null),Lt=g.useCallback(async()=>{const O=i.upstreamProxy?.trim();if(!O)return;const ne=Array.from(r.values()),ze=ne.find(_=>_.enabled)||ne[0];if(ze){L(!0),Ue(null);try{const _=await window.api.proxyPoolDiagnoseChain({targetUrl:ze.url,upstreamProxy:O});Ue({targetUrl:ze.url,..._})}catch(_){Ue({targetUrl:ze.url,success:!1,error:_ instanceof Error?_.message:String(_)})}finally{L(!1)}}},[r,i.upstreamProxy]),xt=g.useMemo(()=>Array.from(r.values()),[r]),Qt=g.useMemo(()=>aR(xt),[xt]),ft=g.useMemo(()=>{const ne=Array.from(j.values()).filter(Ve=>Ve.status==="active").length,ze=Object.keys(T).filter(Ve=>j.has(Ve)).length,_=xt.filter(Ve=>Ve.enabled&&Ve.status!=="dead"),ce={};for(const[Ve,je]of Object.entries(T))j.has(Ve)&&(ce[je]=(ce[je]||0)+1);const Ce=Object.entries(ce).filter(([,Ve])=>Ve>10).map(([Ve,je])=>({pid:Ve,count:je,proxy:r.get(Ve)}));return{totalActive:ne,boundCount:ze,unboundCount:ne-ze,aliveProxyCount:_.length,perProxy:ce,overloadedProxies:Ce}},[j,T,xt,r]),Et=g.useRef(0);g.useEffect(()=>{const O=i.autoValidateIntervalMin;if(!O||O<=0)return;const ze=setInterval(()=>{const _=Date.now();if(_-Et.current<O*6e4)return;const ce=Array.from(r.values()).filter(Ce=>Ce.enabled).map(Ce=>Ce.id);ce.length!==0&&(Et.current=_,console.log(`[ProxyPool] Auto-validate ${ce.length} proxies`),b(ce,i.autoValidateConcurrency||5))},6e4);return()=>clearInterval(ze)},[i.autoValidateIntervalMin,i.autoValidateConcurrency,r,b]);const Ge=g.useCallback(O=>{if(ft.aliveProxyCount===0){alert(s?"No alive proxies. Validate proxies first.":"没有可用代理,请先验活代理");return}const ne=Array.from(j.values()).filter(_=>_.status==="active").map(_=>_.id);if(ne.length===0){alert(s?"No active accounts.":"没有可用账号");return}const ze=R({accountsPerProxy:_e,onlyUnbound:O,accountIds:ne});alert(s?`Distributed ${ze.distributed} accounts, skipped ${ze.skipped}`:`已分配 ${ze.distributed} 个账号,跳过 ${ze.skipped}`)},[j,_e,R,ft.aliveProxyCount,s]),gt=g.useMemo(()=>{let O=0,ne=0,ze=0,_=0,ce=0;for(const Ce of xt)Ce.enabled&&ce++,Ce.status==="alive"?O++:Ce.status==="dead"?ne++:Ce.status==="slow"?ze++:Ce.status==="untested"&&_++;return{total:xt.length,alive:O,dead:ne,slow:ze,untested:_,enabled:ce}},[xt]),Ze=g.useMemo(()=>{const O=Date.now(),ne=3600*1e3,ze=24*ne;return xt.filter(_=>{if(K!=="all"&&_.status!==K||te!=="all"&&_.protocol!==te||P==="enabled"&&!_.enabled||P==="disabled"&&_.enabled)return!1;if(fe!=="all"){const ce=_.latencyMs;if(fe==="unknown"){if(typeof ce=="number")return!1}else{if(typeof ce!="number")return!1;if(fe==="fast"&&ce>=200||fe==="medium"&&(ce<200||ce>=1e3)||fe==="slow"&&ce<1e3)return!1}}if(C!=="all")if(C==="never"){if(_.lastTestedAt)return!1}else if(_.lastTestedAt){const ce=O-_.lastTestedAt;if(C==="1h"&&ce>ne||C==="1d"&&ce>ze||C==="7d"&&ce>7*ze)return!1}else return!1;if(B){const ce=B.toLowerCase().trim();if(![_.host,String(_.port),_.protocol,_.username||"",_.label||"",_.lastBoundEmail||"",_.url||"",(_.tags||[]).join(" "),_.source||""].join(" ").toLowerCase().includes(ce))return!1}return!0})},[xt,B,K,te,P,fe,C]),J=g.useMemo(()=>{let O=0;return te!=="all"&&O++,P!=="all"&&O++,fe!=="all"&&O++,C!=="all"&&O++,O},[te,P,fe,C]),Ne=g.useCallback(()=>{Y("all"),F("all"),pe("all"),z("all")},[]),et=g.useCallback(()=>{if(!I.trim())return;o(I.trim())?M(""):alert(s?"Invalid proxy URL or duplicate":"代理 URL 无效或重复")},[I,o,s]),qe=g.useCallback(()=>{if(!G.trim())return;const O=d(G);alert(s?`Imported: added ${O.added}, skipped ${O.skipped}, failed ${O.failed}`:`导入完成:新增 ${O.added},跳过 ${O.skipped},失败 ${O.failed}`),W(""),q(!1)},[G,d,s]),Je=g.useCallback(async()=>{const O=Ze.map(ne=>ne.id);if(O.length!==0){Oe(!0);try{await b(O,Ee)}finally{Oe(!1)}}},[Ze,b,Ee]),Kt=g.useCallback(async()=>{const O=Array.from(V);if(O.length!==0){Oe(!0);try{await b(O,Ee)}finally{Oe(!1)}}},[V,b,Ee]),Ye=g.useCallback(()=>{V.size!==0&&confirm(s?`Delete ${V.size} proxies?`:`确定删除 ${V.size} 个代理?`)&&(h(Array.from(V)),le(new Set))},[V,h,s]),qt=g.useCallback(()=>{const O=xt.filter(ne=>ne.status==="dead").map(ne=>ne.id);O.length!==0&&confirm(s?`Remove ${O.length} dead proxies?`:`确定移除 ${O.length} 个失效代理?`)&&h(O)},[xt,h,s]),Jt=O=>{le(ne=>{const ze=new Set(ne);return ze.has(O)?ze.delete(O):ze.add(O),ze})},Ct=()=>{V.size===Ze.length&&Ze.length>0?le(new Set):le(new Set(Ze.map(O=>O.id)))};return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-cyan-500/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-cyan-500/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-cyan-500 shadow-lg shadow-cyan-500/25",children:e.jsx(Ki,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-cyan-600 dark:text-cyan-400",children:s?"Proxy Pool":"代理池"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Proxy routing for registration tasks. Use only for legitimate network configuration; it does not bypass provider risk controls.":"注册任务的代理路由配置。仅用于合规网络配置,不能绕过服务商风控。"})]})]})]}),e.jsx(rR,{stats:Qt,isEn:s}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ka,{className:"h-4 w-4 text-primary"}),s?"Pool Configuration":"池配置"]})}),e.jsxs(Pe,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(is,{checked:i.enabled,onCheckedChange:O=>N({enabled:O})}),e.jsxs("div",{children:[e.jsx(Fe,{className:"cursor-pointer text-sm",children:s?"Enable proxy pool for registration":"为注册流程启用代理池"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s?"When enabled, each registration task picks an available proxy by the strategy below.":"开启后,每个注册任务会按下方策略自动选取一个可用代理"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fe,{className:"text-xs",children:s?"Selection Strategy":"调度策略"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:sR.map(O=>e.jsx("button",{type:"button",onClick:()=>N({strategy:O.value}),className:me("px-3 py-1.5 rounded-md border text-xs transition-colors",i.strategy===O.value?"border-primary bg-primary/10 text-primary font-medium":"border-border hover:border-primary/50"),title:s?O.descEn:O.desc,children:s?O.labelEn:O.label},O.value))})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{checked:i.autoDisableDead,onCheckedChange:O=>N({autoDisableDead:O})}),e.jsx(Fe,{className:"text-xs cursor-pointer",children:s?"Auto-disable on failure":"失败自动停用"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Failure threshold":"失败阈值"}),e.jsx(it,{type:"number",min:1,max:20,value:i.failureThreshold,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=1&&N({failureThreshold:ne})},className:"h-8 text-xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"IP Detection Endpoint":"IP 检测端点"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs("select",{value:kf.find(O=>O.url===i.testUrl)?.id||"_custom",onChange:O=>{const ne=kf.find(ze=>ze.id===O.target.value);ne&&N({testUrl:ne.url})},className:"h-8 text-xs rounded-lg border border-foreground/15 bg-[var(--glass-bg)] backdrop-blur-md px-2 flex-shrink-0",children:[kf.map(O=>e.jsx("option",{value:O.id,children:O.label},O.id)),e.jsx("option",{value:"_custom",children:s?"Custom...":"自定义..."})]}),e.jsx(it,{value:i.testUrl,onChange:O=>N({testUrl:O.target.value}),placeholder:"https://api.ipify.org?format=json",className:"h-8 text-xs font-mono flex-1"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Fe,{className:"text-xs flex items-center gap-1",children:[e.jsx(Gn,{className:"h-3 w-3"}),s?"Auto-validate interval (min, 0=off)":"定时自动验活(分钟,0=关闭)"]}),e.jsx(it,{type:"number",min:0,max:1440,value:i.autoValidateIntervalMin,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=0&&N({autoValidateIntervalMin:ne})},className:"h-8 text-xs"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Auto-validate concurrency":"验活并发"}),e.jsx(it,{type:"number",min:1,max:50,value:i.autoValidateConcurrency,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=1&&N({autoValidateConcurrency:ne})},disabled:i.autoValidateIntervalMin===0,className:"h-8 text-xs"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Upstream relay proxy (proxy chaining)":"上游中转代理(代理链)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{value:i.upstreamProxy||"",onChange:O=>N({upstreamProxy:O.target.value}),placeholder:s?"e.g. socks5://127.0.0.1:7890 (empty = off)":"如 socks5://127.0.0.1:7890(留空=不启用)",className:"h-8 text-xs font-mono flex-1"}),e.jsxs(D,{size:"sm",variant:"outline",className:"h-8 px-3 text-xs whitespace-nowrap",disabled:!i.upstreamProxy?.trim()||r.size===0||ae,onClick:()=>void Lt(),title:s?"Diagnose proxy chain (locates failure layer)":"诊断代理链(定位失败在哪一层)",children:[ae?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(jx,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1",children:s?"Diagnose":"诊断"})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:s?"When set, traffic chains: local → relay → target proxy → site. Use only to satisfy your proxy provider routing or allowlist requirements. Supports http/socks5.":"填写后链路为:本机 → 上游中转 → 目标代理 → 目标站点。仅用于满足代理服务商的路由或白名单要求。支持 http/socks5。"}),we&&e.jsx(nR,{diag:we,isEn:s})]})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ts,{className:"h-4 w-4 text-primary"}),s?"Add Proxies":"添加代理"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(it,{value:I,onChange:O=>M(O.target.value),onKeyDown:O=>O.key==="Enter"&&et(),placeholder:s?"http://user:pass@host:port or host:port or socks5://...":"http://user:pass@host:port 或 host:port 或 socks5://...",className:"font-mono text-xs"}),e.jsxs(D,{onClick:et,disabled:!I.trim(),children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),s?"Add":"添加"]}),e.jsxs(D,{variant:"outline",onClick:()=>q(!U),children:[e.jsx(Fa,{className:"h-4 w-4 mr-1"}),s?"Bulk":"批量"]})]}),U&&e.jsxs("div",{className:"space-y-2 p-3 bg-muted/30 rounded-lg border border-dashed",children:[e.jsx(Fe,{className:"text-xs",children:s?"One proxy per line. Supports: http(s)://host:port, user:pass@host:port, host:port:user:pass, socks5://...":"每行一个代理。支持格式: http(s)://host:port、user:pass@host:port、host:port:user:pass、socks5://..."}),e.jsx("textarea",{value:G,onChange:O=>W(O.target.value),rows:5,className:"w-full px-3 py-2 bg-background border rounded-lg text-xs font-mono resize-none",placeholder:`http://127.0.0.1:7890
126
126
  user:pass@1.2.3.4:8080
127
127
  socks5://example.com:1080`}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>{W(""),q(!1)},children:s?"Cancel":"取消"}),e.jsxs(D,{size:"sm",onClick:qe,disabled:!G.trim(),children:[e.jsx(xr,{className:"h-4 w-4 mr-1"}),s?"Import":"导入"]})]})]})]})]}),e.jsx(De,{children:e.jsxs(Pe,{className:"py-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-4 text-sm flex-wrap",children:[e.jsxs("span",{className:"text-muted-foreground",children:[s?"Total:":"总计:"," ",e.jsx("strong",{className:"text-foreground",children:gt.total})]}),e.jsxs($e,{variant:"outline",className:"text-green-600 border-green-200 bg-green-50 dark:bg-green-950/30",children:[s?"Alive":"可用",": ",gt.alive]}),e.jsxs($e,{variant:"outline",className:"text-amber-600 border-amber-200 bg-amber-50 dark:bg-amber-950/30",children:[s?"Slow":"较慢",": ",gt.slow]}),e.jsxs($e,{variant:"outline",className:"text-red-600 border-red-200 bg-red-50 dark:bg-red-950/30",children:[s?"Dead":"失效",": ",gt.dead]}),e.jsxs($e,{variant:"outline",className:"text-muted-foreground",children:[s?"Untested":"未测试",": ",gt.untested]}),e.jsx("span",{className:"ml-auto text-xs text-muted-foreground",children:s?`${gt.enabled} enabled`:`${gt.enabled} 已启用`})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(it,{value:B,onChange:O=>be(O.target.value),placeholder:s?"Search any field (host/port/protocol/user/email/label/url)...":"搜索任意字段(host/端口/协议/user/邮箱/备注/URL)...",className:"h-8 max-w-md text-xs"}),e.jsxs("select",{value:K,onChange:O=>se(O.target.value),className:"h-8 px-2 rounded-md border bg-background text-xs",children:[e.jsx("option",{value:"all",children:s?"All Status":"全部状态"}),e.jsx("option",{value:"alive",children:s?"Alive":"可用"}),e.jsx("option",{value:"slow",children:s?"Slow":"较慢"}),e.jsx("option",{value:"dead",children:s?"Dead":"失效"}),e.jsx("option",{value:"untested",children:s?"Untested":"未测试"})]}),e.jsxs(D,{size:"sm",variant:X||J>0?"default":"outline",className:"h-8",onClick:()=>re(!X),children:[s?"Advanced":"高级",J>0&&e.jsx("span",{className:"ml-1.5 px-1.5 py-0.5 rounded-full bg-background/30 text-[10px]",children:J})]}),(B||K!=="all"||J>0)&&e.jsx(D,{size:"sm",variant:"ghost",className:"h-8 text-xs",onClick:()=>{be(""),se("all"),Ne()},children:s?"Clear":"清空"}),e.jsx("div",{className:"w-px h-6 bg-border"}),e.jsxs(D,{size:"sm",variant:"outline",onClick:Je,disabled:xe||Ze.length===0,children:[xe?e.jsx(bt,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Mt,{className:"h-4 w-4 mr-1"}),s?`Test All (${Ze.length})`:`全部测试 (${Ze.length})`]}),V.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs(D,{size:"sm",variant:"outline",onClick:Kt,children:[e.jsx(Mt,{className:"h-4 w-4 mr-1"}),s?`Test Selected (${V.size})`:`测试选中 (${V.size})`]}),e.jsxs(D,{size:"sm",variant:"outline",className:"text-destructive",onClick:Ye,children:[e.jsx(Vt,{className:"h-4 w-4 mr-1"}),s?`Delete (${V.size})`:`删除 (${V.size})`]})]}),e.jsxs(D,{size:"sm",variant:"ghost",onClick:qt,disabled:gt.dead===0,children:[e.jsx(fs,{className:"h-4 w-4 mr-1"}),s?"Remove Dead":"移除失效"]}),e.jsxs(D,{size:"sm",variant:"ghost",className:"text-destructive ml-auto",onClick:()=>{xt.length!==0&&confirm(s?"Clear all proxies?":"确定清空所有代理?")&&v()},disabled:xt.length===0,children:[e.jsx(Vt,{className:"h-4 w-4 mr-1"}),s?"Clear All":"清空"]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:s?"Concurrency:":"并发:"}),e.jsx(it,{type:"number",min:1,max:50,value:Ee,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=1&&Qe(ne)},className:"h-7 w-14 text-xs text-center"})]})]}),X&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 p-3 rounded-md border bg-muted/30 mt-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Protocol:":"协议:"}),e.jsxs("select",{value:te,onChange:O=>Y(O.target.value),className:"h-7 px-2 rounded-md border bg-background text-xs",children:[e.jsx("option",{value:"all",children:s?"All":"全部"}),e.jsx("option",{value:"http",children:"HTTP"}),e.jsx("option",{value:"https",children:"HTTPS"}),e.jsx("option",{value:"socks5",children:"SOCKS5"}),e.jsx("option",{value:"socks4",children:"SOCKS4"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Enabled:":"启用:"}),e.jsxs("select",{value:P,onChange:O=>F(O.target.value),className:"h-7 px-2 rounded-md border bg-background text-xs",children:[e.jsx("option",{value:"all",children:s?"All":"全部"}),e.jsx("option",{value:"enabled",children:s?"Enabled":"已启用"}),e.jsx("option",{value:"disabled",children:s?"Disabled":"已停用"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Latency:":"延迟:"}),e.jsxs("select",{value:fe,onChange:O=>pe(O.target.value),className:"h-7 px-2 rounded-md border bg-background text-xs",children:[e.jsx("option",{value:"all",children:s?"All":"全部"}),e.jsx("option",{value:"fast",children:s?"< 200ms (Fast)":"< 200ms(快)"}),e.jsx("option",{value:"medium",children:"200-1000ms"}),e.jsx("option",{value:"slow",children:s?"> 1000ms (Slow)":"> 1000ms(慢)"}),e.jsx("option",{value:"unknown",children:s?"Unknown":"未知"})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"Tested:":"验证于:"}),e.jsxs("select",{value:C,onChange:O=>z(O.target.value),className:"h-7 px-2 rounded-md border bg-background text-xs",children:[e.jsx("option",{value:"all",children:s?"Any time":"任意时间"}),e.jsx("option",{value:"1h",children:s?"Last 1h":"最近 1 小时"}),e.jsx("option",{value:"1d",children:s?"Last 1 day":"最近 1 天"}),e.jsx("option",{value:"7d",children:s?"Last 7 days":"最近 7 天"}),e.jsx("option",{value:"never",children:s?"Never tested":"从未测试"})]})]}),J>0&&e.jsx(D,{size:"sm",variant:"ghost",className:"h-7 ml-auto text-xs",onClick:Ne,children:s?"Reset":"重置"}),e.jsx("div",{className:"w-full text-[10px] text-muted-foreground mt-1",children:s?`Matched ${Ze.length} of ${xt.length}`:`匹配 ${Ze.length} / ${xt.length}`})]})]})}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(ql,{className:"h-4 w-4 text-primary"}),s?"Reverse Proxy: Account Routing":"反代路由(账号绑定代理)",e.jsx("span",{className:"text-[10px] font-normal text-muted-foreground",children:s?"— Keep routing explicit and auditable":"— 保持路由配置明确且可审计"})]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2 text-xs",children:[e.jsxs("div",{className:"p-2 bg-muted/30 rounded",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s?"Active Accounts":"可用账号"}),e.jsx("div",{className:"text-lg font-bold",children:ft.totalActive})]}),e.jsxs("div",{className:"p-2 bg-green-50 dark:bg-green-950/20 rounded",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s?"Bound":"已绑定"}),e.jsx("div",{className:"text-lg font-bold text-green-600",children:ft.boundCount})]}),e.jsxs("div",{className:"p-2 bg-amber-50 dark:bg-amber-950/20 rounded",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s?"Unbound":"未绑定"}),e.jsx("div",{className:"text-lg font-bold text-amber-600",children:ft.unboundCount})]}),e.jsxs("div",{className:"p-2 bg-cyan-50 dark:bg-cyan-950/20 rounded",children:[e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s?"Alive Proxies":"可用代理"}),e.jsx("div",{className:"text-lg font-bold text-cyan-600",children:ft.aliveProxyCount})]})]}),ft.overloadedProxies.length>0&&e.jsxs("div",{className:"p-2 bg-red-50 dark:bg-red-950/20 border border-red-200 dark:border-red-800 rounded text-xs",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-medium text-red-700 dark:text-red-300",children:[e.jsx(fs,{className:"h-3.5 w-3.5"}),s?"Risk: Overloaded proxies":"风险:超载代理"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:s?`${ft.overloadedProxies.length} proxy/proxies are carrying more than 10 accounts. Consider re-distributing.`:`${ft.overloadedProxies.length} 个代理承载了超过 10 个账号,建议重新分配。`})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap p-3 bg-muted/20 rounded-lg border border-dashed",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Kn,{className:"h-4 w-4 text-primary"}),e.jsxs(Fe,{className:"text-sm",children:[s?"Accounts per proxy":"每代理承载",":"]}),e.jsx(it,{type:"number",min:0,max:50,value:_e,onChange:O=>{const ne=parseInt(O.target.value,10);!isNaN(ne)&&ne>=0&&st(ne)},className:"h-8 w-20 text-xs text-center"}),e.jsx("span",{className:"text-[10px] text-muted-foreground italic",children:_e===0?s?"(0 = even split)":"(0 = 均分)":s?"accounts → 1 IP":"账号 / IP"})]}),e.jsxs(D,{size:"sm",onClick:()=>Ge(!0),disabled:ft.unboundCount===0,children:[e.jsx(Fn,{className:"h-4 w-4 mr-1"}),s?`Auto-Bind Unbound (${ft.unboundCount})`:`自动绑定未分配 (${ft.unboundCount})`]}),e.jsxs(D,{size:"sm",variant:"outline",onClick:()=>Ge(!1),children:[e.jsx(Mt,{className:"h-4 w-4 mr-1"}),s?"Re-Distribute All":"重新分配全部"]}),e.jsxs(D,{size:"sm",variant:"ghost",className:"text-destructive ml-auto",onClick:()=>{ft.boundCount!==0&&confirm(s?`Unbind all ${ft.boundCount} accounts?`:`解绑全部 ${ft.boundCount} 个账号?`)&&k()},disabled:ft.boundCount===0,children:[e.jsx(ZN,{className:"h-4 w-4 mr-1"}),s?"Unbind All":"解绑全部"]})]}),e.jsx("button",{onClick:()=>ue(!oe),className:"text-xs text-primary hover:underline flex items-center gap-1",children:oe?s?"▼ Hide binding details":"▼ 隐藏绑定明细":s?"▶ Show binding details":"▶ 显示绑定明细"}),oe&&e.jsxs("div",{className:"space-y-2 max-h-64 overflow-y-auto border rounded-lg",children:[xt.filter(O=>O.enabled&&O.status!=="dead").map(O=>{const ne=Object.entries(T).filter(([,ze])=>ze===O.id).map(([ze])=>ze);return ne.length===0?null:e.jsxs("div",{className:"p-2 border-b last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs mb-1",children:[e.jsxs("span",{className:"font-mono truncate",title:O.url,children:[O.host,":",O.port,O.label&&e.jsx($e,{variant:"outline",className:"ml-1.5 h-4 text-[9px]",children:O.label})]}),e.jsxs($e,{variant:"outline",className:"text-[10px]",children:[ne.length," ",s?"accounts":"账号"]})]}),e.jsx("div",{className:"flex flex-wrap gap-1 pl-2",children:ne.map(ze=>{const _=j.get(ze);return e.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-muted text-[10px] hover:bg-destructive/10 transition-colors group",children:[e.jsx("span",{title:_?.email,children:_?.email||ze.slice(0,8)}),e.jsx("button",{onClick:()=>S(ze),className:"opacity-30 group-hover:opacity-100 text-destructive",title:s?"Unbind":"解绑",children:e.jsx(fs,{className:"h-2.5 w-2.5"})})]},ze)})})]},O.id)}),ft.unboundCount>0&&e.jsx("div",{className:"p-2 bg-amber-50 dark:bg-amber-950/10 text-xs",children:e.jsx("span",{className:"text-amber-700 dark:text-amber-300",children:s?`${ft.unboundCount} accounts have no proxy binding (will use global proxy / direct).`:`${ft.unboundCount} 个账号未绑定代理(将走全局代理 / 直连)`})}),ft.boundCount===0&&e.jsx("div",{className:"p-4 text-center text-xs text-muted-foreground",children:s?'No bindings yet. Click "Auto-Bind" above to start.':'尚无绑定。点击上方"自动绑定"开始。'})]})]})]}),Ze.length>0?e.jsx(De,{children:e.jsxs(Pe,{className:"py-0 px-0",children:[e.jsxs("div",{className:"flex items-center gap-3 py-2 px-3 border-b text-xs font-medium text-muted-foreground bg-muted/30",children:[e.jsx("button",{onClick:Ct,className:"flex-shrink-0",children:e.jsx("input",{type:"checkbox",readOnly:!0,checked:V.size===Ze.length&&Ze.length>0,className:"cursor-pointer"})}),e.jsx("span",{className:"w-12 text-center",children:s?"On":"启用"}),e.jsx("span",{className:"flex-1",children:"URL"}),e.jsx("span",{className:"w-24 text-center",children:s?"Status":"状态"}),e.jsx("span",{className:"w-20 text-center",children:s?"Used":"使用"}),e.jsx("span",{className:"w-20 text-center",children:s?"Failed":"失败"}),e.jsx("span",{className:"w-32 text-center",children:s?"External IP / Email":"出口 IP / 邮箱"}),e.jsx("span",{className:"w-24 text-center",children:s?"Actions":"操作"})]}),e.jsx(lR,{filtered:Ze,selectedIds:V,onSelect:Jt,onToggle:f,onTest:y,onDelete:u,onSaveLabel:(O,ne)=>p(O,{label:ne}),isEn:s})]})}):e.jsx(De,{children:e.jsxs(Pe,{className:"py-12 text-center text-muted-foreground",children:[e.jsx(ri,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:xt.length===0?s?"No proxies yet. Add some to begin.":"暂无代理。先添加一些代理。":s?"No proxies match the current filter.":"当前筛选无匹配代理。"})]})})]})}function oj({proxy:n,selected:s,onSelect:r,onToggle:i,onTest:o,onDelete:d,onSaveLabel:u,isEn:h}){const f=g.useMemo(()=>n.password?n.url.replace(/:([^:@\/]+)@/,":***@"):n.url,[n.url,n.password]),p=()=>{navigator.clipboard.writeText(n.url)},[y,b]=g.useState(!1),[v,N]=g.useState(n.label||""),j=()=>{N(n.label||""),b(!0)},T=()=>{const S=v.trim();S!==(n.label||"")&&u(S||void 0),b(!1)};return e.jsxs("div",{className:me("flex items-center gap-3 py-2 px-3 border-b last:border-b-0 hover:bg-muted/40 text-xs transition-colors",s&&"bg-primary/5",!n.enabled&&"opacity-60"),children:[e.jsx("input",{type:"checkbox",checked:s,onChange:r,className:"flex-shrink-0 cursor-pointer"}),e.jsx("button",{onClick:i,className:"w-12 flex justify-center text-muted-foreground hover:text-foreground",title:h?n.enabled?"Disable":"Enable":n.enabled?"停用":"启用",children:n.enabled?e.jsx(kc,{className:"h-4 w-4 text-green-500"}):e.jsx(XN,{className:"h-4 w-4"})}),e.jsxs("span",{className:"flex-1 font-mono truncate flex items-center min-w-0",title:f,children:[e.jsxs("span",{className:"opacity-50 mr-1 flex-shrink-0",children:[n.protocol,"://"]}),e.jsxs("span",{className:"truncate",children:[n.host,":",n.port,n.username&&e.jsxs("span",{className:"opacity-50 ml-1",children:["@",n.username]})]}),y?e.jsx("input",{autoFocus:!0,value:v,onChange:S=>N(S.target.value),onBlur:T,onClick:S=>S.stopPropagation(),onKeyDown:S=>{S.key==="Enter"?T():S.key==="Escape"&&(N(n.label||""),b(!1))},placeholder:h?"Note":"备注",className:"ml-2 px-1.5 h-5 text-[10px] rounded border border-primary bg-background font-sans w-28 flex-shrink-0 focus:outline-none focus:ring-1 focus:ring-primary"}):n.label?e.jsx($e,{variant:"outline",className:"ml-2 h-4 text-[9px] cursor-pointer hover:bg-muted flex-shrink-0",onClick:j,title:h?"Click to edit note":"点击编辑备注",children:n.label}):null]}),e.jsx("span",{className:"w-24 flex justify-center",children:e.jsx(lw,{status:n.status,latency:n.latencyMs})}),e.jsx("span",{className:"w-20 text-center font-mono tabular-nums",children:n.usedCount}),e.jsx("span",{className:me("w-20 text-center font-mono tabular-nums",n.failCount>0&&"text-amber-600"),children:n.failCount}),e.jsx("span",{className:"w-32 text-center text-[10px] truncate",title:n.lastBoundEmail,children:n.lastBoundEmail?e.jsx("span",{className:"text-muted-foreground",children:n.lastBoundEmail}):n.lastTestedAt?e.jsxs("span",{className:"text-muted-foreground inline-flex items-center gap-0.5",children:[e.jsx(Gn,{className:"h-2.5 w-2.5"}),Math.round((Date.now()-n.lastTestedAt)/6e4),"m"]}):e.jsx("span",{className:"opacity-40",children:"-"})}),e.jsxs("span",{className:"w-24 flex justify-center gap-1",children:[e.jsx("button",{onClick:()=>void o(),disabled:n.status==="testing",className:"p-1 rounded hover:bg-muted",title:h?"Test":"测试",children:n.status==="testing"?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Mt,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:j,className:"p-1 rounded hover:bg-muted",title:h?"Edit note":"编辑备注",children:e.jsx(YA,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:p,className:"p-1 rounded hover:bg-muted",title:h?"Copy URL":"复制 URL",children:e.jsx(As,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:d,className:"p-1 rounded hover:bg-destructive/10 text-destructive",title:h?"Delete":"删除",children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]})]})}function lR({filtered:n,selectedIds:s,onSelect:r,onToggle:i,onTest:o,onDelete:d,onSaveLabel:u,isEn:h}){const f=g.useRef(null),p=44,y=lo({count:n.length,getScrollElement:()=>f.current,estimateSize:()=>p,overscan:10});if(n.length<50)return e.jsx("div",{ref:f,className:"max-h-[60vh] overflow-y-auto",children:n.map(v=>e.jsx(oj,{proxy:v,selected:s.has(v.id),onSelect:()=>r(v.id),onToggle:()=>i(v.id),onTest:()=>o(v.id),onDelete:()=>d(v.id),onSaveLabel:N=>u(v.id,N),isEn:h},v.id))});const b=y.getVirtualItems();return e.jsx("div",{ref:f,className:"max-h-[60vh] overflow-y-auto",style:{contain:"strict"},children:e.jsx("div",{style:{height:y.getTotalSize(),position:"relative",width:"100%"},children:b.map(v=>{const N=n[v.index];return N?e.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${v.start}px)`},children:e.jsx(oj,{proxy:N,selected:s.has(N.id),onSelect:()=>r(N.id),onToggle:()=>i(N.id),onTest:()=>o(N.id),onDelete:()=>d(N.id),onSaveLabel:j=>u(N.id,j),isEn:h})},v.key):null})})})}const zf=[{value:"dingtalk",label:"钉钉",labelEn:"DingTalk",placeholder:"https://oapi.dingtalk.com/robot/send?access_token=xxx"},{value:"wechat-work",label:"企业微信",labelEn:"WeCom",placeholder:"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx"},{value:"feishu",label:"飞书",labelEn:"Feishu",placeholder:"https://open.feishu.cn/open-apis/bot/v2/hook/xxx"},{value:"telegram",label:"Telegram",labelEn:"Telegram",placeholder:"https://api.telegram.org/bot<token>"},{value:"discord",label:"Discord",labelEn:"Discord",placeholder:"https://discord.com/api/webhooks/xxx"},{value:"custom",label:"自定义",labelEn:"Custom",placeholder:"https://your-server.com/webhook"}];function oR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",{webhooks:r,addWebhook:i,updateWebhook:o,removeWebhook:d,toggleWebhook:u,testWebhook:h}=_n(),[f,p]=g.useState(null),[y,b]=g.useState(null),[v,N]=g.useState({}),j=g.useMemo(()=>Array.from(r.values()),[r]),T=()=>{if(!f||!f.kind||!f.url)return;const k={kind:f.kind,url:f.url,label:f.label,enabled:f.enabled??!0,telegramChatId:f.telegramChatId,customTemplate:f.customTemplate,events:f.events??["batch-completed","risk-warning","account-banned"]};f.id?o(f.id,k):i(k),p(null)},S=async k=>{b(k);const R=await h(k);N(I=>({...I,[k]:{...R,time:Date.now()}})),b(null)};return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-pink-500/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-pink-500/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-pink-500 shadow-lg shadow-pink-500/25",children:e.jsx(kp,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-pink-600 dark:text-pink-400",children:s?"Webhook Notifications":"Webhook 通知"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Push critical events (batch completed, risk warning, account banned, etc.) to DingTalk / WeCom / Feishu / Telegram / Discord / custom endpoints.":"把关键事件(批量完成、风控警告、账号封禁等)推送到钉钉/企微/飞书/Telegram/Discord/自定义服务"})]})]})]}),e.jsxs(De,{children:[e.jsxs(at,{className:"pb-3 flex flex-row items-center justify-between",children:[e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(yx,{className:"h-4 w-4 text-primary"}),s?`Webhooks (${j.length})`:`Webhook 列表 (${j.length})`]}),e.jsxs(D,{size:"sm",onClick:()=>p({kind:"dingtalk",enabled:!0,events:["batch-completed","risk-warning","account-banned"]}),children:[e.jsx(Ts,{className:"h-4 w-4 mr-1"}),s?"Add Webhook":"添加 Webhook"]})]}),e.jsx(Pe,{children:j.length===0?e.jsxs("div",{className:"py-12 text-center text-muted-foreground",children:[e.jsx(kp,{className:"h-12 w-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:s?"No webhooks configured.":"尚未配置 Webhook"})]}):e.jsx("div",{className:"space-y-2",children:j.map(k=>{const R=v[k.id],I=zf.find(G=>G.value===k.kind),M=I?s?I.labelEn:I.label:k.kind;return e.jsxs("div",{className:me("flex items-start gap-3 p-3 rounded-lg border",k.enabled?"bg-card":"bg-muted/30 opacity-70"),children:[e.jsx("button",{onClick:()=>u(k.id),className:"mt-0.5",title:k.enabled?"点击停用":"点击启用",children:k.enabled?e.jsx(kc,{className:"h-4 w-4 text-green-500"}):e.jsx(XN,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm",children:k.label||M}),e.jsx($e,{variant:"outline",className:"text-[10px]",children:M}),R&&Date.now()-R.time<6e4&&e.jsx($e,{variant:"outline",className:me("text-[10px]",R.success?"text-green-600 border-green-200":"text-red-600 border-red-200"),children:R.success?e.jsxs(e.Fragment,{children:[e.jsx(an,{className:"h-2.5 w-2.5 mr-0.5 inline"})," ",s?"Test OK":"测试成功"]}):e.jsxs(e.Fragment,{children:[e.jsx(fs,{className:"h-2.5 w-2.5 mr-0.5 inline"})," ",s?"Test failed":"测试失败"]})})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono mt-0.5 truncate",title:k.url,children:k.url}),k.events.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1.5",children:k.events.map(G=>{const W=Ov.find(q=>q.value===G),U=W?s?W.labelEn:W.label:G;return e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary",children:U},G)})}),R&&!R.success&&R.error&&e.jsx("p",{className:"text-[10px] text-red-500 mt-1",children:R.error})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(D,{size:"sm",variant:"ghost",onClick:()=>S(k.id),disabled:y===k.id,children:y===k.id?e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(dM,{className:"h-3.5 w-3.5"})}),e.jsx(D,{size:"sm",variant:"ghost",onClick:()=>p({...k}),children:e.jsx(bx,{className:"h-3.5 w-3.5"})}),e.jsx(D,{size:"sm",variant:"ghost",className:"text-destructive",onClick:()=>{confirm(s?`Delete webhook "${k.label||M}"?`:`删除 Webhook "${k.label||M}"?`)&&d(k.id)},children:e.jsx(Vt,{className:"h-3.5 w-3.5"})})]})]},k.id)})})})]}),f&&e.jsxs(De,{className:"border-primary/40 shadow-lg",children:[e.jsx(at,{className:"pb-3",children:e.jsx(rt,{className:"text-base",children:f.id?s?"Edit Webhook":"编辑 Webhook":s?"New Webhook":"新建 Webhook"})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Type":"类型"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:zf.map(k=>e.jsx("button",{onClick:()=>p({...f,kind:k.value}),className:me("px-3 py-1.5 rounded-md border text-xs transition-colors",f.kind===k.value?"border-primary bg-primary/10 text-primary font-medium":"border-border hover:border-primary/50"),children:s?k.labelEn:k.label},k.value))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Label (optional)":"备注名(可选)"}),e.jsx(it,{value:f.label||"",onChange:k=>p({...f,label:k.target.value}),placeholder:s?"e.g. Dev group":"例如:开发群",className:"h-8"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:"Webhook URL"}),e.jsx(it,{value:f.url||"",onChange:k=>p({...f,url:k.target.value}),placeholder:zf.find(k=>k.value===f.kind)?.placeholder,className:"h-8 font-mono text-xs"})]}),f.kind==="telegram"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:"Chat ID"}),e.jsx(it,{value:f.telegramChatId||"",onChange:k=>p({...f,telegramChatId:k.target.value}),placeholder:s?"123456789 or @channel_name":"123456789 或 @channel_name",className:"h-8 font-mono text-xs"})]}),f.kind==="custom"&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs(Fe,{className:"text-xs",children:[s?"Custom JSON template (placeholders: ":"自定义 JSON 模板(占位符:","{{title}} {{message}} {{level}} {{icon}}",s?")":")"]}),e.jsx("textarea",{value:f.customTemplate||"",onChange:k=>p({...f,customTemplate:k.target.value}),rows:4,className:"w-full px-3 py-2 rounded-md border bg-background text-xs font-mono",placeholder:'{"text": "{{title}}", "body": "{{message}}"}'})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Subscribed events":"订阅事件"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Ov.map(k=>{const R=f.events?.includes(k.value)??!1;return e.jsx("button",{onClick:()=>{const I=f.events??[],M=R?I.filter(G=>G!==k.value):[...I,k.value];p({...f,events:M})},className:me("px-2 py-1 rounded-md border text-[11px] transition-colors",R?"border-primary bg-primary/10 text-primary":"border-border hover:border-primary/50"),children:s?k.labelEn:k.label},k.value)})})]}),e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx(is,{checked:f.enabled??!0,onCheckedChange:k=>p({...f,enabled:k})}),e.jsx(Fe,{className:"text-sm cursor-pointer",children:s?"Enabled":"启用"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(D,{variant:"ghost",size:"sm",onClick:()=>p(null),children:s?"Cancel":"取消"}),e.jsx(D,{size:"sm",onClick:T,disabled:!f.kind||!f.url,children:s?"Save":"保存"})]})]})]})]})}const Uf=["claude-sonnet-4.5","claude-sonnet-4","claude-haiku-4.5","claude-opus-4.5","claude-3.7-sonnet","auto"];function cR(n){const s=`${n.error||""} ${n.content||""}`.trim(),r=s.toLowerCase();return r&&(r.includes("auth error 401")||r.includes("auth error 403")||r.includes("temporarily_suspended")||r.includes("permanently_suspended")||r.includes("accountsuspendedexception")||r.includes("temporarily suspended")||r.includes("account suspended")||r.includes("user id is temporarily suspended")||r.includes("unusual user activity")||r.includes("locked it as a security precaution")||r.includes("restricted your ability to use kiro"))?s:null}function dR(n){const s=cR(n);return s?{...n,success:!1,content:void 0,error:s}:n}function uR(n){return n.replace(/:([^:@/]+)@/,":***@")}const hR=[{id:"public-ip",label:{en:"Public connectivity",zh:"Kết nối internet"},url:"https://api.ipify.org?format=json",category:"network",description:{en:"Check basic internet access",zh:"Kiểm tra truy cập internet cơ bản"}},{id:"cloudflare",label:{en:"Cloudflare",zh:"Cloudflare"},url:"https://1.1.1.1",category:"network",description:{en:"Check international network reachability",zh:"Kiểm tra đường mạng quốc tế"}},{id:"kiro-auth",label:{en:"Kiro Auth Endpoint",zh:"Kiro Auth Endpoint"},url:"https://prod.us-east-1.auth.desktop.kiro.dev/.well-known/openid-configuration",category:"kiro",description:{en:"Social login token refresh endpoint",zh:"Endpoint làm mới token đăng nhập"},expectStatus:[200,401,403,404]},{id:"kiro-oidc",label:{en:"AWS OIDC",zh:"AWS OIDC"},url:"https://oidc.us-east-1.amazonaws.com/",category:"kiro",description:{en:"OIDC registration endpoint",zh:"Endpoint đăng ký OIDC"},expectStatus:[200,400,403,405]},{id:"kiro-codewhisperer",label:{en:"CodeWhisperer API",zh:"CodeWhisperer API"},url:"https://q.us-east-1.amazonaws.com/",category:"kiro",description:{en:"Kiro main API endpoint (q.amazonaws.com)",zh:"Endpoint API chính của Kiro (q.amazonaws.com)"},expectStatus:[200,400,403,405]},{id:"aws-signin",label:{en:"AWS SignIn",zh:"AWS SignIn"},url:"https://us-east-1.signin.aws/",category:"kiro",description:{en:"Required endpoint for the signup flow",zh:"Endpoint cần cho luồng đăng ký"},expectStatus:[200,400,403]},{id:"tempmail-plus",label:{en:"TempMail.Plus API",zh:"TempMail.Plus API"},url:"https://tempmail.plus/api/mails?email=test@mailto.plus",category:"email",description:{en:"TempMail.Plus mailbox service",zh:"Dịch vụ hộp thư TempMail.Plus"},expectStatus:[200,400,401,403]},{id:"outlook-login",label:{en:"Outlook Login",zh:"Outlook Login"},url:"https://login.microsoftonline.com/consumers/oauth2/v2.0/token",category:"email",description:{en:"Outlook token refresh endpoint",zh:"Endpoint làm mới token Outlook"},expectStatus:[200,400,405]}],mR=[{id:"network",label:{en:"Network",zh:"Mạng"},icon:ri,color:"text-blue-500"},{id:"kiro",label:{en:"Kiro / AWS",zh:"Kiro / AWS"},icon:Ks,color:"text-purple-500"},{id:"email",label:{en:"Email",zh:"Email"},icon:gx,color:"text-amber-500"},{id:"proxy",label:{en:"Proxy",zh:"Proxy"},icon:Ki,color:"text-cyan-500"},{id:"custom",label:{en:"Custom",zh:"Tùy chỉnh"},icon:Ks,color:"text-emerald-500"}];function fR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",r=J=>s?J.en:J.zh,{proxyPool:i,proxyPoolConfig:o,accounts:d,selectedIds:u,getAccountProxyUrl:h,updateAccount:f,removeAccounts:p}=vt(),y=g.useMemo(()=>Array.from(d.values()),[d]),b=g.useMemo(()=>Array.from(u).map(J=>d.get(J)).filter(J=>!!J),[u,d]),[v,N]=g.useState(()=>vt.getState().selectedIds.size>0?"selected":"single"),[j,T]=g.useState(""),[S,k]=g.useState(()=>{try{return localStorage.getItem("kiro-liveness-model")||Uf[0]}catch{return Uf[0]}}),[R,I]=g.useState('Hi, reply with "pong" only.'),[M,G]=g.useState(!1),[W,U]=g.useState(null),[q,V]=g.useState(new Map),[le]=g.useState(3),B=g.useRef(!1),[be,K]=g.useState(()=>{try{const J=localStorage.getItem("kiro-liveness-models-cache");if(J){const Ne=JSON.parse(J);if(Array.isArray(Ne))return Ne.filter(et=>typeof et=="string")}}catch{}return[]}),[se,te]=g.useState(!1),Y=g.useMemo(()=>Array.from(new Set([...be,...Uf])),[be]);g.useEffect(()=>{try{localStorage.setItem("kiro-liveness-model",S)}catch{}},[S]);const P=g.useCallback(async()=>{te(!0);try{let J=[];try{const Ne=await window.api.proxyGetModels();Ne.success&&Ne.models?.length&&(J=Ne.models.map(et=>et.id))}catch{}if(J.length===0)try{const Ne=await window.api.getKiroAvailableModels();Ne.models?.length&&(J=Ne.models.map(et=>et.id))}catch{}if(J.length>0){K(J);try{localStorage.setItem("kiro-liveness-models-cache",JSON.stringify(J))}catch{}}}finally{te(!1)}},[]);g.useEffect(()=>{P()},[P]),g.useEffect(()=>()=>{B.current=!0},[]);const F=g.useCallback(async J=>{const Ne=J.credentials;try{const et=await window.api.diagnoseAccountLiveness({account:{id:J.id,email:J.email,accessToken:Ne.accessToken,refreshToken:Ne.refreshToken,clientId:Ne.clientId,clientSecret:Ne.clientSecret,region:Ne.region,authMethod:Ne.authMethod,provider:Ne.provider||J.idp,profileArn:J.profileArn,machineId:J.machineId,expiresAt:Ne.expiresAt,proxyUrl:h(J.id)},model:S.trim(),message:R.trim()||void 0}),qe=dR(et);return qe.profileArn&&qe.profileArn!==J.profileArn&&f(J.id,{profileArn:qe.profileArn}),qe}catch(et){return{success:!1,latencyMs:0,error:et instanceof Error?et.message:String(et)}}},[S,R,h,f]),fe=g.useCallback(async()=>{const J=d.get(j);if(!J)return;B.current=!1,G(!0),U(null);const Ne=await F(J);B.current||(U(Ne),Ne.success?f(J.id,{status:"active",lastError:void 0}):f(J.id,{status:"error",lastError:Ne.error||(s?"Liveness test failed":"Kiểm tra liveness thất bại")}),G(!1))},[d,j,F,f,s]),pe=g.useCallback(async()=>{if(b.length===0)return;B.current=!1,G(!0);const J=new Map;for(const Je of b)J.set(Je.id,null);V(new Map(J));const Ne=[...b],et=async()=>{for(;!B.current;){const Je=Ne.shift();if(!Je)break;const Kt=await F(Je);if(B.current)break;V(Ye=>{const qt=new Map(Ye);return qt.set(Je.id,Kt),qt}),Kt.success?f(Je.id,{status:"active",lastError:void 0}):f(Je.id,{status:"error",lastError:Kt.error||(s?"Liveness test failed":"Kiểm tra liveness thất bại")})}},qe=Array.from({length:Math.min(le,b.length)},()=>et());await Promise.all(qe),B.current||G(!1)},[b,F,le,f,s]),C=g.useCallback(()=>{B.current=!0,G(!1)},[]),z=g.useCallback(async J=>{const Ne=d.get(J);if(!Ne)return;B.current=!1,V(qe=>new Map(qe).set(J,null));const et=await F(Ne);B.current||(V(qe=>new Map(qe).set(J,et)),et.success?f(J,{status:"active",lastError:void 0}):f(J,{status:"error",lastError:et.error||(s?"Liveness test failed":"Kiểm tra liveness thất bại")}))},[d,F,f,s]),X=g.useMemo(()=>b.filter(J=>{const Ne=q.get(J.id);return Ne&&!Ne.success}).map(J=>J.id),[b,q]),re=g.useCallback(async()=>{const J=X;if(J.length===0)return;B.current=!1,G(!0),V(Je=>{const Kt=new Map(Je);for(const Ye of J)Kt.set(Ye,null);return Kt});const Ne=J.map(Je=>d.get(Je)).filter(Je=>!!Je),et=async()=>{for(;!B.current;){const Je=Ne.shift();if(!Je)break;const Kt=await F(Je);if(B.current)break;V(Ye=>new Map(Ye).set(Je.id,Kt)),Kt.success?f(Je.id,{status:"active",lastError:void 0}):f(Je.id,{status:"error",lastError:Kt.error||(s?"Liveness test failed":"Kiểm tra liveness thất bại")})}},qe=Array.from({length:Math.min(le,Ne.length)},()=>et());await Promise.all(qe),B.current||G(!1)},[X,d,F,le,f,s]),xe=g.useCallback(()=>{for(const J of X){const Ne=q.get(J);f(J,{status:"error",lastError:Ne?.error||(s?"Liveness test failed":"Kiểm tra liveness thất bại")})}},[X,q,f,s]),Oe=g.useCallback(()=>{const J=X;J.length===0||!window.confirm(s?`Delete ${J.length} accounts that failed the liveness test? This cannot be undone.`:`Xóa ${J.length} tài khoản kiểm tra liveness thất bại? Không thể hoàn tác.`)||(p(J),V(et=>{const qe=new Map(et);for(const Je of J)qe.delete(Je);return qe}))},[X,p,s]),Ee=g.useMemo(()=>{let J=0,Ne=0,et=0;for(const qe of q.values())qe!==null&&(J++,qe.success?Ne++:et++);return{done:J,ok:Ne,fail:et,total:q.size}},[q]),[Qe,_e]=g.useState(()=>{try{const J=localStorage.getItem("kiro-diagnose-probe-url");if(J!==null)return J;const Ne=localStorage.getItem("kiro-diagnose-moemail")||"";if(Ne)try{localStorage.setItem("kiro-diagnose-probe-url",Ne),localStorage.removeItem("kiro-diagnose-moemail")}catch{}return Ne}catch{return""}}),[st,oe]=g.useState(!1),[ue,ae]=g.useState(""),[L,we]=g.useState(!1),[Ue,Lt]=g.useState({}),[xt,Qt]=g.useState({done:0,total:0}),ft=Array.from(i.values()).filter(J=>J.enabled&&J.status!=="dead"),Et=g.useCallback(()=>{const J=[...hR],Ne=Qe.trim();if(Ne){const et=/^https?:\/\//i.test(Ne)?Ne:`https://${Ne}`;J.push({id:"custom-probe",label:{en:"Custom Probe URL",zh:"URL kiểm tra tùy chỉnh"},url:et,category:"custom",description:{en:"User-provided URL for connectivity test",zh:"URL người dùng nhập để kiểm tra kết nối"},expectStatus:[200,201,204,301,302,400,401,403,404,405]})}return J},[Qe,s]),Ge=g.useCallback(async()=>{const J=Et();we(!0),Lt({}),Qt({done:0,total:J.length});const Ne=st&&ue?i.get(ue)?.url:void 0;try{const qe={};for(let Je=0;Je<J.length;Je+=4){const Kt=J.slice(Je,Je+4),Ye=await window.api.diagnoseRun({proxyUrl:Ne,targets:Kt.map(qt=>({id:qt.id,label:r(qt.label),url:qt.url,expectStatus:qt.expectStatus}))});for(const qt of Ye.results)qe[qt.id]=qt;Lt({...qe}),Qt({done:Math.min(Je+4,J.length),total:J.length})}}finally{we(!1);try{localStorage.setItem("kiro-diagnose-probe-url",Qe)}catch{}}},[Et,st,ue,i,Qe]),gt=g.useCallback(()=>{const J=Et(),Ne=[s?"Krouter - Diagnostic Report":"Krouter - 诊断报告",`${s?"Generated":"生成时间"}: ${new Date().toLocaleString()}`,`Proxy: ${st&&ue?i.get(ue)?.url:s?"Direct":"Trực tiếp"}`,"------------------------------------"];for(const et of J){const qe=Ue[et.id];Ne.push(`[${r(et.label)}]`),Ne.push(` URL: ${et.url}`),qe?(Ne.push(` ${s?"Status":"Trạng thái"}: ${qe.success?s?"✓ Pass":"✓ Đạt":s?"✗ Fail":"✗ Lỗi"}`),qe.httpStatus&&Ne.push(` HTTP: ${qe.httpStatus}`),qe.latencyMs!=null&&Ne.push(` ${s?"Latency":"延迟"}: ${qe.latencyMs}ms`),qe.error&&Ne.push(` ${s?"Error":"错误"}: ${qe.error}`)):Ne.push(` ${s?"Status":"Trạng thái"}: ${s?"Not tested":"Chưa kiểm tra"}`),Ne.push("")}navigator.clipboard.writeText(Ne.join(`
128
128
  `)),alert(s?"Report copied to clipboard":"诊断报告已复制到剪贴板")},[Et,Ue,st,ue,i,s]),Ze=(()=>{const J=Object.values(Ue);return{total:J.length,passed:J.filter(Ne=>Ne.success).length,failed:J.filter(Ne=>!Ne.success).length}})();return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-emerald-500/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-emerald-500/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-emerald-500 shadow-lg shadow-emerald-500/25",children:e.jsx(jx,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-emerald-600 dark:text-emerald-400",children:s?"Diagnostics":"一键诊断"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Test network / Kiro API / email service / proxy connectivity in one click.":"Kiểm tra mạng, Kiro/AWS API, email service và proxy trong một lần."})]})]})]}),e.jsxs(De,{children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ks,{className:"h-4 w-4 text-primary"}),s?"Diagnostic Config":"诊断配置"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Custom probe URL (optional)":"URL kiểm tra tùy chỉnh (tùy chọn)"}),e.jsx(it,{value:Qe,onChange:J=>_e(J.target.value),placeholder:"https://example.com/health",disabled:L,className:"font-mono text-xs"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s?"Any HTTP/HTTPS endpoint will be added to the diagnostic list (HEAD request, expecting 2xx/3xx/4xx).":"Có thể nhập endpoint HTTP/HTTPS bất kỳ để kiểm tra kết nối (HEAD, 2xx/3xx/4xx đều tính là thông)."})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:st,onChange:J=>oe(J.target.checked),disabled:L}),e.jsx("span",{children:s?"Test through proxy":"Kiểm tra qua proxy"})]}),st&&(ft.length>0?e.jsxs("select",{value:ue,onChange:J=>ae(J.target.value),disabled:L,className:"h-8 px-2 rounded-md border bg-background text-xs flex-1 max-w-md",children:[e.jsxs("option",{value:"",children:["-- ",s?"Select a proxy":"Chọn proxy"," --"]}),ft.map(J=>e.jsxs("option",{value:J.id,children:[J.protocol,"://",J.host,":",J.port,J.label?` (${J.label})`:"",J.status==="alive"&&J.latencyMs?` - ${J.latencyMs}ms`:""]},J.id))]}):e.jsx("span",{className:"text-xs text-muted-foreground italic",children:o.enabled?s?"No available proxy in pool":"Không có proxy khả dụng trong kho":s?'Proxy pool disabled, configure it in "Proxy Pool" first':"Kho proxy chưa bật, hãy cấu hình trong trang Proxy Pool trước"}))]}),e.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[e.jsxs(D,{onClick:Ge,disabled:L,children:[L?e.jsx(bt,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Ba,{className:"h-4 w-4 mr-1"}),L?`运行中 ${xt.done}/${xt.total}`:s?"Run Diagnostics":"Chạy chẩn đoán"]}),Ze.total>0&&e.jsxs(D,{variant:"outline",size:"sm",onClick:gt,children:[e.jsx(Ns,{className:"h-4 w-4 mr-1"}),s?"Copy Report":"复制报告"]}),Ze.total>0&&e.jsxs("div",{className:"ml-auto flex items-center gap-2 text-xs",children:[e.jsxs($e,{variant:"outline",className:"text-green-600 border-green-200",children:[e.jsx(an,{className:"h-3 w-3 mr-1"})," ",Ze.passed]}),Ze.failed>0&&e.jsxs($e,{variant:"outline",className:"text-red-600 border-red-200",children:[e.jsx(fs,{className:"h-3 w-3 mr-1"})," ",Ze.failed]})]})]})]})]}),e.jsxs(De,{children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-sm flex items-center gap-2",children:[e.jsx(yx,{className:"h-4 w-4 text-emerald-500"}),s?"Account Liveness Test":"Kiểm tra liveness tài khoản"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s?"Send a real chat message to the selected model via the reverse-proxy call path (account-bound proxy applies). Verifies the account can actually get a response.":"Gửi một tin nhắn thật tới model qua đường API proxy, tự dùng proxy đã gán cho tài khoản để xác nhận tài khoản còn trả lời được."}),e.jsxs("div",{className:"flex items-center gap-1 p-0.5 bg-muted rounded-md w-fit",children:[e.jsx("button",{type:"button",onClick:()=>N("single"),disabled:M,className:me("px-3 h-7 rounded text-xs font-medium transition-colors",v==="single"?"bg-background shadow-sm":"text-muted-foreground hover:text-foreground"),children:s?"Single":"Một tài khoản"}),e.jsxs("button",{type:"button",onClick:()=>N("selected"),disabled:M,className:me("px-3 h-7 rounded text-xs font-medium transition-colors flex items-center gap-1",v==="selected"?"bg-background shadow-sm":"text-muted-foreground hover:text-foreground"),children:[s?"Selected":"Đã chọn",e.jsx($e,{variant:"secondary",className:"h-4 px-1.5 text-[10px] tabular-nums",children:b.length})]})]}),v==="selected"&&b.length===0&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-amber-600",children:[e.jsx(Rs,{className:"h-3.5 w-3.5"}),s?"No accounts selected. Go to the Accounts page and multi-select first.":"Chưa chọn tài khoản nào. Hãy sang trang Tài khoản và chọn nhiều tài khoản trước."]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[v==="single"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Account":"Tài khoản"}),e.jsxs("select",{value:j,onChange:J=>T(J.target.value),disabled:M,className:"h-9 w-full px-2 rounded-md border bg-background text-xs",children:[e.jsxs("option",{value:"",children:["-- ",s?"Select an account":"Chọn tài khoản"," --"]}),y.map(J=>{const Ne=h(J.id);return e.jsxs("option",{value:J.id,children:[J.email,J.subscription?.type?` [${J.subscription.type}]`:"",Ne?" 🔗":""]},J.id)})]}),j&&h(j)&&e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[s?"Bound proxy: ":"Proxy đã gán: ",e.jsx("code",{className:"font-mono",children:uR(h(j))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(Fe,{className:"text-xs",children:s?"Model":"模型"}),e.jsxs("button",{type:"button",onClick:()=>void P(),disabled:se,className:"flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",title:s?"Refresh models from proxy cache / Kiro":"Làm mới model từ cache proxy / Kiro",children:[e.jsx(Mt,{className:me("h-3 w-3",se&&"animate-spin")}),be.length>0?s?`${be.length} cached`:`${be.length} 个缓存`:s?"Refresh":"刷新"]})]}),e.jsx("input",{list:"liveness-models",value:S,onChange:J=>k(J.target.value),disabled:M,placeholder:"claude-sonnet-4.5",className:"h-9 w-full px-2 rounded-md border bg-background text-xs font-mono"}),e.jsx("datalist",{id:"liveness-models",children:Y.map(J=>e.jsx("option",{value:J},J))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{className:"text-xs",children:s?"Test message":"Tin nhắn test"}),e.jsx(it,{value:R,onChange:J=>I(J.target.value),disabled:M,placeholder:'Hi, reply with "pong" only.',className:"text-xs"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[v==="single"?e.jsxs(D,{onClick:fe,disabled:M||!j||!S.trim(),children:[M?e.jsx(bt,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Ds,{className:"h-4 w-4 mr-1"}),M?s?"Testing...":"Đang test...":s?"Test Now":"Test ngay"]}):e.jsxs(e.Fragment,{children:[e.jsxs(D,{onClick:pe,disabled:M||b.length===0||!S.trim(),children:[M?e.jsx(bt,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Ds,{className:"h-4 w-4 mr-1"}),M?`${s?"Testing":"Đang test"} ${Ee.done}/${Ee.total}`:`${s?"Test Selected":"Test đã chọn"} (${b.length})`]}),M&&e.jsxs(D,{variant:"destructive",onClick:C,children:[e.jsx(Cn,{className:"h-4 w-4 mr-1"}),s?"Stop":"停止"]})]}),v==="selected"&&Ee.total>0&&e.jsxs("div",{className:"ml-auto flex items-center gap-2 text-xs",children:[e.jsxs($e,{variant:"outline",className:"text-green-600 border-green-200",children:[e.jsx(an,{className:"h-3 w-3 mr-1"})," ",Ee.ok]}),Ee.fail>0&&e.jsxs($e,{variant:"outline",className:"text-red-600 border-red-200",children:[e.jsx(fs,{className:"h-3 w-3 mr-1"})," ",Ee.fail]})]})]}),v==="single"&&W&&e.jsxs("div",{className:me("rounded-md p-3 text-xs space-y-2 border",W.success?"bg-green-50/50 dark:bg-green-950/10 border-green-200 dark:border-green-900":"bg-red-50/50 dark:bg-red-950/10 border-red-200 dark:border-red-900"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[W.success?e.jsx(an,{className:"h-4 w-4 text-green-500"}):e.jsx(fs,{className:"h-4 w-4 text-red-500"}),e.jsx("span",{className:"font-medium",children:W.success?s?"Account is alive":"Tài khoản hoạt động":s?"Failed":"Thất bại"}),e.jsxs("span",{className:"ml-auto font-mono tabular-nums text-muted-foreground",children:[W.latencyMs,"ms"]})]}),W.success&&e.jsxs(e.Fragment,{children:[W.content&&e.jsx("div",{className:"bg-background/60 rounded p-2 font-mono text-[11px] break-all max-h-32 overflow-y-auto",children:W.content||e.jsx("span",{className:"text-muted-foreground italic",children:s?"(empty response)":"(phản hồi trống)"})}),W.usage&&e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-muted-foreground tabular-nums",children:[e.jsxs("span",{children:[s?"Input":"Đầu vào",": ",W.usage.inputTokens]}),e.jsxs("span",{children:[s?"Output":"Đầu ra",": ",W.usage.outputTokens]}),e.jsxs("span",{children:["Credits: ",W.usage.credits]})]})]}),!W.success&&W.error&&e.jsxs("div",{className:"flex items-start gap-1.5 text-red-500",children:[e.jsx(Rs,{className:"h-3.5 w-3.5 flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"break-all",children:W.error})]})]}),v==="selected"&&!M&&X.length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 p-2 rounded-md bg-red-50/50 dark:bg-red-950/10 border border-red-200 dark:border-red-900",children:[e.jsxs("span",{className:"text-xs text-red-600 dark:text-red-400 flex items-center gap-1",children:[e.jsx(Rs,{className:"h-3.5 w-3.5"}),s?`${X.length} failed`:`${X.length} lỗi`]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[e.jsxs(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:()=>void re(),children:[e.jsx(gr,{className:"h-3.5 w-3.5 mr-1"}),s?"Retest failed":"Test lại lỗi"]}),e.jsxs(D,{variant:"outline",size:"sm",className:"h-7 text-xs",onClick:xe,children:[e.jsx(nA,{className:"h-3.5 w-3.5 mr-1"}),s?"Mark as error":"Đánh dấu lỗi"]}),e.jsxs(D,{variant:"destructive",size:"sm",className:"h-7 text-xs",onClick:Oe,children:[e.jsx(Vt,{className:"h-3.5 w-3.5 mr-1"}),s?"Delete failed":"Xóa lỗi"]})]})]}),v==="selected"&&Ee.total>0&&e.jsx("div",{className:"space-y-1 max-h-80 overflow-y-auto",children:b.map(J=>{const Ne=q.get(J.id),et=Ne===null;return e.jsxs("div",{className:me("flex items-center gap-2 p-2 rounded-md text-xs",et&&"bg-muted/30",Ne&&Ne.success&&"bg-green-50/50 dark:bg-green-950/10",Ne&&!Ne.success&&"bg-red-50/50 dark:bg-red-950/10"),children:[e.jsxs("div",{className:"w-5 flex justify-center flex-shrink-0",children:[et&&e.jsx(bt,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),Ne&&Ne.success&&e.jsx(an,{className:"h-4 w-4 text-green-500"}),Ne&&!Ne.success&&e.jsx(fs,{className:"h-4 w-4 text-red-500"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"font-medium truncate flex items-center gap-1",children:[J.email,h(J.id)&&e.jsx("span",{title:s?"bound proxy":"Đã gán proxy",children:"🔗"})]}),Ne&&Ne.success&&Ne.content&&e.jsxs("div",{className:"text-[10px] text-muted-foreground truncate font-mono",title:Ne.content,children:["→ ",Ne.content]}),Ne&&!Ne.success&&Ne.error&&e.jsx("div",{className:"text-[10px] text-red-500 truncate",title:Ne.error,children:Ne.error})]}),Ne&&e.jsxs("span",{className:"font-mono tabular-nums text-[10px] text-muted-foreground flex-shrink-0",children:[Ne.latencyMs,"ms"]}),!et&&e.jsx("button",{type:"button",onClick:()=>void z(J.id),disabled:M,title:s?"Retest this account":"Test lại tài khoản này",className:"flex-shrink-0 p-1 rounded hover:bg-background/80 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-40",children:e.jsx(gr,{className:"h-3.5 w-3.5"})})]},J.id)})})]})]}),mR.map(J=>{const Ne=Et().filter(qe=>qe.category===J.id);if(Ne.length===0)return null;const et=J.icon;return e.jsxs(De,{children:[e.jsx(at,{className:"pb-2",children:e.jsxs(rt,{className:"text-sm flex items-center gap-2",children:[e.jsx(et,{className:me("h-4 w-4",J.color)}),r(J.label)]})}),e.jsx(Pe,{className:"space-y-1.5",children:Ne.map(qe=>{const Je=Ue[qe.id];return e.jsxs("div",{className:me("flex items-center gap-3 p-2 rounded-md text-xs",Je?.success&&"bg-green-50/50 dark:bg-green-950/10",Je&&!Je.success&&"bg-red-50/50 dark:bg-red-950/10",!Je&&"bg-muted/30"),children:[e.jsxs("div",{className:"w-5 flex justify-center",children:[!Je&&e.jsx("span",{className:"h-2 w-2 rounded-full bg-muted-foreground/30"}),Je?.success&&e.jsx(an,{className:"h-4 w-4 text-green-500"}),Je&&!Je.success&&e.jsx(fs,{className:"h-4 w-4 text-red-500"})]}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-medium",children:r(qe.label)}),e.jsx("div",{className:"text-[10px] text-muted-foreground truncate",title:qe.url,children:qe.url}),qe.description&&e.jsx("div",{className:"text-[10px] text-muted-foreground italic",children:r(qe.description)}),Je?.error&&e.jsxs("div",{className:"text-[10px] text-red-500 mt-0.5 flex items-start gap-1",children:[e.jsx(Rs,{className:"h-3 w-3 flex-shrink-0 mt-0.5"}),e.jsx("span",{className:"break-all",children:Je.error})]})]}),Je&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-muted-foreground",children:[Je.httpStatus&&e.jsxs("span",{className:me("font-mono px-1.5 py-0.5 rounded",Je.httpStatus>=200&&Je.httpStatus<300&&"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300",Je.httpStatus>=400&&"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300"),children:["HTTP ",Je.httpStatus]}),Je.latencyMs!=null&&e.jsxs("span",{className:"font-mono tabular-nums",children:[Je.latencyMs,"ms"]})]})]},qe.id)})})]},J.id)})]})}const $f=["kiro-register-ratelimit-enabled","kiro-register-ratelimit-max","kiro-register-autobackoff","kiro-register-dailyquota-limit","kiro-register-schedule-enabled","kiro-register-schedule-time","kiro-register-mixed-sources"];function pR(){const{t:n}=Ut(),s=n("common.unknown")==="Unknown",r=vt(),[i,o]=g.useState({proxyPool:!0,webhooks:!0,registerConfig:!0,registerTemplates:!0,registerSettings:!0,appSettings:!0,includeProxyCredentials:!1,encrypt:!1}),[d,u]=g.useState(""),[h,f]=g.useState(null),[p,y]=g.useState(null),b=g.useCallback(async()=>{const N={version:1,exportedAt:new Date().toISOString(),app:"krouter"};if(i.proxyPool&&r.proxyPool.size>0&&(N.proxyPool=Array.from(r.proxyPool.values()).map(I=>{const M={...I};return i.includeProxyCredentials||(delete M.password,M.url=I.url.replace(/:([^:@/]+)@/,":***@")),M}),N.proxyPoolConfig={...r.proxyPoolConfig}),i.webhooks){const I=Array.from(_n.getState().webhooks.values());N.webhooks=I.map(M=>({...M}))}if(i.registerConfig)try{const I=localStorage.getItem("kiro-register-config");I&&(N.registerConfig=JSON.parse(I))}catch{}if(i.registerTemplates)try{const I=localStorage.getItem("kiro-register-templates");I&&(N.registerTemplates=JSON.parse(I))}catch{}if(i.registerSettings){const I={};for(const M of $f){const G=localStorage.getItem(M);G!=null&&(I[M]=G)}N.registerLocalStorage=I}i.appSettings&&(N.appSettings={theme:r.theme,darkMode:r.darkMode,language:r.language,autoRefreshEnabled:r.autoRefreshEnabled,autoRefreshInterval:r.autoRefreshInterval,autoRefreshConcurrency:r.autoRefreshConcurrency,statusCheckInterval:r.statusCheckInterval,privacyMode:r.privacyMode,usagePrecision:r.usagePrecision,autoSwitchEnabled:r.autoSwitchEnabled,autoSwitchThreshold:r.autoSwitchThreshold,autoSwitchInterval:r.autoSwitchInterval,switchTarget:r.switchTarget});let j=JSON.stringify(N,null,2),T="json";if(i.encrypt){if(!d.trim()){alert(s?"Please enter encryption password":"请输入加密密码");return}try{j=await gR(j,d),T="kcfg"}catch(I){alert(s?`Encryption failed: ${I}`:`加密失败: ${I}`);return}}f(j.length);const S=new Blob([j],{type:i.encrypt?"application/octet-stream":"application/json"}),k=URL.createObjectURL(S),R=document.createElement("a");R.href=k,R.download=`krouter-config-${new Date().toISOString().slice(0,19).replace(/[:.]/g,"-")}.${T}`,R.click(),setTimeout(()=>URL.revokeObjectURL(k),1e3)},[i,r,d,s]),v=g.useCallback(async N=>{try{let j=await N.text();if(N.name.endsWith(".kcfg")||j.startsWith("KCFG1:")){const k=prompt(s?"Enter decryption password:":"请输入解密密码:");if(!k)return;try{j=await yR(j,k)}catch(R){y({success:!1,error:`解密失败:${R instanceof Error?R.message:String(R)}`});return}}const T=JSON.parse(j);if(T.app!=="krouter"&&T.app!=="kiro-account-manager"){y({success:!1,error:"文件不是有效的 Krouter配置(app 标识不匹配)"});return}const S={};if(T.proxyPool&&T.proxyPool.length>0){let k=0;for(const R of T.proxyPool)if(typeof R.url=="string"&&!R.url.includes("***"))r.addProxy(R.url,{label:R.label,source:"import-config",tags:R.tags})&&k++;else if(R.host&&R.port){const M=`${R.protocol||"http"}://${R.host}:${R.port}`;r.addProxy(M,{label:R.label,source:"import-config-masked",tags:R.tags})&&k++}S.代理池=k}if(T.proxyPoolConfig&&r.setProxyPoolConfig(T.proxyPoolConfig),T.webhooks&&T.webhooks.length>0){const k=_n.getState();let R=0;for(const I of T.webhooks){const M=I;M.kind&&M.url&&(k.addWebhook(M),R++)}S.Webhook=R}if(T.registerConfig)try{localStorage.setItem("kiro-register-config",JSON.stringify(T.registerConfig)),S.注册配置=1}catch{}if(T.registerTemplates)try{localStorage.setItem("kiro-register-templates",JSON.stringify(T.registerTemplates)),S.注册模板=T.registerTemplates.length}catch{}if(T.registerLocalStorage){let k=0;for(const[R,I]of Object.entries(T.registerLocalStorage))if($f.includes(R))try{localStorage.setItem(R,I),k++}catch{}S.注册偏好=k}if(T.appSettings){const k=T.appSettings;k.theme!=null&&r.setTheme(k.theme),k.darkMode!=null&&r.setDarkMode(k.darkMode),k.language!=null&&r.setLanguage(k.language),k.autoRefreshEnabled!=null&&r.setAutoRefresh(k.autoRefreshEnabled,k.autoRefreshInterval),k.autoRefreshConcurrency!=null&&r.setAutoRefreshConcurrency(k.autoRefreshConcurrency),k.statusCheckInterval!=null&&r.setStatusCheckInterval(k.statusCheckInterval),k.privacyMode!=null&&r.setPrivacyMode(k.privacyMode),k.usagePrecision!=null&&r.setUsagePrecision(k.usagePrecision),k.autoSwitchEnabled!=null&&r.setAutoSwitch(k.autoSwitchEnabled,k.autoSwitchThreshold,k.autoSwitchInterval),k.switchTarget!=null&&(k.switchTarget==="ide"||k.switchTarget==="cli"||k.switchTarget==="both")&&r.setSwitchTarget(k.switchTarget),S["App 设置"]=1}y({success:!0,counts:S})}catch(j){y({success:!1,error:j instanceof Error?j.message:String(j)})}},[r]);return e.jsxs("div",{className:"flex-1 p-6 space-y-6 overflow-auto",children:[e.jsxs("div",{className:"page-hero p-6",children:[e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-gradient-to-br from-indigo-500/20 to-transparent rounded-full blur-2xl"}),e.jsx("div",{className:"absolute bottom-0 left-0 w-24 h-24 bg-gradient-to-tr from-indigo-500/20 to-transparent rounded-full blur-2xl"}),e.jsxs("div",{className:"relative flex items-center gap-4",children:[e.jsx("div",{className:"p-3 rounded-xl bg-indigo-500 shadow-lg shadow-indigo-500/25",children:e.jsx(zN,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-indigo-600 dark:text-indigo-400",children:s?"Config Sync":"配置同步"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Export & import non-sensitive app config (proxy pool, webhooks, register templates, app preferences) for multi-device sync.":"导出/导入非敏感配置(代理池、Webhook、注册模板、应用偏好),用于多设备同步"})]})]})]}),e.jsx(De,{className:"border-amber-200 dark:border-amber-800 bg-amber-50/30 dark:bg-amber-950/10",children:e.jsxs(Pe,{className:"py-3 flex items-start gap-2",children:[e.jsx(xc,{className:"h-4 w-4 text-amber-600 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs space-y-1",children:[e.jsx("p",{className:"font-medium text-amber-700 dark:text-amber-300",children:s?"Security Notice":"安全提示"}),e.jsx("p",{className:"text-muted-foreground",children:s?'This export does NOT include account credentials, refresh tokens, or other sensitive secrets — use "Account Export" (under Accounts page) for those.':'本页导出"不包含"账号凭据、Refresh Token 等敏感数据。账号导出请走"账户管理 → 导出"专用通道。'}),e.jsx("p",{className:"text-muted-foreground",children:s?'Tip: keep "Include proxy credentials" OFF when sharing the file with others.':'提示:分享给他人时,建议关闭"包含代理密码"选项,密码会被打码。'})]})]})}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Ns,{className:"h-4 w-4 text-primary"}),s?"Export":"导出"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsx($l,{label:`${s?"Proxy Pool":"代理池"} (${r.proxyPool.size})`,checked:i.proxyPool,onChange:N=>o(j=>({...j,proxyPool:N}))}),e.jsx($l,{label:`${s?"Webhooks":"Webhook"} (${_n.getState().webhooks.size})`,checked:i.webhooks,onChange:N=>o(j=>({...j,webhooks:N}))}),e.jsx($l,{label:s?"Register Config":"注册配置",checked:i.registerConfig,onChange:N=>o(j=>({...j,registerConfig:N}))}),e.jsx($l,{label:s?"Register Templates":"注册模板",checked:i.registerTemplates,onChange:N=>o(j=>({...j,registerTemplates:N}))}),e.jsx($l,{label:s?"Register Preferences":"注册偏好(限速/定时/配额等)",checked:i.registerSettings,onChange:N=>o(j=>({...j,registerSettings:N}))}),e.jsx($l,{label:s?"App Settings (theme/lang/auto-refresh)":"App 设置(主题/语言/自动刷新)",checked:i.appSettings,onChange:N=>o(j=>({...j,appSettings:N}))})]}),e.jsxs("div",{className:"border-t pt-3 flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{checked:i.includeProxyCredentials,onCheckedChange:N=>o(j=>({...j,includeProxyCredentials:N}))}),e.jsxs(Fe,{className:"text-xs cursor-pointer flex items-center gap-1.5",children:[i.includeProxyCredentials?e.jsx(Rs,{className:"h-3.5 w-3.5 text-amber-500"}):e.jsx(xc,{className:"h-3.5 w-3.5 text-muted-foreground"}),s?"Include proxy credentials (NOT recommended for sharing)":"包含代理密码(分享时不建议)"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{checked:i.encrypt,onCheckedChange:N=>o(j=>({...j,encrypt:N}))}),e.jsxs(Fe,{className:"text-xs cursor-pointer flex items-center gap-1.5",children:[e.jsx(xc,{className:"h-3.5 w-3.5 text-green-500"}),s?"Encrypt (AES-GCM)":"加密导出 (AES-GCM)"]})]}),i.encrypt&&e.jsx("input",{type:"password",value:d,onChange:N=>u(N.target.value),placeholder:s?"Password...":"加密密码...",className:"h-8 px-2 rounded-md border bg-background text-xs flex-1 max-w-xs"}),e.jsxs(D,{className:"ml-auto",onClick:b,disabled:i.encrypt&&!d.trim(),children:[e.jsx(KN,{className:"h-4 w-4 mr-2"}),s?"Export":"导出"]})]}),h!==null&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s?`Last export: ${(h/1024).toFixed(1)} KB`:`上次导出大小: ${(h/1024).toFixed(1)} KB`})]})]}),e.jsxs(De,{className:"hover-lift",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-base flex items-center gap-2",children:[e.jsx(Fa,{className:"h-4 w-4 text-primary"}),s?"Import":"导入"]})}),e.jsxs(Pe,{className:"space-y-3",children:[e.jsx(Fe,{className:"text-xs",children:s?"Choose a previously exported config JSON. Duplicates will be merged/skipped automatically.":"选择之前导出的配置 JSON 文件。重复项会自动合并/跳过。"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("input",{type:"file",accept:"application/json,.json",className:"text-xs",onChange:N=>{const j=N.target.files?.[0];j&&v(j),N.currentTarget.value=""}})}),p&&e.jsx("div",{className:`p-3 rounded-lg border ${p.success?"border-green-200 dark:border-green-800 bg-green-50/50 dark:bg-green-950/10":"border-red-200 dark:border-red-800 bg-red-50/50 dark:bg-red-950/10"}`,children:p.success?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium text-green-700 dark:text-green-300",children:[e.jsx(an,{className:"h-4 w-4"}),s?"Import Successful":"导入成功"]}),p.counts&&e.jsx("div",{className:"mt-2 grid grid-cols-2 gap-1 text-xs",children:Object.entries(p.counts).map(([N,j])=>e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:N}),e.jsx("span",{className:"font-mono tabular-nums",children:j})]},N))})]}):e.jsxs("div",{className:"flex items-start gap-2 text-sm text-red-700 dark:text-red-300",children:[e.jsx(Rs,{className:"h-4 w-4 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s?"Import Failed":"导入失败"}),e.jsx("div",{className:"text-xs mt-0.5",children:p.error})]})]})})]})]}),e.jsxs(De,{className:"border-red-200 dark:border-red-800",children:[e.jsx(at,{className:"pb-3",children:e.jsxs(rt,{className:"text-sm flex items-center gap-2 text-red-600",children:[e.jsx(Vt,{className:"h-4 w-4"}),s?"Danger Zone":"危险操作"]})}),e.jsx(Pe,{className:"space-y-2",children:e.jsxs(D,{variant:"outline",size:"sm",className:"text-red-600 border-red-200 hover:bg-red-50 dark:hover:bg-red-950/20",onClick:()=>{if(confirm(s?"Reset register page preferences (rate limit / schedule / quota / mixed sources / blacklist / templates)? This does NOT affect accounts.":"重置注册页所有偏好(限速/定时/配额/混合源/黑名单/模板)?不影响账号数据。")){for(const N of $f)localStorage.removeItem(N);localStorage.removeItem("kiro-register-templates"),localStorage.removeItem("kiro-register-email-blacklist"),alert(s?"Done. Please reload the page.":"已重置,请刷新页面")}},children:[e.jsx(Mt,{className:"h-3.5 w-3.5 mr-1.5"}),s?"Reset Register Preferences":"重置注册页偏好"]})})]})]})}function $l({label:n,checked:s,onChange:r}){return e.jsxs("label",{className:"flex items-center gap-2 p-2 rounded hover:bg-muted/40 cursor-pointer",children:[e.jsx(is,{checked:s,onCheckedChange:r}),e.jsx("span",{className:"text-sm",children:n})]})}const Dp="KCFG1:",xR=1e5;async function ow(n,s){const r=new TextEncoder,i=await crypto.subtle.importKey("raw",r.encode(n).slice().buffer,{name:"PBKDF2"},!1,["deriveKey"]);return crypto.subtle.deriveKey({name:"PBKDF2",salt:s.slice().buffer,iterations:xR,hash:"SHA-256"},i,{name:"AES-GCM",length:256},!1,["encrypt","decrypt"])}function Bf(n){const s=n instanceof Uint8Array?n:new Uint8Array(n);let r="";for(let i=0;i<s.length;i++)r+=String.fromCharCode(s[i]);return btoa(r)}function _f(n){const s=atob(n),r=new Uint8Array(s.length);for(let i=0;i<s.length;i++)r[i]=s.charCodeAt(i);return r}async function gR(n,s){const r=crypto.getRandomValues(new Uint8Array(16)),i=crypto.getRandomValues(new Uint8Array(12)),o=await ow(s,r),d=new TextEncoder().encode(n),u=await crypto.subtle.encrypt({name:"AES-GCM",iv:i.slice().buffer},o,d.slice().buffer);return`${Dp}${Bf(r)}.${Bf(i)}.${Bf(u)}`}async function yR(n,s){if(!n.startsWith(Dp))throw new Error("Not an encrypted KCFG payload");const r=n.slice(Dp.length).split(".");if(r.length!==3)throw new Error("Invalid encrypted payload format");const[i,o,d]=r,u=_f(i),h=_f(o),f=_f(d),p=await ow(s,u),y=await crypto.subtle.decrypt({name:"AES-GCM",iv:h.slice().buffer},p,f.slice().buffer);return new TextDecoder().decode(y)}const cj={maxPerMinute:10,burst:3,windowSec:120,successRateThreshold:.5,minSamples:5,consecutiveFailureThreshold:3,backoffBaseMs:8e3,backoffMaxMs:12e4};function bR(n={}){const s={config:{...cj,...n},lastRefillTime:Date.now(),tokens:n.burst??cj.burst,events:[],consecutiveFailures:0,backoffEndAt:0};function r(){const o=Date.now(),d=o-s.lastRefillTime;if(d<=0)return;const u=s.config.maxPerMinute/6e4;s.tokens=Math.min(s.config.burst,s.tokens+d*u),s.lastRefillTime=o}function i(){const o=Date.now()-s.config.windowSec*1e3;for(;s.events.length>0&&s.events[0][0]<o;)s.events.shift()}return{waitForSlot:async o=>{for(;;){if(o?.aborted)return;const d=Date.now();if(s.backoffEndAt>d){const p=Math.min(s.backoffEndAt-d,1e3);await new Promise(y=>setTimeout(y,p));continue}if(r(),s.tokens>=1){s.tokens-=1;return}const u=s.config.maxPerMinute/6e4,h=1-s.tokens,f=Math.max(50,Math.min(2e3,h/u));await new Promise(p=>setTimeout(p,f))}},reportResult:o=>{const d=Date.now();if(s.events.push([d,o]),i(),o)s.consecutiveFailures=0;else if(s.consecutiveFailures+=1,s.consecutiveFailures>=s.config.consecutiveFailureThreshold){const u=s.consecutiveFailures-s.config.consecutiveFailureThreshold+1,h=Math.min(s.config.backoffBaseMs*Math.pow(2,u-1),s.config.backoffMaxMs);s.backoffEndAt=d+h}},snapshot:()=>{r(),i();const o=Date.now();let d=0,u=0;for(const[,v]of s.events)v?d++:u++;const h=d+u,f=h>0?d/h:1,y=h>=s.config.minSamples&&f<s.config.successRateThreshold,b=s.config.windowSec>0?d*60/s.config.windowSec:0;return{availableTokens:Math.floor(s.tokens),windowSuccess:d,windowFailed:u,successRate:f,consecutiveFailures:s.consecutiveFailures,backoffRemainingMs:Math.max(0,s.backoffEndAt-o),riskWarning:y,throughputPerMinute:Math.round(b*10)/10}},updateConfig:o=>{s.config={...s.config,...o}},reset:()=>{s.events=[],s.consecutiveFailures=0,s.backoffEndAt=0,s.tokens=s.config.burst,s.lastRefillTime=Date.now()}}}function vR(n){if(!n.credentials?.accessToken)return{eligible:!1,reason:"no-token"};const s=(n.subscription?.type||"").toUpperCase(),r=(n.subscription?.title||"").toUpperCase(),i=s.includes("FREE")||r.includes("FREE")||!s&&!r;if(s.includes("PRO")||s.includes("ENTERPRISE")||s.includes("TEAMS")||r.includes("PRO")||r.includes("ENTERPRISE")||r.includes("TEAMS"))return{eligible:!1,reason:"already-pro",detail:n.subscription?.title||n.subscription?.type};if(!i)return{eligible:!1,reason:"unknown-status",detail:n.subscription?.title||n.subscription?.type||"未检测"};const d=(n.lastError||"").toLowerCase();if(n.status==="error"&&(d.includes("suspended")||d.includes("封禁")||d.includes("temporarily")))return{eligible:!1,reason:"banned",detail:n.lastError};const h=n.subscription?.upgradeCapability;return h&&h.toUpperCase().includes("NOT")?{eligible:!1,reason:"cant-upgrade",detail:h}:{eligible:!0,reason:"ok"}}let ti=[],$u=null;function jR(n){ti=[...ti,n],$u?.(ti)}function Vf(n,s){ti=ti.map(r=>r.accountId===n?{...r,...s}:r),$u?.(ti)}let dj=[],uj="",hj=new Set,mj="overage",fj=[],pj=10;function cw(n){const s=[];for(const r of n.split(/\r?\n/)){const i=r.trim();if(!i)continue;const o=i.match(/https?:\/\/[^\s,|]+/i);if(!o||o.index===void 0)continue;const d=o[0].replace(/[)\]}>.,;'"]+$/,""),h=i.slice(0,o.index).trim().match(/[^\s,|<>"']+@[^\s,|<>"']+\.[^\s,|<>"']+/);s.push({email:h?h[0]:"",url:d})}return s}function NR(){const{accounts:n,selectedIds:s,updateAccount:r}=vt(),{actualLanguage:i}=Ut(),o=i==="en",[d,u]=g.useState(mj),h=_=>{mj=_,u(_)},[f,p]=g.useState(ti),[y,b]=g.useState(!1),[v,N]=g.useState(hj),[j,T]=g.useState(!1),[S,k]=g.useState(pj),[R,I]=g.useState(0),M=_=>{pj=_,k(_)},[G,W]=g.useState(dj),[U,q]=g.useState(uj),[V,le]=g.useState(!1),[B,be]=g.useState(fj),[K,se]=g.useState(!1),te=g.useRef(null),Y=_=>{p(ce=>{const Ce=typeof _=="function"?_(ce):_;return ti=Ce,Ce})},P=_=>{N(ce=>{const Ce=typeof _=="function"?_(ce):_;return hj=Ce,Ce})},F=_=>{dj=_,W(_)},fe=_=>{uj=_,q(_)},pe=_=>{be(ce=>{const Ce=typeof _=="function"?_(ce):_;return fj=Ce,Ce})};g.useEffect(()=>($u=p,()=>{$u=null}),[]),g.useEffect(()=>{const _=te.current;_&&(_.scrollTop=_.scrollHeight)},[B]);const C=g.useCallback(()=>(s.size>0?Array.from(s).map(ce=>n.get(ce)).filter(Boolean):Array.from(n.values())).filter(ce=>{if(!ce)return!1;const Ce=(ce.subscription?.type||"").toUpperCase(),Ve=(ce.subscription?.title||"").toUpperCase(),je=Ce.includes("FREE")||Ve.includes("FREE")||!Ce&&!Ve,He=!!ce.credentials?.accessToken;return je&&He}),[n,s]),z=g.useMemo(()=>{const _=s.size>0?Array.from(s).map(je=>n.get(je)).filter(Boolean):Array.from(n.values()),ce=[],Ce=[];for(const je of _){if(!je)continue;const He=vR(je);He.eligible?ce.push(je):Ce.push({account:je,reason:He.reason,detail:He.detail})}const Ve={ok:ce.length,"no-token":0,"already-pro":0,banned:0,"cant-upgrade":0,"unknown-status":0};for(const je of Ce)Ve[je.reason]++;return{eligible:ce,blocked:Ce,reasonBuckets:Ve,totalScanned:_.length}},[n,s]),X=async()=>{const _=C();if(_.length===0)return;le(!0);const ce=_[0];try{const Ce=await window.api.accountGetSubscriptions(ce.credentials.accessToken,ce.credentials?.region,ce.profileArn,ce.machineId,ce.credentials?.provider||ce.idp,ce.credentials?.authMethod,ce.id);if(Ce.success&&Ce.plans&&Ce.plans.length>0){F(Ce.plans);const Ve=Ce.plans.find(je=>je.qSubscriptionType?.toUpperCase().includes("PRO")&&!je.qSubscriptionType?.toUpperCase().includes("PLUS"))||Ce.plans[0];fe(Ve.qSubscriptionType)}}catch(Ce){console.error("[SubscriptionPage] Failed to load plans:",Ce)}le(!1)},[re,xe]=g.useState(5),Oe=async()=>{const _=C();if(_.length===0||!U)return;b(!0);const ce=_.map(H=>({accountId:H.id,email:H.email||"Unknown",status:"pending"}));Y(ce),P(new Set);const Ce=async H=>{const Se=_[H];Y(Xe=>Xe.map((Nt,nt)=>nt===H?{...Nt,status:"loading"}:Nt));try{const Xe=await window.api.accountGetSubscriptionUrl(Se.credentials.accessToken,U,Se.credentials?.region,Se.profileArn,Se.machineId,Se.credentials?.provider||Se.idp,Se.credentials?.authMethod,Se.id);Xe.success&&Xe.url?Y(Nt=>Nt.map((nt,$t)=>$t===H?{...nt,status:"success",url:Xe.url,generatedAt:Date.now(),validated:!1}:nt)):Y(Nt=>Nt.map((nt,$t)=>$t===H?{...nt,status:"error",error:Xe.error||"Failed to get URL"}:nt))}catch(Xe){Y(Nt=>Nt.map((nt,$t)=>$t===H?{...nt,status:"error",error:Xe instanceof Error?Xe.message:"Unknown error"}:nt))}},Ve=Array.from({length:_.length},(H,Se)=>Se);let je=0;const He=async()=>{for(;je<Ve.length;){const H=je++;await Ce(H)}},Tt=Array.from({length:Math.min(re,Ve.length)},()=>He());await Promise.all(Tt),b(!1)},Ee=_=>{P(ce=>{const Ce=new Set(ce);return Ce.has(_)?Ce.delete(_):Ce.add(_),Ce})},Qe=()=>{v.size===f.length&&f.length>0?P(new Set):P(new Set(f.map(_=>_.accountId)))},_e=()=>{P(_=>{const ce=new Set;for(const Ce of f)_.has(Ce.accountId)||ce.add(Ce.accountId);return ce})},st=()=>{P(new Set)},oe=_=>{P(ce=>{const Ce=new Set(ce);for(const Ve of f)Ve.status===_&&Ce.add(Ve.accountId);return Ce})},ue=()=>{const _=f.filter(Ve=>Ve.status==="success"&&Ve.url),ce=Math.max(1,S),Ce=_.slice(0,ce);P(new Set(Ce.map(Ve=>Ve.accountId))),I(Ce.length)},ae=()=>{const _=f.filter(je=>je.status==="success"&&je.url);if(_.length===0)return;const ce=Math.max(1,S);let Ce=R;Ce>=_.length&&(Ce=0);const Ve=_.slice(Ce,Ce+ce);P(new Set(Ve.map(je=>je.accountId))),I(Ce+Ve.length)},L=_=>{const ce=cw(_);if(ce.length===0)return 0;const Ce=new Set(f.map(Tt=>Tt.url).filter(Boolean)),Ve=Date.now(),je=[];let He=f.length;for(const{email:Tt,url:H}of ce)Ce.has(H)||(Ce.add(H),He++,je.push({accountId:`import-${Oi()}`,email:Tt||(o?`(Imported #${He})`:`(导入 #${He})`),status:"success",url:H,generatedAt:Ve,validated:!1}));return je.length>0&&Y(Tt=>[...Tt,...je]),je.length},we=()=>{v.size!==0&&confirm(o?`Remove ${v.size} selected links from the list?`:`从列表移除选中的 ${v.size} 个链接?`)&&(Y(_=>_.filter(ce=>!v.has(ce.accountId))),P(new Set))},Ue=()=>{const _=f.filter(ce=>ce.status==="error"||ce.status==="expired").length;_!==0&&confirm(o?`Remove ${_} failed/expired links?`:`移除 ${_} 个失败/过期的链接?`)&&Y(ce=>{const Ce=ce.filter(je=>je.status!=="error"&&je.status!=="expired"),Ve=ce.filter(je=>je.status==="error"||je.status==="expired").map(je=>je.accountId);return Ve.length>0&&P(je=>{const He=new Set(je);for(const Tt of Ve)He.delete(Tt);return He}),Ce})},Lt=_=>{const ce=f.filter(Ce=>Ce.status==="success"&&Ce.url);return _==="selected"?ce.filter(Ce=>v.has(Ce.accountId)):ce},xt=async _=>{await window.api.openSubscriptionWindow(_)},Qt=async _=>{if(!U){alert(o?"Please select a plan first":"请先选择计划");return}const ce=n.get(_);if(!(!ce||!ce.credentials?.accessToken)){Y(Ce=>Ce.map(Ve=>Ve.accountId===_?{...Ve,status:"loading",error:void 0}:Ve));try{const Ce=await window.api.accountGetSubscriptionUrl(ce.credentials.accessToken,U,ce.credentials?.region,ce.profileArn,ce.machineId,ce.credentials?.provider||ce.idp,ce.credentials?.authMethod,ce.id);Y(Ve=>Ve.map(je=>je.accountId===_?Ce.success&&Ce.url?{...je,status:"success",url:Ce.url,error:void 0,generatedAt:Date.now(),validated:!1}:{...je,status:"error",error:Ce.error||"Failed"}:je))}catch(Ce){Y(Ve=>Ve.map(je=>je.accountId===_?{...je,status:"error",error:Ce instanceof Error?Ce.message:"Unknown error"}:je))}}},[ft,Et]=g.useState(!1),Ge=async()=>{Et(!0);try{const _=f.filter(nt=>nt.status==="success"&&nt.url),ce=900*1e3,Ce=Date.now(),Ve={},je=_.filter(nt=>(nt.generatedAt?Ce-nt.generatedAt:Number.POSITIVE_INFINITY)>ce?(Ve[nt.accountId]="expired",!1):!0);let He=0;const Tt=async()=>{for(;He<je.length;){const nt=He++,$t=je[nt];if($t.url)try{const Bt=await window.api.diagnoseHttpProbe({url:$t.url,method:"HEAD",timeoutMs:6e3});Ve[$t.accountId]=Bt.success||Bt.status!==void 0&&Bt.status<400?"success":"expired"}catch{Ve[$t.accountId]="expired"}}},H=Array.from({length:Math.min(re,je.length)},()=>Tt());await Promise.all(H);const Se=f.map(nt=>{const $t=Ve[nt.accountId];return $t?$t==="expired"?{...nt,status:"expired",error:"链接已失效(HTTP 探测失败或超过 15 分钟)"}:{...nt,validated:!0}:nt});Y(Se);const Xe=Se.filter(nt=>nt.status==="expired").length,Nt=Se.filter(nt=>nt.status==="success"&&nt.validated).length;gt(`[Validate] 检测完成:${Nt} 个有效,${Xe} 个失效`)}finally{Et(!1)}};function gt(_){console.log(`[SubscriptionPage] ${_}`)}const Ze=async _=>{const ce=Lt(_);await Promise.all(ce.filter(Ce=>Ce.url).map(Ce=>window.api.openSubscriptionWindow(Ce.url)))},J=async _=>{await navigator.clipboard.writeText(_)},Ne=async _=>{const Ce=Lt(_).map(Ve=>Ve.url).join(`