@markus-global/cli 0.9.6 → 0.9.7-rc.0

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.
Files changed (85) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/skill.d.ts +3 -0
  3. package/dist/commands/skill.d.ts.map +1 -0
  4. package/dist/commands/skill.js +148 -0
  5. package/dist/commands/skill.js.map +1 -0
  6. package/dist/commands/start.d.ts.map +1 -1
  7. package/dist/commands/start.js +17 -1
  8. package/dist/commands/start.js.map +1 -1
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/markus.mjs +5302 -2735
  12. package/dist/web-ui/assets/{CommentInput-CBNbViJY.js → CommentInput-Dvlq2svZ.js} +1 -1
  13. package/dist/web-ui/assets/{ContentRenderer-DE3pZgeX.js → ContentRenderer-BfnvpFM7.js} +2 -2
  14. package/dist/web-ui/assets/DeliverableShareModal-DkGpQmZ8.js +1 -0
  15. package/dist/web-ui/assets/Deliverables-CtPvquKO.js +3 -0
  16. package/dist/web-ui/assets/{Notifications-DnOdXHNc.js → Notifications-C_e9_V74.js} +1 -1
  17. package/dist/web-ui/assets/{Search-BxFLlgcf.js → Search-DZBGpN3c.js} +1 -1
  18. package/dist/web-ui/assets/Settings-6xm2sHhm.js +8 -0
  19. package/dist/web-ui/assets/{Store-BELkjEqO.js → Store-dbJSFCFw.js} +1 -1
  20. package/dist/web-ui/assets/Team-vmqHkmh8.js +81 -0
  21. package/dist/web-ui/assets/Work-Ds7q6pZg.js +11 -0
  22. package/dist/web-ui/assets/{arc-CyhYnNcy.js → arc-BLoofCdL.js} +1 -1
  23. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-BYIYNrCP.js → architectureDiagram-3BPJPVTR-BGO4nFRN.js} +1 -1
  24. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-Tj8Yz066.js → blockDiagram-GPEHLZMM-Cn1E0037.js} +1 -1
  25. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-Ifa4IAJa.js → c4Diagram-AAUBKEIU-DXFAnq3E.js} +1 -1
  26. package/dist/web-ui/assets/channel-Cw25sYRm.js +1 -0
  27. package/dist/web-ui/assets/{chunk-2J33WTMH-CNSbz4EK.js → chunk-2J33WTMH-BXCSmrWD.js} +1 -1
  28. package/dist/web-ui/assets/{chunk-4BX2VUAB-DhNtaIHh.js → chunk-4BX2VUAB-CIWJeena.js} +1 -1
  29. package/dist/web-ui/assets/{chunk-55IACEB6-WUpOSLP9.js → chunk-55IACEB6-BuQ5-tdz.js} +1 -1
  30. package/dist/web-ui/assets/{chunk-727SXJPM-BJV_Jz1H.js → chunk-727SXJPM-q9Yx_12l.js} +1 -1
  31. package/dist/web-ui/assets/{chunk-AQP2D5EJ-BHu_5o0Y.js → chunk-AQP2D5EJ-DqaehwKB.js} +1 -1
  32. package/dist/web-ui/assets/{chunk-FMBD7UC4-CfxugWTK.js → chunk-FMBD7UC4-BFs2IYjK.js} +1 -1
  33. package/dist/web-ui/assets/{chunk-ND2GUHAM-hIFBUDLZ.js → chunk-ND2GUHAM-DyYGWpbj.js} +1 -1
  34. package/dist/web-ui/assets/{chunk-QZHKN3VN-DF0OYrsG.js → chunk-QZHKN3VN-DmbA4AU_.js} +1 -1
  35. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-CDWjvgnK.js +1 -0
  36. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-CDWjvgnK.js +1 -0
  37. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-C3LM31P0.js → cose-bilkent-S5V4N54A-BLWm27gv.js} +1 -1
  38. package/dist/web-ui/assets/{dagre-BM42HDAG-C_m79Kes.js → dagre-BM42HDAG-Cb2YgHjF.js} +1 -1
  39. package/dist/web-ui/assets/{diagram-2AECGRRQ-D8liSSSE.js → diagram-2AECGRRQ-hMyyF4SK.js} +1 -1
  40. package/dist/web-ui/assets/{diagram-5GNKFQAL-DqtsU-bB.js → diagram-5GNKFQAL-DQvYRI_z.js} +1 -1
  41. package/dist/web-ui/assets/{diagram-KO2AKTUF-C6zkMDRo.js → diagram-KO2AKTUF-CPOv2Kga.js} +1 -1
  42. package/dist/web-ui/assets/{diagram-LMA3HP47-Dx2JnYqj.js → diagram-LMA3HP47-DvgOU39M.js} +1 -1
  43. package/dist/web-ui/assets/{diagram-OG6HWLK6-ZI_lN3Ui.js → diagram-OG6HWLK6-DhLJ9Bog.js} +1 -1
  44. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-DQ5VepuZ.js → erDiagram-TEJ5UH35-C4MKvJYc.js} +1 -1
  45. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-6GiDnWFL.js → flowDiagram-I6XJVG4X-C4KiUPBX.js} +1 -1
  46. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-D6HROKP8.js → ganttDiagram-6RSMTGT7-CFiAe8nx.js} +1 -1
  47. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-CXm0stFt.js → gitGraphDiagram-PVQCEYII-y6rZo1sT.js} +1 -1
  48. package/dist/web-ui/assets/index-BbQpGkiM.css +1 -0
  49. package/dist/web-ui/assets/index-CcppNtga.js +672 -0
  50. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-C1RxESvu.js → infoDiagram-5YYISTIA-LLlnmiVb.js} +1 -1
  51. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-K65PlAf9.js → ishikawaDiagram-YF4QCWOH-Brs-NT84.js} +1 -1
  52. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-_Rs_Vudv.js → journeyDiagram-JHISSGLW-um06-20P.js} +1 -1
  53. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-Jf6WnoNW.js → kanban-definition-UN3LZRKU-yws0Rgw8.js} +1 -1
  54. package/dist/web-ui/assets/{mermaid.core-C6jfI8lj.js → mermaid.core-C0Q8mcc_.js} +5 -5
  55. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-CuVR_m6C.js → mindmap-definition-RKZ34NQL-xCtHajk4.js} +1 -1
  56. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-BiPJBXLU.js → pieDiagram-4H26LBE5-BhKiwY7r.js} +1 -1
  57. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-C4hoAfNv.js → quadrantDiagram-W4KKPZXB-CGmxw13s.js} +1 -1
  58. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-BmjjjPuK.js → requirementDiagram-4Y6WPE33-CYJRHrZE.js} +1 -1
  59. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-ts7xFx2o.js → sankeyDiagram-5OEKKPKP-CgkdSCTc.js} +1 -1
  60. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-C3je_x5z.js → sequenceDiagram-3UESZ5HK-BD2dXCDe.js} +1 -1
  61. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-CREzVZ-3.js → stateDiagram-AJRCARHV-DdEvCrm2.js} +1 -1
  62. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-DKPteYMC.js +1 -0
  63. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-CriALCTC.js → timeline-definition-PNZ67QCA-CWfdKPN1.js} +1 -1
  64. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-Bc9NNe3M.js → vennDiagram-CIIHVFJN-BTiDdRt6.js} +1 -1
  65. package/dist/web-ui/assets/{wardley-L42UT6IY-psF9We_q.js → wardley-L42UT6IY-eDkltTBC.js} +1 -1
  66. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-DNZ9Jdgm.js → wardleyDiagram-YWT4CUSO-DLOZOKTX.js} +1 -1
  67. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-COezi66E.js → xychartDiagram-2RQKCTM6-RU8GlPu6.js} +1 -1
  68. package/dist/web-ui/index.html +2 -2
  69. package/package.json +2 -2
  70. package/templates/roles/{SHARED.md → HANDBOOK.md} +17 -7
  71. package/templates/roles/org-manager/ROLE.md +1 -5
  72. package/templates/roles/skill-architect/ROLE.md +1 -1
  73. package/templates/skills/agent-building/SKILL.md +109 -11
  74. package/templates/skills/skill-building/SKILL.md +61 -0
  75. package/templates/skills/team-building/SKILL.md +110 -4
  76. package/dist/web-ui/assets/Deliverables-Cx97uG2f.js +0 -6
  77. package/dist/web-ui/assets/Settings-D0i8Lnsk.js +0 -8
  78. package/dist/web-ui/assets/Team-D_C3tvWh.js +0 -80
  79. package/dist/web-ui/assets/Work-DpRdSwD5.js +0 -11
  80. package/dist/web-ui/assets/channel-B33xJsNY.js +0 -1
  81. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-BePK-BYt.js +0 -1
  82. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-BePK-BYt.js +0 -1
  83. package/dist/web-ui/assets/index-BMzsi3-i.js +0 -670
  84. package/dist/web-ui/assets/index-C9gwAZYM.css +0 -1
  85. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-CZU51KZ-.js +0 -1
@@ -1,8 +0,0 @@
1
- import{u as ge,r as l,j as e,V as Cn,H as la,l as $,a as da,b as ca,c as ua,a6 as Er,n as ns,a7 as xa,a8 as Ir,P as Lr,h as Ve,i as ma,a9 as Sn,w as ga,aa as as,ab as Os,_ as fa}from"./index-BMzsi3-i.js";function pa(s,r){for(var i=0;i<r.length;i++){const n=r[i];if(typeof n!="string"&&!Array.isArray(n)){for(const a in n)if(a!=="default"&&!(a in s)){const t=Object.getOwnPropertyDescriptor(n,a);t&&Object.defineProperty(s,a,t.get?t:{enumerable:!0,get:()=>n[a]})}}}return Object.freeze(Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}))}function ha(s){return s>=1e6?`${(s/1e6).toFixed(s%1e6===0?0:1)}M`:s>=1e3?`${(s/1e3).toFixed((s%1e3===0,0))}K`:String(s)}function ba(s){return s.maxInputTokens>0||s.inputCostPer1MTokens>0||s.outputCostPer1MTokens>0}function os(s){if(s.tier)return s.tier;const r=s.id.toLowerCase(),i=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,n=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;return/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(r)?"pro":i.test(r)?"max":n.test(r)?"base":"pro"}const Rr={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30"};function Pn({models:s,selectedModel:r,onSelect:i,loading:n,compact:a,maxVisible:t,showTiers:d}){const{t:c}=ge("settings"),[u,f]=l.useState(""),[N,M]=l.useState(!1),[m,y]=l.useState(""),k=l.useMemo(()=>{let g=s;if(u){const j=u.toLowerCase();g=g.filter(C=>C.id.toLowerCase().includes(j))}return m&&(g=g.filter(j=>os(j)===m)),g},[s,u,m]),b=l.useMemo(()=>{const g={max:0,pro:0,base:0};for(const j of s)g[os(j)]++;return g},[s]),U=t??(a?5:10),v=N?k:k.slice(0,U),P=k.length>U;return n?e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-fg-tertiary",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),c("modelPicker.loading")]}):s.length===0?e.jsx("div",{className:"py-3 text-sm text-fg-tertiary",children:c("modelPicker.empty")}):e.jsxs("div",{className:"space-y-2",children:[d&&s.length>3&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{onClick:()=>y(""),className:`px-2 py-0.5 rounded text-[10px] transition-colors ${m?"bg-surface-overlay text-fg-tertiary hover:text-fg-secondary":"bg-brand-500/20 text-brand-500"}`,children:c("modelPicker.allCount",{count:s.length})}),["max","pro","base"].filter(g=>b[g]>0).map(g=>e.jsx("button",{onClick:()=>y(m===g?"":g),className:`px-2 py-0.5 rounded text-[10px] font-medium uppercase transition-colors border ${m===g?Rr[g]:"border-transparent bg-surface-overlay text-fg-tertiary hover:text-fg-secondary"}`,children:c("modelPicker.tierCount",{tier:c(`modelRouting.tier.${g}`),count:b[g]})},g))]}),s.length>5&&e.jsx("input",{type:"text",value:u,onChange:g=>{f(g.target.value),M(!1)},placeholder:c("modelPicker.filterPlaceholder"),className:"w-full px-3 py-1.5 bg-surface-overlay border border-border-default rounded-lg text-xs text-fg-primary placeholder:text-fg-tertiary focus:outline-none focus:border-brand-500"}),e.jsx("div",{className:`space-y-1 ${a?"max-h-[280px] overflow-y-auto":""}`,children:v.map(g=>{const j=g.id===r,C=os(g);return e.jsxs("button",{type:"button",onClick:()=>i(g.id),className:`w-full text-left px-3 py-2 rounded-lg transition-colors ${j?"bg-brand-500/10 border border-brand-500/30":"hover:bg-surface-overlay border border-transparent"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`w-3 h-3 rounded-full border-2 flex items-center justify-center ${j?"border-brand-500":"border-border-default"}`,children:j&&e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-brand-500"})}),e.jsx("span",{className:`text-xs font-medium ${j?"text-brand-500":"text-fg-primary"}`,children:g.id}),d&&e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase border ${Rr[C]}`,children:c(`modelRouting.tier.${C}`)})]}),e.jsx("div",{className:"flex items-center gap-2",children:j&&e.jsx("span",{className:"text-[10px] text-brand-500 font-medium",children:c("modelPicker.active")})})]}),ba(g)&&g.maxInputTokens>0&&e.jsx("div",{className:"ml-5 mt-0.5 flex items-center gap-2 text-[10px] text-fg-tertiary flex-wrap",children:e.jsxs("span",{children:[ha(g.maxInputTokens)," ",c("modelPicker.ctx")]})}),!a&&e.jsxs("div",{className:"ml-5 mt-1 flex items-center gap-1.5 flex-wrap",children:[g.capabilities.functionCalling&&e.jsx(it,{label:c("modelPicker.capabilities.tools")}),g.capabilities.vision&&e.jsx(it,{label:c("modelPicker.capabilities.vision")}),g.capabilities.reasoning&&e.jsx(it,{label:c("modelPicker.capabilities.reasoning")}),g.capabilities.promptCaching&&e.jsx(it,{label:c("modelPicker.capabilities.caching")}),g.capabilities.webSearch&&e.jsx(it,{label:c("modelPicker.capabilities.search")})]})]},g.id)})}),P&&!N&&e.jsx("button",{type:"button",onClick:()=>M(!0),className:"text-xs text-brand-500 hover:text-brand-400 px-3",children:c("modelPicker.showAll",{count:k.length})}),N&&P&&e.jsx("button",{type:"button",onClick:()=>M(!1),className:"text-xs text-fg-tertiary hover:text-fg-secondary px-3",children:c("modelPicker.showLess")})]})}function it({label:s}){return e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] bg-surface-overlay text-fg-tertiary border border-border-default",children:s})}function _s({value:s,options:r,placeholder:i,onChange:n}){const{t:a}=ge("settings"),[t,d]=l.useState(!1),[c,u]=l.useState(""),f=l.useRef(null),N=l.useRef(null),M=l.useRef(null),[m,y]=l.useState(-1);l.useEffect(()=>{function g(j){f.current&&!f.current.contains(j.target)&&d(!1)}return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[]),l.useEffect(()=>{t&&N.current&&N.current.focus()},[t]);const k=l.useMemo(()=>{if(!c.trim())return r;const g=c.toLowerCase();return r.filter(j=>j.modelId.toLowerCase().includes(g)||j.modelName.toLowerCase().includes(g)||j.provider.toLowerCase().includes(g)||j.providerLabel.toLowerCase().includes(g)||j.tier&&j.tier.toLowerCase().includes(g))},[r,c]),b=l.useMemo(()=>{const g=new Map;for(const C of k){const B=C.providerLabel;g.has(B)||g.set(B,[]),g.get(B).push(C)}const j={max:0,pro:1,base:2};for(const C of g.values())C.sort((B,I)=>(j[B.tier??"base"]??9)-(j[I.tier??"base"]??9));return g},[k]),U=l.useMemo(()=>{const g=[];for(const j of b.values())g.push(...j);return g},[b]),v=l.useMemo(()=>{if(!s)return i??a("modelRouting.auto");const g=r.find(j=>`${j.provider}/${j.modelId}`===s);return g?`${g.providerLabel}/${g.modelName}`:s},[s,r,i,a]);function P(g){if(!t){(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),d(!0));return}switch(g.key){case"ArrowDown":g.preventDefault(),y(j=>Math.min(j+1,U.length-1));break;case"ArrowUp":g.preventDefault(),y(j=>Math.max(j-1,-1));break;case"Enter":g.preventDefault(),m===-1?n(""):U[m]&&n(`${U[m].provider}/${U[m].modelId}`),d(!1),u("");break;case"Escape":d(!1),u("");break}}return l.useEffect(()=>{M.current&&m>=0&&M.current.querySelector(`[data-focus-index="${m}"]`)?.scrollIntoView({block:"nearest"})},[m]),e.jsxs("div",{ref:f,className:"relative",onKeyDown:P,children:[e.jsx("button",{type:"button",onClick:()=>{d(!t),u(""),y(-1)},className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary text-left truncate focus:outline-none focus:border-brand-500",children:v}),t&&e.jsxs("div",{className:"absolute z-50 mt-1 w-full min-w-[240px] max-h-[280px] bg-surface-elevated border border-border-default rounded-lg shadow-xl overflow-hidden flex flex-col",children:[e.jsx("div",{className:"p-1.5 border-b border-border-default",children:e.jsx("input",{ref:N,type:"text",value:c,onChange:g=>{u(g.target.value),y(-1)},placeholder:a("modelPicker.searchPlaceholder")||"Search models...",className:"w-full px-2 py-1 bg-surface-overlay border border-border-default rounded text-xs text-fg-primary focus:outline-none focus:border-brand-500"})}),e.jsxs("div",{ref:M,className:"overflow-y-auto flex-1",children:[e.jsx("div",{className:`px-3 py-1.5 text-xs cursor-pointer ${m===-1?"bg-brand-500/20 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,onClick:()=>{n(""),d(!1),u("")},children:i??a("modelRouting.auto")}),[...b.entries()].map(([g,j])=>e.jsxs("div",{children:[e.jsx("div",{className:"px-3 py-1 text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider bg-surface-overlay/50 sticky top-0",children:g}),j.map(C=>{const B=U.indexOf(C),I=`${C.provider}/${C.modelId}`===s;return e.jsxs("div",{"data-focus-index":B,className:`px-3 py-1.5 text-xs cursor-pointer flex items-center gap-2 ${B===m?"bg-brand-500/20":I?"bg-surface-overlay":"hover:bg-surface-overlay/50"}`,onClick:()=>{n(`${C.provider}/${C.modelId}`),d(!1),u("")},children:[e.jsx("span",{className:"flex-1 truncate text-fg-primary",children:C.modelName}),C.tier&&e.jsx(ya,{tier:C.tier}),C.costTier&&e.jsx("span",{className:"text-[9px] text-fg-tertiary",children:C.costTier})]},`${C.provider}/${C.modelId}`)})]},g)),U.length===0&&e.jsx("div",{className:"px-3 py-3 text-xs text-fg-tertiary text-center",children:a("modelPicker.empty")})]})]})]})}function ya({tier:s}){const r={max:"bg-purple-500/20 text-purple-400",pro:"bg-blue-500/20 text-blue-400",base:"bg-gray-500/20 text-gray-400"};return e.jsx("span",{className:`px-1 py-0.5 rounded text-[8px] font-bold uppercase ${r[s]??r.base}`,children:s})}const va=500,Br=[{groupKey:"image",capabilities:["image_recognition","image_generation"]},{groupKey:"audio",capabilities:["audio_tts","audio_stt"]},{groupKey:"video",capabilities:["video_generation"]}];function ja({onSave:s,configuredProviders:r}){const{t:i}=ge(["settings","common"]),[n,a]=l.useState({}),[t,d]=l.useState(null),[c,u]=l.useState(!1),[f,N]=l.useState(null),[M,m]=l.useState("idle"),[y,k]=l.useState(null),[b,U]=l.useState({}),[v,P]=l.useState(!1),[g,j]=l.useState("idle"),[C,B]=l.useState(null),[I,O]=l.useState(!1),K=l.useRef(null),_=l.useRef(null),D=l.useMemo(()=>r.map(T=>T.name).sort().join(","),[r]);l.useEffect(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{a(T.capabilityRouting?.assignments??{}),d(T.routingDefaultModel??null),u(!0)}).catch(T=>{N(String(T)),u(!0)})},[D]),l.useEffect(()=>{fetch("/api/models/routing-candidates",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{const q=[];for(const V of T.providers)for(const x of V.models)q.push({provider:V.provider,providerLabel:V.displayName,modelId:x.id,modelName:x.name,mode:x.mode,tier:x.tier,costTier:x.costTier,capabilities:x.capabilities});k(q)}).catch(()=>k(null))},[D]),l.useEffect(()=>{fetch("/api/models/suggested-assignments",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{U(T.suggestions),P(!0)}).catch(()=>P(!0))},[D]);const F=l.useCallback(T=>{m("saving"),s(T).then(()=>{m("saved"),setTimeout(()=>m(q=>q==="saved"?"idle":q),2e3)}).catch(()=>{m("error"),setTimeout(()=>m(q=>q==="error"?"idle":q),3e3)})},[s]),p=l.useCallback((T,q)=>{_.current={capabilityRouting:T!==void 0?{assignments:T}:_.current?.capabilityRouting,routingDefaultModel:q!==void 0?q:_.current?.routingDefaultModel},K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{const V=_.current;_.current=null,V&&F(V)},va)},[F]),S=l.useMemo(()=>r.flatMap(T=>(T.models??[{id:T.model,name:T.model}]).map(q=>({provider:T.name,providerLabel:T.displayName??T.name,modelId:q.id,modelName:q.name}))),[r]),A=y??S,z=l.useMemo(()=>Object.entries(n).map(([T,q])=>`${T}:${q?.provider??""}/${q?.model??""}`).sort().join("|"),[n]);l.useEffect(()=>{!c||!y||y.length===0||y.some(T=>!!T.modelId)&&(a(T=>{let q=!1;const V={...T};for(const x of Br)for(const L of x.capabilities){const H=V[L];if(!H?.model)continue;const Q=An(y,L);if(Q.length===0)continue;Q.some(ee=>ee.provider===H.provider&&ee.modelId===H.model)||(delete V[L],q=!0)}return q?(p(V),V):T}),d(T=>{if(!T?.model||y.some(L=>L.provider===T.provider&&L.modelId===T.model))return T;const V=y.find(L=>L.provider==="markus"),x=V?{provider:V.provider,model:V.modelId}:{provider:y[0].provider,model:y[0].modelId};return s({routingDefaultModel:x}),x}))},[c,y,D,p,z]);const J=l.useCallback(()=>{fetch("/api/settings/llm/routing",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{a(T.capabilityRouting?.assignments??{}),d(T.routingDefaultModel??null)}).catch(()=>{}),fetch("/api/models/routing-candidates",{credentials:"include"}).then(T=>{if(!T.ok)throw new Error(`HTTP ${T.status}`);return T.json()}).then(T=>{const q=[];for(const V of T.providers)for(const x of V.models)q.push({provider:V.provider,providerLabel:V.displayName,modelId:x.id,modelName:x.name,mode:x.mode,tier:x.tier,costTier:x.costTier,capabilities:x.capabilities});k(q)}).catch(()=>{})},[]),ne=l.useCallback(async()=>{if(g!=="working"){j("working"),B(null);try{const T=await fetch("/api/settings/llm/restore-recommended",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"}}),q=await T.json().catch(()=>({}));if(!T.ok||!q.ok)throw new Error(q.error??`HTTP ${T.status}`);q.capabilityRouting&&a(q.capabilityRouting.assignments??{}),q.routingDefaultModel!==void 0&&d(q.routingDefaultModel),J(),j("idle"),m("saved"),setTimeout(()=>m(V=>V==="saved"?"idle":V),2e3)}catch(T){j("error"),B(T instanceof Error?T.message:String(T)),setTimeout(()=>j("idle"),4e3)}}},[g,J]);return c?f?e.jsx("div",{className:"bg-red-500/10 border border-red-500/30 rounded-xl p-4 text-xs text-red-400",children:i("modelRouting.loadError",{error:f})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(ka,{status:M,t:i}),e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[e.jsx("button",{type:"button",onClick:()=>O(!0),disabled:g==="working",className:"text-xs px-3 py-1.5 rounded-lg border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500/40 disabled:opacity-50 transition-colors",children:i(g==="working"?"modelRouting.restoreWorking":"modelRouting.restoreRecommended")}),C&&e.jsx("span",{className:"text-[10px] text-red-400 max-w-xs text-right",children:C})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:i("modelRouting.defaultModelTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:i("modelRouting.defaultModelDesc")})]}),e.jsx("div",{className:"max-w-md",children:e.jsx(_s,{value:t?`${t.provider}/${t.model}`:"",options:A,placeholder:i("modelRouting.defaultModelPlaceholder"),onChange:T=>{if(!T)d(null),p(void 0,null);else{const[q,...V]=T.split("/"),x={provider:q,model:V.join("/")};if(d(x),n.text){const L={...n};delete L.text,a(L),p(L,x)}else p(void 0,x)}}})})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:i("modelRouting.capabilityAssignTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:i("modelRouting.capabilityAssignDesc")})]}),r.length===0&&e.jsx("div",{className:"p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg text-xs text-yellow-400",children:i("modelRouting.noProvidersHint")}),r.length>0&&e.jsx("div",{className:"space-y-4",children:Br.map(T=>e.jsx(Na,{groupKey:T.groupKey,capabilities:T.capabilities,assignments:n,suggestions:b,allModels:A,configuredProviderNames:new Set(r.map(q=>q.name)),t:i,onAssign:(q,V)=>{const x={...n};V?x[q]=V:delete x[q],a(x),p(x)}},T.groupKey))})]}),I&&e.jsx(Cn,{variant:"primary",title:i("modelRouting.restoreRecommended"),message:i("modelRouting.restoreConfirm"),confirmLabel:i("common:confirm"),onConfirm:()=>{O(!1),ne()},onCancel:()=>O(!1)})]}):e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 animate-pulse",children:[e.jsx("div",{className:"h-4 bg-surface-overlay rounded w-1/3 mb-3"}),e.jsx("div",{className:"h-3 bg-surface-overlay rounded w-2/3 mb-4"}),e.jsx("div",{className:"space-y-2",children:[1,2,3,4,5].map(T=>e.jsx("div",{className:"h-10 bg-surface-overlay rounded-lg"},T))})]})})}function Na({groupKey:s,capabilities:r,assignments:i,suggestions:n,allModels:a,configuredProviderNames:t,t:d,onAssign:c}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider mb-2 px-1",children:d(`modelRouting.capabilityGroups.${s}`)}),e.jsx("div",{className:"space-y-1",children:r.map(u=>{const f=i[u],N=n[u],M=f?`${f.provider}/${f.model}`:"",m=An(a,u),y=N?m.find(P=>P.provider===N.provider&&P.modelId===N.model)?.modelName??N.model:void 0,k=m.length>0,b=f?wa(a,f.provider,f.model):void 0,U=f&&!t.has(f.provider),v=!!(f&&k&&u!=="text"&&!m.some(P=>P.provider===f.provider&&P.modelId===f.model));return e.jsxs("div",{className:`flex items-center gap-3 px-3 py-2 rounded-lg ${v?"bg-red-500/10 border border-red-500/30":U?"bg-yellow-500/10 border border-yellow-500/30":!k&&!f?"bg-amber-500/5 border border-amber-500/20":"bg-surface-overlay/40"}`,children:[e.jsx("div",{className:"w-28 shrink-0",children:e.jsx("span",{className:"text-xs text-fg-primary",children:d(`modelRouting.capabilities.${u}`)})}),e.jsx("div",{className:"flex-1 min-w-0",children:v?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("span",{className:"text-xs text-red-400",children:["⚠ ",f.model]}),e.jsx("span",{className:"text-[10px] text-red-400/70",children:d("modelRouting.mismatchHint")})]}),e.jsx(_s,{value:"",options:m,placeholder:d("modelRouting.selectModel"),onChange:P=>{if(!P)c(u,null);else{const[g,...j]=P.split("/");c(u,{provider:g,model:j.join("/")})}}})]}):k?e.jsx(_s,{value:M,options:m,placeholder:y?`${y} (${d("modelRouting.suggested")})`:d("modelRouting.selectModel"),onChange:P=>{if(!P)c(u,null);else{const[g,...j]=P.split("/");c(u,{provider:g,model:j.join("/")})}}}):e.jsxs("span",{className:"text-xs text-amber-400",children:[d("modelRouting.noModelAvailable"),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",d("modelRouting.addProviderHint")]})]})}),e.jsxs("div",{className:"w-14 shrink-0 flex justify-end",children:[v&&e.jsx("span",{className:"text-[10px] text-red-400 font-medium",title:d("modelRouting.mismatchHint"),children:"⚠"}),!v&&U&&e.jsx("span",{className:"text-[10px] text-yellow-400 font-medium",title:d("modelRouting.staleProvider"),children:"⚠"}),!v&&!U&&b&&e.jsx(Or,{tier:b}),!v&&!U&&!b&&f&&e.jsx(Or,{tier:"unknown"})]}),e.jsx("div",{className:"w-8 shrink-0 flex justify-end",children:f&&e.jsx("button",{onClick:()=>c(u,null),className:"text-fg-tertiary hover:text-red-400 transition-colors",title:d("modelRouting.clear"),children:e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})})]},u)})})]})}function wa(s,r,i){return s.find(a=>a.provider===r&&a.modelId===i)?.tier}function ka({status:s,t:r}){if(s==="idle")return null;const i={idle:"",saving:"text-fg-tertiary",saved:"text-green-400",error:"text-red-400"},n={idle:"",saving:r("modelRouting.saving"),saved:r("modelRouting.saved"),error:r("modelRouting.saveError")};return e.jsx("div",{className:`text-xs font-medium transition-opacity ${i[s]}`,children:n[s]})}function Or({tier:s}){const r={max:"bg-purple-500/20 text-purple-400 border-purple-500/30",pro:"bg-blue-500/20 text-blue-400 border-blue-500/30",base:"bg-gray-500/20 text-gray-400 border-gray-500/30",unknown:"bg-gray-500/10 text-fg-tertiary border-border-default"};return e.jsx("span",{className:`px-1.5 py-0.5 text-[9px] rounded font-semibold uppercase border ${r[s]??r.unknown}`,children:s==="unknown"?"—":s})}const Ca=new Set(["imageGeneration","tts","stt","videoGeneration","audioOutput","audioInput"]);function An(s,r){if(r==="text")return s.filter(d=>!(d.capabilities&&d.capabilities.some(c=>Ca.has(c))||d.mode&&d.mode!=="chat"));const i={image_generation:["image_generation"],audio_tts:["audio_speech"],audio_stt:["audio_transcription"],video_generation:["video_generation"]},n={image_recognition:["vision"],image_generation:["imageGeneration"],audio_tts:["tts"],audio_stt:["stt"],video_generation:["videoGeneration"]},a=i[r],t=n[r];return s.filter(d=>!!(d.capabilities&&d.capabilities.length>0&&t&&t.some(c=>d.capabilities.includes(c))||a&&d.mode&&a.includes(d.mode)))}const Pt=[{id:"markus",label:"Markus Cloud AI",envKey:"MARKUS_SUBSCRIPTION_KEY",defaultModel:""},{id:"anthropic",label:"Anthropic",envKey:"ANTHROPIC_API_KEY",defaultModel:"claude-opus-4-6"},{id:"openai",label:"OpenAI",envKey:"OPENAI_API_KEY",defaultModel:"gpt-5.4"},{id:"google",label:"Google Gemini",envKey:"GOOGLE_API_KEY",defaultModel:"gemini-3-1-pro"},{id:"deepseek",label:"DeepSeek",envKey:"DEEPSEEK_API_KEY",baseUrl:"https://api.deepseek.com",defaultModel:"deepseek-v4-flash"},{id:"siliconflow",label:"SiliconFlow (中国)",envKey:"SILICONFLOW_API_KEY",baseUrl:"https://api.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"siliconflow-intl",label:"SiliconFlow (Global)",envKey:"SILICONFLOW_INTL_API_KEY",baseUrl:"https://api-st.siliconflow.cn/v1",defaultModel:"Qwen/Qwen3.5-35B-A3B"},{id:"minimax",label:"MiniMax (Global)",envKey:"MINIMAX_API_KEY",baseUrl:"https://api.minimax.io/v1",defaultModel:"MiniMax-M3"},{id:"minimax-cn",label:"MiniMax (中国)",envKey:"MINIMAX_CN_API_KEY",baseUrl:"https://api.minimaxi.com/v1",defaultModel:"MiniMax-M3"},{id:"openrouter",label:"OpenRouter",envKey:"OPENROUTER_API_KEY",baseUrl:"https://openrouter.ai/api/v1",defaultModel:"xiaomi/mimo-v2-pro:free"},{id:"zai",label:"ZAI (GLM)",envKey:"ZAI_API_KEY",baseUrl:"https://api.z.ai/api/paas/v4",defaultModel:"glm-5.1"},{id:"xai",label:"xAI (Grok)",envKey:"XAI_API_KEY",baseUrl:"https://api.x.ai/v1",defaultModel:"grok-3"},{id:"mistral",label:"Mistral AI",envKey:"MISTRAL_API_KEY",baseUrl:"https://api.mistral.ai/v1",defaultModel:"mistral-large-latest"},{id:"groq",label:"Groq",envKey:"GROQ_API_KEY",baseUrl:"https://api.groq.com/openai/v1",defaultModel:"llama-3.3-70b-versatile"},{id:"perplexity",label:"Perplexity",envKey:"PERPLEXITY_API_KEY",baseUrl:"https://api.perplexity.ai",defaultModel:"sonar-pro"},{id:"cohere",label:"Cohere",envKey:"COHERE_API_KEY",baseUrl:"https://api.cohere.ai/compatibility/v1",defaultModel:"command-r-plus"},{id:"together_ai",label:"Together AI",envKey:"TOGETHER_API_KEY",baseUrl:"https://api.together.xyz/v1",defaultModel:"meta-llama/Llama-3.3-70B-Instruct-Turbo"},{id:"fireworks_ai",label:"Fireworks AI",envKey:"FIREWORKS_API_KEY",baseUrl:"https://api.fireworks.ai/inference/v1",defaultModel:"accounts/fireworks/models/llama-v3p3-70b-instruct"},{id:"moonshot",label:"Moonshot (Kimi)",envKey:"MOONSHOT_API_KEY",baseUrl:"https://api.moonshot.cn/v1",defaultModel:"moonshot-v1-auto"},{id:"volcengine",label:"Volcengine (Doubao)",envKey:"VOLCENGINE_API_KEY",baseUrl:"https://ark.cn-beijing.volces.com/api/v3",defaultModel:"doubao-1.5-pro-32k"},{id:"dashscope",label:"DashScope (Qwen)",envKey:"DASHSCOPE_API_KEY",baseUrl:"https://dashscope.aliyuncs.com/compatible-mode/v1",defaultModel:"qwen-max"},{id:"ollama",label:"Ollama (Local)",envKey:"OLLAMA_BASE_URL",baseUrl:"http://localhost:11434/v1",defaultModel:"llama3"},{id:"atlascloud",label:"Atlas Cloud (Full-Modal)",envKey:"ATLASCLOUD_API_KEY",baseUrl:"https://api.atlascloud.ai/v1",defaultModel:"claude-sonnet-4-6"},{id:"strongly",label:"Strongly.AI (Full-Modal)",envKey:"STRONGLY_API_KEY",baseUrl:"https://api.strongly.ai/v1",defaultModel:"claude-sonnet-4-6"}];var Je={},is,_r;function Sa(){return _r||(_r=1,is=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),is}var ls={},Ke={},Dr;function He(){if(Dr)return Ke;Dr=1;let s;const r=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return Ke.getSymbolSize=function(n){if(!n)throw new Error('"version" cannot be null or undefined');if(n<1||n>40)throw new Error('"version" should be in range from 1 to 40');return n*4+17},Ke.getSymbolTotalCodewords=function(n){return r[n]},Ke.getBCHDigit=function(i){let n=0;for(;i!==0;)n++,i>>>=1;return n},Ke.setToSJISFunction=function(n){if(typeof n!="function")throw new Error('"toSJISFunc" is not a valid function.');s=n},Ke.isKanjiModeEnabled=function(){return typeof s<"u"},Ke.toSJIS=function(n){return s(n)},Ke}var ds={},Kr;function Ks(){return Kr||(Kr=1,(function(s){s.L={bit:1},s.M={bit:0},s.Q={bit:3},s.H={bit:2};function r(i){if(typeof i!="string")throw new Error("Param is not a string");switch(i.toLowerCase()){case"l":case"low":return s.L;case"m":case"medium":return s.M;case"q":case"quartile":return s.Q;case"h":case"high":return s.H;default:throw new Error("Unknown EC Level: "+i)}}s.isValid=function(n){return n&&typeof n.bit<"u"&&n.bit>=0&&n.bit<4},s.from=function(n,a){if(s.isValid(n))return n;try{return r(n)}catch{return a}}})(ds)),ds}var cs,Ur;function Pa(){if(Ur)return cs;Ur=1;function s(){this.buffer=[],this.length=0}return s.prototype={get:function(r){const i=Math.floor(r/8);return(this.buffer[i]>>>7-r%8&1)===1},put:function(r,i){for(let n=0;n<i;n++)this.putBit((r>>>i-n-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(r){const i=Math.floor(this.length/8);this.buffer.length<=i&&this.buffer.push(0),r&&(this.buffer[i]|=128>>>this.length%8),this.length++}},cs=s,cs}var us,Fr;function Aa(){if(Fr)return us;Fr=1;function s(r){if(!r||r<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=r,this.data=new Uint8Array(r*r),this.reservedBit=new Uint8Array(r*r)}return s.prototype.set=function(r,i,n,a){const t=r*this.size+i;this.data[t]=n,a&&(this.reservedBit[t]=!0)},s.prototype.get=function(r,i){return this.data[r*this.size+i]},s.prototype.xor=function(r,i,n){this.data[r*this.size+i]^=n},s.prototype.isReserved=function(r,i){return this.reservedBit[r*this.size+i]},us=s,us}var xs={},$r;function Ma(){return $r||($r=1,(function(s){const r=He().getSymbolSize;s.getRowColCoords=function(n){if(n===1)return[];const a=Math.floor(n/7)+2,t=r(n),d=t===145?26:Math.ceil((t-13)/(2*a-2))*2,c=[t-7];for(let u=1;u<a-1;u++)c[u]=c[u-1]-d;return c.push(6),c.reverse()},s.getPositions=function(n){const a=[],t=s.getRowColCoords(n),d=t.length;for(let c=0;c<d;c++)for(let u=0;u<d;u++)c===0&&u===0||c===0&&u===d-1||c===d-1&&u===0||a.push([t[c],t[u]]);return a}})(xs)),xs}var ms={},Vr;function Ta(){if(Vr)return ms;Vr=1;const s=He().getSymbolSize,r=7;return ms.getPositions=function(n){const a=s(n);return[[0,0],[a-r,0],[0,a-r]]},ms}var gs={},Hr;function Ea(){return Hr||(Hr=1,(function(s){s.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const r={N1:3,N2:3,N3:40,N4:10};s.isValid=function(a){return a!=null&&a!==""&&!isNaN(a)&&a>=0&&a<=7},s.from=function(a){return s.isValid(a)?parseInt(a,10):void 0},s.getPenaltyN1=function(a){const t=a.size;let d=0,c=0,u=0,f=null,N=null;for(let M=0;M<t;M++){c=u=0,f=N=null;for(let m=0;m<t;m++){let y=a.get(M,m);y===f?c++:(c>=5&&(d+=r.N1+(c-5)),f=y,c=1),y=a.get(m,M),y===N?u++:(u>=5&&(d+=r.N1+(u-5)),N=y,u=1)}c>=5&&(d+=r.N1+(c-5)),u>=5&&(d+=r.N1+(u-5))}return d},s.getPenaltyN2=function(a){const t=a.size;let d=0;for(let c=0;c<t-1;c++)for(let u=0;u<t-1;u++){const f=a.get(c,u)+a.get(c,u+1)+a.get(c+1,u)+a.get(c+1,u+1);(f===4||f===0)&&d++}return d*r.N2},s.getPenaltyN3=function(a){const t=a.size;let d=0,c=0,u=0;for(let f=0;f<t;f++){c=u=0;for(let N=0;N<t;N++)c=c<<1&2047|a.get(f,N),N>=10&&(c===1488||c===93)&&d++,u=u<<1&2047|a.get(N,f),N>=10&&(u===1488||u===93)&&d++}return d*r.N3},s.getPenaltyN4=function(a){let t=0;const d=a.data.length;for(let u=0;u<d;u++)t+=a.data[u];return Math.abs(Math.ceil(t*100/d/5)-10)*r.N4};function i(n,a,t){switch(n){case s.Patterns.PATTERN000:return(a+t)%2===0;case s.Patterns.PATTERN001:return a%2===0;case s.Patterns.PATTERN010:return t%3===0;case s.Patterns.PATTERN011:return(a+t)%3===0;case s.Patterns.PATTERN100:return(Math.floor(a/2)+Math.floor(t/3))%2===0;case s.Patterns.PATTERN101:return a*t%2+a*t%3===0;case s.Patterns.PATTERN110:return(a*t%2+a*t%3)%2===0;case s.Patterns.PATTERN111:return(a*t%3+(a+t)%2)%2===0;default:throw new Error("bad maskPattern:"+n)}}s.applyMask=function(a,t){const d=t.size;for(let c=0;c<d;c++)for(let u=0;u<d;u++)t.isReserved(u,c)||t.xor(u,c,i(a,u,c))},s.getBestMask=function(a,t){const d=Object.keys(s.Patterns).length;let c=0,u=1/0;for(let f=0;f<d;f++){t(f),s.applyMask(f,a);const N=s.getPenaltyN1(a)+s.getPenaltyN2(a)+s.getPenaltyN3(a)+s.getPenaltyN4(a);s.applyMask(f,a),N<u&&(u=N,c=f)}return c}})(gs)),gs}var At={},qr;function Mn(){if(qr)return At;qr=1;const s=Ks(),r=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],i=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return At.getBlocksCount=function(a,t){switch(t){case s.L:return r[(a-1)*4+0];case s.M:return r[(a-1)*4+1];case s.Q:return r[(a-1)*4+2];case s.H:return r[(a-1)*4+3];default:return}},At.getTotalCodewordsCount=function(a,t){switch(t){case s.L:return i[(a-1)*4+0];case s.M:return i[(a-1)*4+1];case s.Q:return i[(a-1)*4+2];case s.H:return i[(a-1)*4+3];default:return}},At}var fs={},lt={},zr;function Ia(){if(zr)return lt;zr=1;const s=new Uint8Array(512),r=new Uint8Array(256);return(function(){let n=1;for(let a=0;a<255;a++)s[a]=n,r[n]=a,n<<=1,n&256&&(n^=285);for(let a=255;a<512;a++)s[a]=s[a-255]})(),lt.log=function(n){if(n<1)throw new Error("log("+n+")");return r[n]},lt.exp=function(n){return s[n]},lt.mul=function(n,a){return n===0||a===0?0:s[r[n]+r[a]]},lt}var Wr;function La(){return Wr||(Wr=1,(function(s){const r=Ia();s.mul=function(n,a){const t=new Uint8Array(n.length+a.length-1);for(let d=0;d<n.length;d++)for(let c=0;c<a.length;c++)t[d+c]^=r.mul(n[d],a[c]);return t},s.mod=function(n,a){let t=new Uint8Array(n);for(;t.length-a.length>=0;){const d=t[0];for(let u=0;u<a.length;u++)t[u]^=r.mul(a[u],d);let c=0;for(;c<t.length&&t[c]===0;)c++;t=t.slice(c)}return t},s.generateECPolynomial=function(n){let a=new Uint8Array([1]);for(let t=0;t<n;t++)a=s.mul(a,new Uint8Array([1,r.exp(t)]));return a}})(fs)),fs}var ps,Gr;function Ra(){if(Gr)return ps;Gr=1;const s=La();function r(i){this.genPoly=void 0,this.degree=i,this.degree&&this.initialize(this.degree)}return r.prototype.initialize=function(n){this.degree=n,this.genPoly=s.generateECPolynomial(this.degree)},r.prototype.encode=function(n){if(!this.genPoly)throw new Error("Encoder not initialized");const a=new Uint8Array(n.length+this.degree);a.set(n);const t=s.mod(a,this.genPoly),d=this.degree-t.length;if(d>0){const c=new Uint8Array(this.degree);return c.set(t,d),c}return t},ps=r,ps}var hs={},bs={},ys={},Yr;function Tn(){return Yr||(Yr=1,ys.isValid=function(r){return!isNaN(r)&&r>=1&&r<=40}),ys}var Ae={},Jr;function En(){if(Jr)return Ae;Jr=1;const s="[0-9]+",r="[A-Z $%*+\\-./:]+";let i="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";i=i.replace(/u/g,"\\u");const n="(?:(?![A-Z0-9 $%*+\\-./:]|"+i+`)(?:.|[\r
2
- ]))+`;Ae.KANJI=new RegExp(i,"g"),Ae.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Ae.BYTE=new RegExp(n,"g"),Ae.NUMERIC=new RegExp(s,"g"),Ae.ALPHANUMERIC=new RegExp(r,"g");const a=new RegExp("^"+i+"$"),t=new RegExp("^"+s+"$"),d=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Ae.testKanji=function(u){return a.test(u)},Ae.testNumeric=function(u){return t.test(u)},Ae.testAlphanumeric=function(u){return d.test(u)},Ae}var Qr;function qe(){return Qr||(Qr=1,(function(s){const r=Tn(),i=En();s.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},s.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},s.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},s.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},s.MIXED={bit:-1},s.getCharCountIndicator=function(t,d){if(!t.ccBits)throw new Error("Invalid mode: "+t);if(!r.isValid(d))throw new Error("Invalid version: "+d);return d>=1&&d<10?t.ccBits[0]:d<27?t.ccBits[1]:t.ccBits[2]},s.getBestModeForData=function(t){return i.testNumeric(t)?s.NUMERIC:i.testAlphanumeric(t)?s.ALPHANUMERIC:i.testKanji(t)?s.KANJI:s.BYTE},s.toString=function(t){if(t&&t.id)return t.id;throw new Error("Invalid mode")},s.isValid=function(t){return t&&t.bit&&t.ccBits};function n(a){if(typeof a!="string")throw new Error("Param is not a string");switch(a.toLowerCase()){case"numeric":return s.NUMERIC;case"alphanumeric":return s.ALPHANUMERIC;case"kanji":return s.KANJI;case"byte":return s.BYTE;default:throw new Error("Unknown mode: "+a)}}s.from=function(t,d){if(s.isValid(t))return t;try{return n(t)}catch{return d}}})(bs)),bs}var Xr;function Ba(){return Xr||(Xr=1,(function(s){const r=He(),i=Mn(),n=Ks(),a=qe(),t=Tn(),d=7973,c=r.getBCHDigit(d);function u(m,y,k){for(let b=1;b<=40;b++)if(y<=s.getCapacity(b,k,m))return b}function f(m,y){return a.getCharCountIndicator(m,y)+4}function N(m,y){let k=0;return m.forEach(function(b){const U=f(b.mode,y);k+=U+b.getBitsLength()}),k}function M(m,y){for(let k=1;k<=40;k++)if(N(m,k)<=s.getCapacity(k,y,a.MIXED))return k}s.from=function(y,k){return t.isValid(y)?parseInt(y,10):k},s.getCapacity=function(y,k,b){if(!t.isValid(y))throw new Error("Invalid QR Code version");typeof b>"u"&&(b=a.BYTE);const U=r.getSymbolTotalCodewords(y),v=i.getTotalCodewordsCount(y,k),P=(U-v)*8;if(b===a.MIXED)return P;const g=P-f(b,y);switch(b){case a.NUMERIC:return Math.floor(g/10*3);case a.ALPHANUMERIC:return Math.floor(g/11*2);case a.KANJI:return Math.floor(g/13);case a.BYTE:default:return Math.floor(g/8)}},s.getBestVersionForData=function(y,k){let b;const U=n.from(k,n.M);if(Array.isArray(y)){if(y.length>1)return M(y,U);if(y.length===0)return 1;b=y[0]}else b=y;return u(b.mode,b.getLength(),U)},s.getEncodedBits=function(y){if(!t.isValid(y)||y<7)throw new Error("Invalid QR Code version");let k=y<<12;for(;r.getBCHDigit(k)-c>=0;)k^=d<<r.getBCHDigit(k)-c;return y<<12|k}})(hs)),hs}var vs={},Zr;function Oa(){if(Zr)return vs;Zr=1;const s=He(),r=1335,i=21522,n=s.getBCHDigit(r);return vs.getEncodedBits=function(t,d){const c=t.bit<<3|d;let u=c<<10;for(;s.getBCHDigit(u)-n>=0;)u^=r<<s.getBCHDigit(u)-n;return(c<<10|u)^i},vs}var js={},Ns,en;function _a(){if(en)return Ns;en=1;const s=qe();function r(i){this.mode=s.NUMERIC,this.data=i.toString()}return r.getBitsLength=function(n){return 10*Math.floor(n/3)+(n%3?n%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(n){let a,t,d;for(a=0;a+3<=this.data.length;a+=3)t=this.data.substr(a,3),d=parseInt(t,10),n.put(d,10);const c=this.data.length-a;c>0&&(t=this.data.substr(a),d=parseInt(t,10),n.put(d,c*3+1))},Ns=r,Ns}var ws,tn;function Da(){if(tn)return ws;tn=1;const s=qe(),r=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function i(n){this.mode=s.ALPHANUMERIC,this.data=n}return i.getBitsLength=function(a){return 11*Math.floor(a/2)+6*(a%2)},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(a){let t;for(t=0;t+2<=this.data.length;t+=2){let d=r.indexOf(this.data[t])*45;d+=r.indexOf(this.data[t+1]),a.put(d,11)}this.data.length%2&&a.put(r.indexOf(this.data[t]),6)},ws=i,ws}var ks,sn;function Ka(){if(sn)return ks;sn=1;const s=qe();function r(i){this.mode=s.BYTE,typeof i=="string"?this.data=new TextEncoder().encode(i):this.data=new Uint8Array(i)}return r.getBitsLength=function(n){return n*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(i){for(let n=0,a=this.data.length;n<a;n++)i.put(this.data[n],8)},ks=r,ks}var Cs,rn;function Ua(){if(rn)return Cs;rn=1;const s=qe(),r=He();function i(n){this.mode=s.KANJI,this.data=n}return i.getBitsLength=function(a){return a*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(n){let a;for(a=0;a<this.data.length;a++){let t=r.toSJIS(this.data[a]);if(t>=33088&&t<=40956)t-=33088;else if(t>=57408&&t<=60351)t-=49472;else throw new Error("Invalid SJIS character: "+this.data[a]+`
3
- Make sure your charset is UTF-8`);t=(t>>>8&255)*192+(t&255),n.put(t,13)}},Cs=i,Cs}var Ss={exports:{}},nn;function Fa(){return nn||(nn=1,(function(s){var r={single_source_shortest_paths:function(i,n,a){var t={},d={};d[n]=0;var c=r.PriorityQueue.make();c.push(n,0);for(var u,f,N,M,m,y,k,b,U;!c.empty();){u=c.pop(),f=u.value,M=u.cost,m=i[f]||{};for(N in m)m.hasOwnProperty(N)&&(y=m[N],k=M+y,b=d[N],U=typeof d[N]>"u",(U||b>k)&&(d[N]=k,c.push(N,k),t[N]=f))}if(typeof a<"u"&&typeof d[a]>"u"){var v=["Could not find a path from ",n," to ",a,"."].join("");throw new Error(v)}return t},extract_shortest_path_from_predecessor_list:function(i,n){for(var a=[],t=n;t;)a.push(t),i[t],t=i[t];return a.reverse(),a},find_path:function(i,n,a){var t=r.single_source_shortest_paths(i,n,a);return r.extract_shortest_path_from_predecessor_list(t,a)},PriorityQueue:{make:function(i){var n=r.PriorityQueue,a={},t;i=i||{};for(t in n)n.hasOwnProperty(t)&&(a[t]=n[t]);return a.queue=[],a.sorter=i.sorter||n.default_sorter,a},default_sorter:function(i,n){return i.cost-n.cost},push:function(i,n){var a={value:i,cost:n};this.queue.push(a),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};s.exports=r})(Ss)),Ss.exports}var an;function $a(){return an||(an=1,(function(s){const r=qe(),i=_a(),n=Da(),a=Ka(),t=Ua(),d=En(),c=He(),u=Fa();function f(v){return unescape(encodeURIComponent(v)).length}function N(v,P,g){const j=[];let C;for(;(C=v.exec(g))!==null;)j.push({data:C[0],index:C.index,mode:P,length:C[0].length});return j}function M(v){const P=N(d.NUMERIC,r.NUMERIC,v),g=N(d.ALPHANUMERIC,r.ALPHANUMERIC,v);let j,C;return c.isKanjiModeEnabled()?(j=N(d.BYTE,r.BYTE,v),C=N(d.KANJI,r.KANJI,v)):(j=N(d.BYTE_KANJI,r.BYTE,v),C=[]),P.concat(g,j,C).sort(function(I,O){return I.index-O.index}).map(function(I){return{data:I.data,mode:I.mode,length:I.length}})}function m(v,P){switch(P){case r.NUMERIC:return i.getBitsLength(v);case r.ALPHANUMERIC:return n.getBitsLength(v);case r.KANJI:return t.getBitsLength(v);case r.BYTE:return a.getBitsLength(v)}}function y(v){return v.reduce(function(P,g){const j=P.length-1>=0?P[P.length-1]:null;return j&&j.mode===g.mode?(P[P.length-1].data+=g.data,P):(P.push(g),P)},[])}function k(v){const P=[];for(let g=0;g<v.length;g++){const j=v[g];switch(j.mode){case r.NUMERIC:P.push([j,{data:j.data,mode:r.ALPHANUMERIC,length:j.length},{data:j.data,mode:r.BYTE,length:j.length}]);break;case r.ALPHANUMERIC:P.push([j,{data:j.data,mode:r.BYTE,length:j.length}]);break;case r.KANJI:P.push([j,{data:j.data,mode:r.BYTE,length:f(j.data)}]);break;case r.BYTE:P.push([{data:j.data,mode:r.BYTE,length:f(j.data)}])}}return P}function b(v,P){const g={},j={start:{}};let C=["start"];for(let B=0;B<v.length;B++){const I=v[B],O=[];for(let K=0;K<I.length;K++){const _=I[K],D=""+B+K;O.push(D),g[D]={node:_,lastCount:0},j[D]={};for(let F=0;F<C.length;F++){const p=C[F];g[p]&&g[p].node.mode===_.mode?(j[p][D]=m(g[p].lastCount+_.length,_.mode)-m(g[p].lastCount,_.mode),g[p].lastCount+=_.length):(g[p]&&(g[p].lastCount=_.length),j[p][D]=m(_.length,_.mode)+4+r.getCharCountIndicator(_.mode,P))}}C=O}for(let B=0;B<C.length;B++)j[C[B]].end=0;return{map:j,table:g}}function U(v,P){let g;const j=r.getBestModeForData(v);if(g=r.from(P,j),g!==r.BYTE&&g.bit<j.bit)throw new Error('"'+v+'" cannot be encoded with mode '+r.toString(g)+`.
4
- Suggested mode is: `+r.toString(j));switch(g===r.KANJI&&!c.isKanjiModeEnabled()&&(g=r.BYTE),g){case r.NUMERIC:return new i(v);case r.ALPHANUMERIC:return new n(v);case r.KANJI:return new t(v);case r.BYTE:return new a(v)}}s.fromArray=function(P){return P.reduce(function(g,j){return typeof j=="string"?g.push(U(j,null)):j.data&&g.push(U(j.data,j.mode)),g},[])},s.fromString=function(P,g){const j=M(P,c.isKanjiModeEnabled()),C=k(j),B=b(C,g),I=u.find_path(B.map,"start","end"),O=[];for(let K=1;K<I.length-1;K++)O.push(B.table[I[K]].node);return s.fromArray(y(O))},s.rawSplit=function(P){return s.fromArray(M(P,c.isKanjiModeEnabled()))}})(js)),js}var on;function Va(){if(on)return ls;on=1;const s=He(),r=Ks(),i=Pa(),n=Aa(),a=Ma(),t=Ta(),d=Ea(),c=Mn(),u=Ra(),f=Ba(),N=Oa(),M=qe(),m=$a();function y(B,I){const O=B.size,K=t.getPositions(I);for(let _=0;_<K.length;_++){const D=K[_][0],F=K[_][1];for(let p=-1;p<=7;p++)if(!(D+p<=-1||O<=D+p))for(let S=-1;S<=7;S++)F+S<=-1||O<=F+S||(p>=0&&p<=6&&(S===0||S===6)||S>=0&&S<=6&&(p===0||p===6)||p>=2&&p<=4&&S>=2&&S<=4?B.set(D+p,F+S,!0,!0):B.set(D+p,F+S,!1,!0))}}function k(B){const I=B.size;for(let O=8;O<I-8;O++){const K=O%2===0;B.set(O,6,K,!0),B.set(6,O,K,!0)}}function b(B,I){const O=a.getPositions(I);for(let K=0;K<O.length;K++){const _=O[K][0],D=O[K][1];for(let F=-2;F<=2;F++)for(let p=-2;p<=2;p++)F===-2||F===2||p===-2||p===2||F===0&&p===0?B.set(_+F,D+p,!0,!0):B.set(_+F,D+p,!1,!0)}}function U(B,I){const O=B.size,K=f.getEncodedBits(I);let _,D,F;for(let p=0;p<18;p++)_=Math.floor(p/3),D=p%3+O-8-3,F=(K>>p&1)===1,B.set(_,D,F,!0),B.set(D,_,F,!0)}function v(B,I,O){const K=B.size,_=N.getEncodedBits(I,O);let D,F;for(D=0;D<15;D++)F=(_>>D&1)===1,D<6?B.set(D,8,F,!0):D<8?B.set(D+1,8,F,!0):B.set(K-15+D,8,F,!0),D<8?B.set(8,K-D-1,F,!0):D<9?B.set(8,15-D-1+1,F,!0):B.set(8,15-D-1,F,!0);B.set(K-8,8,1,!0)}function P(B,I){const O=B.size;let K=-1,_=O-1,D=7,F=0;for(let p=O-1;p>0;p-=2)for(p===6&&p--;;){for(let S=0;S<2;S++)if(!B.isReserved(_,p-S)){let A=!1;F<I.length&&(A=(I[F]>>>D&1)===1),B.set(_,p-S,A),D--,D===-1&&(F++,D=7)}if(_+=K,_<0||O<=_){_-=K,K=-K;break}}}function g(B,I,O){const K=new i;O.forEach(function(S){K.put(S.mode.bit,4),K.put(S.getLength(),M.getCharCountIndicator(S.mode,B)),S.write(K)});const _=s.getSymbolTotalCodewords(B),D=c.getTotalCodewordsCount(B,I),F=(_-D)*8;for(K.getLengthInBits()+4<=F&&K.put(0,4);K.getLengthInBits()%8!==0;)K.putBit(0);const p=(F-K.getLengthInBits())/8;for(let S=0;S<p;S++)K.put(S%2?17:236,8);return j(K,B,I)}function j(B,I,O){const K=s.getSymbolTotalCodewords(I),_=c.getTotalCodewordsCount(I,O),D=K-_,F=c.getBlocksCount(I,O),p=K%F,S=F-p,A=Math.floor(K/F),z=Math.floor(D/F),J=z+1,ne=A-z,T=new u(ne);let q=0;const V=new Array(F),x=new Array(F);let L=0;const H=new Uint8Array(B.buffer);for(let le=0;le<F;le++){const fe=le<S?z:J;V[le]=H.slice(q,q+fe),x[le]=T.encode(V[le]),q+=fe,L=Math.max(L,fe)}const Q=new Uint8Array(K);let te=0,ee,X;for(ee=0;ee<L;ee++)for(X=0;X<F;X++)ee<V[X].length&&(Q[te++]=V[X][ee]);for(ee=0;ee<ne;ee++)for(X=0;X<F;X++)Q[te++]=x[X][ee];return Q}function C(B,I,O,K){let _;if(Array.isArray(B))_=m.fromArray(B);else if(typeof B=="string"){let A=I;if(!A){const z=m.rawSplit(B);A=f.getBestVersionForData(z,O)}_=m.fromString(B,A||40)}else throw new Error("Invalid data");const D=f.getBestVersionForData(_,O);if(!D)throw new Error("The amount of data is too big to be stored in a QR Code");if(!I)I=D;else if(I<D)throw new Error(`
5
- The chosen QR Code version cannot contain this amount of data.
6
- Minimum version required to store current data is: `+D+`.
7
- `);const F=g(I,O,_),p=s.getSymbolSize(I),S=new n(p);return y(S,I),k(S),b(S,I),v(S,O,0),I>=7&&U(S,I),P(S,F),isNaN(K)&&(K=d.getBestMask(S,v.bind(null,S,O))),d.applyMask(K,S),v(S,O,K),{modules:S,version:I,errorCorrectionLevel:O,maskPattern:K,segments:_}}return ls.create=function(I,O){if(typeof I>"u"||I==="")throw new Error("No input text");let K=r.M,_,D;return typeof O<"u"&&(K=r.from(O.errorCorrectionLevel,r.M),_=f.from(O.version),D=d.from(O.maskPattern),O.toSJISFunc&&s.setToSJISFunction(O.toSJISFunc)),C(I,_,K,D)},ls}var Ps={},As={},ln;function In(){return ln||(ln=1,(function(s){function r(i){if(typeof i=="number"&&(i=i.toString()),typeof i!="string")throw new Error("Color should be defined as hex string");let n=i.slice().replace("#","").split("");if(n.length<3||n.length===5||n.length>8)throw new Error("Invalid hex color: "+i);(n.length===3||n.length===4)&&(n=Array.prototype.concat.apply([],n.map(function(t){return[t,t]}))),n.length===6&&n.push("F","F");const a=parseInt(n.join(""),16);return{r:a>>24&255,g:a>>16&255,b:a>>8&255,a:a&255,hex:"#"+n.slice(0,6).join("")}}s.getOptions=function(n){n||(n={}),n.color||(n.color={});const a=typeof n.margin>"u"||n.margin===null||n.margin<0?4:n.margin,t=n.width&&n.width>=21?n.width:void 0,d=n.scale||4;return{width:t,scale:t?4:d,margin:a,color:{dark:r(n.color.dark||"#000000ff"),light:r(n.color.light||"#ffffffff")},type:n.type,rendererOpts:n.rendererOpts||{}}},s.getScale=function(n,a){return a.width&&a.width>=n+a.margin*2?a.width/(n+a.margin*2):a.scale},s.getImageWidth=function(n,a){const t=s.getScale(n,a);return Math.floor((n+a.margin*2)*t)},s.qrToImageData=function(n,a,t){const d=a.modules.size,c=a.modules.data,u=s.getScale(d,t),f=Math.floor((d+t.margin*2)*u),N=t.margin*u,M=[t.color.light,t.color.dark];for(let m=0;m<f;m++)for(let y=0;y<f;y++){let k=(m*f+y)*4,b=t.color.light;if(m>=N&&y>=N&&m<f-N&&y<f-N){const U=Math.floor((m-N)/u),v=Math.floor((y-N)/u);b=M[c[U*d+v]?1:0]}n[k++]=b.r,n[k++]=b.g,n[k++]=b.b,n[k]=b.a}}})(As)),As}var dn;function Ha(){return dn||(dn=1,(function(s){const r=In();function i(a,t,d){a.clearRect(0,0,t.width,t.height),t.style||(t.style={}),t.height=d,t.width=d,t.style.height=d+"px",t.style.width=d+"px"}function n(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}s.render=function(t,d,c){let u=c,f=d;typeof u>"u"&&(!d||!d.getContext)&&(u=d,d=void 0),d||(f=n()),u=r.getOptions(u);const N=r.getImageWidth(t.modules.size,u),M=f.getContext("2d"),m=M.createImageData(N,N);return r.qrToImageData(m.data,t,u),i(M,f,N),M.putImageData(m,0,0),f},s.renderToDataURL=function(t,d,c){let u=c;typeof u>"u"&&(!d||!d.getContext)&&(u=d,d=void 0),u||(u={});const f=s.render(t,d,u),N=u.type||"image/png",M=u.rendererOpts||{};return f.toDataURL(N,M.quality)}})(Ps)),Ps}var Ms={},cn;function qa(){if(cn)return Ms;cn=1;const s=In();function r(a,t){const d=a.a/255,c=t+'="'+a.hex+'"';return d<1?c+" "+t+'-opacity="'+d.toFixed(2).slice(1)+'"':c}function i(a,t,d){let c=a+t;return typeof d<"u"&&(c+=" "+d),c}function n(a,t,d){let c="",u=0,f=!1,N=0;for(let M=0;M<a.length;M++){const m=Math.floor(M%t),y=Math.floor(M/t);!m&&!f&&(f=!0),a[M]?(N++,M>0&&m>0&&a[M-1]||(c+=f?i("M",m+d,.5+y+d):i("m",u,0),u=0,f=!1),m+1<t&&a[M+1]||(c+=i("h",N),N=0)):u++}return c}return Ms.render=function(t,d,c){const u=s.getOptions(d),f=t.modules.size,N=t.modules.data,M=f+u.margin*2,m=u.color.light.a?"<path "+r(u.color.light,"fill")+' d="M0 0h'+M+"v"+M+'H0z"/>':"",y="<path "+r(u.color.dark,"stroke")+' d="'+n(N,f,u.margin)+'"/>',k='viewBox="0 0 '+M+" "+M+'"',U='<svg xmlns="http://www.w3.org/2000/svg" '+(u.width?'width="'+u.width+'" height="'+u.width+'" ':"")+k+' shape-rendering="crispEdges">'+m+y+`</svg>
8
- `;return typeof c=="function"&&c(null,U),U},Ms}var un;function za(){if(un)return Je;un=1;const s=Sa(),r=Va(),i=Ha(),n=qa();function a(t,d,c,u,f){const N=[].slice.call(arguments,1),M=N.length,m=typeof N[M-1]=="function";if(!m&&!s())throw new Error("Callback required as last argument");if(m){if(M<2)throw new Error("Too few arguments provided");M===2?(f=c,c=d,d=u=void 0):M===3&&(d.getContext&&typeof f>"u"?(f=u,u=void 0):(f=u,u=c,c=d,d=void 0))}else{if(M<1)throw new Error("Too few arguments provided");return M===1?(c=d,d=u=void 0):M===2&&!d.getContext&&(u=c,c=d,d=void 0),new Promise(function(y,k){try{const b=r.create(c,u);y(t(b,d,u))}catch(b){k(b)}})}try{const y=r.create(c,u);f(null,t(y,d,u))}catch(y){f(y)}}return Je.create=r.create,Je.toCanvas=a.bind(null,i.render),Je.toDataURL=a.bind(null,i.renderToDataURL),Je.toString=a.bind(null,function(t,d,c){return n.render(t,c)}),Je}var Ln=za();const Rn=la(Ln),Wa=pa({__proto__:null,default:Rn},[Ln]),xn={appId:"",appSecret:"",enabled:!1,connected:!1,notifyChatId:"",notifyOnApproval:!0,notifyOnNotification:!1,notifyPriority:["high","urgent"]},Ga=[{value:"normal",color:"bg-green-400"},{value:"low",color:"bg-gray-400"},{value:"medium",color:"bg-blue-400"},{value:"high",color:"bg-amber-400"},{value:"urgent",color:"bg-red-400"}];function Ya({connected:s}){return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${s?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-gray-500/10 text-gray-500 border border-gray-500/30"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${s?"bg-green-500 animate-pulse":"bg-gray-400"}`}),s?"Connected":"Disconnected"]})}function dt({title:s,children:r}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary uppercase tracking-wider",children:s}),r]})}function mn({type:s,text:r}){return e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2 rounded-lg text-xs ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-600 border border-red-500/30"}`,children:[s==="ok"?e.jsx("svg",{className:"w-4 h-4 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}):e.jsx("svg",{className:"w-4 h-4 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),r]})}function Ja(){const{t:s}=ge(["settings","common"]),[r,i]=l.useState(xn),[n,a]=l.useState(!0),[t,d]=l.useState(!1),[c,u]=l.useState(!1),[f,N]=l.useState(!1),[M,m]=l.useState(null),[y,k]=l.useState(""),[b,U]=l.useState([]),[v,P]=l.useState(!1),[g,j]=l.useState("idle"),[C,B]=l.useState(null),[I,O]=l.useState(null),[K,_]=l.useState(0),D=l.useRef(null),F=l.useRef(null),[p,S]=l.useState(!1),[A,z]=l.useState(!1),J=l.useRef(null),ne=l.useRef(r);ne.current=r;const T=l.useRef(!1),q=l.useCallback(async()=>{P(!0);try{const E=await $.settings.listFeishuChats();U(E.chats??[])}catch{}finally{P(!1)}},[]),V=l.useCallback(async()=>{a(!0);try{const E=await $.settings.getFeishuIntegration();E&&(i({appId:E.appId??"",appSecret:E.appSecret??"",enabled:E.enabled??!1,connected:E.connected??!1,notifyChatId:E.notifyChatId??"",notifyOnApproval:E.notifyOnApproval??!0,notifyOnNotification:E.notifyOnNotification??!1,notifyPriority:E.notifyPriority??["high","urgent"]}),E.appId&&E.appSecret&&q())}catch{}finally{a(!1),T.current=!0}},[]);l.useEffect(()=>{V()},[V]),l.useEffect(()=>()=>{D.current&&clearInterval(D.current)},[]);const x=l.useCallback(async E=>{if(!(!E.appId||!E.appSecret)){d(!0);try{const ae=await $.settings.saveFeishuIntegration({appId:E.appId,appSecret:E.appSecret,enabled:E.enabled,notifyChatId:E.notifyChatId||void 0,notifyOnApproval:E.notifyOnApproval,notifyOnNotification:E.notifyOnNotification,notifyPriority:E.notifyPriority});ae.connected!==void 0&&i(xe=>({...xe,connected:ae.connected})),m({type:"ok",text:s("settings:feishu.saved",{defaultValue:"Saved"})}),setTimeout(()=>m(xe=>xe?.type==="ok"?null:xe),2e3)}catch(ae){m({type:"err",text:String(ae instanceof Error?ae.message:ae)})}finally{d(!1)}}},[s]),L=l.useCallback(()=>{T.current&&(J.current&&clearTimeout(J.current),J.current=setTimeout(()=>{x(ne.current)},600))},[x]),H=(E,ae)=>{i(xe=>({...xe,[E]:ae})),m(null),L()},Q=(E,ae)=>{i(xe=>{const we={...xe,[E]:ae};return ne.current=we,we}),m(null),J.current&&clearTimeout(J.current),x({...ne.current,[E]:ae})},te=E=>{i(ae=>{const xe=ae.notifyPriority,we=xe.includes(E)?xe.filter(mt=>mt!==E):[...xe,E],et={...ae,notifyPriority:we};return ne.current=et,et}),m(null),J.current&&clearTimeout(J.current),J.current=setTimeout(()=>{x(ne.current)},300)},ee=async()=>{j("waiting_qr"),B(null),O(null),m(null),D.current=setInterval(async()=>{try{const E=await $.settings.getFeishuRegisterStatus();if(E.active&&E.url){B(E.url),_(E.expireIn??300),j("scanning");try{const ae=await Rn.toDataURL(E.url,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"}});O(ae)}catch{}}}catch{}},1e3);try{const E=await $.settings.registerFeishuApp();D.current&&(clearInterval(D.current),D.current=null),E.success&&E.appId?(j("done"),m({type:"ok",text:s("settings:feishu.registerSuccess",{defaultValue:"App created successfully! Integration is now active."})}),await V()):(j("error"),m({type:"err",text:E.message||s("settings:feishu.registerFailed",{defaultValue:"Registration failed"})}))}catch(E){D.current&&(clearInterval(D.current),D.current=null),j("error"),m({type:"err",text:String(E instanceof Error?E.message:E)})}},X=()=>{D.current&&(clearInterval(D.current),D.current=null),F.current&&F.current.abort(),j("idle"),B(null),O(null)},le=async()=>{if(!r.appId||!r.appSecret){m({type:"err",text:s("settings:feishu.fillRequired",{defaultValue:"Please fill in App ID and App Secret first"})});return}u(!0),m(null);try{const E=await $.settings.testFeishuConnection({appId:r.appId,appSecret:r.appSecret});E.success?(i(ae=>({...ae,connected:!0})),m({type:"ok",text:E.message||s("settings:feishu.testSuccess",{defaultValue:"Connection successful"})})):m({type:"err",text:E.message||s("settings:feishu.testFailed",{defaultValue:"Connection failed"})})}catch(E){m({type:"err",text:String(E instanceof Error?E.message:E)})}finally{u(!1)}},fe=async()=>{if(!y.trim()){m({type:"err",text:s("settings:feishu.chatIdRequired",{defaultValue:"Please select a group chat"})});return}N(!0),m(null);try{const E=await $.settings.sendFeishuTestMessage({chatId:y.trim()});E.success?m({type:"ok",text:E.message||s("settings:feishu.testMsgSent",{defaultValue:"Test message sent"})}):m({type:"err",text:E.message||s("settings:feishu.testMsgFailed",{defaultValue:"Failed to send test message"})})}catch(E){m({type:"err",text:String(E instanceof Error?E.message:E)})}finally{N(!1)}},Ue=async()=>{d(!0),m(null);try{await $.settings.deleteFeishuIntegration(),T.current=!1,i(xn),T.current=!0,S(!1),m({type:"ok",text:s("settings:feishu.disconnected",{defaultValue:"Disconnected from Feishu"})})}catch(E){m({type:"err",text:String(E instanceof Error?E.message:E)})}finally{d(!1)}},[Fe,xt]=l.useState(!1),Ze=!!(r.appId&&r.appSecret),be=e.jsxs("button",{type:"button",onClick:()=>xt(E=>!E),className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${Fe?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),e.jsx("div",{className:"w-8 h-8 rounded-lg bg-blue-500/10 flex items-center justify-center shrink-0",children:e.jsx("svg",{className:"w-5 h-5 text-blue-500",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M6.3 10.5c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8zm12.4 0c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8zm-6.2 10c-.8 0-1.5-.3-2-.9-.6-.6-.9-1.3-.9-2 0-.8.3-1.5.9-2 .6-.5 1.3-.8 2-.8.8 0 1.5.3 2 .9.6.6.9 1.3.9 2 0 .8-.3 1.5-.9 2-.5.5-1.2.8-2 .8z"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:"飞书 (Feishu / Lark)"}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 hidden sm:inline",children:s("settings:feishu.description",{defaultValue:"Configure Feishu integration for notifications and approvals"})})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[n&&e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t&&e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx(Ya,{connected:r.connected&&r.enabled})]})]});return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[be,Fe&&e.jsxs("div",{className:"px-6 pb-6 pt-2 space-y-8 border-t border-border-default",children:[n&&e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"ml-2 text-sm text-fg-tertiary",children:s("common:loading",{defaultValue:"Loading..."})})]}),!n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-blue-500/5 border border-blue-500/20",children:[e.jsx("svg",{className:"w-4 h-4 text-blue-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 10V3L4 14h7v7l9-11h-7z"})}),e.jsx("span",{className:"text-xs text-fg-secondary",children:s("settings:feishu.longConnectionMode",{defaultValue:"Using long connection mode (WebSocket) — no public IP required"})})]}),Ze?e.jsxs(e.Fragment,{children:[e.jsx(dt,{title:s("settings:feishu.appInfo",{defaultValue:"App Information"}),children:e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:"App ID:"}),e.jsx("code",{className:"text-xs font-mono text-fg-primary bg-surface-primary px-2 py-0.5 rounded",children:r.appId})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:"App Secret:"}),e.jsx("code",{className:"text-xs font-mono text-fg-primary bg-surface-primary px-2 py-0.5 rounded",children:"•".repeat(Math.min(r.appSecret.length,20))})]})]}),e.jsxs("button",{onClick:Ue,disabled:t,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium text-red-500 border border-red-500/30 rounded-lg hover:bg-red-500/10 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),s("settings:feishu.removeApp",{defaultValue:"Remove"})]})]})})}),e.jsx(dt,{title:s("settings:feishu.integrationState",{defaultValue:"Integration State"}),children:e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("settings:feishu.enableIntegration",{defaultValue:"Enable Feishu Integration"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.enableHint",{defaultValue:"When enabled, Markus will establish a long connection to Feishu and start processing events"})})]}),e.jsx("button",{onClick:()=>Q("enabled",!r.enabled),className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${r.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${r.enabled?"translate-x-6":"translate-x-0.5"}`})})]})})}),e.jsxs(dt,{title:s("settings:feishu.actions",{defaultValue:"Actions"}),children:[e.jsx("div",{className:"flex flex-wrap items-center gap-3",children:e.jsxs("button",{onClick:le,disabled:c,className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium bg-surface-primary border border-border-default rounded-lg text-fg-primary hover:bg-surface-overlay disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[c?e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})]}),s("settings:feishu.testConnection",{defaultValue:"Test Connection"})]})}),r.connected&&r.enabled&&e.jsxs("div",{className:"mt-4 p-4 bg-surface-secondary border border-border-default rounded-xl space-y-3",children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary",children:s("settings:feishu.sendTestMessage",{defaultValue:"Send Test Message"})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsxs("select",{value:y,onChange:E=>k(E.target.value),className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors appearance-none pr-8",children:[e.jsx("option",{value:"",children:s("settings:feishu.selectTestChat",{defaultValue:"— Select a group chat —"})}),b.map(E=>e.jsx("option",{value:E.chatId,children:E.name||E.chatId},E.chatId))]}),e.jsx("svg",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-fg-tertiary pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),e.jsxs("button",{onClick:fe,disabled:f||!y.trim(),className:"inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium bg-surface-primary border border-border-default rounded-lg text-fg-primary hover:bg-surface-overlay disabled:opacity-50 disabled:cursor-not-allowed transition-colors whitespace-nowrap",children:[f?e.jsx("div",{className:"w-4 h-4 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}):e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})}),s("settings:feishu.send",{defaultValue:"Send"})]})]})]}),M&&e.jsx(mn,{type:M.type,text:M.text})]}),e.jsx(dt,{title:s("settings:feishu.notificationForwarding",{defaultValue:"Notification Forwarding"}),children:e.jsxs("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-5 space-y-5",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary",children:s("settings:feishu.notifyChatId",{defaultValue:"Notification Target Group"})}),e.jsxs("button",{onClick:q,disabled:v,className:"inline-flex items-center gap-1 text-[11px] text-brand-600 hover:text-brand-700 disabled:opacity-50 transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 ${v?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),s("settings:feishu.refreshChats",{defaultValue:"Refresh"})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:r.notifyChatId,onChange:E=>Q("notifyChatId",E.target.value),className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors appearance-none pr-8",children:[e.jsx("option",{value:"",children:v?s("settings:feishu.loadingChats",{defaultValue:"Loading groups..."}):s("settings:feishu.selectChat",{defaultValue:"— Private message (default) —"})}),b.map(E=>e.jsx("option",{value:E.chatId,children:E.name||E.chatId},E.chatId))]}),e.jsx("svg",{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-4 h-4 text-fg-tertiary pointer-events-none",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),!r.notifyChatId&&!v&&e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1",children:s("settings:feishu.noChatFallbackHint",{defaultValue:"No group selected — notifications will be sent to you as private messages."})}),b.length===0&&!v&&r.notifyChatId===""&&e.jsx("p",{className:"text-[11px] text-amber-600 dark:text-amber-400 mt-0.5",children:s("settings:feishu.noChatHint",{defaultValue:"No groups found. Add the bot to a group chat to enable group notifications."})}),r.notifyChatId&&e.jsxs("p",{className:"text-[11px] text-fg-tertiary mt-1 font-mono",children:["ID: ",r.notifyChatId]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary",children:s("settings:feishu.forwardApprovals",{defaultValue:"Forward Approval Requests"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.forwardApprovalsHint",{defaultValue:"Send approval requests to Feishu as interactive cards"})})]}),e.jsx("button",{onClick:()=>Q("notifyOnApproval",!r.notifyOnApproval),className:`relative w-10 h-5 rounded-full transition-colors duration-200 ${r.notifyOnApproval?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-4 h-4 bg-white rounded-full shadow transform transition-transform duration-200 ${r.notifyOnApproval?"translate-x-5":"translate-x-0.5"}`})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary",children:s("settings:feishu.forwardNotifications",{defaultValue:"Forward General Notifications"})}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("settings:feishu.forwardNotificationsHint",{defaultValue:"Send system notifications to Feishu chat"})})]}),e.jsx("button",{onClick:()=>Q("notifyOnNotification",!r.notifyOnNotification),className:`relative w-10 h-5 rounded-full transition-colors duration-200 ${r.notifyOnNotification?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} cursor-pointer`,children:e.jsx("span",{className:`block w-4 h-4 bg-white rounded-full shadow transform transition-transform duration-200 ${r.notifyOnNotification?"translate-x-5":"translate-x-0.5"}`})})]})]}),(r.notifyOnApproval||r.notifyOnNotification)&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-fg-secondary mb-2",children:s("settings:feishu.notifyPriority",{defaultValue:"Minimum Notification Priority"})}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Ga.map(({value:E,color:ae})=>{const xe=r.notifyPriority.includes(E);return e.jsxs("button",{onClick:()=>te(E),className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-xs rounded-lg border transition-colors ${xe?"bg-brand-500/10 border-brand-500/30 text-brand-600":"bg-surface-primary border-border-default text-fg-tertiary hover:border-fg-tertiary"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ae}`}),E.charAt(0).toUpperCase()+E.slice(1)]},E)})}),e.jsx("p",{className:"text-[11px] text-fg-tertiary mt-1.5",children:s("settings:feishu.priorityHint",{defaultValue:"Only notifications with the selected priority levels will be forwarded"})})]})]})})]}):e.jsxs(dt,{title:s("settings:feishu.quickSetup",{defaultValue:"Quick Setup"}),children:[e.jsx("div",{className:"bg-surface-secondary border border-border-default rounded-xl p-6 space-y-5",children:g==="idle"||g==="error"||g==="done"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx("div",{className:"w-16 h-16 mx-auto rounded-2xl bg-gradient-to-br from-blue-500/20 to-indigo-500/20 border border-blue-500/30 flex items-center justify-center",children:e.jsx("svg",{className:"w-8 h-8 text-blue-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"})})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-primary",children:s("settings:feishu.oneClickTitle",{defaultValue:"One-Click Feishu Integration"})}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1 max-w-sm mx-auto",children:s("settings:feishu.oneClickDesc",{defaultValue:"Scan a QR code with Feishu to automatically create and configure the app. No manual setup needed."})})]}),e.jsxs("button",{onClick:ee,disabled:g==="done",className:"inline-flex items-center gap-2 px-6 py-2.5 text-sm font-medium bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors shadow-sm",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 4v1m6 11h2m-6 0h-2v4m0-11v3m0 0h.01M12 12h4.01M16 20h4M4 12h4m12 0h.01M5 8h2a1 1 0 001-1V5a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1zm12 0h2a1 1 0 001-1V5a1 1 0 00-1-1h-2a1 1 0 00-1 1v2a1 1 0 001 1zM5 20h2a1 1 0 001-1v-2a1 1 0 00-1-1H5a1 1 0 00-1 1v2a1 1 0 001 1z"})}),s("settings:feishu.scanToCreate",{defaultValue:"Scan QR Code to Create App"})]})]}),e.jsx("div",{className:"border-t border-border-default pt-4",children:e.jsx("p",{className:"text-[11px] text-fg-tertiary text-center",children:s("settings:feishu.oneClickPermissions",{defaultValue:"The app will be created with permissions: bot messaging, message receiving, user info reading, and group chat management."})})})]}):e.jsxs("div",{className:"text-center space-y-4",children:[g==="waiting_qr"&&!C&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[e.jsx("div",{className:"w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm text-fg-secondary",children:s("settings:feishu.generatingQR",{defaultValue:"Generating QR code..."})})]}),C&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"inline-block p-4 bg-white rounded-xl shadow-sm border border-gray-200",children:I?e.jsx("img",{src:I,alt:"Feishu QR Code",className:"w-48 h-48"}):e.jsx("div",{className:"w-48 h-48 flex items-center justify-center",children:e.jsx("div",{className:"w-5 h-5 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"})})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-sm font-medium text-fg-primary",children:s("settings:feishu.scanWithFeishu",{defaultValue:"Scan with Feishu app"})}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:s("settings:feishu.scanHint",{defaultValue:"Use your Feishu mobile app to scan and authorize. The app will be created in your organization."})}),K>0&&e.jsx("p",{className:"text-[11px] text-fg-tertiary",children:s("settings:feishu.qrExpire",{defaultValue:`QR code expires in ${Math.floor(K/60)} minutes`,minutes:Math.floor(K/60)})})]}),e.jsx("button",{onClick:X,className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs text-fg-tertiary hover:text-fg-secondary border border-border-default rounded-lg hover:bg-surface-overlay transition-colors",children:s("common:cancel",{defaultValue:"Cancel"})})]})]})}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("button",{onClick:()=>S(!p),className:"inline-flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${p?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),s("settings:feishu.manualConfig",{defaultValue:"Manual configuration (advanced)"})]}),p&&e.jsxs("div",{className:"mt-3 bg-surface-secondary border border-border-default rounded-xl p-5 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-fg-secondary mb-1.5",children:["App ID ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:r.appId,onChange:E=>H("appId",E.target.value),onBlur:()=>{r.appId&&r.appSecret&&(J.current&&clearTimeout(J.current),x(ne.current))},placeholder:"cli_xxxxxxxxxxxxxx",className:"w-full px-3 py-2 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors font-mono"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-fg-secondary mb-1.5",children:["App Secret ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:A?"text":"password",value:r.appSecret,onChange:E=>H("appSecret",E.target.value),onBlur:()=>{r.appId&&r.appSecret&&(J.current&&clearTimeout(J.current),x(ne.current))},placeholder:"Enter your Feishu app secret",className:"w-full px-3 py-2 pr-10 text-sm bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:outline-none focus:ring-2 focus:ring-brand-500/40 focus:border-brand-500 transition-colors font-mono"}),e.jsx("button",{type:"button",onClick:()=>z(!A),className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-fg-tertiary hover:text-fg-secondary transition-colors",children:A?e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"})}):e.jsxs("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})]})})]})]})]})]})]}),M&&!Ze&&e.jsx(mn,{type:M.type,text:M.text})]})]})]})}const Xe=["claude-code","codex","cursor-agent"],Bn=10;function gn(s){const r={};for(const i of Xe){const n=s.tools[i],a=n?.timeoutMs??Bn*6e4;r[i]={enabled:n?.enabled??!0,binaryPath:n?.binaryPath??"",defaultArgs:(n?.defaultArgs??[]).join(" "),timeoutMin:String(Math.round(a/6e4)),defaultModel:n?.defaultModel??"",maxBudgetPerSessionUsd:n?.maxBudgetPerSessionUsd?String(n.maxBudgetPerSessionUsd):"",approvalRequired:n?.approvalRequired??!1}}return r}function Ts({checked:s,onChange:r,disabled:i}){return e.jsx("button",{type:"button",onClick:r,disabled:i,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${s?"bg-green-500":"bg-gray-600"} ${i?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${s?"translate-x-4":"translate-x-1"}`})})}function Ds({type:s,text:r}){return e.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:r})}function ut({className:s="w-3 h-3"}){return e.jsxs("svg",{className:`animate-spin ${s}`,viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function fn({children:s}){return e.jsx("div",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider",children:s})}function Qa({expanded:s}){return e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})}function Xa({info:s}){const{t:r}=ge("settings"),i=s?.available&&s?.authenticated,n=s?.available,a=r(i?"codingTools.ready":n?"codingTools.needsAuth":"codingTools.notInstalled"),t=i?"bg-green-500/15 text-green-500":n?"bg-amber-500/15 text-amber-500":"bg-gray-600/20 text-fg-tertiary",d=i?"bg-green-400":n?"bg-amber-400":"bg-gray-500";return e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium ${t}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${d}`}),a]})}const Za=new Set(["cursor-agent","claude-code"]),eo={"cursor-agent":"CURSOR_API_KEY","claude-code":"ANTHROPIC_API_KEY",codex:"CODEX_API_KEY"},to=15e3,so=12;function ro({name:s,onAuthDone:r}){const{t:i}=ge(["settings","common"]),[n,a]=l.useState("idle"),[t,d]=l.useState(!1),[c,u]=l.useState(!1),[f,N]=l.useState(""),[M,m]=l.useState(null),y=l.useRef(null),k=l.useRef(0),b=Za.has(s),U=eo[s]??"",v=l.useCallback(()=>{y.current&&(clearInterval(y.current),y.current=null),k.current=0,u(!1)},[]);l.useEffect(()=>()=>v(),[v]);const P=l.useCallback(()=>{v(),k.current=0,u(!0),y.current=setInterval(async()=>{k.current++;try{(await $.settings.detectCodingTool(s))?.authenticated&&(v(),m({ok:!0,text:i("codingTools.authSuccess")}),d(!1),r())}catch{}k.current>=so&&(v(),d(!1),m({ok:!1,text:i("codingTools.authPollTimeout")}))},to)},[s,r,v,i]),g=async()=>{d(!0),m(null);try{const C=await $.settings.authCodingTool(s,"cli_login");C.success&&C.authenticated?(m({ok:!0,text:i("codingTools.authSuccess")}),r(),d(!1)):C.success?(m({ok:!1,text:i("codingTools.authBrowserHint")}),P()):(m({ok:!1,text:C.error??i("codingTools.authFailed")}),d(!1))}catch{m({ok:!1,text:i("codingTools.authFailed")}),d(!1)}},j=async()=>{if(f.trim()){d(!0),m(null);try{const C=await $.settings.authCodingTool(s,"api_key",f.trim());C.success?(m({ok:!0,text:i("codingTools.apiKeySaved",{envVar:C.envVar??U})}),N(""),r()):m({ok:!1,text:i("codingTools.authFailed")})}catch{m({ok:!1,text:i("codingTools.authFailed")})}finally{d(!1)}}};return n==="idle"?e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[b&&e.jsx("button",{type:"button",onClick:()=>{a("login"),g()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:i("codingTools.loginBtn")}),e.jsx("button",{type:"button",onClick:()=>a("key"),className:"px-2.5 py-1 text-[10px] font-medium border border-border-default text-fg-secondary rounded-md hover:text-fg-primary hover:border-gray-600 transition-colors",children:i("codingTools.apiKeyBtn")})]}):n==="login"?e.jsxs("div",{className:"space-y-1.5",children:[(t||c)&&e.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-brand-500",children:[e.jsx(ut,{}),e.jsx("span",{children:i(c?"codingTools.authPolling":"codingTools.loginWaiting")})]}),M&&e.jsx(Ds,{type:M.ok?"ok":"err",text:M.text}),!t&&!c&&e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("button",{type:"button",onClick:()=>{m(null),r()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:i("codingTools.recheckAuth")}),e.jsx("button",{type:"button",onClick:()=>{a("idle"),m(null),v()},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary",children:i("common:cancel")})]}),c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{v(),d(!1),m(null),r()},className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors",children:i("codingTools.recheckAuth")}),e.jsx("button",{type:"button",onClick:()=>{v(),d(!1),m(null),a("idle")},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary",children:i("common:cancel")})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[s==="cursor-agent"&&e.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[i("codingTools.cursorApiKeyNote")," ",e.jsx("a",{href:i("codingTools.cursorDashboardUrl"),target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:underline",children:"↗"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"password",value:f,onChange:C=>N(C.target.value),placeholder:U,className:"flex-1 px-2.5 py-1 text-[10px] bg-surface-primary border border-border-default rounded-md text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono min-w-0",onKeyDown:C=>{C.key==="Enter"&&j()}}),e.jsx("button",{type:"button",onClick:()=>{j()},disabled:t||!f.trim(),className:"px-2.5 py-1 text-[10px] font-medium bg-brand-500 text-white rounded-md hover:bg-brand-600 transition-colors disabled:opacity-40 shrink-0",children:t?"...":i("common:save")}),e.jsx("button",{type:"button",onClick:()=>{a("idle"),m(null),N("")},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0",children:i("common:cancel")})]}),M&&e.jsx(Ds,{type:M.ok?"ok":"err",text:M.text})]})}function no({source:s}){const{t:r}=ge("settings");if(!s)return null;const i=r(s==="api"?"codingTools.modelSourceApi":s==="static"?"codingTools.modelSourceStatic":"codingTools.modelSourceCli"),n=s==="api"?"bg-green-500/15 text-green-500":s==="static"?"bg-blue-500/15 text-blue-400":"bg-amber-500/15 text-amber-500";return e.jsx("span",{className:`text-[9px] font-medium px-1.5 py-0.5 rounded-full ${n}`,children:i})}function ao({name:s,value:r,onChange:i}){const{t:n}=ge("settings"),[a,t]=l.useState([]),[d,c]=l.useState(!1),[u,f]=l.useState(null),[N,M]=l.useState(),[m,y]=l.useState(!1),[k,b]=l.useState(""),U=l.useRef(null),v=l.useRef(!1),P=l.useCallback(async(C=!1)=>{if(!(v.current&&!C)){v.current=!0,c(!0),f(null);try{const B=await $.settings.listCodingToolModels(s),I=B.models??[];t(I),M(B.source),I.length===0&&f(n("codingTools.modelsEmpty"))}catch{f(n("codingTools.modelsFetchError"))}c(!1)}},[s,n]);l.useEffect(()=>{P()},[P]),l.useEffect(()=>{const C=B=>{U.current&&!U.current.contains(B.target)&&y(!1)};return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[]);const g=a.filter(C=>!k||C.id.toLowerCase().includes(k.toLowerCase())||C.name.toLowerCase().includes(k.toLowerCase())),j=s==="cursor-agent"?"codingTools.modelGuidanceCursor":s==="claude-code"?"codingTools.modelGuidanceClaude":s==="codex"?"codingTools.modelGuidanceCodex":null;return e.jsxs("div",{ref:U,className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:m?k:r,onChange:C=>{b(C.target.value),i(C.target.value)},onFocus:()=>{y(!0),b(r)},placeholder:n("codingTools.modelPlaceholder"),className:"flex-1 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),!d&&N&&e.jsx(no,{source:N}),d&&e.jsx(ut,{className:"w-3.5 h-3.5 text-fg-tertiary shrink-0"}),!d&&u&&e.jsx("button",{type:"button",onClick:()=>{v.current=!1,P(!0)},title:n("codingTools.modelsRetry"),className:"text-[10px] text-amber-500 hover:text-amber-400 shrink-0",children:"↻"})]}),u&&!d&&e.jsx("div",{className:"text-[10px] text-amber-500 mt-0.5",children:u}),j&&!d&&e.jsx("div",{className:"text-[10px] mt-1 text-fg-tertiary",children:n(j)}),m&&e.jsx("div",{className:"absolute z-50 mt-1 w-full bg-surface-secondary border border-border-default rounded-lg shadow-xl max-h-48 overflow-y-auto",children:d?e.jsxs("div",{className:"px-3 py-2 text-[10px] text-fg-tertiary flex items-center gap-2",children:[e.jsx(ut,{}),n("codingTools.modelsLoading")]}):g.length===0&&!k?e.jsx("div",{className:"px-3 py-2 text-[10px] text-fg-tertiary",children:n("codingTools.noModelsFound")}):e.jsxs(e.Fragment,{children:[r&&e.jsx("button",{type:"button",onClick:()=>{i(""),b(""),y(!1)},className:"w-full text-left px-3 py-1.5 text-xs text-fg-tertiary hover:bg-surface-elevated transition-colors italic",children:n("codingTools.useToolDefault")}),g.map(C=>e.jsxs("button",{type:"button",onClick:()=>{i(C.id),b(C.id),y(!1)},className:`w-full text-left px-3 py-1.5 text-xs hover:bg-surface-elevated transition-colors ${C.id===r?"bg-brand-500/10 text-brand-500":"text-fg-primary"}`,children:[e.jsx("span",{className:"font-mono",children:C.id}),C.name!==C.id&&e.jsx("span",{className:"text-fg-tertiary ml-2",children:C.name}),C.isDefault&&e.jsx("span",{className:"text-[9px] text-fg-tertiary ml-1.5 bg-surface-primary px-1.5 py-0.5 rounded",children:"default"})]},C.id))]})})]})}const Tt="markus_coding_tool_detect",oo=1440*60*1e3;function io(){const s={"claude-code":{status:"idle"},codex:{status:"idle"},"cursor-agent":{status:"idle"}};try{const r=localStorage.getItem(Tt);if(!r)return s;const i=JSON.parse(r),n={...s};for(const a of Xe){const t=i[a];if(!t)continue;const d="data"in t&&"ts"in t?t.data:t;n[a]={status:"done",data:d}}return n}catch{return s}}function lo(s){try{const r=localStorage.getItem(Tt);return r?!!JSON.parse(r)[s]:!1}catch{return!1}}function co(s){try{const r=localStorage.getItem(Tt);if(!r)return!0;const n=JSON.parse(r)[s];return n&&"ts"in n&&typeof n.ts=="number"?Date.now()-n.ts>oo:!0}catch{return!0}}function Es(s){try{const r={},i=Date.now();for(const n of Xe){const a=s[n];a.status==="done"&&(r[n]={data:a.data,ts:i})}localStorage.setItem(Tt,JSON.stringify(r))}catch{}}const uo=800;function xo(s,r){const i={};for(const n of Xe){const a=r[n],t=a.defaultArgs.trim()?a.defaultArgs.trim().split(/\s+/).filter(Boolean):void 0,d=parseFloat(a.timeoutMin),c=Number.isFinite(d)&&d>0?Math.round(d*6e4):Bn*6e4,u=parseFloat(a.maxBudgetPerSessionUsd);i[n]={tool:n,enabled:a.enabled,binaryPath:a.binaryPath.trim()||void 0,defaultArgs:t,timeoutMs:c,defaultModel:a.defaultModel.trim()||void 0,maxBudgetPerSessionUsd:n==="claude-code"&&Number.isFinite(u)&&u>0?u:void 0,approvalRequired:a.approvalRequired||void 0}}return{enabled:s,tools:i}}function mo(){const{t:s}=ge(["settings","common"]),[r,i]=l.useState(!0),[n,a]=l.useState(!1),[t,d]=l.useState(!1),[c,u]=l.useState(io),[f,N]=l.useState(()=>gn({tools:{}})),[M,m]=l.useState(null),[y,k]=l.useState(new Set),[b,U]=l.useState(null),[v,P]=l.useState({}),g=l.useRef(null),j=l.useRef(!1),C=l.useCallback(async(p,S=!1)=>{S||u(A=>({...A,[p]:{status:"loading"}}));try{const A=await $.settings.detectCodingTool(p);u(z=>{const J={...z,[p]:{status:"done",data:A}};return Es(J),J})}catch{S||u(A=>({...A,[p]:{status:"idle"}}))}},[]),B=l.useCallback(async p=>{U(p),P(S=>({...S,[p]:null}));try{const S=await $.settings.testCodingTool(p);let A;if(S.success){const z=[s("codingTools.testSuccess")];S.model&&z.push(s("codingTools.testModel",{model:S.model})),S.apiKeySource&&!S.apiKeySource.includes("@")?z.push(s("codingTools.testAuthVia",{source:S.apiKeySource})):S.apiKeySource?.includes("@")&&z.push(S.apiKeySource),A=z.join(" · ")}else A=S.error?`${s("codingTools.testFailed")}:${S.error}`:s("codingTools.testFailed");P(z=>({...z,[p]:{success:S.success,detail:A}})),S.success&&u(z=>{const J=z[p];if(J.status==="done"&&!J.data.authenticated){const ne={...z,[p]:{status:"done",data:{...J.data,authenticated:!0}}};return Es(ne),ne}return z})}catch{P(A=>({...A,[p]:{success:!1,detail:s("codingTools.testFailed")}}))}finally{U(null)}},[s]),I=l.useCallback(p=>{k(S=>{const A=new Set(S);return A.has(p)?A.delete(p):A.add(p),A.has(p)&&c[p].status==="idle"&&C(p),A})},[c,C]),O=l.useCallback(async()=>{i(!0),m(null);try{const p=await $.settings.getCodingTools();if(d(p.enabled),N(gn(p)),j.current=!0,p.enabled)for(const S of Xe)p.tools[S]?.enabled&&co(S)&&C(S,lo(S))}catch{m({type:"err",text:s("codingTools.failedToLoad")})}finally{i(!1)}},[s,C]);l.useEffect(()=>{O()},[O]),l.useEffect(()=>{if(j.current)return g.current&&clearTimeout(g.current),g.current=setTimeout(async()=>{m(null);try{await $.settings.updateCodingTools(xo(t,f)),m({type:"ok",text:s("codingTools.saved")})}catch{m({type:"err",text:s("codingTools.failedToSave")})}},uo),()=>{g.current&&clearTimeout(g.current)}},[t,f,s]);const K=async()=>{a(!0),m(null);try{const p=await $.settings.detectCodingTools(),S={"claude-code":{status:"idle"},codex:{status:"idle"},"cursor-agent":{status:"idle"}};for(const A of p.tools)S[A.name]={status:"done",data:A};u(S),Es(S)}catch{m({type:"err",text:s("codingTools.detectionFailed")})}finally{a(!1)}},_=(p,S)=>{N(A=>({...A,[p]:{...A[p],...S}}))},D=p=>{const S=c[p];return S.status==="done"?S.data:void 0},F=p=>c[p].status==="loading";return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s("codingTools.title")}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:s("codingTools.description")}),e.jsx("div",{className:"bg-surface-elevated rounded-xl px-4 py-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:s("codingTools.globalEnable")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:s("codingTools.globalEnableDesc")})]}),e.jsx(Ts,{checked:t,onChange:()=>d(p=>!p),disabled:r})]})}),r?e.jsx("div",{className:"text-sm text-fg-tertiary py-8 text-center",children:s("common:loading")}):Xe.map(p=>{const S=D(p),A=f[p],z=F(p),J={"claude-code":"Claude Code",codex:"Codex","cursor-agent":"Cursor Agent"},ne=S?.displayName??J[p]??p,T=y.has(p),q=S&&!S.available,V=S?.available&&!S?.authenticated,x=S?!S.available:!1;return e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>I(p),className:"w-full flex items-center gap-3 px-4 py-3 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx(Qa,{expanded:T}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1 flex-wrap",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:ne}),z?e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium bg-gray-600/20 text-fg-tertiary",children:[e.jsx(ut,{}),s("codingTools.detectingTool")]}):e.jsx(Xa,{info:S}),S?.version&&e.jsx("span",{className:"text-[10px] text-fg-tertiary font-mono truncate",children:S.version})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",onClick:L=>L.stopPropagation(),children:e.jsx(Ts,{checked:A.enabled,onChange:()=>_(p,{enabled:!A.enabled})})})]}),T&&e.jsxs("div",{className:"px-4 pb-4 border-t border-border-default",children:[S?.path&&e.jsx("div",{className:"text-[10px] text-fg-tertiary font-mono mt-3 truncate",title:S.path,children:S.path}),q&&S&&e.jsxs("div",{className:"mt-3 p-3 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:[e.jsx("div",{className:"text-xs text-amber-500 font-medium mb-1",children:s("codingTools.stepInstall")}),S.installHint&&e.jsx("code",{className:"text-[10px] bg-surface-primary px-2 py-1 rounded block text-fg-secondary",children:S.installHint})]}),V&&e.jsxs("div",{className:"mt-3 p-3 bg-amber-500/5 border border-amber-500/20 rounded-lg",children:[e.jsx("div",{className:"text-xs text-amber-500 font-medium mb-2",children:s("codingTools.stepAuth")}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mb-2",children:s("codingTools.authHint")}),e.jsx(ro,{name:p,onAuthDone:()=>{C(p)}})]}),e.jsxs("div",{className:"grid gap-4 mt-4",children:[x&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.binaryPath")}),e.jsx("input",{type:"text",value:A.binaryPath,onChange:L=>_(p,{binaryPath:L.target.value}),placeholder:s("codingTools.binaryPathPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"})]}),e.jsx(fn,{children:s("codingTools.sectionModelExec")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.defaultModel")}),e.jsx(ao,{name:p,value:A.defaultModel,onChange:L=>_(p,{defaultModel:L})}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.defaultModelHint")})]}),p==="claude-code"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.budgetCap")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-tertiary",children:"$"}),e.jsx("input",{type:"number",min:0,step:.5,value:A.maxBudgetPerSessionUsd,onChange:L=>_(p,{maxBudgetPerSessionUsd:L.target.value}),placeholder:"5.00",className:"w-32 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none tabular-nums"}),e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:"USD"})]}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.budgetCapHint")})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-fg-secondary",children:s("codingTools.approvalRequired")}),e.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:s("codingTools.approvalRequiredHint")})]}),e.jsx(Ts,{checked:A.approvalRequired,onChange:()=>_(p,{approvalRequired:!A.approvalRequired})})]}),e.jsx("div",{className:"flex items-center gap-4",children:e.jsxs("div",{className:"flex-1",children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.timeout")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:1,step:1,value:A.timeoutMin,onChange:L=>_(p,{timeoutMin:L.target.value}),className:"w-24 px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary focus:border-brand-500 outline-none tabular-nums"}),e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("codingTools.timeoutUnit")})]})]})}),e.jsx(fn,{children:s("codingTools.sectionAdvanced")}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-fg-secondary block mb-1",children:s("codingTools.defaultArgs")}),e.jsx("input",{type:"text",value:A.defaultArgs,onChange:L=>_(p,{defaultArgs:L.target.value}),placeholder:s("codingTools.defaultArgsPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"})]}),e.jsxs("div",{className:"pt-3 border-t border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",disabled:b===p,onClick:()=>B(p),className:"px-3 py-1.5 text-xs font-medium bg-brand-500 text-white rounded-lg hover:bg-brand-600 disabled:opacity-50 transition-colors flex items-center gap-1.5 shrink-0",children:[b===p&&e.jsx(ut,{className:"w-3 h-3"}),s(b===p?"codingTools.testing":"codingTools.testConfig")]}),!v[p]&&e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s("codingTools.testConfigHint")})]}),v[p]&&e.jsx("div",{className:`mt-2 px-3 py-2 rounded-lg text-xs ${v[p].success?"bg-green-500/10 border border-green-500/20 text-green-600":"bg-red-500/10 border border-red-500/20 text-red-500"}`,children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"shrink-0 mt-0.5",children:v[p].success?"✓":"✗"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{children:v[p].detail}),!v[p].success&&e.jsx("div",{className:"text-[10px] mt-1 opacity-80",children:s("codingTools.testFailedHint")})]})]})})]})]})]})]},p)}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("div",{className:"flex items-center gap-2",children:M&&e.jsx(Ds,{type:M.type,text:M.text})}),e.jsx("button",{type:"button",onClick:()=>{K()},disabled:n||r,className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:text-fg-primary hover:border-gray-600 rounded-lg transition-colors disabled:opacity-40",children:s(n?"codingTools.detecting":"codingTools.redetect")})]})]})]})}const ct=[{id:"serper",labelKey:"searchApi.serper",hintKey:"searchApi.serperHint",field:"serperApiKey"},{id:"tavily",labelKey:"searchApi.tavily",hintKey:"searchApi.tavilyHint",field:"tavilyApiKey"},{id:"google",labelKey:"searchApi.google",hintKey:"searchApi.googleHint",field:"googleSearchApiKey",extraField:"googleSearchCx",extraPlaceholderKey:"searchApi.googleCxPlaceholder"},{id:"bing",labelKey:"searchApi.bing",hintKey:"searchApi.bingHint",field:"bingApiKey"},{id:"brave",labelKey:"searchApi.brave",hintKey:"searchApi.braveHint",field:"braveApiKey"},{id:"serpapi",labelKey:"searchApi.serpapi",hintKey:"searchApi.serpapiHint",field:"serpApiKey"},{id:"exa",labelKey:"searchApi.exa",hintKey:"searchApi.exaHint",field:"exaApiKey"},{id:"bocha",labelKey:"searchApi.bocha",hintKey:"searchApi.bochaHint",field:"bochaApiKey"}],go=800,pn=[{id:"perplexity/sonar",labelKey:"searchApi.modelSonar"},{id:"perplexity/sonar-pro",labelKey:"searchApi.modelSonarPro"}];function hn({expanded:s}){return e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${s?"rotate-90":""}`,viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})}function Mt({className:s="w-3 h-3"}){return e.jsxs("svg",{className:`${s} animate-spin`,viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function fo(){const{t:s}=ge(["settings","common"]),[r,i]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState(new Set),[c,u]=l.useState({}),[f,N]=l.useState({}),[M,m]=l.useState(!1),[y,k]=l.useState(!1),[b,U]=l.useState({}),[v,P]=l.useState({}),[g,j]=l.useState({}),[C,B]=l.useState({}),I=l.useRef({}),O=l.useCallback(async()=>{a(!0);try{const x=await $.settings.getSearch();x&&(i(x),ct.some(H=>!!x[H.id]?.configured)&&k(!0))}catch{}a(!1)},[]);l.useEffect(()=>{O()},[O]),l.useEffect(()=>()=>{Object.values(I.current).forEach(clearTimeout)},[]);const K=x=>{d(L=>{const H=new Set(L);return H.has(x)?H.delete(x):H.add(x),H})},_=(x,L,H)=>{u(Q=>({...Q,[L]:H})),I.current[x]&&clearTimeout(I.current[x]),I.current[x]=setTimeout(()=>{D(x)},go)},D=async x=>{const L=ct.find(te=>te.id===x);if(!L)return;const H=c[L.field]?.trim(),Q=L.extraField?c[L.extraField]?.trim():void 0;if(!(!H&&!Q)){N(te=>({...te,[x]:!0})),U(te=>{const ee={...te};return delete ee[x],ee});try{const te={};H&&(te[L.field]=H),Q&&L.extraField&&(te[L.extraField]=Q);const ee=await $.settings.updateSearch(te);i(ee),u(X=>{const le={...X};return delete le[L.field],L.extraField&&delete le[L.extraField],le}),U(X=>({...X,[x]:{type:"ok",text:s("searchApi.saved")}})),setTimeout(()=>U(X=>{const le={...X};return delete le[x],le}),3e3)}catch{U(te=>({...te,[x]:{type:"err",text:s("searchApi.failedToSave")}}))}N(te=>({...te,[x]:!1}))}},F=x=>r?.[x],p=x=>F(x)?.configured??!1,S=x=>F(x)?.enabled!==!1,A=async(x,L)=>{B(H=>({...H,[x]:!0}));try{const H={[`${x}Enabled`]:L},Q=await $.settings.updateSearch(H);i(Q)}catch{}B(H=>({...H,[x]:!1}))},z=async x=>{I.current[x]&&(clearTimeout(I.current[x]),delete I.current[x],await D(x)),P(L=>({...L,[x]:!0})),j(L=>{const H={...L};return delete H[x],H});try{const L=await $.settings.testSearch(x);if(L.ok){const H=[s("searchApi.testOk",{count:L.count??0})];L.latencyMs!=null&&H.push(`${L.latencyMs}ms`),L.sample?.title&&H.push(L.sample.title.slice(0,48)),j(Q=>({...Q,[x]:{ok:!0,text:H.join(" · ")}}))}else j(H=>({...H,[x]:{ok:!1,text:L.error||s("searchApi.testFailed")}}))}catch{j(L=>({...L,[x]:{ok:!1,text:s("searchApi.testFailed")}}))}P(L=>({...L,[x]:!1}))},J=async x=>{m(!0);try{const L=await $.settings.updateSearch(x);i(L)}catch{}m(!1)},ne=({id:x,disabled:L})=>{const H=v[x];return e.jsxs("button",{type:"button",onClick:()=>{z(x)},disabled:H||L,className:"inline-flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium bg-surface-primary border border-border-default text-fg-secondary hover:text-fg-primary hover:border-brand-500 disabled:opacity-50 transition-colors",children:[H?e.jsx(Mt,{}):e.jsx("svg",{className:"w-3 h-3",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.5 2a6.5 6.5 0 104.096 11.553l3.925 3.925a.75.75 0 101.06-1.06l-3.925-3.925A6.5 6.5 0 008.5 2zM3.5 8.5a5 5 0 1110 0 5 5 0 01-10 0z",clipRule:"evenodd"})}),s(H?"searchApi.testing":"searchApi.test")]})},T=({id:x})=>{const L=g[x];return L?e.jsxs("div",{className:`text-[11px] flex items-start gap-1.5 ${L.ok?"text-green-500":"text-red-500"}`,children:[e.jsx("span",{className:"shrink-0 mt-px",children:L.ok?"✓":"✕"}),e.jsx("span",{className:"break-all",children:L.text})]}):null},q=({id:x})=>{const L=S(x),H=C[x];return e.jsxs("label",{className:"inline-flex items-center gap-2 cursor-pointer shrink-0",onClick:Q=>Q.stopPropagation(),title:s(L?"searchApi.enabled":"searchApi.disabled"),children:[H&&e.jsx(Mt,{className:"w-3 h-3 text-fg-tertiary"}),e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:L,disabled:H,onChange:Q=>{A(x,Q.target.checked)}}),e.jsx("span",{className:"relative w-9 h-5 rounded-full bg-gray-500/40 peer-checked:bg-brand-500 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:transition-transform peer-checked:after:translate-x-4"})]})},V=r?.markus;return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s("searchApi.title")}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:s("searchApi.description")}),n?e.jsx("div",{className:"text-sm text-fg-tertiary py-8 text-center",children:s("common:loading")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"rounded-xl border border-border-default px-4 py-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s("searchApi.markus")}),e.jsx("span",{className:"text-[10px] font-medium text-brand-400",children:s("searchApi.markusBadge")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 truncate",children:s("searchApi.markusHint")})]}),V?.available&&V.enabled&&e.jsx(ne,{id:"markus"}),V?.available?e.jsxs("label",{className:"inline-flex items-center gap-2 cursor-pointer shrink-0",children:[M&&e.jsx(Mt,{className:"w-3 h-3 text-fg-tertiary"}),e.jsx("input",{type:"checkbox",className:"sr-only peer",checked:V.enabled,disabled:M,onChange:x=>{J({useMarkusHosted:x.target.checked})}}),e.jsx("span",{className:"relative w-9 h-5 rounded-full bg-gray-500/40 peer-checked:bg-brand-500 transition-colors after:content-[''] after:absolute after:top-0.5 after:left-0.5 after:w-4 after:h-4 after:rounded-full after:bg-white after:transition-transform peer-checked:after:translate-x-4"})]}):e.jsx("span",{className:"text-[11px] text-amber-500 shrink-0",children:s("searchApi.markusUnavailable")})]}),!V?.available&&e.jsx("div",{className:"text-[11px] text-amber-500/90",children:s("searchApi.markusUnavailableHint")}),V?.available&&V.enabled&&e.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary shrink-0",htmlFor:"markus-search-model",children:s("searchApi.modelLabel")}),e.jsxs("select",{id:"markus-search-model",value:V.markusSearchModel||"perplexity/sonar",disabled:M,onChange:x=>{J({markusSearchModel:x.target.value})},className:"flex-1 min-w-0 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary outline-none focus:border-brand-500",children:[pn.map(x=>e.jsx("option",{value:x.id,children:s(x.labelKey)},x.id)),V.markusSearchModel&&!pn.some(x=>x.id===V.markusSearchModel)&&e.jsx("option",{value:V.markusSearchModel,children:V.markusSearchModel})]})]}),e.jsx("div",{className:"text-[11px] text-fg-tertiary",children:s("searchApi.modelHint")}),e.jsx(T,{id:"markus"})]}),e.jsxs("div",{className:"rounded-xl border border-border-default overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>k(x=>!x),className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-white/[0.02] transition-colors text-left",children:[e.jsx(hn,{expanded:y}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-baseline gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s("searchApi.ownKeysTitle")}),e.jsx("span",{className:"text-xs text-fg-tertiary truncate",children:s("searchApi.ownKeysHint")})]}),e.jsxs("span",{className:"text-[10px] text-fg-tertiary shrink-0 tabular-nums",children:[ct.filter(x=>p(x.id)).length,"/",ct.length]})]}),y&&e.jsx("div",{className:"border-t border-border-default px-2 pb-2 space-y-1",children:ct.map(x=>{const L=p(x.id),H=t.has(x.id),Q=b[x.id],te=f[x.id];return e.jsxs("div",{className:"rounded-lg overflow-hidden",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsxs("button",{type:"button",onClick:()=>K(x.id),className:`flex-1 min-w-0 flex items-center gap-3 px-3 py-2.5 hover:bg-white/[0.02] transition-colors text-left ${L&&!S(x.id)?"opacity-50":""}`,children:[e.jsx(hn,{expanded:H}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary",children:s(x.labelKey)}),e.jsx("span",{className:"text-xs text-fg-tertiary ml-2 hidden sm:inline",children:s(x.hintKey)})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:L?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-400"}),e.jsx("span",{className:"text-[10px] font-medium text-green-500",children:s("searchApi.configured")})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-500"}),e.jsx("span",{className:"text-[10px] font-medium text-fg-tertiary",children:s("searchApi.notConfigured")})]})})]}),e.jsx("div",{className:"shrink-0 pr-3 pl-2 border-l border-border-default self-stretch flex items-center",children:e.jsx(q,{id:x.id})})]}),H&&e.jsx("div",{className:"px-3 pb-3",children:e.jsxs("div",{className:"mt-1 space-y-2",children:[e.jsx("input",{type:"password",value:c[x.field]??"",onChange:ee=>_(x.id,x.field,ee.target.value),placeholder:s(L?"modelProviders.apiKeyPlaceholder":"searchApi.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),x.extraField&&e.jsx("input",{type:"text",value:c[x.extraField]??"",onChange:ee=>_(x.id,x.extraField,ee.target.value),placeholder:x.extraPlaceholderKey?s(x.extraPlaceholderKey):"",className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none font-mono"}),e.jsxs("div",{className:"flex items-center gap-2 min-h-[28px] flex-wrap",children:[e.jsx(ne,{id:x.id,disabled:!L&&!c[x.field]?.trim()}),te&&e.jsxs("span",{className:"text-[10px] text-fg-tertiary flex items-center gap-1",children:[e.jsx(Mt,{}),s("common:saving")]}),Q&&e.jsx("span",{className:`text-[10px] ${Q.type==="ok"?"text-green-500":"text-red-500"}`,children:Q.text})]}),e.jsx(T,{id:x.id})]})})]},x.id)})})]})]})]})]})}const po=new Set(["claude-opus-4-6","claude-sonnet-4-20250514","claude-3-5-haiku-20241022","gpt-5.4","gpt-4o","o4-mini","gemini-3-1-pro","gemini-2.5-flash","MiniMax-M2.7","MiniMax-M2.5","xiaomi/mimo-v2-pro","anthropic/claude-opus-4-6","openai/gpt-5.4","google/gemini-3-1-pro","deepseek-v4-flash","deepseek-v4-pro","deepseek-chat","deepseek-reasoner"]),On=[{id:"appearance",labelKey:"nav.appearance"},{id:"storage",labelKey:"nav.storage",adminOnly:!0},{id:"providers",labelKey:"nav.providers",adminOnly:!0},{id:"execution",labelKey:"nav.execution",adminOnly:!0},{id:"browser",labelKey:"nav.browser",adminOnly:!0},{id:"coding-tools",labelKey:"nav.codingTools",adminOnly:!0},{id:"search",labelKey:"nav.search",adminOnly:!0},{id:"integrations",labelKey:"nav.integrations",adminOnly:!0},{id:"account",labelKey:"nav.account"}],Is=[{labelKey:"nav.group.general",tabs:["appearance","storage"]},{labelKey:"nav.group.aiConfig",tabs:["providers","execution"]},{labelKey:"nav.group.tools",tabs:["browser","coding-tools","search"]},{labelKey:"nav.group.connections",tabs:["integrations"]},{labelKey:"nav.group.account",tabs:["account"]}],ho={Database:"database",Agents:"agents",Skills:"skills","LLM Logs":"llmLogs","Builder Artifacts":"builderArtifacts",Teams:"teams",Shared:"shared",Knowledge:"knowledge"},Ls={Database:"keep",Agents:"keep",Skills:"caution","LLM Logs":"safe","Builder Artifacts":"caution",Teams:"keep",Shared:"caution",Knowledge:"caution"},bn={appearance:"M21 4H14 M10 4H3 M21 12H12 M8 12H3 M21 20H16 M12 20H3 M14 2v4 M8 10v4 M16 18v4",storage:"M12 8c4.418 0 8-1.343 8-3s-3.582-3-8-3-8 1.343-8 3 3.582 3 8 3Z M4 5v6c0 1.657 3.582 3 8 3s8-1.343 8-3V5 M4 11v6c0 1.657 3.582 3 8 3s8-1.343 8-3v-6",providers:"M9 2v3 M15 2v3 M9 19v3 M15 19v3 M2 9h3 M2 15h3 M19 9h3 M19 15h3 M6 6h12v12H6z M9 9h6v6H9z",execution:"M12 8V4H8 M4 8h16a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2z M2 14h2 M20 14h2 M15 13v2 M9 13v2",browser:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20z M2 12h20 M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z","coding-tools":"M16 18l6-6-6-6 M8 6l-6 6 6 6",search:"M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16z M21 21l-4.3-4.3",integrations:"M9 17H7A5 5 0 0 1 7 7h2 M15 7h2a5 5 0 1 1 0 10h-2 M8 12h8",account:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2 M12 7a4 4 0 1 0 0 8 4 4 0 0 0 0-8Z",_default:"M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"};function yn({id:s,className:r}){return e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 ${r??""}`,children:e.jsx("path",{d:bn[s]??bn._default})})}const bo={users:"account",organization:"account",license:"account",remote:"account"};function vn(){const r=window.location.hash.slice(1).split("/");if(r[0]==="settings"&&r[1]){const i=r[1],a=bo[i]??i;if(On.some(t=>t.id===a))return a}return null}function Do({theme:s,onThemeChange:r,authUser:i,onLogout:n,onUserUpdated:a}={}){const{t,i18n:d}=ge(["settings","common"]),c=da(),u=ca(Lr.SETTINGS),f=ua(),N=f?.keyboardPane??"content",[M,m]=l.useState(vn);l.useEffect(()=>{const o=()=>m(vn());return window.addEventListener("hashchange",o),()=>window.removeEventListener("hashchange",o)},[]);const y=l.useCallback(o=>{m(o),history.pushState(null,"",`#settings/${o}`)},[]),k=l.useCallback(()=>{m(null),history.pushState(null,"","#settings")},[]),b=M??(c?null:"appearance"),[U,v]=l.useState(!1),[P,g]=l.useState(!1);l.useEffect(()=>{!Er()||!window.markusDesktop?.getLoginItemSettings||window.markusDesktop.getLoginItemSettings().then(o=>v(!!o.openAtLogin)).catch(()=>{})},[]);const j=l.useCallback(async()=>{if(!window.markusDesktop?.setLoginItemSettings||P)return;const o=!U;g(!0),v(o);try{const h=await window.markusDesktop.setLoginItemSettings(o);v(!!h.openAtLogin)}catch{v(!o)}finally{g(!1)}},[U,P]),[C,B]=l.useState(null),[I,O]=l.useState(null),[K,_]=l.useState(""),[D,F]=l.useState(!1),[p,S]=l.useState(null),[A,z]=l.useState(null),[J,ne]=l.useState(null),[T,q]=l.useState({}),[V,x]=l.useState(null),[L,H]=l.useState(null),[Q,te]=l.useState(null),[ee,X]=l.useState(!1),[le,fe]=l.useState(null),[Ue,Fe]=l.useState({}),[xt,Ze]=l.useState(!1),[be,E]=l.useState(null),[ae,xe]=l.useState(!1),[we,et]=l.useState(""),[mt,Us]=l.useState(!1),[Et,Ie]=l.useState(null),[Fs,$s]=l.useState(""),[Le,It]=l.useState(!0),[ke,_n]=l.useState(null),[Vs,Hs]=l.useState(!1),[Lt,gt]=l.useState(null),[qs,Dn]=l.useState([]),[zs,Rt]=l.useState([]),[tt,ze]=l.useState(null),[Bt,pe]=l.useState(null),[ft,Ws]=l.useState(""),[Kn,st]=l.useState(null),[rt,Ot]=l.useState(null),me=l.useRef(null),Gs=l.useRef(!1),[Ys,_t]=l.useState(200),[Js,Qs]=l.useState(!1),[Dt,pt]=l.useState(null),[ht,Kt]=l.useState(!1),[Xs,Ut]=l.useState(1),[Zs,er]=l.useState(!1),[Ft,nt]=l.useState(null),[$t,bt]=l.useState(!1),[Re,Vt]=l.useState(0),[Ht,yt]=l.useState(!0),[Be,vt]=l.useState(!1),[ye,tr]=l.useState(!1),[Ro,Un]=l.useState(9333),[ve,he]=l.useState(!1),[qt,de]=l.useState(null),[Te,Fn]=l.useState(null),[zt,sr]=l.useState(!1),[jt,$n]=l.useState(null),[Bo,Oo]=l.useState(!1),oe=()=>({"Content-Type":"application/json",Authorization:`Bearer ${localStorage.getItem("markus_token")??""}`}),rr=l.useRef(new Set),nr=l.useCallback(()=>{$.health().then(B).catch(()=>{})},[]),Oe=l.useCallback(()=>{fetch("/api/settings/llm").then(o=>o.ok?o.json():Promise.reject(o.status)).then(o=>{o&&typeof o=="object"&&"providers"in o&&(O(o),_(o.defaultProvider))}).catch(()=>{})},[]),at=l.useCallback(()=>{fetch("/api/settings/network").then(o=>o.ok?o.json():Promise.reject(o.status)).then(o=>{$s(o.network?.proxy??""),It(o.network?.proxyEnabled!==!1),_n(o.effective)}).catch(()=>{})},[]),ar=l.useCallback(()=>{fetch("/api/settings/oauth/providers").then(o=>o.ok?o.json():Promise.reject(o.status)).then(o=>Dn(o.providers??[])).catch(()=>{})},[]),Nt=l.useCallback((o=!1)=>{fetch(`/api/settings/oauth/profiles${o?"?validate=1":""}`,{headers:oe()}).then(R=>R.ok?R.json():Promise.reject(R.status)).then(R=>Rt(R.profiles??[])).catch(()=>{})},[]),or=l.useCallback(()=>{$.settings.getAgent().then(o=>{o&&typeof o.maxToolIterations=="number"&&_t(o.maxToolIterations),o?.cognitive&&(Kt(o.cognitive.enabled??!1),Ut(o.cognitive.maxDepth??1))}).catch(()=>{})},[]),ir=l.useCallback(()=>{$.settings.getBrowser().then(o=>{o&&(bt(o.bringToFront??!1),Vt(o.remoteDebuggingPort??0),yt(o.autoCloseTabs??!0),vt(o.autoClickAllowDialog??!1),tr(o.extensionConnected??!1),Un(o.extensionBridgePort??9333))}).catch(()=>{})},[]),We=l.useCallback(()=>{sr(!0),$.system.storage().then(Fn).catch(()=>{}).finally(()=>sr(!1)),$.system.orphans().then($n).catch(()=>{})},[]);l.useEffect(()=>{nr()},[nr]),l.useEffect(()=>{if(b&&!rr.current.has(b))switch(rr.current.add(b),b){case"providers":Oe(),at(),ar(),Nt(!0);break;case"execution":or();break;case"browser":ir();break;case"storage":We();break}},[b,Oe,at,ar,Nt,or,ir,We]),l.useEffect(()=>{const o=()=>We();return window.addEventListener("markus:data-changed",o),()=>window.removeEventListener("markus:data-changed",o)},[We]),l.useEffect(()=>{!A||T[A]||(x(A),A==="markus"&&H(null),$.modelCatalog.getLive(A).then(o=>{q(h=>({...h,[A]:o.models})),A==="markus"&&(o.error&&H(String(o.error)),Oe())}).catch(o=>{A==="markus"&&H(o instanceof Error?o.message:String(o)),$.modelCatalog.getByProvider(A).then(h=>{q(R=>({...R,[A]:h.models}))}).catch(()=>{})}).finally(()=>x(null)))},[A]);const Wt=l.useCallback(async()=>{X(!0),fe(null),te(null),Fe({});try{const o=await fetch("/api/settings/env-models",{headers:oe()});if(!o.ok){fe({type:"err",text:t("envConfig.detectionFailedHttp",{status:o.status})});return}const h=await o.json();if(te(h),h.detected.length===0)fe({type:"err",text:t("envConfig.noKeysFound")});else{const R={};for(const G of h.detected)R[G.provider]=!0;Fe(R)}}catch{fe({type:"err",text:t("envConfig.failedToDetect")})}finally{X(!1)}},[t]),Gt=l.useCallback(async()=>{xe(!0),Ie(null),E(null);try{const o=await fetch("/api/settings/detect-ollama",{headers:oe()});if(!o.ok){Ie({type:"err",text:t("ollama.detectFailed")});return}const h=await o.json();E(h),h.found&&h.models&&h.models.length>0?et(h.models[0].name):h.found||Ie({type:"err",text:h.error||t("ollama.notRunning")})}catch{Ie({type:"err",text:t("ollama.detectFailed")})}finally{xe(!1)}},[t]),lr=I?Object.values(I.providers).some(o=>o.configured):!1;l.useEffect(()=>{I&&!lr&&!Gs.current&&(Gs.current=!0,Wt(),Gt())},[I,lr,Wt,Gt]);const Vn=async()=>{if(!(!K||K===I?.defaultProvider)){F(!0),S(null);try{const o=await fetch("/api/settings/llm",{method:"POST",headers:oe(),body:JSON.stringify({defaultProvider:K})}),h=await o.json();o.ok?(O(h),S({type:"ok",text:t("defaultProvider.updated",{name:h.defaultProvider})})):S({type:"err",text:h.error??t("modelProviders.saveFailed")})}catch{S({type:"err",text:t("common:networkError")})}finally{F(!1)}}},Hn=async(o,h)=>{ne(o);try{const R=await fetch(`/api/settings/llm/providers/${o}/toggle`,{method:"POST",headers:oe(),body:JSON.stringify({enabled:h})});if(R.ok){const G=await R.json();O(G)}}catch{}finally{ne(null)}},qn=async()=>{if(!Q)return;const o=Q.detected.filter(h=>Ue[h.provider]);if(o.length===0){fe({type:"err",text:t("envConfig.selectAtLeastOne")});return}Ze(!0),fe(null);try{const h=await fetch("/api/settings/env-models",{method:"POST",headers:oe(),body:JSON.stringify({providers:o.map(G=>({provider:G.provider,model:G.model,baseUrl:G.baseUrl,enabled:!0}))})});if(!h.ok){fe({type:"err",text:t("envConfig.applyFailed",{status:h.status})});return}const R=await h.json();fe({type:"ok",text:R.message}),te(null),Fe({}),Oe()}catch{fe({type:"err",text:t("envConfig.failedToApply")})}finally{Ze(!1)}},zn=async()=>{if(!(!be?.found||!we)){Us(!0),Ie(null);try{const o=await fetch("/api/settings/llm/providers",{method:"POST",headers:oe(),body:JSON.stringify({name:"ollama",model:we,baseUrl:be.baseUrl||"http://localhost:11434"})});if(o.ok){const h=await o.json();O(h),Ie({type:"ok",text:t("ollama.configured",{model:we})}),E(null)}else{const h=await o.json();Ie({type:"err",text:h.error||t("ollama.applyFailed")})}}catch{Ie({type:"err",text:t("ollama.applyFailed")})}finally{Us(!1)}}},dr=async o=>{ze(o),pe(null);try{const h=await fetch("/api/settings/oauth/login",{method:"POST",headers:oe(),body:JSON.stringify({provider:o})}),R=await h.json();if(!h.ok||R.error){pe({type:"err",text:R.error??t("oauth.loginFailed")});return}R.authorizeUrl&&(window.open(R.authorizeUrl,"_blank","noopener"),st(o),pe({type:"ok",text:t("browserOpened")}),me.current&&clearInterval(me.current),me.current=setInterval(async()=>{try{const Z=await(await fetch(`/api/settings/oauth/status?provider=${o}`,{headers:oe()})).json();!Z.pending&&Z.profiles.some(Y=>Y.provider===o&&Y.hasOAuth)&&(me.current&&clearInterval(me.current),me.current=null,st(null),Rt(Z.profiles),pe({type:"ok",text:t("oauthConnected",{provider:o})}),Oe())}catch{}},2e3))}catch{pe({type:"err",text:t("oauth.networkErrorDuringLogin")})}finally{ze(null)}},Wn=async o=>{ze(o),pe(null),Ot(null);try{const h=await fetch("/api/settings/oauth/device-code",{method:"POST",headers:oe(),body:JSON.stringify({provider:o})}),R=await h.json();if(!h.ok||R.error){pe({type:"err",text:R.error??t("oauthAuth.deviceCodeFailed")});return}R.userCode&&R.verificationUri&&(Ot({userCode:R.userCode,verificationUri:R.verificationUri,provider:o}),st(o),pe({type:"ok",text:t("oauthAuth.deviceInstructions")}),me.current&&clearInterval(me.current),me.current=setInterval(async()=>{try{const Z=await(await fetch(`/api/settings/oauth/status?provider=${o}`,{headers:oe()})).json();!Z.pending&&Z.profiles.some(Y=>Y.provider===o&&Y.hasOAuth)&&(me.current&&clearInterval(me.current),me.current=null,st(null),Ot(null),Rt(Z.profiles),pe({type:"ok",text:t("oauthConnected",{provider:o})}),Oe())}catch{}},3e3))}catch{pe({type:"err",text:t("oauth.networkErrorDuringLogin")})}finally{ze(null)}},Gn=async()=>{if(ft.trim()){ze("manual"),pe(null);try{const o=await fetch("/api/settings/oauth/callback",{method:"POST",headers:oe(),body:JSON.stringify({callbackUrl:ft})}),h=await o.json();if(!o.ok||h.error){pe({type:"err",text:h.error??t("oauth.callbackFailed")});return}pe({type:"ok",text:t("oauthConnected",{provider:h.profile?.provider??t("common:unknown")})}),Ws(""),st(null),me.current&&(clearInterval(me.current),me.current=null),Nt(),Oe()}catch{pe({type:"err",text:t("common:networkError")})}finally{ze(null)}}},Yn=async o=>{try{(await fetch(`/api/settings/oauth/profiles/${encodeURIComponent(o)}`,{method:"DELETE",headers:oe()})).ok&&(Nt(),Oe(),pe({type:"ok",text:t("authProfileDeleted")}))}catch{}};l.useEffect(()=>()=>{me.current&&clearInterval(me.current)},[]),l.useEffect(()=>{if(b!=="browser"||ye)return;const o=setInterval(async()=>{try{(await $.settings.getBrowser()).extensionConnected&&(tr(!0),clearInterval(o))}catch{}},5e3);return()=>clearInterval(o)},[b,ye]);const[Jn,Yt]=l.useState(!1),[se,_e]=l.useState({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),[wt,cr]=l.useState(!1),[Jt,ur]=l.useState(null),[Qt,$e]=l.useState([]),[Qn,xr]=l.useState(!1),[Xn,Xt]=l.useState(null),[ue,Zt]=l.useState({apiKey:"",baseUrl:"",model:"",contextWindow:0,maxOutputTokens:0,costInput:0,costOutput:0}),[mr,gr]=l.useState(!1),[fr,pr]=l.useState(null),[es,ts]=l.useState(null),[Ee,Ge]=l.useState(""),[hr,br]=l.useState(!1),[ss,je]=l.useState(null),[yr,kt]=l.useState(null),[Ce,Ct]=l.useState({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1}),[Zn,vr]=l.useState(!1),jr=async(o,h)=>{if(!o||o==="__custom__")return;xr(!0),je(null);const R=Pt.find(Z=>Z.id===o),G=se.baseUrl||R?.baseUrl;try{if(h){const Z=await $.modelCatalog.validateKey(o,h,G||void 0);!Z.valid&&Z.error&&je({type:"err",text:Z.error}),$e(Z.models)}else{const Z=await $.modelCatalog.getByProvider(o);$e(Z.models)}}catch{$e([])}finally{xr(!1)}},Nr=async()=>{if(!(!se.name||!se.model)){cr(!0),ur(null),je(null);try{const o=await fetch("/api/settings/llm/providers",{method:"POST",headers:oe(),body:JSON.stringify({name:se.name,apiKey:se.apiKey||void 0,baseUrl:se.baseUrl||void 0,model:se.model,contextWindow:se.contextWindow||void 0,maxOutputTokens:se.maxOutputTokens||void 0,cost:se.costInput||se.costOutput?{input:se.costInput,output:se.costOutput}:void 0})}),h=await o.json();o.ok?(O(h),Yt(!1),Ge(""),$e([]),_e({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5}),je({type:"ok",text:t("modelProviders.providerAdded",{name:se.name})})):je({type:"err",text:h.error??t("modelProviders.failedToAdd")})}catch{je({type:"err",text:t("common:networkError")})}finally{cr(!1)}}},ea=async(o,h)=>{if(!Ee.trim())return;br(!0),je(null);const R=Pt.find(Y=>Y.id===o),G=R?.defaultModel??o,Z=R?.baseUrl;try{const Y=await fetch("/api/settings/llm/providers",{method:"POST",headers:oe(),body:JSON.stringify({name:o,apiKey:Ee.trim(),model:G,baseUrl:Z})}),ce=await Y.json();Y.ok?(O(ce),Ge(""),$e([]),je({type:"ok",text:t("modelProviders.quickSetupSuccess",{name:R?.label??o})})):je({type:"err",text:ce.error??t("modelProviders.failedToAdd")})}catch{je({type:"err",text:t("common:networkError")})}finally{br(!1)}},ta=(o,h)=>{Xt(o),Zt({apiKey:"",baseUrl:h.baseUrl??"",model:h.model,contextWindow:h.contextWindow??0,maxOutputTokens:h.maxOutputTokens??0,costInput:h.cost?.input??0,costOutput:h.cost?.output??0})},sa=async o=>{gr(!0);try{const h={};ue.apiKey&&(h.apiKey=ue.apiKey),ue.baseUrl!==void 0&&(h.baseUrl=ue.baseUrl),ue.model&&(h.model=ue.model),ue.contextWindow&&(h.contextWindow=ue.contextWindow),ue.maxOutputTokens&&(h.maxOutputTokens=ue.maxOutputTokens),(ue.costInput||ue.costOutput)&&(h.cost={input:ue.costInput,output:ue.costOutput});const R=await fetch(`/api/settings/llm/providers/${o}`,{method:"PUT",headers:oe(),body:JSON.stringify(h)});if(R.ok){const G=await R.json();O(G),Xt(null)}}catch{}finally{gr(!1)}},ra=async o=>{pr(o);try{const h=await fetch(`/api/settings/llm/providers/${o}`,{method:"DELETE",headers:oe()});if(h.ok){const R=await h.json();O(R),_(R.defaultProvider)}}catch{}finally{pr(null)}},na=async o=>{if(!(!Ce.id||!Ce.name)){vr(!0);try{const h=await fetch(`/api/settings/llm/providers/${o}/models`,{method:"POST",headers:oe(),body:JSON.stringify({id:Ce.id,name:Ce.name,contextWindow:Ce.contextWindow,maxOutputTokens:Ce.maxOutputTokens,cost:{input:Ce.costInput,output:Ce.costOutput},reasoning:Ce.reasoning||void 0,inputTypes:Ce.vision?["text","image"]:["text"]})});if(h.ok){const R=await h.json();O(R),kt(null),Ct({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})}}catch{}finally{vr(!1)}}},aa=async(o,h)=>{try{const R=await fetch(`/api/settings/llm/providers/${o}/models/${encodeURIComponent(h)}`,{method:"DELETE",headers:oe()});if(R.ok){const G=await R.json();O(G)}}catch{}},[wr,kr]=l.useState(null),[re,St]=l.useState({}),oa=async o=>{kr(o),St(h=>{const R={...h};return delete R[o],R});try{const h=await fetch(`/api/settings/llm/providers/${o}/test`,{method:"POST",headers:oe()});if(!h.ok){const G=await h.json().catch(()=>({}));St(Z=>({...Z,[o]:{ok:!1,error:G.error??`HTTP ${h.status}`,errorCode:h.status}}));return}const R=await h.json();St(G=>({...G,[o]:R}))}catch{St(h=>({...h,[o]:{ok:!1,error:t("common:networkError")}}))}finally{kr(null)}},Cr=I?.providers?Object.entries(I.providers).filter(([,o])=>o.configured&&o.enabled).map(([o])=>o):[],Sr=i?.role==="owner"||i?.role==="admin",ot=On.filter(o=>!o.adminOnly||Sr),Pr=l.useMemo(()=>{const o=[];for(const h of Is)for(const R of h.tabs){const G=ot.find(Z=>Z.id===R);G&&o.push(G)}return o},[ot]),Ar=l.useRef(Pr);Ar.current=Pr;const Mr=l.useRef(b);Mr.current=b;const Tr=!c&&u&&N==="l1";return l.useEffect(()=>{if(c||!u)return;const o=h=>{if(f?.keyboardPane==="l0"||h.metaKey||h.ctrlKey||h.altKey||ma(h.target))return;const R=h.key.length===1?h.key.toLowerCase():h.key;if(R==="h"||R==="ArrowLeft")return;const G=R==="j"||R==="ArrowDown"?1:R==="k"||R==="ArrowUp"?-1:0;if(!G)return;h.preventDefault(),h.stopPropagation(),f?.setKeyboardPane("l1");const Z=Ar.current;if(Z.length===0)return;const Y=Mr.current;let ce=Y?Z.findIndex(Ye=>Ye.id===Y):-1;ce<0&&(ce=G>0?-1:0);const w=Math.max(0,Math.min(Z.length-1,ce+G)),W=Z[w];y(W.id),requestAnimationFrame(()=>{document.querySelector(`[data-settings-tab-id="${W.id}"]`)?.scrollIntoView({block:"nearest"})})};return document.addEventListener("keydown",o,!0),()=>document.removeEventListener("keydown",o,!0)},[c,u,f,y]),e.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[e.jsxs("aside",{"data-keyboard-pane":"l1",className:`hidden md:flex flex-col w-56 shrink-0 border-r border-border-default bg-surface-secondary overflow-y-auto ${Tr?"ring-1 ring-inset ring-brand-500/30":""}`,children:[e.jsx("div",{"data-electron-drag":!0,className:"electron-mac-top-safe px-3 pt-4 pb-2",children:e.jsxs("button",{"data-no-drag":!0,onClick:()=>{ns.leaveSettings()},className:"flex items-center gap-2 px-2 py-1.5 rounded-lg text-sm text-fg-secondary hover:text-fg-primary hover:bg-surface-overlay transition-colors",title:`${t("common:back",{defaultValue:"Back"})} (H)`,children:[e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]}),t("common:back",{defaultValue:"Back"})]})}),e.jsx("div",{className:"px-5 pb-4",children:e.jsx("h2",{className:"text-base font-semibold text-fg-primary",children:t("title")})}),e.jsx("nav",{className:"flex-1 px-3 pb-4 space-y-3",children:Is.map(o=>{const h=o.tabs.map(R=>ot.find(G=>G.id===R)).filter(R=>!!R);return h.length===0?null:e.jsxs("div",{children:[e.jsx("div",{className:"px-3 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:t(`settings:${o.labelKey}`)}),e.jsx("div",{className:"space-y-0.5",children:h.map(R=>e.jsxs("button",{"data-settings-tab-id":R.id,onClick:()=>{y(R.id),f?.setKeyboardPane("l1")},className:`w-full flex items-center gap-2.5 text-left px-3 py-2 rounded-lg text-sm font-medium transition-colors text-fg-primary ${b===R.id?Tr?"bg-brand-500/25 ring-1 ring-inset ring-brand-500/40":"bg-surface-overlay":"hover:bg-surface-overlay/60"}`,children:[e.jsx(yn,{id:R.id,className:b===R.id?"text-fg-secondary":"text-fg-tertiary"}),e.jsx("span",{className:"truncate",children:t(`settings:${R.labelKey}`)})]},R.id))})]},o.labelKey)})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto",children:[c&&b===null&&e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary",children:[e.jsx("button",{onClick:()=>ns.leaveSettings(),className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",title:`${t("common:back",{defaultValue:"Back"})} (H)`,children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),e.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:t("title")})]}),e.jsx("nav",{className:"flex-1 overflow-y-auto py-2 px-3",children:Is.map((o,h)=>{const R=o.tabs.map(G=>ot.find(Z=>Z.id===G)).filter(G=>!!G);return R.length===0?null:e.jsxs("div",{children:[h>0&&e.jsx("div",{className:"border-t border-border-default my-2 mx-2"}),e.jsx("div",{className:"px-4 pt-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-fg-tertiary",children:t(`settings:${o.labelKey}`)}),R.map(G=>e.jsxs("button",{onClick:()=>y(G.id),className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg text-sm text-fg-primary hover:bg-surface-overlay transition-colors",children:[e.jsx(yn,{id:G.id,className:"text-fg-tertiary"}),e.jsx("span",{className:"flex-1 text-left",children:t(`settings:${G.labelKey}`)}),e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-fg-tertiary",children:e.jsx("polyline",{points:"9 18 15 12 9 6"})})]},G.id))]},o.labelKey)})})]}),c&&b!==null&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border-default bg-surface-secondary sticky top-0 z-10",children:[e.jsx("button",{onClick:k,className:"p-1.5 rounded-lg hover:bg-surface-overlay transition-colors",children:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M19 12H5"}),e.jsx("polyline",{points:"12 19 5 12 12 5"})]})}),e.jsx("h1",{className:"text-base font-semibold text-fg-primary",children:t(`settings:${ot.find(o=>o.id===b)?.labelKey||"title"}`)})]}),b!==null&&e.jsxs("div",{className:"p-7 space-y-10 max-w-4xl mx-auto w-full",children:[b==="appearance"&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{title:t("systemStatus.title"),children:C?e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsx(Bs,{label:t("systemStatus.status"),value:C.status==="ok"?t("systemStatus.healthy"):C.status,color:"green"}),e.jsx(Bs,{label:t("systemStatus.version"),value:C.version,color:"indigo"}),e.jsx(Bs,{label:t("systemStatus.activeAgents"),value:String(C.agents),color:"purple"})]}):e.jsx("div",{className:"text-sm text-fg-tertiary",children:t("common:loading")})}),e.jsx(Pe,{title:t("appearance.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.theme")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.themeDesc")})]}),e.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:xa.map(({value:o})=>e.jsx("button",{onClick:()=>r?.(o),className:`px-3 py-1.5 text-xs rounded-md transition-colors ${s===o?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:t(`appearance.modes.${o}`)},o))})]}),e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.language")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.languageDesc")})]}),e.jsx("div",{className:"flex flex-wrap gap-1 bg-surface-elevated rounded-lg p-0.5",children:Ir.map(({code:o,label:h})=>e.jsx("button",{onClick:()=>{d.changeLanguage(o),$.settings.updateSearch({language:o}).catch(()=>{})},className:`px-3 py-1.5 text-xs rounded-md transition-colors ${d.language===o||o==="en"&&!Ir.some(R=>R.code===d.language)?"bg-brand-600 text-white":"text-fg-secondary hover:text-fg-primary"}`,children:h},o))})]}),Er()&&e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between mt-5 pt-5 border-t border-border-default/50",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("appearance.launchAtLogin")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("appearance.launchAtLoginDesc")})]}),e.jsx("button",{type:"button",role:"switch","aria-checked":U,disabled:P,onClick:()=>{j()},className:`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors disabled:opacity-50 ${U?"bg-brand-600":"bg-surface-elevated border border-border-default"}`,children:e.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform ${U?"translate-x-6":"translate-x-1"}`})})]})]})})]}),Sr&&e.jsxs(e.Fragment,{children:[b==="providers"&&e.jsxs(e.Fragment,{children:[I&&(()=>{const o=[],h=new Set,R=[],G=[];for(const[w,W]of Object.entries(I.providers))W.configured?R.push([w,W]):w!=="markus"&&G.push([w,W]),h.add(w);for(const w of Pt)!h.has(w.id)&&w.id!=="markus"&&(G.push([w.id,{name:w.id,displayName:w.label,model:w.defaultModel,configured:!1,enabled:!1}]),h.add(w.id));R.sort((w,W)=>(W[1].enabled?1:0)-(w[1].enabled?1:0)),o.push(...R,...G);const Z=R.length>0,ce=I.providers.markus?.configured??!1;return e.jsxs(e.Fragment,{children:[!ce&&e.jsx(Pe,{title:"Markus Cloud AI",children:e.jsxs("div",{className:"bg-surface-secondary border border-brand-500/30 rounded-xl overflow-hidden transition-colors hover:border-brand-500/50",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{z(A==="markus"?null:"markus"),Ge(""),je(null)},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-brand-500 shadow-[0_0_6px_rgba(99,102,241,0.4)]"}),e.jsxs("div",{children:[e.jsx("span",{className:"text-sm font-medium",children:"Markus Cloud AI"}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("modelProviders.markusHint")})]})]}),e.jsx("svg",{className:`w-4 h-4 text-fg-tertiary transition-transform ${A==="markus"?"rotate-180":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})})]}),A==="markus"&&e.jsxs("div",{className:"px-5 pb-5 space-y-3 border-t border-border-default/50",children:[e.jsx("p",{className:"text-xs text-fg-tertiary pt-3",children:t("modelProviders.markusSetupLogin")}),e.jsx("button",{onClick:()=>ns.navigate(Lr.SETTINGS,{tab:"account"}),className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-sm rounded-lg transition-colors",children:t("modelProviders.goToAccount")})]})]})}),e.jsxs(Co,{title:t("modelProviders.title"),defaultCollapsed:Z,configuredProviders:R,t,onBadgeClick:w=>{z(w),Ge(""),je(null),setTimeout(()=>{document.querySelector(`[data-provider-id="${w}"]`)?.scrollIntoView({behavior:"smooth",block:"center"})},80)},children:[e.jsxs("div",{className:"space-y-3",children:[Z&&e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-1",children:t("modelProviders.groupConfigured",{count:R.length})}),o.map(([w,W],Ye)=>{const rs=!W.configured&&(Ye===0||o[Ye-1][1].configured);return e.jsxs("div",{"data-provider-id":w,children:[rs&&Z&&e.jsx("div",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider px-1 mt-4 mb-2",children:t("modelProviders.groupUnconfigured")}),e.jsxs("div",{className:`bg-surface-secondary border rounded-xl overflow-hidden transition-colors ${W.configured?"border-border-default hover:border-gray-600":"border-border-default/50 hover:border-brand-500/30"}`,children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4 cursor-pointer",onClick:()=>{z(A===w?null:w),Ge(""),je(null),$e([]),_e(ie=>({...ie,name:"",model:""}))},children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${W.configured&&W.enabled?"bg-green-400":W.configured?"bg-amber-400":"bg-gray-600"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:W.displayName??w}),w===I.defaultProvider&&e.jsx("span",{className:"text-[10px] bg-brand-500/15 text-brand-500 px-1.5 py-0.5 rounded",children:t("modelProviders.badgeDefault")}),W.configured&&!W.enabled&&e.jsx("span",{className:"text-[10px] bg-amber-500/15 text-amber-600 px-1.5 py-0.5 rounded",children:t("modelProviders.disabled")}),W.oauthConnected&&e.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:t("modelProviders.badgeOAuth")}),re[w]?.ok===!0&&e.jsx("span",{className:"text-[10px] bg-green-500/15 text-green-600 px-1.5 py-0.5 rounded",children:t("modelProviders.testOk",{ms:re[w].durationMs})}),re[w]?.ok===!1&&e.jsx("span",{className:"text-[10px] bg-red-500/15 text-red-500 px-1.5 py-0.5 rounded",title:re[w].error,children:re[w].errorCode?t("modelProviders.testFailedCode",{code:re[w].errorCode}):t("modelProviders.testFailed")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:W.configured?e.jsxs(e.Fragment,{children:[W.models&&W.models.length>0?t("modelProviders.modelsAvailable",{count:W.models.length}):"",w!=="markus"&&W.apiKeyPreview&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:"text-fg-secondary",children:W.apiKeyPreview})]})]}):t("modelProviders.notConfigured")})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[W.configured&&e.jsx("button",{onClick:ie=>{ie.stopPropagation(),Hn(w,!W.enabled)},disabled:J===w,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${W.enabled?"bg-green-500":"bg-gray-600"} ${J===w?"opacity-50":""}`,title:W.enabled?t("modelProviders.clickToDisable"):t("modelProviders.clickToEnable"),children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${W.enabled?"translate-x-4":"translate-x-1"}`})}),e.jsx("span",{className:"text-fg-tertiary text-xs",children:A===w?"▲":"▼"})]})]}),A===w&&e.jsxs("div",{className:"px-5 pb-4 border-t border-border-default pt-4 space-y-4",children:[W.configured&&e.jsxs(e.Fragment,{children:[Xn===w?e.jsxs("div",{className:"bg-surface-elevated/40 rounded-lg p-4 space-y-3",children:[e.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("modelProviders.editProvider")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:ue.apiKey,onChange:ie=>Zt({...ue,apiKey:ie.target.value}),placeholder:t("modelProviders.apiKeyPlaceholder"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.baseUrl")}),e.jsx("input",{type:"text",value:ue.baseUrl,onChange:ie=>Zt({...ue,baseUrl:ie.target.value}),placeholder:t("modelProviders.baseUrlDisplayDefault"),className:"w-full px-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{sa(w)},disabled:mr,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(mr?"common:saving":"common:save")}),e.jsx("button",{onClick:()=>Xt(null),className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:cancel")})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:ie=>{ie.stopPropagation(),oa(w)},disabled:wr===w,className:"px-3 py-1.5 text-xs border border-green-500/30 text-green-500 hover:bg-green-500/10 rounded-lg transition-colors disabled:opacity-40 flex items-center gap-1.5",children:wr===w?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"w-3 h-3 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8v4a4 4 0 00-4 4H4z"})]}),t("modelProviders.testing")]}):t("modelProviders.test")}),w!=="markus"&&e.jsx("button",{onClick:ie=>{ie.stopPropagation(),ta(w,W)},className:"px-3 py-1.5 text-xs border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:edit")}),w!=="markus"&&e.jsx("button",{onClick:ie=>{ie.stopPropagation(),ts({name:w,label:W.displayName??w})},disabled:fr===w,className:"px-3 py-1.5 text-xs border border-red-500/30 text-red-400 hover:bg-red-500/10 rounded-lg transition-colors disabled:opacity-40",children:t(fr===w?"common:deleting":"common:delete")})]}),re[w]&&e.jsxs("details",{className:`text-xs rounded-lg border ${re[w].ok?"bg-green-500/10 border-green-500/30":"bg-red-500/10 border-red-500/30"}`,children:[e.jsx("summary",{className:`px-3 py-2 cursor-pointer select-none ${re[w].ok?"text-green-600":"text-red-500"}`,children:re[w].ok?t("modelProviders.testSuccess",{ms:re[w].durationMs,reply:re[w].reply}):re[w].error}),e.jsxs("div",{className:"px-3 pb-2 pt-1 space-y-1 text-[11px] text-fg-muted border-t border-current/10",children:[w!=="markus"&&re[w].requestUrl&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.requestUrl"),":"]})," ",e.jsx("code",{className:"font-mono text-fg-primary",children:re[w].requestUrl})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.model"),":"]})," ",e.jsx("code",{className:"font-mono text-fg-primary",children:re[w].model??W.model})]}),!!re[w].requestBody&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.requestBody"),":"]}),e.jsx("pre",{className:"mt-0.5 p-1.5 rounded bg-surface-primary/50 font-mono overflow-x-auto whitespace-pre-wrap",children:JSON.stringify(re[w].requestBody,null,2)})]}),re[w].ok&&re[w].reply&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.response"),":"]})," ",re[w].reply]}),re[w].usage&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.tokens"),":"]})," ",t("modelProviders.testDetail.inputTokens")," ",re[w].usage.inputTokens??re[w].usage.prompt_tokens??"-"," / ",t("modelProviders.testDetail.outputTokens")," ",re[w].usage.outputTokens??re[w].usage.completion_tokens??"-"]}),re[w].durationMs!=null&&e.jsxs("div",{children:[e.jsxs("span",{className:"text-fg-secondary",children:[t("modelProviders.testDetail.duration"),":"]})," ",re[w].durationMs,"ms"]})]})]})]}),w==="markus"&&W.configured&&e.jsxs("div",{className:"bg-green-500/5 border border-green-500/20 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400 shadow-[0_0_4px_rgba(74,222,128,0.4)]"}),e.jsx("span",{className:"text-sm font-medium text-green-400",children:t("modelProviders.markusConnected")})]}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-2",children:t("modelProviders.markusConnectedHint")})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider",children:t("modelProviders.availableModels")}),W.configured&&w!=="markus"&&yr!==w&&e.jsx("button",{onClick:()=>{kt(w),Ct({id:"",name:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5,reasoning:!1,vision:!1})},className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:t("modelProviders.addModel")})]}),yr===w&&e.jsx("div",{className:"bg-surface-elevated/40 rounded-lg p-3 mb-2 space-y-2",children:e.jsx(ko,{providerName:w,addModelForm:Ce,setAddModelForm:Ct,addModelSaving:Zn,onAdd:()=>{na(w)},onCancel:()=>kt(null),t})}),w==="markus"&&W.configured&&(!W.models||W.models.length===0)&&(V===w?e.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.loadingHubCatalog")]}):e.jsx("div",{className:"mt-1 text-xs text-amber-400/90",children:L?t("modelProviders.hubCatalogError",{error:L}):t("modelProviders.hubCatalogEmpty")})),W.models&&W.models.length>0&&e.jsx(No,{models:W.models,providerName:w,activeModelId:W.model,t,onDeleteCustom:ie=>{aa(w,ie)}}),W.configured&&V===w&&e.jsxs("div",{className:"flex items-center gap-2 mt-2 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.loadingCatalog")]}),W.configured&&T[w]&&T[w].length>0&&(()=>{const ie=new Set(W.models?.map(Ne=>Ne.id)??[]),De=T[w].filter(Ne=>!ie.has(String(Ne.id??"")));return De.length===0?null:e.jsx(wo,{models:De,providerName:w,t,onAdd:Ne=>{const Se=De.find(ia=>String(ia.id??"")===Ne);Se&&(kt(w),Ct({id:String(Se.id??""),name:String(Se.id??""),contextWindow:Se.maxInputTokens??128e3,maxOutputTokens:Se.maxOutputTokens??16384,costInput:Se.inputCostPer1MTokens??1,costOutput:Se.outputCostPer1MTokens??5,reasoning:Se.capabilities?.reasoning??!1,vision:Se.capabilities?.vision??!1}))}})})()]}),!W.configured&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"text-xs text-fg-secondary",children:t("modelProviders.quickSetupHint")}),w==="markus"&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 rounded-lg bg-brand-600/8 border border-brand-500/15 text-xs text-fg-secondary",children:[e.jsx("svg",{className:"w-4 h-4 shrink-0 text-brand-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsxs("span",{children:[t("modelProviders.markusKeyHint")," ",e.jsx("a",{href:`${Ve.getUrl()}/settings`,target:"_blank",rel:"noopener noreferrer",className:"text-brand-500 hover:text-brand-400 underline underline-offset-2",children:t("modelProviders.markusKeyLink")})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:A===w?Ee:"",onChange:ie=>Ge(ie.target.value),placeholder:t("modelProviders.quickSetupPlaceholder"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none",onBlur:()=>{Ee.trim().length>=8&&A===w&&jr(w,Ee.trim())},onKeyDown:ie=>{ie.key==="Enter"&&Ee.trim().length>=8&&jr(w,Ee.trim())}}),Qn&&A===w&&e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-fg-tertiary",children:[e.jsx("div",{className:"w-3 h-3 border-2 border-brand-500 border-t-transparent rounded-full animate-spin"}),t("modelProviders.validatingKey")]})]}),A===w&&Qt.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-2",children:t("modelProviders.selectModel")}),e.jsx(Pn,{provider:w,models:Qt,selectedModel:se.model,showTiers:!0,onSelect:ie=>{const De=Qt.find(Ne=>Ne.id===ie);_e(Ne=>({...Ne,name:w,model:ie,apiKey:Ee.trim(),baseUrl:Pt.find(Se=>Se.id===w)?.baseUrl??"",contextWindow:De?.maxInputTokens??Ne.contextWindow,maxOutputTokens:De?.maxOutputTokens??Ne.maxOutputTokens,costInput:De?.inputCostPer1MTokens??Ne.costInput,costOutput:De?.outputCostPer1MTokens??Ne.costOutput}))},compact:!0,maxVisible:8})]}),A===w&&Ee.trim()&&e.jsx("button",{onClick:()=>{se.model&&se.name===w?Nr():ea(w)},disabled:hr||wt,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(hr||wt?"modelProviders.quickSetupSaving":"modelProviders.quickSetupSubmit")}),ss&&A===w&&e.jsx(Me,{type:ss.type,text:ss.text})]})]})]})]},w)})]}),Jn?e.jsxs("div",{className:"mt-3 bg-surface-secondary border border-brand-500/30 rounded-xl p-4 space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-fg-primary",children:t("modelProviders.customProvider")}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.providerName")}),e.jsx("input",{type:"text",value:se.name==="__custom__"?"":se.name,onChange:w=>_e(W=>({...W,name:w.target.value||"__custom__"})),placeholder:"my-provider",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.baseUrl")}),e.jsx("input",{type:"text",value:se.baseUrl,onChange:w=>_e({...se,baseUrl:w.target.value}),placeholder:"https://api.example.com/v1",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.apiKey")}),e.jsx("input",{type:"password",value:se.apiKey,onChange:w=>_e({...se,apiKey:w.target.value}),placeholder:t("modelProviders.placeholderApiKeySk"),className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[10px] text-fg-tertiary uppercase block mb-1",children:t("modelProviders.defaultModel")}),e.jsx("input",{type:"text",value:se.model,onChange:w=>_e({...se,model:w.target.value}),placeholder:"gpt-4o",className:"w-full px-3 py-2 text-sm bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>{Nr()},disabled:wt||!se.name||se.name==="__custom__"||!se.model,className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(wt?"modelProviders.adding":"modelProviders.addProviderSubmit")}),e.jsx("button",{onClick:()=>{Yt(!1),ur(null),$e([]),_e({name:"",apiKey:"",baseUrl:"",model:"",contextWindow:128e3,maxOutputTokens:16384,costInput:1,costOutput:5})},className:"px-4 py-2 text-sm border border-border-default text-fg-secondary hover:bg-surface-elevated rounded-lg transition-colors",children:t("common:cancel")})]}),Jt&&e.jsx(Me,{type:Jt.type,text:Jt.text})]}):e.jsxs("button",{onClick:()=>Yt(!0),className:"w-full mt-3 px-4 py-2.5 border border-dashed border-border-default hover:border-brand-500/50 hover:bg-brand-500/5 rounded-xl text-xs text-fg-tertiary hover:text-brand-500 transition-colors",children:["+ ",t("modelProviders.customProvider")]})]})]})})(),e.jsx(Rs,{title:t("autoDetect.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[e.jsx("div",{className:"text-sm text-fg-secondary",children:t("autoDetect.description")}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:t("envConfig.title")}),e.jsxs("button",{onClick:()=>{Wt()},disabled:ee,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${ee?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),t(ee?"common:detecting":"envConfig.refreshEnv")]})]}),Q&&Q.detected.length>0&&e.jsxs("div",{className:"space-y-2",children:[Q.detected.map(o=>e.jsxs("label",{className:"flex items-center justify-between bg-surface-elevated/30 rounded-lg px-4 py-3 cursor-pointer hover:bg-surface-elevated/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"checkbox",checked:Ue[o.provider]??!1,onChange:h=>Fe({...Ue,[o.provider]:h.target.checked}),className:"w-4 h-4 rounded bg-surface-overlay border-gray-600 text-brand-500 focus:ring-brand-500"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary font-medium",children:o.displayName}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[t("envConfig.keyLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:o.apiKeyPreview})," / ",t("envConfig.modelLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:o.model}),o.baseUrl&&e.jsxs(e.Fragment,{children:[" / ",t("envConfig.urlLabel")," ",e.jsx("code",{className:"text-fg-secondary",children:o.baseUrl})]})]})]})]}),e.jsx("div",{className:"text-xs text-fg-tertiary",children:Object.keys(o.envVars).map(h=>e.jsx("div",{children:e.jsx("code",{children:h})},h))})]},o.provider)),Q.timeoutMs&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("envConfig.llmTimeout",{ms:Q.timeoutMs})}),e.jsx("button",{onClick:()=>{qn()},disabled:xt||Object.values(Ue).filter(Boolean).length===0,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:xt?t("common:applying"):t("envConfig.applyToConfig",{count:Object.values(Ue).filter(Boolean).length})})]}),le&&e.jsx(Me,{type:le.type,text:le.text})]}),e.jsx("div",{className:"border-t border-border-default"}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary uppercase tracking-wider",children:t("ollama.title")}),e.jsxs("button",{onClick:()=>{Gt()},disabled:ae,className:"px-3 py-1 border border-border-default hover:bg-surface-elevated disabled:opacity-40 text-fg-tertiary text-xs rounded-md transition-colors flex items-center gap-1.5",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${ae?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})}),t(ae?"common:detecting":"ollama.detect")]})]}),be?.found&&be.models&&be.models.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs text-green-600",children:t("ollama.foundModels",{count:be.models.length,url:be.baseUrl})}),e.jsx("div",{className:"space-y-1",children:be.models.map(o=>e.jsx("label",{className:`flex items-center justify-between rounded-lg px-4 py-3 cursor-pointer transition-colors ${we===o.name?"bg-brand-500/15 border border-brand-500/40":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"radio",name:"ollama-model",value:o.name,checked:we===o.name,onChange:()=>et(o.name),className:"w-4 h-4 text-brand-500 focus:ring-brand-500"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-fg-primary font-medium",children:o.name}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[o.parameterSize&&e.jsx("span",{children:o.parameterSize}),o.family&&e.jsx("span",{className:"ml-2",children:o.family}),o.quantization&&e.jsx("span",{className:"ml-2",children:o.quantization}),o.size&&e.jsx("span",{className:"ml-2",children:Qe(o.size)})]})]})]})},o.name))}),e.jsx("button",{onClick:()=>{zn()},disabled:mt||!we,className:"px-4 py-2 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-sm rounded-lg transition-colors",children:mt?t("common:applying"):t("ollama.useModel",{model:we})})]}),be&&!be.found&&e.jsx("div",{className:"text-xs text-fg-tertiary",children:be.error||t("ollama.notRunning")}),Et&&e.jsx(Me,{type:Et.type,text:Et.text})]})]})}),e.jsx(Rs,{title:t("oauthAuth.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.description")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[qs.map(o=>e.jsxs("div",{className:"flex",children:[e.jsx("button",{onClick:()=>dr(o.name),disabled:!!tt,className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-l-lg transition-colors",children:tt===o.name?t("oauthAuth.connecting"):t("oauthAuth.signInWith",{name:o.displayName})}),e.jsx("button",{onClick:()=>Wn(o.name),disabled:!!tt,title:t("oauthAuth.deviceTitle"),className:"px-2.5 py-2 text-xs bg-surface-secondary text-fg-secondary border border-border-default border-l-0 rounded-r-lg hover:bg-surface-tertiary disabled:opacity-40 transition-colors",children:t("oauthAuth.device")})]},o.name)),qs.length===0&&e.jsx("span",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.noProviders")})]}),rt&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-secondary border border-border-default space-y-2",children:[e.jsx("p",{className:"text-xs text-fg-primary font-medium",children:t("oauthAuth.deviceCodeTitle")}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.deviceInstructions")}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("a",{href:rt.verificationUri,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-brand-500 underline hover:text-brand-400",children:rt.verificationUri}),e.jsx("code",{className:"px-2.5 py-1 text-sm font-mono font-bold bg-surface-elevated border border-border-default rounded-lg text-fg-primary select-all",children:rt.userCode})]}),e.jsx("p",{className:"text-[10px] text-fg-muted",children:t("oauthAuth.deviceWaiting")})]}),Kn&&!rt&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-secondary border border-border-default space-y-2",children:[e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("oauthAuth.manualCallbackHint")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:ft,onChange:o=>Ws(o.target.value),placeholder:t("oauthAuth.manualPlaceholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-muted/50 focus:border-brand-500 outline-none"}),e.jsx("button",{onClick:Gn,disabled:!ft.trim()||tt==="manual",className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t("oauthAuth.submit")})]})]}),Bt&&e.jsx(Me,{type:Bt.type,text:Bt.text}),zs.filter(o=>o.hasOAuth).length>0&&e.jsxs("div",{className:"space-y-2 border-t border-border-default pt-4",children:[e.jsx("span",{className:"text-xs font-medium text-fg-secondary",children:t("oauthAuth.connectedAccounts")}),zs.filter(o=>o.hasOAuth).map(o=>e.jsxs("div",{className:`flex items-center justify-between px-4 py-3 rounded-lg border ${o.oauthExpired?"bg-amber-500/5 border-amber-500/20":"bg-surface-secondary border-border-default"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${o.oauthExpired?"bg-amber-400":"bg-green-400"}`}),e.jsx("span",{className:"text-xs text-fg-primary font-medium",children:o.label??o.provider}),o.accountId&&e.jsxs("span",{className:"text-[10px] text-fg-muted",children:["(",o.accountId.slice(0,12),"...)"]}),o.oauthExpired&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded-md bg-amber-500/15 text-amber-600 font-medium",children:t("oauthAuth.expired")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o.oauthExpired&&e.jsx("button",{onClick:()=>dr(o.provider),disabled:!!tt,className:"text-[10px] px-2 py-1 rounded-md text-brand-500 hover:text-brand-400 hover:bg-brand-500/10 transition-colors",children:t("oauthAuth.reconnect")}),e.jsx("button",{onClick:()=>Yn(o.id),className:"text-[10px] px-2 py-1 rounded-md text-red-400 hover:text-red-300 hover:bg-red-500/10 transition-colors",children:t("oauthAuth.disconnect")})]})]},o.id))]})]})}),e.jsx(Pe,{title:t("defaultProvider.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium",children:t("defaultProvider.primaryProvider")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("defaultProvider.primaryProviderDesc")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[I?e.jsx("select",{value:K,onChange:o=>{_(o.target.value),S(null)},className:"px-3 py-1.5 bg-surface-elevated border border-border-default rounded-lg text-sm w-48 focus:border-brand-500 outline-none",children:Cr.length>0?Cr.map(o=>e.jsx("option",{value:o,children:I.providers[o]?.displayName??o},o)):e.jsx("option",{value:"",children:t("defaultProvider.noProviders")})}):e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("common:loading")}),K!==I?.defaultProvider&&e.jsx("button",{onClick:()=>{Vn()},disabled:D,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(D?"common:saving":"common:save")})]})]}),p&&e.jsx(Me,{type:p.type,text:p.text}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("defaultProvider.autoFallback")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("defaultProvider.autoFallbackDesc")})]}),e.jsx("button",{onClick:async()=>{const o=!(I?.autoFallback??!1);try{const h=await fetch("/api/settings/llm",{method:"POST",headers:oe(),body:JSON.stringify({autoFallback:o})});if(h.ok){const R=await h.json();O(R)}}catch{}},className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${I?.autoFallback??!1?"bg-green-500":"bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${I?.autoFallback??!1?"translate-x-4":"translate-x-1"}`})})]})]})}),e.jsx(Pe,{title:t("modelRouting.title"),children:e.jsx(ja,{configuredProviders:Object.entries(I?.providers??{}).filter(([,o])=>o.configured&&o.enabled).map(([o,h])=>({name:o,displayName:h.displayName,model:h.model,models:h.models?.map(R=>({id:R.id,name:R.name}))})),onSave:async o=>{const h=await fetch("/api/settings/llm",{method:"POST",headers:oe(),body:JSON.stringify(o)});if(!h.ok)throw new Error(`HTTP ${h.status}`)}},I?.defaultProvider??"no-default")}),e.jsx(Rs,{title:t("networkProxy.title"),defaultOpen:!1,children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{children:e.jsx("p",{className:"text-xs text-fg-tertiary",children:t("networkProxy.description")})}),e.jsx("button",{onClick:async()=>{const o=!Le;It(o);try{await fetch("/api/settings/network",{method:"POST",headers:oe(),body:JSON.stringify({proxyEnabled:o})}),at()}catch{It(!o)}},className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors ${Le?"bg-green-500":"bg-gray-600"}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Le?"translate-x-4":"translate-x-1"}`})})]}),ke&&e.jsxs("div",{className:`flex items-center gap-2 px-3 py-2.5 rounded-lg bg-surface-secondary border border-border-default transition-opacity ${Le?"":"opacity-50"}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${Le&&ke.proxy?"bg-green-400":"bg-gray-600"}`}),e.jsx("span",{className:"text-xs text-fg-secondary",children:Le?ke.proxy?e.jsxs(e.Fragment,{children:[t("networkProxy.active")," ",e.jsx("code",{className:"text-fg-primary font-mono",children:ke.proxy})]}):t("networkProxy.noProxy"):t("networkProxy.disabled")}),Le&&ke.source!=="none"&&ke.source!=="disabled"&&e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-md font-medium ${ke.source==="config"?"bg-brand-500/15 text-brand-500":ke.source==="env"?"bg-amber-500/15 text-amber-600":ke.source==="system"?"bg-blue-500/15 text-blue-500":"bg-gray-500/15 text-fg-muted"}`,children:ke.source==="config"?t("networkProxy.sourceConfig"):ke.source==="env"?t("networkProxy.sourceEnv"):ke.source==="system"?t("networkProxy.sourceSystem"):""}),e.jsxs("button",{onClick:()=>at(),className:"ml-auto text-[10px] px-1.5 py-0.5 rounded-md text-fg-muted hover:text-fg-secondary hover:bg-surface-tertiary transition-colors",title:t("networkProxy.refresh"),children:["↻ ",t("networkProxy.refresh")]})]}),e.jsxs("div",{className:`flex gap-2 items-center transition-opacity ${Le?"":"opacity-50 pointer-events-none"}`,children:[e.jsx("input",{type:"text",value:Fs,onChange:o=>$s(o.target.value),placeholder:t("networkProxy.placeholder"),className:"flex-1 px-3 py-2 text-xs bg-surface-elevated border border-border-default rounded-lg text-fg-primary placeholder:text-fg-muted/50 focus:border-brand-500 outline-none"}),e.jsx("button",{onClick:async()=>{Hs(!0),gt(null);try{const o=await fetch("/api/settings/network",{method:"POST",headers:oe(),body:JSON.stringify({proxy:Fs.trim()})});if(o.ok)gt({type:"ok",text:t("networkProxy.saved")}),at();else{const h=await o.json();gt({type:"err",text:h.error??t("networkProxy.saveFailed")})}}catch{gt({type:"err",text:t("networkProxy.networkError")})}finally{Hs(!1)}},disabled:Vs,className:"px-3 py-2 text-xs bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded-lg transition-colors",children:t(Vs?"networkProxy.saving":"networkProxy.save")})]}),Lt&&e.jsx(Me,{type:Lt.type,text:Lt.text})]})})]}),b==="execution"&&e.jsxs(e.Fragment,{children:[e.jsx(Pe,{title:t("agentExecution.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("agentExecution.maxToolIterations")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("agentExecution.maxToolIterationsDesc")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,value:Ys,onChange:o=>{_t(Number(o.target.value)),pt(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right"}),e.jsx("button",{disabled:Js,onClick:async()=>{Qs(!0),pt(null);try{const o=await $.settings.updateAgent({maxToolIterations:Ys});_t(o.maxToolIterations),pt({type:"ok",text:t("agentExecution.saved")})}catch{pt({type:"err",text:t("agentExecution.failedToSave")})}Qs(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(Js?"common:saving":"common:save")})]})]}),Dt&&e.jsx(Me,{type:Dt.type,text:Dt.text})]})}),e.jsx(Pe,{title:t("cognitive.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("cognitive.description")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("cognitive.enabled")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("cognitive.enabledDesc")})]}),e.jsx("button",{onClick:()=>{Kt(!ht),nt(null)},className:`relative w-10 h-5 rounded-full transition-colors ${ht?"bg-brand-500":"bg-fg-quaternary"}`,children:e.jsx("span",{className:`absolute top-0.5 left-0.5 w-4 h-4 bg-white rounded-full shadow transition-transform ${ht?"translate-x-5":""}`})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("cognitive.maxDepth")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("cognitive.maxDepthDesc")})]}),e.jsxs("select",{value:Xs,onChange:o=>{Ut(Number(o.target.value)),nt(null)},className:"px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary",children:[e.jsxs("option",{value:1,children:["D1 — ",t("cognitive.depthD1")]}),e.jsxs("option",{value:2,children:["D2 — ",t("cognitive.depthD2")]}),e.jsxs("option",{value:3,children:["D3 — ",t("cognitive.depthD3")]})]})]}),e.jsx("div",{className:"flex items-center justify-end gap-2",children:e.jsx("button",{disabled:Zs,onClick:async()=>{er(!0),nt(null);try{const o=await $.settings.updateAgent({cognitive:{enabled:ht,maxDepth:Xs}});Kt(o.cognitive.enabled),Ut(o.cognitive.maxDepth??1),nt({type:"ok",text:t("cognitive.saved")})}catch{nt({type:"err",text:t("cognitive.failedToSave")})}er(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(Zs?"common:saving":"common:save")})}),Ft&&e.jsx(Me,{type:Ft.type,text:Ft.text})]})})]}),b==="browser"&&e.jsxs(e.Fragment,{children:[e.jsxs(Pe,{title:t("browserAutomation.title"),children:[e.jsxs("div",{className:`rounded-xl p-4 mb-4 flex items-start gap-3 ${ye?"bg-green-500/10 border border-green-500/20":Re>0?"bg-blue-500/10 border border-blue-500/20":Be?"bg-amber-500/10 border border-amber-500/20":"bg-surface-elevated border border-border-default"}`,children:[e.jsx("div",{className:`mt-0.5 w-2.5 h-2.5 rounded-full shrink-0 ${ye?"bg-green-400":Re>0?"bg-blue-400":Be?"bg-amber-400":"bg-gray-400"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:`text-sm font-semibold ${ye?"text-green-400":Re>0?"text-blue-400":Be?"text-amber-400":"text-fg-secondary"}`,children:ye?t("browserAutomation.modeExtension"):Re>0?t("browserAutomation.modeDebuggingPort",{port:Re}):t(Be?"browserAutomation.modeAutoClick":"browserAutomation.modeManual")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:ye?t("browserAutomation.modeExtensionDesc"):Re>0?t("browserAutomation.modeDebuggingPortDesc"):t(Be?"browserAutomation.modeAutoClickDesc":"browserAutomation.modeManualDesc")})]})]}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4 mb-4",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.generalSettings")}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.bringToFront")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.bringToFrontDesc")})]}),e.jsx("button",{onClick:async()=>{const o=!$t;bt(o),he(!0),de(null);try{const h=await $.settings.updateBrowser({bringToFront:o});bt(h.bringToFront),de({type:"ok",text:t(o?"browserAutomation.tabsForeground":"browserAutomation.tabsBackground")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),bt(!o)}he(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${$t?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${$t?"translate-x-4":"translate-x-1"}`})})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border-default pt-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.autoCloseTabs")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.autoCloseTabsDesc")})]}),e.jsx("button",{onClick:async()=>{const o=!Ht;yt(o),he(!0),de(null);try{const h=await $.settings.updateBrowser({autoCloseTabs:o});yt(h.autoCloseTabs),de({type:"ok",text:t("agentExecution.saved")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),yt(!o)}he(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Ht?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Ht?"translate-x-4":"translate-x-1"}`})})]})]}),e.jsxs("div",{className:`rounded-xl p-5 mb-4 transition-colors ${ye?"bg-green-500/5 border border-green-500/20":"bg-surface-elevated"}`,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:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStatus")}),e.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",t("browserAutomation.modeRecommended"),")"]})]}),e.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium ${ye?"bg-green-500/20 text-green-400":"bg-gray-600/20 text-gray-400"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ye?"bg-green-400":"bg-gray-400"}`}),t(ye?"browserAutomation.extensionConnected":"browserAutomation.extensionDisconnected")]})]}),e.jsx("div",{className:"text-xs text-fg-tertiary",children:t("browserAutomation.extensionStatusDesc")}),ye?e.jsxs("div",{className:"mt-3 flex items-center gap-1.5 text-xs text-green-400",children:[e.jsx("svg",{className:"w-3.5 h-3.5 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})}),t("browserAutomation.extensionActiveNote")]}):e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.extensionSetupTitle")}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"1"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep1")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep1Desc")}),e.jsxs("button",{disabled:ve,onClick:async()=>{he(!0),de(null);try{await $.settings.downloadExtensionZip()}catch{de({type:"err",text:t("browserAutomation.extensionDownloadError")})}he(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"})}),t(ve?"browserAutomation.extensionStep1Downloading":"browserAutomation.extensionStep1Btn")]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"2"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep2")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep2Desc")}),navigator.platform.toUpperCase().includes("WIN")?e.jsxs("div",{className:"mt-2 text-xs text-fg-secondary",children:[t("browserAutomation.extensionStep2Desc"),":",e.jsx("code",{className:"ml-1.5 px-1.5 py-0.5 bg-surface-elevated rounded text-fg-primary font-mono text-[11px] select-all",children:"chrome://extensions"})]}):e.jsxs("button",{disabled:ve,onClick:async()=>{he(!0),de(null);try{await $.settings.openExtensionsPage()}catch{de({type:"err",text:t("browserAutomation.extensionOpenError")})}he(!1)},className:"mt-2 inline-flex items-center gap-1.5 px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),t("browserAutomation.extensionStep2Btn")]})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-surface-primary/50",children:[e.jsx("span",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-brand-500 text-white text-[10px] font-bold shrink-0 mt-0.5",children:"3"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.extensionStep3")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.extensionStep3Desc")})]})]})]})]}),!ye&&e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-4",children:[e.jsx("div",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:t("browserAutomation.fallbackModes")}),e.jsx("div",{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex-1 mr-4",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.autoClickAllowDialog")}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5",children:t("browserAutomation.autoClickAllowDialogDesc")}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-2 space-y-0.5",children:[e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogMacNote")}),e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogWinNote")}),e.jsx("div",{children:t("browserAutomation.autoClickAllowDialogLinuxNote")})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{disabled:ve,onClick:async()=>{he(!0),de(null);try{const o=await $.settings.testAutoClick(),h={success:{type:"ok",text:t("browserAutomation.autoClickTestSuccess",{title:o.pageTitle||"example.com"})},no_permission:{type:"err",text:t("browserAutomation.autoClickTestNoPermission")},chrome_not_running:{type:"err",text:t("browserAutomation.autoClickTestChromeNotRunning")},unsupported:{type:"err",text:t("browserAutomation.autoClickTestUnsupported")},error:{type:"err",text:t("browserAutomation.autoClickTestError",{error:o.error||"unknown"})}};de(h[o.clickResult]??{type:"err",text:o.clickResult})}catch{de({type:"err",text:t("browserAutomation.autoClickTestError",{error:"request failed"})})}he(!1)},className:"px-3 py-1.5 text-xs bg-surface-primary border border-border-default text-fg-primary rounded-lg hover:bg-surface-elevated transition-colors disabled:opacity-40",children:t(ve?"browserAutomation.autoClickTesting":"browserAutomation.autoClickTest")}),e.jsx("button",{onClick:async()=>{const o=!Be;vt(o),he(!0),de(null);try{const h=await $.settings.updateBrowser({autoClickAllowDialog:o});vt(h.autoClickAllowDialog),de({type:"ok",text:t("agentExecution.saved")})}catch{de({type:"err",text:t("agentExecution.failedToSave")}),vt(!o)}he(!1)},disabled:ve,className:`relative inline-flex h-5 w-9 items-center rounded-full transition-colors ${Be?"bg-green-500":"bg-gray-600"} ${ve?"opacity-50":""}`,children:e.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full bg-white transition-transform ${Be?"translate-x-4":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"border-t border-border-default pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary",children:t("browserAutomation.remoteDebuggingPort")}),e.jsxs("div",{className:"text-xs text-fg-tertiary mt-0.5",children:[t("browserAutomation.remoteDebuggingPortDescLead")," ",e.jsx("code",{className:"text-fg-secondary bg-surface-primary px-1 rounded",children:"--remote-debugging-port=9222"})," ",t("browserAutomation.remoteDebuggingPortDescTail")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",min:0,max:65535,value:Re,onChange:o=>{Vt(Number(o.target.value)),de(null)},className:"w-24 px-3 py-1.5 text-sm border border-border-default rounded-lg bg-surface-primary text-fg-primary text-right",placeholder:"0"}),e.jsx("button",{disabled:ve,onClick:async()=>{he(!0),de(null);try{const o=await $.settings.updateBrowser({remoteDebuggingPort:Re});Vt(o.remoteDebuggingPort),de({type:"ok",text:o.remoteDebuggingPort>0?t("browserAutomation.usingPort",{port:o.remoteDebuggingPort}):t("browserAutomation.usingAutoConnect")})}catch{de({type:"err",text:t("agentExecution.failedToSave")})}he(!1)},className:"px-3 py-1.5 text-xs bg-brand-500 text-white rounded-lg hover:bg-brand-600 transition-colors disabled:opacity-40",children:t(ve?"common:saving":"common:save")})]})]})})]}),qt&&e.jsx("div",{className:"mt-4",children:e.jsx(Me,{type:qt.type,text:qt.text})})]}),!1]}),b==="search"&&e.jsx(fo,{}),b==="storage"&&e.jsx(e.Fragment,{children:e.jsx(Pe,{title:t("dataStorage.title"),children:e.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5 space-y-5",children:[zt&&!Te&&e.jsx("div",{className:"text-sm text-fg-tertiary",children:t("dataStorage.scanning")}),Te&&(()=>{const o=[...Te.breakdown].filter(Y=>Y.size>0).sort((Y,ce)=>ce.size-Y.size),h=Math.max(Te.totalSize,1),G=o.filter(Y=>Ls[Y.name]==="safe").reduce((Y,ce)=>Y+ce.size,0),Z=Y=>Y==="safe"?"bg-fg-secondary/55":Y==="caution"?"bg-fg-tertiary/45":"bg-fg-primary/25";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-2xl font-semibold tracking-tight text-fg-primary tabular-nums",children:Qe(Te.totalSize,t)}),e.jsx("div",{className:"text-xs text-fg-tertiary font-mono mt-1 truncate",title:Te.dataDir,children:Te.dataDir})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsx("button",{onClick:()=>We(),disabled:zt,className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-primary/60 rounded-lg text-fg-secondary transition-colors disabled:opacity-40",children:t(zt?"dataStorage.scanning":"common:refresh")}),e.jsx("button",{onClick:()=>{$.system.openPath(Te.dataDir)},className:"px-3 py-1.5 text-xs border border-border-default hover:bg-surface-primary/60 rounded-lg text-fg-secondary transition-colors",children:t("dataStorage.openInFinder")})]})]}),e.jsx("div",{className:"h-2 rounded-full bg-surface-primary overflow-hidden flex","aria-hidden":!0,children:o.map(Y=>{const ce=Ls[Y.name]??"caution",w=Math.max(Y.size/h*100,Y.size>0?.8:0);return e.jsx("div",{className:`h-full ${Z(ce)}`,style:{width:`${w}%`},title:`${Y.name}: ${Qe(Y.size,t)}`},Y.name)})}),G>0&&e.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:t("dataStorage.clearableHint",{size:Qe(G,t),percent:Math.round(G/h*100)})})]}),e.jsxs("div",{className:"border-t border-border-default pt-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3 mb-3",children:[e.jsx("h4",{className:"text-xs font-semibold text-fg-secondary",children:t("dataStorage.storageBreakdown")}),e.jsx("span",{className:"text-[11px] text-fg-tertiary",children:t("dataStorage.sortedBySize")})]}),e.jsx("div",{className:"divide-y divide-border-default/70 rounded-xl border border-border-default/70 overflow-hidden",children:o.map(Y=>{const ce=ho[Y.name],w=Ls[Y.name]??"caution",W=ce?t(`dataStorage.items.${ce}.label`):Y.name,Ye=ce?t(`dataStorage.items.${ce}.blurb`):Y.description,rs=Math.round(Y.size/h*100);return e.jsxs("div",{className:"flex items-center gap-3 px-3.5 py-3 bg-surface-primary/25 hover:bg-surface-primary/45 transition-colors",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:W}),w==="safe"&&e.jsx("span",{className:"shrink-0 text-[10px] px-1.5 py-0.5 rounded-md bg-surface-elevated text-fg-secondary border border-border-default/80",children:t("dataStorage.safetyLevel.safe")})]}),e.jsx("div",{className:"text-xs text-fg-tertiary mt-0.5 leading-relaxed",children:Ye})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("div",{className:"text-sm font-medium text-fg-primary tabular-nums",children:Qe(Y.size,t)}),e.jsxs("div",{className:"text-[11px] text-fg-tertiary tabular-nums mt-0.5",children:[rs,"%"]})]}),e.jsx("button",{type:"button",onClick:()=>{$.system.openPath(Y.path)},className:"shrink-0 px-2.5 py-1 text-xs border border-border-default hover:bg-surface-elevated rounded-lg text-fg-secondary transition-colors",title:Y.path,children:t("dataStorage.openFolder")})]},Y.name)})})]}),jt&&(jt.orphanAgents.length>0||jt.orphanTeams.length>0)&&e.jsx(So,{orphanInfo:jt,dataDir:Te.dataDir,onPurged:We,formatBytes:Y=>Qe(Y,t)})]})})()]})})}),(b==="account"||b==="users"||b==="organization"||b==="license")&&e.jsx(To,{authUser:i}),b==="remote"&&e.jsx(Po,{}),b==="integrations"&&e.jsx(e.Fragment,{children:e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:t("nav.integrations")}),e.jsx("div",{className:"space-y-3",children:e.jsx(Ja,{})})]})}),b==="coding-tools"&&e.jsx(mo,{})]}),e.jsx("div",{className:"h-8"})]}),es&&e.jsx(Cn,{title:t("common:delete"),message:t("modelProviders.deleteConfirm",{name:es.label}),confirmLabel:t("common:delete"),onConfirm:()=>{const o=es.name;ts(null),ra(o)},onCancel:()=>ts(null)})]})]})}const jn=["owner","admin","member","guest"],yo={owner:"bg-amber-500/10 text-amber-600 border-amber-500/30",admin:"bg-brand-500/10 text-brand-500 border-brand-500/30",member:"bg-green-500/10 text-green-600 border-green-500/30",guest:"bg-gray-500/10 text-gray-500 border-gray-500/30"};function vo({authUser:s}){const{t:r}=ge(["settings","common"]),[i,n]=l.useState([]),[a,t]=l.useState(null),[d,c]=l.useState(""),[u,f]=l.useState(""),[N,M]=l.useState(""),[m,y]=l.useState(null),[k,b]=l.useState(""),[U,v]=l.useState(null),[P,g]=l.useState(null),[j,C]=l.useState(null),[B,I]=l.useState(!1),[O,K]=l.useState(""),[_,D]=l.useState(""),[F,p]=l.useState("member"),[S,A]=l.useState(""),z=l.useCallback(()=>{$.users.list(s?.orgId).then(x=>n(x.users)).catch(()=>{})},[s?.orgId]);l.useEffect(()=>{z()},[z]);const J=x=>{t(x.id),c(x.name),f(x.role),M(x.email??""),C(null)},ne=async()=>{if(a)try{await $.users.update(a,{name:d,role:u,email:N||void 0}),t(null),C({type:"ok",text:r("settings:userManagement.updateSuccess")}),z()}catch(x){C({type:"err",text:`${r("settings:userManagement.error")}: ${String(x)}`})}},T=async()=>{if(!(!m||!k))try{await $.users.resetPassword(m,k),y(null),b(""),C({type:"ok",text:r("settings:userManagement.resetSuccess")})}catch(x){C({type:"err",text:`${r("settings:userManagement.error")}: ${String(x)}`})}},q=async x=>{if(x===s?.id){C({type:"err",text:r("settings:userManagement.cannotDeleteSelf")}),v(null);return}if(i.find(H=>H.id===x)?.role==="owner"){C({type:"err",text:r("settings:userManagement.cannotDeleteOwner")}),v(null);return}try{await $.users.remove(x),v(null),C({type:"ok",text:r("settings:userManagement.deleteSuccess")}),z()}catch(H){C({type:"err",text:`${r("settings:userManagement.error")}: ${String(H)}`})}},V=async()=>{if(O.trim())try{const x=await $.users.create(O.trim(),F,void 0,_.trim()||void 0,S||void 0);I(!1),K(""),D(""),p("member"),A(""),C({type:"ok",text:r("settings:userManagement.addSuccess",{defaultValue:"User created"})}),x.inviteToken&&g(`${window.location.origin}/#invite?token=${x.inviteToken}`),z()}catch(x){C({type:"err",text:`${r("settings:userManagement.error")}: ${x instanceof Error?x.message:String(x)}`})}};return e.jsxs(Pe,{title:r("settings:userManagement.title"),children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("p",{className:"text-xs text-fg-tertiary leading-relaxed",children:r("settings:userManagement.sharedInstanceDesc")}),e.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:r("settings:userManagement.orgHint")})]}),B?e.jsxs("div",{className:"mb-3 p-4 rounded-lg border border-border-default space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.name")}),e.jsx("input",{value:O,onChange:x=>K(x.target.value),autoFocus:!0,className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.email")}),e.jsx("input",{value:_,onChange:x=>D(x.target.value),type:"email",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.role")}),e.jsx("select",{value:F,onChange:x=>p(x.target.value),className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary",children:jn.map(x=>e.jsx("option",{value:x,children:r(`settings:userManagement.roles.${x}`)},x))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-fg-tertiary mb-1 block",children:r("settings:userManagement.password",{defaultValue:"Password"})}),e.jsx("input",{value:S,onChange:x=>A(x.target.value),type:"password",className:"w-full px-3 py-1.5 text-sm bg-surface-elevated border border-border-default rounded-md text-fg-primary"})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>{I(!1),K(""),D(""),p("member"),A("")},className:"px-3 py-1.5 text-xs text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:V,disabled:!O.trim(),className:"px-4 py-1.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white text-xs font-medium rounded-lg",children:r("settings:userManagement.save")})]})]}):e.jsx("button",{onClick:()=>I(!0),className:"mb-3 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:r("settings:userManagement.addUser",{defaultValue:"Add User"})}),e.jsxs("div",{className:"bg-surface-elevated rounded-xl overflow-hidden",children:[j&&e.jsx("div",{className:`px-4 py-2 text-xs border-b ${j.type==="ok"?"bg-green-500/10 text-green-600 border-green-500/20":"bg-red-500/10 text-red-500 border-red-500/20"}`,children:j.text}),P&&e.jsxs("div",{className:"px-4 py-3 bg-brand-500/5 border-b border-brand-500/20 flex items-center gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-[11px] text-fg-tertiary mb-1",children:r("settings:userManagement.copyInviteLink")}),e.jsx("code",{className:"text-[10px] text-brand-500 bg-surface-elevated px-2 py-1 rounded block truncate",children:P})]}),e.jsx("button",{onClick:()=>{navigator.clipboard.writeText(P),C({type:"ok",text:r("settings:userManagement.linkCopied")})},className:"shrink-0 px-3 py-1.5 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg font-medium",children:r("settings:userManagement.copy")}),e.jsx("button",{onClick:()=>g(null),className:"shrink-0 text-fg-tertiary hover:text-fg-secondary text-sm",children:"×"})]}),e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border-default/60 text-fg-tertiary text-[11px] uppercase tracking-wider",children:[e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.name")}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.email")}),e.jsx("th",{className:"text-left px-4 py-2.5 font-medium",children:r("settings:userManagement.role")}),e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:r("settings:userManagement.actions")})]})}),e.jsxs("tbody",{children:[i.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-4 py-6 text-center text-fg-tertiary text-xs",children:r("settings:userManagement.noUsers")})}),i.map(x=>{const L=a===x.id,H=m===x.id,Q=U===x.id,te=x.id===s?.id,ee=x.role==="owner";return e.jsxs("tr",{className:"border-b border-border-default/40 last:border-b-0 hover:bg-surface-elevated/40 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5",children:L?e.jsx("input",{value:d,onChange:X=>c(X.target.value),className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-fg-primary font-medium text-xs",children:x.name}),te&&e.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-500",children:"you"})]})}),e.jsx("td",{className:"px-4 py-2.5",children:L?e.jsx("input",{value:N,onChange:X=>M(X.target.value),placeholder:"email@example.com",className:"w-full px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}):e.jsx("span",{className:"text-fg-secondary text-xs",children:x.email||"—"})}),e.jsx("td",{className:"px-4 py-2.5",children:L?e.jsx("select",{value:u,onChange:X=>f(X.target.value),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50",children:jn.map(X=>e.jsx("option",{value:X,children:r(`settings:userManagement.roles.${X}`)},X))}):e.jsx("span",{className:`inline-block text-[10px] px-2 py-0.5 rounded-full border font-medium ${yo[x.role]??""}`,children:r(`settings:userManagement.roles.${x.role}`)})}),e.jsx("td",{className:"px-4 py-2.5 text-right",children:L?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>t(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:ne,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium",children:r("settings:userManagement.save")})]}):H?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("input",{type:"password",value:k,onChange:X=>b(X.target.value),placeholder:r("settings:userManagement.newPassword"),autoFocus:!0,className:"w-32 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded-md focus:outline-none focus:ring-1 focus:ring-brand-500/50"}),e.jsx("button",{onClick:()=>{y(null),b("")},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:T,disabled:k.length<6,className:"text-[11px] text-brand-500 hover:text-brand-400 font-medium disabled:opacity-40",children:r("settings:userManagement.confirmReset")})]}):Q?e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("span",{className:"text-[10px] text-red-500",children:r("settings:userManagement.confirmDelete")}),e.jsx("button",{onClick:()=>v(null),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary",children:r("settings:userManagement.cancel")}),e.jsx("button",{onClick:()=>q(x.id),className:"text-[11px] text-red-500 hover:text-red-400 font-medium",children:r("settings:userManagement.deleteUser")})]}):e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{onClick:()=>J(x),className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:r("settings:userManagement.editUser")}),x.email&&e.jsx("button",{onClick:()=>{y(x.id),b(""),C(null)},className:"text-[11px] text-fg-tertiary hover:text-fg-secondary px-1.5 py-0.5 rounded hover:bg-surface-elevated",children:r("settings:userManagement.resetPassword")}),x.email&&!ee&&!x.hasJoined&&e.jsx("button",{onClick:async()=>{try{const{inviteToken:X}=await $.users.reinvite(x.id),le=`${window.location.origin}/#invite?token=${X}`;g(le),C({type:"ok",text:r("settings:userManagement.inviteLinkGenerated")})}catch(X){C({type:"err",text:String(X)})}},className:"text-[11px] text-brand-400 hover:text-brand-500 px-1.5 py-0.5 rounded hover:bg-brand-500/10",children:r("settings:userManagement.inviteLink")}),!ee&&!te&&e.jsx("button",{onClick:()=>{v(x.id),C(null)},className:"text-[11px] text-red-400 hover:text-red-500 px-1.5 py-0.5 rounded hover:bg-red-500/10",children:r("settings:userManagement.deleteUser")})]})})]},x.id)})]})]})]})]})}const jo={audio_speech:{label:"TTS",color:"bg-purple-500/20 text-purple-400"},image_generation:{label:"Image",color:"bg-blue-500/20 text-blue-400"},video_generation:{label:"Video",color:"bg-pink-500/20 text-pink-400"},audio_transcription:{label:"STT",color:"bg-teal-500/20 text-teal-400"},ocr:{label:"OCR",color:"bg-orange-500/20 text-orange-400"}},Nn={chat:0,image_generation:1,video_generation:2,audio_speech:3,audio_transcription:4,ocr:5},wn=5;function No({models:s,providerName:r,activeModelId:i,t:n,onDeleteCustom:a}){const t=s.length>wn,[d,c]=l.useState(!t),[u,f]=l.useState(""),N=l.useMemo(()=>{const m=u.trim().toLowerCase();return m?s.filter(y=>y.id.toLowerCase().includes(m)||y.name.toLowerCase().includes(m)):s},[s,u]),M=d?N:N.slice(0,wn);return e.jsxs("div",{className:"space-y-1",children:[t&&e.jsxs("div",{className:"flex items-center justify-between gap-2 px-1 mb-1",children:[e.jsxs("button",{type:"button",onClick:()=>c(m=>!m),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${d?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),d?n("modelProviders.collapseModels"):n("modelProviders.showAllModels",{count:s.length})]}),d&&e.jsx("input",{value:u,onChange:m=>f(m.target.value),placeholder:n("modelProviders.filterModels"),className:"flex-1 max-w-[220px] px-2 py-1 text-[10px] rounded-md bg-surface-overlay/50 border border-border-default text-fg-secondary placeholder:text-fg-tertiary"})]}),e.jsx("div",{className:d&&t?"max-h-64 overflow-y-auto space-y-1 pr-0.5":"space-y-1",children:M.map(m=>{const y=!po.has(m.id),k=m.capabilities??[],b=i===m.id;return e.jsxs("div",{className:`flex items-center justify-between px-3 py-1.5 rounded-lg text-xs ${b?"bg-brand-500/10 border border-brand-500/20":"bg-surface-elevated/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap min-w-0",children:[e.jsx("span",{className:"text-fg-secondary truncate",children:m.name}),b&&e.jsx("span",{className:"text-[9px] bg-brand-500/15 text-brand-500 px-1 py-0.5 rounded shrink-0",children:n("modelProviders.badgeDefault")}),e.jsx(Lo,{modelId:m.id,tier:m.tier}),m.reasoning&&e.jsx("span",{className:"text-[9px] bg-amber-500/15 text-amber-600 px-1 py-0.5 rounded",children:n("modelProviders.reasoning")}),(m.inputTypes?.includes("image")||k.includes("vision"))&&e.jsx("span",{className:"text-[9px] bg-blue-500/15 text-blue-600 px-1 py-0.5 rounded",children:n("modelProviders.vision")}),k.includes("imageGeneration")&&e.jsx("span",{className:"text-[9px] bg-cyan-500/15 text-cyan-600 px-1 py-0.5 rounded",children:n("modelProviders.capImageGen")}),(k.includes("tts")||k.includes("audioOutput"))&&e.jsx("span",{className:"text-[9px] bg-emerald-500/15 text-emerald-600 px-1 py-0.5 rounded",children:n("modelProviders.capTts")}),(k.includes("stt")||k.includes("audioInput"))&&e.jsx("span",{className:"text-[9px] bg-teal-500/15 text-teal-600 px-1 py-0.5 rounded",children:n("modelProviders.capStt")}),k.includes("videoGeneration")&&e.jsx("span",{className:"text-[9px] bg-orange-500/15 text-orange-600 px-1 py-0.5 rounded",children:n("modelProviders.capVideo")}),y&&r!=="markus"&&e.jsx("span",{className:"text-[9px] bg-purple-500/15 text-purple-400 px-1 py-0.5 rounded",children:n("modelProviders.custom")})]}),e.jsxs("div",{className:"flex items-center gap-3 text-fg-tertiary shrink-0",children:[(m.contextWindow??0)>0&&e.jsx("span",{children:n("modelProviders.ctxTokens",{size:((m.contextWindow??0)/1e3).toFixed(0)})}),y&&r!=="markus"&&e.jsx("button",{onClick:U=>{U.stopPropagation(),a(m.id)},className:"text-red-400 hover:text-red-300 transition-colors",title:n("modelProviders.deleteCustomModelTitle"),children:e.jsx("svg",{className:"w-3 h-3",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})]},m.id)})}),t&&!d&&e.jsx("button",{type:"button",onClick:()=>c(!0),className:"w-full text-[10px] text-fg-tertiary hover:text-brand-500 transition-colors py-1.5",children:n("modelProviders.showAllModels",{count:s.length})}),d&&u&&N.length===0&&e.jsx("div",{className:"text-[10px] text-fg-tertiary px-1 py-2",children:n("modelProviders.noFilterMatches")})]})}function wo({models:s,providerName:r,t:i,onAdd:n}){const[a,t]=l.useState(!1),d=l.useMemo(()=>[...s].sort((c,u)=>{const f=Nn[c.mode??"chat"]??99,N=Nn[u.mode??"chat"]??99;return f!==N?f-N:String(c.id??"").localeCompare(String(u.id??""))}),[s]);return e.jsxs("div",{className:"mt-2",children:[e.jsxs("button",{onClick:()=>t(!a),className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors px-1",children:[e.jsx("svg",{className:`w-3 h-3 transition-transform ${a?"rotate-90":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5l7 7-7 7"})}),i("modelProviders.catalogModelsAvailable",{count:s.length})]}),a&&e.jsx("div",{className:"mt-1 space-y-0.5 pl-1 max-h-64 overflow-y-auto",children:d.map(c=>{const u=String(c.id??""),f=c.mode??"chat",N=jo[f];return e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 rounded hover:bg-surface-overlay/60 group",children:[e.jsx("span",{className:"text-[11px] text-fg-secondary flex-1 truncate",children:u}),N&&e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full shrink-0 ${N.color}`,children:N.label}),e.jsx("button",{onClick:()=>n(u),className:"text-[9px] text-brand-500 hover:text-brand-400 opacity-0 group-hover:opacity-100 transition-opacity shrink-0",children:i("modelProviders.addModel")})]},u)})})]})}function ko({providerName:s,addModelForm:r,setAddModelForm:i,addModelSaving:n,onAdd:a,onCancel:t,t:d}){const[c,u]=l.useState([]),[f,N]=l.useState(!1),[M,m]=l.useState(!1),y=async()=>{N(!0);try{const k=await $.modelCatalog.getByProvider(s);u(k.models),m(!0)}catch{u([])}finally{N(!1)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[10px] text-fg-secondary",children:d("modelProviders.addModelTitle")}),e.jsx("button",{onClick:()=>{y()},disabled:f,className:"text-[10px] text-brand-500 hover:text-brand-400 disabled:opacity-40 transition-colors",children:f?"...":d("modelProviders.browseFromCatalog")})]}),M&&c.length>0&&e.jsx("div",{className:"border border-border-default rounded-lg p-2 mb-2",children:e.jsx(Pn,{provider:s,models:c,selectedModel:r.id,showTiers:!0,onSelect:k=>{const b=c.find(U=>U.id===k);b&&i(U=>({...U,id:b.id,name:b.id,contextWindow:b.maxInputTokens,maxOutputTokens:b.maxOutputTokens,costInput:b.inputCostPer1MTokens,costOutput:b.outputCostPer1MTokens,reasoning:b.capabilities.reasoning,vision:b.capabilities.vision}))},compact:!0,maxVisible:5})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsx("input",{type:"text",placeholder:d("modelProviders.modelId"),value:r.id,onChange:k=>i({...r,id:k.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"text",placeholder:d("modelProviders.displayName"),value:r.name,onChange:k=>i({...r,name:k.target.value}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary placeholder-fg-tertiary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"number",placeholder:d("modelProviders.placeholderContextTokens"),value:r.contextWindow,onChange:k=>i({...r,contextWindow:Number(k.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"}),e.jsx("input",{type:"number",placeholder:d("modelProviders.maxOutput"),value:r.maxOutputTokens,onChange:k=>i({...r,maxOutputTokens:Number(k.target.value)}),className:"px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d("modelProviders.costPerMillionIn")}),e.jsx("input",{type:"number",step:"0.01",value:r.costInput,onChange:k=>i({...r,costInput:Number(k.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-[10px] text-fg-tertiary",children:d("modelProviders.costPerMillionOut")}),e.jsx("input",{type:"number",step:"0.01",value:r.costOutput,onChange:k=>i({...r,costOutput:Number(k.target.value)}),className:"w-16 px-2 py-1 text-xs bg-surface-primary border border-border-default rounded text-fg-primary focus:border-brand-500 outline-none"})]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.reasoning,onChange:k=>i({...r,reasoning:k.target.checked}),className:"rounded"}),d("modelProviders.reasoning")]}),e.jsxs("label",{className:"flex items-center gap-1 text-[10px] text-fg-tertiary cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:r.vision,onChange:k=>i({...r,vision:k.target.checked}),className:"rounded"}),d("modelProviders.vision")]}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:a,disabled:n||!r.id||!r.name,className:"px-2 py-1 text-[10px] bg-brand-600 hover:bg-brand-500 disabled:opacity-40 text-white rounded transition-colors",children:d(n?"modelProviders.adding":"common:create")}),e.jsx("button",{onClick:t,className:"px-2 py-1 text-[10px] border border-border-default text-fg-secondary hover:bg-surface-elevated rounded transition-colors",children:d("common:cancel")})]})]})}function Me({type:s,text:r}){return e.jsx("div",{className:`text-xs px-3 py-2 rounded-lg ${s==="ok"?"bg-green-500/10 text-green-600 border border-green-500/30":"bg-red-500/10 text-red-500 border border-red-500/30"}`,children:r})}function Co({title:s,defaultCollapsed:r,configuredProviders:i,t:n,children:a,onBadgeClick:t}){const[d,c]=l.useState(r);return e.jsxs("section",{children:[e.jsxs("button",{type:"button",onClick:()=>c(!d),className:"flex items-center justify-between w-full group mb-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s}),d&&i.length>0&&e.jsxs("span",{className:"text-xs text-fg-tertiary",children:["(",i.length," ",n("modelProviders.configuredCount"),")"]})]}),e.jsx("span",{className:`text-fg-tertiary text-xs transition-transform group-hover:text-fg-secondary ${d?"-rotate-90":""}`,children:"▼"})]}),d&&i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:i.map(([u,f])=>e.jsxs("button",{type:"button",onClick:N=>{N.stopPropagation(),c(!1),t?.(u)},className:`inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-lg border cursor-pointer transition-colors ${f.enabled?"bg-green-500/10 border-green-500/30 text-green-400 hover:bg-green-500/20":"bg-surface-elevated border-border-default text-fg-tertiary hover:border-gray-500"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${f.enabled?"bg-green-400":"bg-gray-500"}`}),f.displayName??u]},u))}),!d&&e.jsx("div",{className:"space-y-4",children:a})]})}function Pe({title:s,children:r}){return e.jsxs("section",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-4",children:s}),e.jsx("div",{className:"space-y-4",children:r})]})}function Rs({title:s,children:r,defaultOpen:i=!0}){const[n,a]=l.useState(i);return e.jsxs("section",{children:[e.jsxs("button",{type:"button",onClick:()=>a(!n),className:"flex items-center justify-between w-full group mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s}),e.jsx("span",{className:`text-fg-tertiary text-xs transition-transform group-hover:text-fg-secondary ${n?"":"-rotate-90"}`,children:"▼"})]}),n&&e.jsx("div",{className:"space-y-4",children:r})]})}function Bs({label:s,value:r,color:i}){const n=i==="green"?"bg-green-500/10 text-green-600":"bg-brand-500/10 text-brand-500";return e.jsxs("div",{className:`rounded-xl px-5 py-4 ${n}`,children:[e.jsx("div",{className:"text-2xl font-bold",children:r}),e.jsx("div",{className:"text-xs mt-1 opacity-70",children:s})]})}function Qe(s,r){if(s===0)return r?r("dataStorage.bytesZero"):"0 B";const i=r?[r("dataStorage.unitB"),r("dataStorage.unitKB"),r("dataStorage.unitMB"),r("dataStorage.unitGB")]:["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(s)/Math.log(1024)),i.length-1),a=s/Math.pow(1024,n);return`${a<10?a.toFixed(1):Math.round(a)} ${i[n]}`}function So({orphanInfo:s,dataDir:r,onPurged:i,formatBytes:n}){const{t:a}=ge(["settings","common"]),t=[...s.orphanAgents.map(v=>({...v,kind:"agent"})),...s.orphanTeams.map(v=>({...v,kind:"team"}))],[d,c]=l.useState(new Set),[u,f]=l.useState(!1),[N,M]=l.useState(null),m=v=>c(P=>{const g=new Set(P);return g.has(v)?g.delete(v):g.add(v),g}),y=d.size===t.length&&t.length>0,k=()=>c(y?new Set:new Set(t.map(v=>v.id))),b=t.filter(v=>d.has(v.id)).reduce((v,P)=>v+P.size,0),U=async v=>{f(!0),M(null);try{const P=await $.system.purgeOrphans(v),g=P.purgedAgents.length+P.purgedTeams.length,j=a("dataStorage.cleaned",{count:g,size:n(P.freedBytes)});M(P.failures.length?a("dataStorage.cleanedWithFailureNote",{base:j,count:P.failures.length}):j),c(new Set),i()}catch{M(a("dataStorage.cleanupFailed"))}finally{f(!1)}};return e.jsxs("div",{className:"border-t border-border-default pt-4",children:[e.jsx("h4",{className:"text-xs font-semibold text-amber-500 mb-2",children:a("dataStorage.orphanedDirectories")}),e.jsxs("p",{className:"text-xs text-fg-tertiary mb-3",children:[a("dataStorage.orphanedDesc")," ",a("dataStorage.orphanedTotal",{size:n(s.totalOrphanSize),count:t.length})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2 px-1",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] text-fg-tertiary cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:y,onChange:k,className:"rounded"}),a("common:selectAll")]}),d.size>0&&e.jsx("span",{className:"text-[10px] text-fg-secondary",children:a("dataStorage.selectedWithSize",{count:d.size,size:n(b)})})]}),e.jsx("div",{className:"space-y-0.5 mb-3 max-h-52 overflow-y-auto",children:t.map(v=>e.jsxs("div",{className:`flex items-center gap-2 text-xs py-1.5 px-2 rounded transition-colors ${d.has(v.id)?"bg-amber-500/10":"bg-surface-elevated/30 hover:bg-surface-elevated/50"}`,children:[e.jsx("input",{type:"checkbox",checked:d.has(v.id),onChange:()=>m(v.id),className:"rounded shrink-0"}),v.kind==="team"&&e.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:a("dataStorage.teamKind")}),e.jsx("span",{className:"text-fg-tertiary font-mono truncate min-w-0 flex-1",children:v.id}),e.jsx("span",{className:"text-fg-secondary tabular-nums shrink-0",children:n(v.size)}),e.jsx("button",{onClick:()=>{$.system.openPath(v.path)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary shrink-0 underline",children:a("common:open")})]},v.id))}),e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[d.size>0&&e.jsx("button",{disabled:u,onClick:()=>{U([...d])},className:"px-3 py-1.5 text-xs bg-amber-600 hover:bg-amber-500 text-white rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanSelected",{size:n(b)})}),e.jsx("button",{disabled:u,onClick:()=>{U()},className:"px-3 py-1.5 text-xs border border-amber-600/50 hover:bg-amber-600/10 text-amber-500 rounded-lg transition-colors disabled:opacity-50",children:u?a("dataStorage.cleaning"):a("dataStorage.cleanAll",{size:n(s.totalOrphanSize)})})]}),N&&e.jsx("div",{className:"text-xs text-fg-tertiary mt-2",children:N})]})}function Po(){const{t:s}=ge(["settings","common"]),[r,i]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState(!1),[c,u]=l.useState(null),[f,N]=l.useState(!1),M=Sn(),m=l.useCallback(async()=>{try{const P=await $.settings.getRemote();i(P)}catch{i(null)}finally{a(!1)}},[]);l.useEffect(()=>{m()},[m]),l.useEffect(()=>ga.on("remote:status",P=>{const g=P.payload;g&&(i(g),d(!1))}),[]);const y=async()=>{d(!0),u(null);try{r?.enabled?(await $.settings.disableRemote(),await m(),d(!1)):(Ve.isAuthenticated()||await Os(),await $.settings.enableRemote())}catch(P){u(String(P instanceof Error?P.message:P)),d(!1)}},k=async()=>{try{await Os(),await m()}catch{}},b=()=>{r?.remoteUrl&&(navigator.clipboard.writeText(r.remoteUrl),N(!0),setTimeout(()=>N(!1),2e3))},U=t||r?.enabled&&!r?.connected&&r?.state!=="idle",v=r?.remoteUrl??null;return e.jsx(Pe,{title:s("settings:remoteAccess.title"),children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-content-secondary",children:s("settings:remoteAccess.description")}),Ve.isAuthenticated()?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-content-secondary",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),s("settings:remoteAccess.signedInAs")," ",e.jsx("strong",{children:M?.username??M?.displayName})]}):e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-amber-500/10 border border-amber-500/20",children:[e.jsx("svg",{className:"w-5 h-5 text-amber-500 shrink-0",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),e.jsx("span",{className:"text-sm text-amber-600 dark:text-amber-400",children:s("settings:remoteAccess.loginRequired")}),e.jsx("button",{onClick:k,className:"ml-auto px-3 py-1.5 text-xs font-medium bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors",children:s("settings:remoteAccess.signIn")})]}),Ve.isAuthenticated()&&e.jsxs("div",{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("button",{onClick:y,disabled:t||n,className:`relative w-12 h-6 rounded-full transition-colors duration-200 ${r?.enabled?"bg-brand-600":"bg-gray-300 dark:bg-gray-600"} ${t||n?"opacity-50 cursor-not-allowed":"cursor-pointer"}`,children:e.jsx("span",{className:`block w-5 h-5 bg-white rounded-full shadow transform transition-transform duration-200 ${r?.enabled?"translate-x-6":"translate-x-0.5"}`})}),e.jsx("span",{className:"text-sm font-medium",children:U?s("settings:remoteAccess.connecting"):r?.enabled?s("settings:remoteAccess.enabled"):s("settings:remoteAccess.disabled")}),U&&e.jsx(kn,{})]}),r?.enabled&&e.jsxs("div",{className:`flex items-center gap-1.5 text-xs ${r.connected?"text-green-600 dark:text-green-400":r.state==="registering"||r.state==="connecting"?"text-blue-600 dark:text-blue-400":"text-amber-600 dark:text-amber-400"}`,children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${r.connected?"bg-green-500 animate-pulse":r.state==="registering"||r.state==="connecting"?"bg-blue-500 animate-pulse":"bg-amber-500"}`}),r.connected?s("settings:remoteAccess.connected"):r.state==="registering"?s("settings:remoteAccess.registering"):r.state==="connecting"?s("settings:remoteAccess.connecting"):s("settings:remoteAccess.disconnected"),r.connected&&r.peerCount>0&&e.jsxs(e.Fragment,{children:[" · ",s("settings:remoteAccess.peerCount",{count:r.peerCount})]}),(r.state==="registering"||r.state==="connecting")&&e.jsx(kn,{})]})]}),c&&e.jsx("div",{className:"p-2 rounded-lg bg-red-500/10 text-red-500 text-sm",children:c}),r?.enabled&&r.peers&&r.peers.length>0&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-2",children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.connectedPeers")}),e.jsx("div",{className:"space-y-2 mt-1",children:r.peers.map(P=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-surface-inset",children:[e.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${P.transport==="p2p"?"bg-green-500":P.transport==="relay"?"bg-blue-500":"bg-amber-500 animate-pulse"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-sm font-mono text-content-primary truncate",children:[P.peerId.slice(0,8),"..."]}),e.jsx("div",{className:"text-xs text-content-tertiary",children:s("settings:remoteAccess.connectedSince",{time:new Date(P.connectedAt).toLocaleTimeString()})})]}),e.jsx("span",{className:`px-2 py-0.5 text-xs font-medium rounded-full ${P.transport==="p2p"?"bg-green-500/10 text-green-600 dark:text-green-400":P.transport==="relay"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":"bg-amber-500/10 text-amber-600 dark:text-amber-400"}`,children:P.transport==="p2p"?"P2P":P.transport==="relay"?"Relay":s("settings:remoteAccess.peerConnecting")})]},P.peerId))})]}),r?.enabled&&r.remoteUrl&&e.jsxs("div",{className:"p-4 rounded-lg bg-surface-elevated border border-border-default space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.url")}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("code",{className:"flex-1 px-3 py-1.5 text-sm bg-surface-inset rounded font-mono truncate",children:r.remoteUrl}),e.jsx("button",{onClick:b,className:`px-2 py-1.5 text-xs border rounded transition-colors ${f?"border-green-500 text-green-600 dark:text-green-400":"border-border-default hover:bg-surface-elevated"}`,children:s(f?"settings:remoteAccess.copied":"settings:remoteAccess.copy")})]})]}),v&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-content-tertiary uppercase tracking-wider",children:s("settings:remoteAccess.qrCode")}),e.jsx("p",{className:"text-xs text-content-secondary mt-0.5 mb-2",children:s("settings:remoteAccess.scanQr")}),e.jsx(Ao,{url:v})]})]})]})]})})}function kn(){return e.jsxs("svg",{className:"w-4 h-4 animate-spin text-content-secondary",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function Ao({url:s}){const r=l.useRef(null),[i,n]=l.useState(!1);return l.useEffect(()=>{const a=r.current;a&&(n(!1),fa(()=>Promise.resolve().then(()=>Wa),void 0).then(t=>{t.toCanvas(a,s,{width:200,margin:2,color:{dark:"#000000",light:"#ffffff"},errorCorrectionLevel:"M"})}).catch(()=>n(!0)))},[s]),i?e.jsx("a",{href:s,target:"_blank",rel:"noopener",className:"text-sm text-brand-500 underline",children:s}):e.jsx("div",{className:"inline-block p-2 bg-white rounded-lg",children:e.jsx("canvas",{ref:r,className:"block",style:{width:160,height:160}})})}const Mo={multi_user:"👥",sso:"🔐",audit_enhanced:"📋",multi_instance:"🌐",offline_license:"📡"};function To({authUser:s}){const{t:r}=ge(["settings","common"]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-fg-primary mb-1",children:r("account.title")}),e.jsx("p",{className:"text-xs text-fg-tertiary",children:r("account.subtitle")})]}),e.jsx(Eo,{}),e.jsx(vo,{authUser:s})]})}function Eo(){const{t:s}=ge(["settings","common"]),[r,i]=l.useState(null),[n,a]=l.useState(!0),[t,d]=l.useState([]),[c,u]=l.useState([]),[f,N]=l.useState(null),[M,m]=l.useState(!0),[y,k]=l.useState(!1),[b,U]=l.useState(null),[v,P]=l.useState(!1),g=l.useCallback((A=!1)=>{m(!0),$.hubOrgs.mine().catch(z=>(A&&N({type:"err",text:z instanceof Error?z.message:s("org.loadFailed")}),{orgs:[]})).then(z=>{d(z.orgs),$.hubOrgs.invitations().then(J=>u(J.invitations)).catch(()=>{})}).finally(()=>m(!1))},[s]);l.useEffect(()=>{if(!Sn()&&!as()){m(!1),a(!1);return}g(),Ve.user.plan().then(A=>i(A)).catch(()=>{}).finally(()=>a(!1))},[g]);const j=l.useCallback((A=!1)=>{P(!0),(A?$.license.refresh():$.license.get()).then(J=>U(J)).catch(()=>{}).finally(()=>setTimeout(()=>P(!1),400))},[]);l.useEffect(()=>{j(!0)},[j]);const C=b?.plan==="enterprise",B=async A=>{try{await $.hubOrgs.acceptInvitation(A),u(z=>z.filter(J=>J.orgId!==A)),g()}catch(z){N({type:"err",text:z instanceof Error?z.message:"Failed"})}},I=b?.validUntil?Math.max(0,Math.ceil((new Date(b.validUntil).getTime()-Date.now())/864e5)):null,O=["multi_user","multi_instance"],K={multi_user:s("license.featureMultiUser"),multi_instance:s("license.featureMultiInstance")},_=t.find(A=>A.id===r?.orgId)??t[0],D=r?r.creditsBudgetCu??(r.monthlyQuotaCu??0)+(r.bonusCu??0)+(r.purchasedCu??0):0,F=!!(r?.memberCuLimit!=null&&r.memberCuLimit>0&&_&&_.role!=="owner"&&_.role!=="admin"&&_.memberCount>1),p=Math.round(F?r?.memberCuUsed??0:r?.totalConsumedThisPeriod??r?.cuUsed??0),S=F?r?.memberCuLimit??0:D;return M||n?e.jsx("div",{className:"text-center py-8 text-fg-tertiary text-sm",children:s("common:loading")}):e.jsxs("div",{className:"space-y-6",children:[f&&e.jsxs("div",{className:`flex items-center gap-2 text-sm px-4 py-3 rounded-lg ${f.type==="ok"?"bg-green-500/10 text-green-600 border border-green-500/20":"bg-red-500/10 text-red-500 border border-red-500/20"}`,children:[e.jsx("span",{children:f.type==="ok"?"✓":"✕"}),e.jsx("span",{children:f.text})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-3",children:s("account.cloudAiTitle")}),e.jsxs("div",{className:"rounded-lg border border-border-default bg-gradient-to-r from-brand-600/5 to-transparent px-5 py-4 space-y-3",children:[r?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-fg-tertiary",children:s("account.currentPlan")}),e.jsx("span",{className:"px-2 py-0.5 rounded text-xs font-semibold capitalize bg-brand-600/10 text-brand-500 border border-brand-500/15",children:r.planType})]}),S>0&&e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s(F?"account.personalLimit":"account.credits")}),e.jsxs("span",{className:"font-medium text-fg-primary tabular-nums",children:[p.toLocaleString()," / ",S.toLocaleString()]})]})]}):e.jsx("p",{className:"text-xs text-fg-secondary",children:s("license.cloudAiDesc")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs("a",{href:`${Ve.getUrl()}/settings?tab=billing`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-4 py-2 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors no-underline",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),s("account.manageBilling")]})})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider mb-3",children:s("account.orgSection")}),c.length>0&&e.jsx("div",{className:"space-y-2 mb-3",children:c.map(A=>e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 rounded-lg border border-amber-500/20 bg-amber-500/5",children:[e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"font-medium text-fg-primary",children:A.orgName}),e.jsxs("span",{className:"text-fg-tertiary ml-1",children:["— ",s("org.invitedBy")," ",A.invitedBy]})]}),e.jsx("button",{onClick:()=>{B(A.orgId)},className:"px-3 py-1.5 bg-brand-600 hover:bg-brand-500 text-white text-xs font-medium rounded-lg transition-colors",children:s("org.accept")})]},A.orgId))}),_?e.jsxs("div",{className:"rounded-lg border border-border-default px-5 py-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("org.nameLabel")}),e.jsx("span",{className:"font-medium text-fg-primary",children:_.name})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("account.memberCount")}),e.jsx("span",{className:"font-medium text-fg-primary",children:_.memberCount})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-fg-tertiary",children:s("org.orgId")}),e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-surface-elevated text-fg-secondary text-[11px]",children:_.id})]}),e.jsxs("a",{href:`${Ve.getUrl()}/settings?tab=organization`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 px-4 py-2 border border-border-default text-fg-secondary hover:bg-surface-elevated text-xs font-medium rounded-lg transition-colors no-underline",children:[e.jsx("svg",{className:"w-3.5 h-3.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}),s("account.manageOrg")]})]}):e.jsxs("div",{className:"rounded-lg border border-border-default px-5 py-6 text-center space-y-3",children:[e.jsx("div",{className:"text-sm text-fg-tertiary",children:s("org.noOrg")}),!!as()&&e.jsx("div",{className:"text-xs text-amber-500/90",children:s("org.staleSessionHint")}),e.jsxs("button",{disabled:y,onClick:()=>{N(null),k(!0),Os({force:!0}).then(()=>g(!0)).catch(A=>{const z=A instanceof Error?A.message:String(A),J=z.includes("Popup blocked")?s("org.popupBlocked"):z.includes("cancelled")?s("org.loginCancelled"):z;N({type:"err",text:J})}).finally(()=>k(!1))},className:"px-5 py-2.5 bg-brand-600 hover:bg-brand-500 disabled:opacity-60 text-white text-sm font-medium rounded-lg transition-colors inline-flex items-center gap-2",children:[y&&e.jsx("svg",{className:"w-4 h-4 animate-spin",viewBox:"0 0 24 24",fill:"none",children:e.jsx("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"3",strokeDasharray:"30 70",strokeLinecap:"round"})}),y?s("org.connecting"):as()?s("org.reconnectHub"):s("org.connectHub")]})]})]}),C&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-fg-secondary uppercase tracking-wider",children:s("license.title")}),e.jsxs("button",{onClick:()=>j(!0),disabled:v,className:"ml-auto flex items-center gap-1.5 text-xs text-fg-tertiary hover:text-fg-secondary disabled:opacity-50 transition-colors",children:[e.jsx("svg",{className:`w-3.5 h-3.5 ${v?"animate-spin":""}`,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 4v5h5M20 20v-5h-5M4.05 11A8 8 0 0119.95 9M19.95 13A8 8 0 014.05 15"})}),s("license.refresh")]})]}),e.jsx(Io,{isEnterprise:!0,licenseInfo:b,daysRemaining:I,effectiveValidUntil:b?.validUntil,effectiveMaxSeats:b?.maxSeats,effectiveUsedSeats:_?.memberCount??b?.usedSeats??0,effectiveOrgName:_?.name??b?.orgName,featureKeys:O,featureI18n:K,t:s})]}),e.jsxs("div",{className:"flex items-center gap-4 text-[11px] text-fg-tertiary pt-1",children:[e.jsx("a",{href:"https://markus.global",target:"_blank",rel:"noopener noreferrer",className:"hover:text-fg-secondary transition-colors",children:s("license.website")}),e.jsx("a",{href:`mailto:${s("license.salesEmail")}`,className:"hover:text-fg-secondary transition-colors",children:s("license.salesEmail")})]})]})}function Io({isEnterprise:s,licenseInfo:r,daysRemaining:i,effectiveValidUntil:n,effectiveMaxSeats:a,effectiveUsedSeats:t,effectiveOrgName:d,featureKeys:c,featureI18n:u,t:f}){return s?e.jsx("div",{className:"rounded-lg border border-brand-500/20 overflow-hidden",children:e.jsxs("div",{className:"px-5 py-4 bg-gradient-to-r from-brand-600/5 to-transparent",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-base font-semibold text-fg-primary",children:f("license.planEnterprise")}),e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-green-500/12 text-green-600 border border-green-500/15",children:f("license.statusActive")}),r?.isTrial&&e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] font-medium bg-amber-500/12 text-amber-600 border border-amber-500/15",children:f("license.trial")})]}),i!==null&&e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:`text-sm font-semibold tabular-nums ${i===0?"text-red-500":i<=7?"text-amber-500":i<=60?"text-amber-600":"text-fg-primary"}`,children:i>0?f("license.daysRemaining",{count:i}):f("license.expired")}),e.jsx("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:f("license.expiresOn",{date:new Date(n).toLocaleDateString()})})]})]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-1.5",children:c.map(N=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-[10px] font-medium text-brand-500 bg-brand-600/6 border border-brand-500/10",children:[Mo[N]," ",u[N]]},N))}),d&&e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-3 text-xs",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[e.jsx("span",{className:"text-fg-tertiary",children:f("license.organization")}),e.jsx("span",{className:"font-medium text-fg-primary",children:d})]}),a!=null&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg bg-surface-primary/40 border border-border-default/30",children:[e.jsx("span",{className:"text-fg-tertiary",children:f("license.seats")}),e.jsxs("span",{className:"font-medium text-fg-primary",children:[t," / ",a]})]})]})]})}):null}function Lo({modelId:s,tier:r}){const{t:i}=ge("settings");let n;if(r==="max"||r==="pro"||r==="base")n=r;else{const t=s.toLowerCase(),d=/opus|5\.4|o3-(?!mini)|o1-(?!mini)|gemini.*ultra|sonnet-4-20/,c=/haiku|flash|nano|lite|small|fast|free|8b|7b|1b|3b/;/o4-mini|o3-mini|o1-mini|gpt-4o-mini/.test(t)?n="pro":d.test(t)?n="max":c.test(t)?n="base":n="pro"}const a={max:"bg-purple-500/15 text-purple-400",pro:"bg-blue-500/15 text-blue-400",base:"bg-gray-500/15 text-gray-400"};return e.jsx("span",{className:`text-[9px] px-1 py-0.5 rounded font-semibold uppercase ${a[n]}`,children:i(`modelRouting.tier.${n}`)})}export{Do as Settings};