import{u as V,r as o,j as e}from"./index-CHN8jahE.js";import{u as I,a as L,b as A,c as D}from"./use-profiles-C1vlPE-2.js";import{B as N}from"./button-BWFTEdOr.js";import{P as M,T,M as U}from"./modal-D_AU4URz.js";import{P as z}from"./pencil-BMxBxIhw.js";import"./utils-CkSf8FUe.js";function B(s){return Object.entries(s).map(([c,u])=>`${c}: ${JSON.stringify(u)}`).join(", ")}const g={CLAUDE_CODE:"Claude Code",GEMINI_CLI:"Gemini CLI",CURSOR_AGENT:"Cursor Agent"};function H(){const{t:s}=V(),{data:c,isLoading:u}=I(),{data:v}=L(),d=A(),C=D(),[a,l]=o.useState(null),[f,x]=o.useState(""),[m,p]=o.useState(""),[h,i]=o.useState(""),S=(t,n,r)=>{l({agentType:t,variant:n,config:r,isNew:!1}),p(n),x(JSON.stringify(r,null,2)),i("")},y=t=>{l({agentType:t,variant:"",config:{},isNew:!0}),p(""),x(`{
  
}`),i("")},E=()=>{if(!(!a||!m.trim()))try{const t=JSON.parse(f);i(""),d.mutate({agentType:a.agentType,variant:m.trim().toUpperCase(),config:t},{onSuccess:()=>l(null)})}catch{i(s("JSON 格式错误"))}},w=(t,n)=>{confirm(s("确定删除 {agentType} / {variant}？",{agentType:t,variant:n}))&&C.mutate({agentType:t,variant:n})},O=(t,n)=>!!v?.executors[t]?.[n];if(u)return e.jsx("div",{className:"p-6 text-sm text-neutral-400",children:s("加载中...")});const P=c?.executors??{};return e.jsxs("div",{className:"px-10 py-6 mx-auto w-full max-w-3xl",children:[Object.entries(P).map(([t,n])=>e.jsxs("div",{className:"mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-[13px] font-semibold text-neutral-900",children:g[t]??t}),e.jsxs("button",{onClick:()=>y(t),className:"flex items-center gap-1 text-xs text-neutral-400 hover:text-neutral-900 transition-colors",children:[e.jsx(M,{size:12}),e.jsx("span",{children:s("新增")})]})]}),e.jsx("div",{className:"border border-neutral-100 rounded-lg overflow-hidden",children:Object.entries(n).map(([r,b],k,J)=>{const j=O(t,r);return e.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 hover:bg-neutral-50 transition-colors group ${k<J.length-1?"border-b border-neutral-100":""}`,children:[e.jsx("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-[11px] font-semibold tracking-wide ${r==="DEFAULT"?"bg-blue-50 text-blue-600":"bg-neutral-50 text-neutral-600"}`,children:r}),e.jsx("span",{className:"flex-1 text-[12px] text-neutral-400 font-mono truncate",children:B(b)}),j&&e.jsx("span",{className:"text-[11px] text-neutral-300 font-medium",children:s("内置")}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx("button",{onClick:()=>S(t,r,b),className:"p-1 text-neutral-300 hover:text-neutral-700 rounded transition-colors",children:e.jsx(z,{size:13})}),!j&&e.jsx("button",{onClick:()=>w(t,r),className:"p-1 text-neutral-300 hover:text-red-500 rounded transition-colors",children:e.jsx(T,{size:13})})]})]},r)})})]},t)),e.jsx(U,{isOpen:!!a,onClose:()=>l(null),title:a?.isNew?s("新增 Variant — {agentType}",{agentType:g[a.agentType]??a.agentType}):s("编辑 {variant}",{variant:a?.variant??""}),action:e.jsxs(e.Fragment,{children:[e.jsx(N,{variant:"outline",onClick:()=>l(null),children:s("取消")}),e.jsx(N,{onClick:E,disabled:d.isPending,children:d.isPending?s("保存中..."):s("保存")})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-[13px] font-medium text-neutral-700 mb-1",children:s("Variant 名称")}),e.jsx("input",{type:"text",value:m,onChange:t=>p(t.target.value),disabled:!a?.isNew,placeholder:s("例如: CUSTOM"),className:"w-full px-3 py-2 border border-neutral-200 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-neutral-300 disabled:bg-neutral-50 disabled:text-neutral-500 font-mono"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-[13px] font-medium text-neutral-700 mb-1",children:s("配置 (JSON)")}),e.jsx("textarea",{value:f,onChange:t=>{x(t.target.value),i("")},rows:6,className:"w-full px-3 py-2 border border-neutral-200 rounded-lg text-sm font-mono focus:outline-none focus:ring-1 focus:ring-neutral-300 resize-none"}),h&&e.jsx("p",{className:"mt-1 text-xs text-red-500",children:h})]})]})})]})}export{H as ProfileSettingsPage};
