import{c as w,u as I,j as e,r as y,d as O,t as k,E as be,S as ve}from"./index-qMrAuFFG.js";import{B as M,I as N,S as le,a as oe,b as ie,c as ce,d as de,L as Ne,P as we,e as Se,f as Ce}from"./loading-PETOxw4W.js";import{D as ke,a as Me,E as Ie,b as Be,c as Y,T as Fe,d as Ee,e as Le,f as G,g as W,h as Ke,i as J,P as Z}from"./table-BTToAg72.js";import{C as Te,u as T,F as b,K as me,k as _e,R as Ue,M as qe,a as Oe,L as Pe,m as Re,o as $e,b as u,B as P}from"./badge-BOFxe4_3.js";import{c as $,u as Ae,C as He,a as Ve,b as ze,d as Ye,e as Ge}from"./queries-B0q6a4VE.js";import{C as R,a as We}from"./clock-Dmcvs345.js";import{F as Je}from"./folder-DSkD5gAR.js";import{H as Q,D as X,a as D,b as ee,c as se,d as te}from"./dialog-DlDaQf4g.js";/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ze=[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]],Qe=w("Cloud",Ze);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Xe=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],De=w("Copy",Xe);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const es=[["rect",{width:"16",height:"16",x:"4",y:"4",rx:"2",key:"14l7u7"}],["rect",{width:"6",height:"6",x:"9",y:"9",rx:"1",key:"5aljv4"}],["path",{d:"M15 2v2",key:"13l42r"}],["path",{d:"M15 20v2",key:"15mkzm"}],["path",{d:"M2 15h2",key:"1gxd5l"}],["path",{d:"M2 9h2",key:"1bbxkp"}],["path",{d:"M20 15h2",key:"19e6y8"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M9 2v2",key:"165o2o"}],["path",{d:"M9 20v2",key:"i2bqo8"}]],ss=w("Cpu",es);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ts=[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]],ne=w("Database",ts);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ns=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M8 12h8",key:"1wcyev"}],["path",{d:"M10 11v2",key:"1s651w"}],["path",{d:"M8 17h8",key:"wh5c61"}],["path",{d:"M14 16v2",key:"12fp5e"}]],as=w("FileSliders",ns);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const rs=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]],ls=w("Info",rs);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const os=[["path",{d:"m5 8 6 6",key:"1wu5hv"}],["path",{d:"m4 14 6-6 2-3",key:"1k1g8d"}],["path",{d:"M2 5h12",key:"or177f"}],["path",{d:"M7 2h1",key:"1t2jsx"}],["path",{d:"m22 22-5-10-5 10",key:"don7ne"}],["path",{d:"M14 18h6",key:"1m8k6r"}]],is=w("Languages",os);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const cs=[["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"m15.2 4.9-.9-.4",key:"12wd2u"}],["path",{d:"m15.2 7.1-.9.4",key:"1r2vl7"}],["path",{d:"m16.9 3.2-.4-.9",key:"3zbo91"}],["path",{d:"m16.9 8.8-.4.9",key:"1qr2dn"}],["path",{d:"m19.5 2.3-.4.9",key:"1rjrkq"}],["path",{d:"m19.5 9.7-.4-.9",key:"heryx5"}],["path",{d:"m21.7 4.5-.9.4",key:"17fqt1"}],["path",{d:"m21.7 7.5-.9-.4",key:"14zyni"}],["path",{d:"M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7",key:"1tnzv8"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}]],ds=w("MonitorCog",cs);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ms=[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]],hs=w("Monitor",ms);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const us=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],ae=w("Server",us);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const gs=[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]],xs=w("SquarePen",gs);function ps({columns:r,configData:t,showActions:i=!0,onDelete:h,onEdit:a}){const{t:g,i18n:s}=I(),l=s.resolvedLanguage??s.language??"en-US",f=o=>new Date(o).toLocaleString(l),x=(o,c)=>{let m;try{typeof o=="string"?m=JSON.parse(o):m=o}catch(S){console.error(S),m=o}const d=c.key;return c.render?c.render(m):d==="created_at"?f(m==null?void 0:m[d]):(m==null?void 0:m[d])||"-"};return e.jsx("div",{className:"space-y-4",children:t.map(o=>{const c=r;return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-sm border overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-4 py-3 bg-gray-50 border-b border-gray-200",children:[e.jsxs("h3",{className:"text-sm font-medium text-gray-900",children:[o.name,e.jsx("span",{className:"ml-2 text-gray-500",children:g("settings.tables.createdAt",{date:f(o.created_at)})})]}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("span",{className:"text-gray-500",children:g("settings.tables.idLabel")}),e.jsx("span",{className:"ml-2 font-medium",children:g("settings.tables.idValue",{id:o.id})}),i&&e.jsxs(ke,{children:[e.jsx(Me,{asChild:!0,children:e.jsx(M,{className:"ml-2",variant:"outline",size:"sm",children:e.jsx(Ie,{className:"w-4 h-4"})})}),e.jsxs(Be,{align:"end",children:[e.jsxs(Y,{onClick:()=>a==null?void 0:a(o),children:[e.jsx(xs,{className:"w-4 h-4 mr-2"}),g("common.edit")]}),e.jsxs(Y,{className:"text-red-600",onClick:()=>h==null?void 0:h(o.id),children:[e.jsx(Fe,{className:"w-4 h-4 mr-2"}),g("common.delete")]})]})]})]})]}),e.jsxs(Ee,{children:[e.jsx(Le,{children:e.jsxs(G,{children:[e.jsx(W,{children:g("common.field")}),e.jsx(W,{children:g("common.value")})]})}),e.jsx(Ke,{children:c.map(m=>e.jsxs(G,{children:[e.jsx(J,{className:"font-medium",children:m.label}),e.jsx(J,{children:x(o.value,m)})]},m.key))})]})]})},o.id)})})}function ys({className:r,...t}){return e.jsx("textarea",{"data-slot":"textarea",className:$("border-input placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 flex field-sizing-content min-h-16 w-full rounded-md border bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",r),...t})}function fs(r=6){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let i="";for(let h=0;h<r;h++)i+=t.charAt(Math.floor(Math.random()*t.length));return i}function E(r,t){const i=t||Te[r]||"config",h=fs(6);return`${i}_${h}`}const _={mineru:r=>E("mineru",r),knowledgeBase:r=>E("knowledge_base",r),s3:r=>E("s3",r),system:r=>E("system",r),custom:r=>E("custom",r)};function js({onSubmit:r,initialData:t={},disabled:i=!1,isLoading:h=!1,placeholder:a,description:g}){const{t:s}=I(),l=a??s("settings.forms.json.placeholder"),f=g??s("settings.forms.json.configHelp"),x=T({defaultValues:{name:t.name||_.custom(s("settings.forms.json.defaultName")),config:t.config||""},onSubmit:({value:c})=>{r(c)}}),o=()=>{const c=x.getFieldValue("config");if(c.trim())try{const m=JSON.parse(c),d=JSON.stringify(m,null,2);x.setFieldValue("config",d)}catch(m){console.error(m)}};return e.jsxs("form",{onSubmit:c=>{c.preventDefault(),x.handleSubmit()},className:"space-y-4",children:[e.jsx(x.Field,{name:"name",validators:{onChange:({value:c})=>!c||c.trim().length===0?s("settings.forms.common.nameRequired"):void 0},children:c=>e.jsx(b,{label:s("settings.forms.common.nameLabel"),htmlFor:"name",required:!0,error:c.state.meta.errors[0],children:e.jsx(N,{id:"name",placeholder:s("settings.forms.json.namePlaceholder"),value:c.state.value,onChange:m=>c.handleChange(m.target.value),onBlur:c.handleBlur,disabled:i})})}),e.jsx(x.Field,{name:"config",validators:{onChange:({value:c})=>{if(c.trim())try{JSON.parse(c);return}catch{return s("settings.forms.json.configInvalid")}}},children:c=>e.jsx(b,{label:s("settings.forms.json.configLabel"),htmlFor:"config",error:c.state.meta.errors[0],help:f,children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:o,disabled:i,className:"text-xs text-blue-600 hover:text-blue-800 disabled:text-gray-400",children:s("settings.forms.json.formatButton")})}),e.jsx(ys,{id:"config",placeholder:l,value:c.state.value,onChange:m=>c.handleChange(m.target.value),onBlur:c.handleBlur,rows:15,className:"font-mono text-sm",disabled:i})]})})}),e.jsx("div",{className:"flex justify-end pt-4",children:e.jsx(M,{type:"submit",disabled:i||h,className:"min-w-24",children:s(h?"settings.forms.common.saving":"settings.forms.common.save")})})]})}function bs({onSubmit:r,initialData:t,disabled:i=!1,isLoading:h=!1}){const{t:a}=I(),g=(t==null?void 0:t.type)??"ragflow",[s,l]=y.useState(g),f=T({defaultValues:{name:(t==null?void 0:t.name)||_.knowledgeBase(a("settings.forms.knowledgeBase.defaultName")),type:"ragflow",...t},onSubmit:({value:o})=>{try{const m=_e[o.type].parse(o);r(m)}catch(c){console.error(a("settings.forms.knowledgeBase.validationFailed"),c)}}}),x=()=>e.jsxs(e.Fragment,{children:[e.jsx(f.Field,{name:"baseUrl",children:o=>e.jsx(b,{label:a("settings.forms.knowledgeBase.baseUrlLabel"),htmlFor:"baseUrl",error:o.state.meta.errors[0],required:!0,children:e.jsx(N,{id:"baseUrl",type:"url",placeholder:a("settings.forms.knowledgeBase.baseUrlPlaceholder"),value:o.state.value||"",onChange:c=>o.handleChange(c.target.value),onBlur:o.handleBlur,disabled:i})})}),e.jsx(f.Field,{name:"apiKey",children:o=>e.jsx(b,{label:a("settings.forms.knowledgeBase.apiKeyLabel"),htmlFor:"apiKey",error:o.state.meta.errors[0],required:!0,children:e.jsx(N,{id:"apiKey",type:"password",placeholder:a("settings.forms.knowledgeBase.apiKeyPlaceholder"),value:o.state.value||"",onChange:c=>o.handleChange(c.target.value),onBlur:o.handleBlur,disabled:i})})})]});return e.jsxs("form",{onSubmit:o=>{o.preventDefault(),f.handleSubmit()},className:"space-y-4",children:[e.jsx(f.Field,{name:"name",validators:{onChange:({value:o})=>!o||o.trim().length===0?a("settings.forms.common.nameRequired"):void 0},children:o=>{var c;return e.jsx(b,{label:a("settings.forms.common.nameLabel"),error:(c=o.state.meta.errors)==null?void 0:c[0],required:!0,htmlFor:"name",children:e.jsx(N,{id:"name",placeholder:a("settings.forms.common.namePlaceholder"),value:o.state.value,onChange:m=>o.handleChange(m.target.value),onBlur:o.handleBlur,disabled:i})})}}),e.jsx(f.Field,{name:"type",validators:{onChange:({value:o})=>!o||o.trim().length===0?a("settings.forms.knowledgeBase.typeRequired"):void 0},children:o=>{var c;return e.jsx(b,{label:a("settings.forms.knowledgeBase.typeLabel"),required:!0,error:(c=o.state.meta.errors)==null?void 0:c[0],htmlFor:"type",children:e.jsxs(le,{value:o.state.value,onValueChange:m=>{o.handleChange(m),l(m)},disabled:i,children:[e.jsx(oe,{children:e.jsx(ie,{placeholder:a("settings.forms.knowledgeBase.typePlaceholder")})}),e.jsx(ce,{children:Object.keys(me).map(m=>e.jsx(de,{value:m,children:a(`settings.forms.knowledgeBase.subtypes.${m}`)},m))})]})})}}),x(),e.jsx("div",{className:"flex justify-end pt-4",children:e.jsx(M,{type:"submit",disabled:i||h,className:"min-w-24",children:a(h?"settings.forms.common.saving":"settings.forms.common.save")})})]})}function vs({onSubmit:r,initialData:t={},disabled:i=!1,isLoading:h=!1}){const{t:a}=I(),g=T({defaultValues:{name:t.name||_.mineru(a("settings.forms.mineru.defaultName")),baseUrl:"https://mineru.net",apiKey:"",type:"saas",...t},onSubmit:({value:s})=>{try{const l=Re.parse(s);r(l)}catch(l){console.error(a("settings.forms.mineru.validationFailed"),l)}}});return e.jsxs("form",{onSubmit:s=>{s.preventDefault(),g.handleSubmit()},className:"space-y-4",children:[e.jsx(g.Field,{name:"name",validators:{onChange:({value:s})=>!s||s.trim().length===0?a("settings.forms.common.nameRequired"):void 0},children:s=>e.jsx(b,{label:a("settings.forms.common.nameLabel"),htmlFor:"name",required:!0,error:s.state.meta.errors[0],children:e.jsx(N,{id:"name",placeholder:a("settings.forms.mineru.namePlaceholder"),value:s.state.value,onChange:l=>s.handleChange(l.target.value),onBlur:s.handleBlur,disabled:i})})}),e.jsx(g.Field,{name:"type",children:s=>e.jsx(b,{label:a("settings.forms.mineru.typeLabel"),htmlFor:"type",required:!0,error:s.state.meta.errors[0],help:a("settings.forms.mineru.typeHelp"),children:e.jsx(Ue,{value:s.state.value,onValueChange:l=>s.handleChange(l),disabled:i,className:"flex items-center space-x-6 mt-2",children:Object.values(qe).map(l=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Oe,{value:l,id:`type-${l}`}),e.jsx(Pe,{htmlFor:`type-${l}`,children:a(`settings.forms.mineru.types.${l}`)})]},l))})})}),e.jsx(g.Field,{name:"baseUrl",validators:{onChange:({value:s})=>{if(!s||s.trim().length===0)return a("settings.forms.mineru.baseUrlRequired");try{new URL(s);return}catch{return a("settings.forms.mineru.baseUrlInvalid")}}},children:s=>e.jsx(b,{label:a("settings.forms.mineru.baseUrlLabel"),htmlFor:"baseUrl",required:!0,error:s.state.meta.errors[0],help:a("settings.forms.mineru.baseUrlHelp"),children:e.jsx(N,{id:"baseUrl",type:"url",placeholder:a("settings.forms.mineru.baseUrlPlaceholder"),value:s.state.value,onChange:l=>s.handleChange(l.target.value),onBlur:s.handleBlur,disabled:i})})}),e.jsx(g.Subscribe,{selector:s=>s.values.type,children:s=>e.jsx(g.Field,{name:"apiKey",validators:{onChange:({value:l})=>{if(g.state.values.type!=="selfhost")return!l||l.trim().length===0?a("settings.forms.mineru.apiKeyRequired"):void 0}},children:l=>e.jsx(b,{label:a("settings.forms.mineru.apiKeyLabel"),htmlFor:"apiKey",required:s==="saas",error:l.state.meta.errors[0],help:e.jsxs("div",{children:[a("settings.forms.mineru.apiKeyHelp.prefix"),e.jsx("a",{href:"https://mineru.net/apiManage/docs",target:"_blank",rel:"noreferrer",className:"text-blue-500",children:a("settings.forms.mineru.apiKeyHelp.link")}),a("settings.forms.mineru.apiKeyHelp.suffix")]}),children:e.jsx(N,{id:"apiKey",type:"password",placeholder:a("settings.forms.mineru.apiKeyPlaceholder"),value:l.state.value,onChange:f=>l.handleChange(f.target.value),onBlur:l.handleBlur,disabled:i})})})}),e.jsx("div",{className:"flex justify-end pt-4",children:e.jsx(M,{type:"submit",disabled:i||h,className:"min-w-24",children:a(h?"settings.forms.common.saving":"settings.forms.common.save")})})]})}function Ns({onSubmit:r,initialData:t={},disabled:i=!1,isLoading:h=!1}){const{t:a}=I(),g=T({defaultValues:{name:t.name||_.s3(a("settings.forms.oss.defaultName")),accessKeyId:"",secretKeyId:"",endpoint:"",...t},onSubmit:({value:s})=>{try{const l=$e.parse(s);r(l)}catch(l){console.error(a("settings.forms.oss.validationFailed"),l)}}});return e.jsxs("form",{onSubmit:s=>{s.preventDefault(),g.handleSubmit()},className:"space-y-4",children:[e.jsx(g.Field,{name:"name",validators:{onChange:({value:s})=>!s||s.trim().length===0?a("settings.forms.common.nameRequired"):void 0},children:s=>e.jsx(b,{label:a("settings.forms.common.nameLabel"),htmlFor:"name",required:!0,error:s.state.meta.errors[0],children:e.jsx(N,{id:"name",placeholder:a("settings.forms.oss.namePlaceholder"),value:s.state.value,onChange:l=>s.handleChange(l.target.value),onBlur:s.handleBlur,disabled:i})})}),e.jsx(g.Field,{name:"accessKeyId",validators:{onChange:({value:s})=>!s||s.trim().length===0?a("settings.forms.oss.accessKeyIdRequired"):void 0},children:s=>e.jsx(b,{label:a("settings.forms.oss.accessKeyIdLabel"),htmlFor:"accessKeyId",required:!0,error:s.state.meta.errors[0],help:a("settings.forms.oss.accessKeyIdHelp"),children:e.jsx(N,{id:"accessKeyId",placeholder:a("settings.forms.oss.accessKeyIdPlaceholder"),value:s.state.value,onChange:l=>s.handleChange(l.target.value),onBlur:s.handleBlur,disabled:i})})}),e.jsx(g.Field,{name:"secretKeyId",validators:{onChange:({value:s})=>!s||s.trim().length===0?a("settings.forms.oss.secretKeyIdRequired"):void 0},children:s=>e.jsx(b,{label:a("settings.forms.oss.secretKeyIdLabel"),htmlFor:"secretKeyId",required:!0,error:s.state.meta.errors[0],help:a("settings.forms.oss.secretKeyIdHelp"),children:e.jsx(N,{id:"secretKeyId",type:"password",placeholder:a("settings.forms.oss.secretKeyIdPlaceholder"),value:s.state.value,onChange:l=>s.handleChange(l.target.value),onBlur:s.handleBlur,disabled:i})})}),e.jsx(g.Field,{name:"endpoint",validators:{onChange:({value:s})=>{if(!s||s.trim().length===0)return a("settings.forms.oss.endpointRequired");try{new URL(s);return}catch{return a("settings.forms.oss.endpointInvalid")}}},children:s=>e.jsx(b,{label:a("settings.forms.oss.endpointLabel"),htmlFor:"endpoint",required:!0,error:s.state.meta.errors[0],help:a("settings.forms.oss.endpointHelp"),children:e.jsx(N,{id:"endpoint",type:"url",placeholder:a("settings.forms.oss.endpointPlaceholder"),value:s.state.value,onChange:l=>s.handleChange(l.target.value),onBlur:s.handleBlur,disabled:i})})}),e.jsx("div",{className:"flex justify-end pt-4",children:e.jsx(M,{type:"submit",disabled:i||h,className:"min-w-24",children:a(h?"settings.forms.common.saving":"settings.forms.common.save")})})]})}function re({configType:r,onSubmit:t,initialData:i,disabled:h=!1,isLoading:a=!1}){const{t:g}=I(),s=l=>({name:f,...x})=>{t({name:f,type:l,value:r==="system"?x.value:r==="custom"?x.config:x})};switch(r){case u.KNOWLEDGE_BASE:return e.jsx(bs,{onSubmit:s(u.KNOWLEDGE_BASE),initialData:i,disabled:h,isLoading:a});case u.MINERU:return e.jsx(vs,{onSubmit:s(u.MINERU),initialData:i,disabled:h,isLoading:a});case u.S3:return e.jsx(Ns,{onSubmit:s(u.S3),initialData:i,disabled:h,isLoading:a});case u.SYSTEM:case u.CUSTOM:default:return e.jsx(js,{onSubmit:s(u.CUSTOM),initialData:i,disabled:h,isLoading:a,placeholder:g("settings.forms.json.placeholder"),description:g("settings.forms.json.description")})}}const v=({label:r,value:t,formatter:i,copyable:h=!1,icon:a,onCopy:g,copyLabel:s})=>{const l=i(t);return e.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-gray-100 last:border-b-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[a&&e.jsx("div",{className:"text-gray-500",children:a}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:r})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"text-sm text-gray-900 text-right max-w-xs truncate font-mono",children:l}),h&&e.jsx(M,{type:"button",variant:"outline",size:"sm",title:s,onClick:()=>g==null?void 0:g(String(t),r),children:e.jsx(De,{className:"w-2 h-2"})})]})]})};function ws({className:r}){const{t,i18n:i}=I(),{data:h,isLoading:a}=Ae(),[g,s]=y.useState(i.resolvedLanguage??i.language??O[0]),l=i.resolvedLanguage??i.language??"en-US",f=y.useMemo(()=>O.map(d=>({value:d,label:t(`settings.general.language.options.${d}`)})),[t]),x=y.useMemo(()=>({time:d=>new Date(d).toLocaleString(l),duration:d=>{const S=Math.floor(d/86400),j=Math.floor(d%86400/3600),C=Math.floor(d%3600/60),L=Math.floor(d%60);return S>0?t("settings.systemInfo.duration.days",{days:S,hours:j,minutes:C}):j>0?t("settings.systemInfo.duration.hours",{hours:j,minutes:C}):C>0?t("settings.systemInfo.duration.minutes",{minutes:C,seconds:L}):t("settings.systemInfo.duration.seconds",{seconds:L})},memory:d=>{const S=["B","KB","MB","GB"];if(d===0)return"0 B";const j=Math.floor(Math.log(d)/Math.log(1024));return`${(d/1024**j).toFixed(2)} ${S[j]}`},path:d=>d,text:d=>String(d),status:d=>t(`settings.systemInfo.status.${d}`,{defaultValue:d}),component:d=>d}),[l,t]),o=y.useCallback(async(d,S)=>{try{await navigator.clipboard.writeText(d),k.success(t("settings.systemInfo.copySuccess",{label:S??t("settings.systemInfo.copyDefaultLabel")}))}catch(j){console.error("Copy failed:",j),k.error(t("settings.systemInfo.copyFailed"))}},[t]);y.useEffect(()=>{const d=i.resolvedLanguage??i.language??O[0];s(d)},[i.language,i.resolvedLanguage]);const c=y.useCallback(d=>{s(d),be(d),k.success(t("settings.general.language.toast",{language:t(`settings.general.language.options.${d}`)}))},[t]),m=t("settings.systemInfo.copyButton");return h?e.jsx(Ne,{loading:a,loadingText:t("settings.systemInfo.refreshing"),children:e.jsxs("div",{className:$("space-y-6",r),children:[e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(ds,{className:"h-5 w-5"}),t("settings.systemInfo.sections.display")]}),e.jsx("div",{className:"space-y-1",children:e.jsx(v,{label:t("settings.systemInfo.fields.language"),value:e.jsxs(le,{value:g,onValueChange:d=>c(d),children:[e.jsx(oe,{size:"sm",children:e.jsx(ie,{placeholder:t("common.select")})}),e.jsx(ce,{children:f.map(d=>e.jsx(de,{value:d.value,children:d.label},d.value))})]}),formatter:x.component,copyLabel:m,icon:e.jsx(is,{className:"h-4 w-4"})})})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(ls,{className:"h-5 w-5"}),t("settings.systemInfo.sections.general")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{label:t("settings.systemInfo.fields.version"),value:h.version,formatter:x.text,copyable:!0,copyLabel:m,onCopy:o,icon:e.jsx(ae,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.environment"),value:h.environment,formatter:x.text,icon:e.jsx(hs,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.platform"),value:h.platform,formatter:x.text,icon:e.jsx(ss,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.pythonVersion"),value:h.pythonVersion,formatter:x.text,copyable:!0,copyLabel:m,onCopy:o,icon:e.jsx(ne,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.pid"),value:h.pid,formatter:x.text,icon:e.jsx(ae,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(R,{className:"h-5 w-5"}),t("settings.systemInfo.sections.runtime")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{label:t("settings.systemInfo.fields.startTime"),value:h.startTime,formatter:x.time,icon:e.jsx(R,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.uptime"),value:h.uptime,formatter:x.duration,icon:e.jsx(R,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.status"),value:h.status,formatter:x.status,icon:e.jsx(We,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg p-6",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 mb-4 flex items-center gap-2",children:[e.jsx(Je,{className:"h-5 w-5"}),t("settings.systemInfo.sections.paths")]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(v,{label:t("settings.systemInfo.fields.mediaDir"),value:h.mediaDir,formatter:x.path,copyable:!0,copyLabel:m,onCopy:o,icon:e.jsx(Q,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.cacheDir"),value:h.cacheDir,formatter:x.path,copyable:!0,copyLabel:m,onCopy:o,icon:e.jsx(Q,{className:"h-4 w-4"})}),e.jsx(v,{label:t("settings.systemInfo.fields.databasePath"),value:h.databasePath,formatter:x.path,copyable:!0,copyLabel:m,onCopy:o,icon:e.jsx(ne,{className:"h-4 w-4"})})]})]})]})}):e.jsx("div",{className:$("space-y-6",r),children:e.jsxs("div",{className:"flex items-center justify-center py-8",children:[e.jsx(He,{className:"h-6 w-6 text-red-400"}),e.jsx("span",{className:"ml-2 text-red-500",children:t("settings.systemInfo.fetchError")})]})})}const Ss={[u.MINERU]:e.jsx(Ce,{className:"w-5 h-5"}),[u.KNOWLEDGE_BASE]:e.jsx(Se,{className:"w-5 h-5"}),[u.S3]:e.jsx(Qe,{className:"w-5 h-5"}),[u.SYSTEM]:e.jsx(ve,{className:"w-5 h-5"}),[u.CUSTOM]:e.jsx(as,{className:"w-5 h-5"})};function Ks(){const{t:r}=I(),[t,i]=y.useState(u.SYSTEM),[h,a]=y.useState(!1),[g,s]=y.useState(!1),[l,f]=y.useState(null),x=y.useMemo(()=>({[u.SYSTEM]:r("settings.configTypes.system.label"),[u.KNOWLEDGE_BASE]:r("settings.configTypes.knowledge_base.label"),[u.MINERU]:r("settings.configTypes.mineru.label"),[u.S3]:r("settings.configTypes.s3.label"),[u.CUSTOM]:r("settings.configTypes.custom.label")}),[r]),o=y.useMemo(()=>({[u.SYSTEM]:r("settings.configTypes.system.description"),[u.KNOWLEDGE_BASE]:r("settings.configTypes.knowledge_base.description"),[u.MINERU]:r("settings.configTypes.mineru.description"),[u.S3]:r("settings.configTypes.s3.description"),[u.CUSTOM]:r("settings.configTypes.custom.description")}),[r]),c=y.useMemo(()=>[{key:"type",label:r("settings.knowledgeBase.columns.type"),render:n=>{const p=n==null?void 0:n.type;return p?e.jsx("span",{className:"inline-flex px-2 py-1 text-xs font-semibold rounded-full bg-blue-100 text-blue-800",children:me[p]||p}):"-"}}],[r]),m=y.useMemo(()=>({ragflow:[...c,{key:"baseUrl",label:r("settings.knowledgeBase.columns.baseUrl"),render:n=>(n==null?void 0:n.baseUrl)||"-"},{key:"apiKey",label:r("settings.knowledgeBase.columns.apiKey"),render:n=>n!=null&&n.apiKey?"••••••••":"-"}]}),[c,r]),d=y.useMemo(()=>({[u.SYSTEM]:[],[u.KNOWLEDGE_BASE]:[],[u.MINERU]:[{key:"baseUrl",label:"Base URL"},{key:"type",label:r("settings.mineru.columns.type"),render:n=>{const p=n==null?void 0:n.type;return p==="selfhost"?e.jsx(P,{className:"bg-yellow-100 text-yellow-800",children:r("tasks.detail.mineru.badges.selfhost")}):p==="saas"?e.jsx(P,{className:"bg-green-100 text-green-800",children:r("tasks.detail.mineru.badges.saas")}):"-"}},{key:"apiKey",label:r("settings.mineru.columns.apiKey"),render:n=>n!=null&&n.apiKey?"••••••••":"-"}],[u.S3]:[{key:"accessKeyId",label:"Access Key ID",render:n=>{const p=n==null?void 0:n.accessKeyId;return p?`${p.substring(0,8)}••••••••`:"-"}},{key:"secretKeyId",label:"Secret Key ID",render:n=>n!=null&&n.secretKeyId?"••••••••":"-"},{key:"endpoint",label:"Endpoint",render:n=>(n==null?void 0:n.endpoint)||"-"},{key:"region",label:r("settings.s3.columns.region"),render:n=>(n==null?void 0:n.region)||"-"}],[u.CUSTOM]:[{key:"raw",label:r("settings.custom.columns.raw"),render:n=>e.jsx("div",{className:"max-w-md",children:e.jsx("pre",{className:"text-xs text-gray-600 whitespace-pre-wrap overflow-hidden",children:JSON.stringify(n,null,2)})})}]}),[r]),S=y.useCallback(n=>{const p=n==null?void 0:n.type;return m[p]??c},[m,c]),j=y.useCallback(n=>x[n]??n,[x]);y.useEffect(()=>{const n=()=>{const p=window.location.hash.slice(1);p&&Object.values(u).includes(p)?i(p):(i(u.SYSTEM),window.location.hash||(window.location.hash=u.SYSTEM))};return n(),window.addEventListener("hashchange",n),()=>window.removeEventListener("hashchange",n)},[]);const{data:C,isLoading:L}=Ve({}),A=ze(),H=Ye(),he=Ge(),ue=async({name:n,type:p,value:K})=>{try{await A.mutateAsync({name:n,type:p,value:K}),a(!1),k.success(r("settings.toasts.createSuccess"))}catch(q){console.error("Failed to create configuration:",q),k.error(r("settings.toasts.createFailed"))}},ge=async n=>{if(l)try{await H.mutateAsync({id:l.id,data:n}),s(!1),f(null),k.success(r("settings.toasts.updateSuccess"))}catch(p){console.error("Failed to update configuration:",p),k.error(r("settings.toasts.updateFailed"))}},xe=n=>{f(n),s(!0)},pe=async n=>{if(confirm(r("settings.confirmDelete")))try{await he.mutateAsync(n),k.success(r("settings.toasts.deleteSuccess"))}catch(p){console.error("Failed to delete configuration:",p),k.error(r("settings.toasts.deleteFailed"))}},B=y.useMemo(()=>C==null?void 0:C.reduce((n,p)=>(n[p.type]=[...n[p.type]||[],p],n),{}),[C]),F=(B==null?void 0:B[t])??[],ye=y.useMemo(()=>{if(t===u.KNOWLEDGE_BASE&&F.length){const n=F[0],p=n.value?n.value:{};return S(p)}return d[t]},[t,F]),U=n=>n===u.SYSTEM,fe=y.useMemo(()=>Object.values(u).filter(n=>n!==u.CUSTOM).map(n=>({type:n,label:j(n)})),[j]);return e.jsx("div",{className:"container mx-auto py-8 px-4",children:e.jsxs(we,{loading:L,loadingText:r("settings.loading"),children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:r("settings.title")}),e.jsx("p",{className:"text-gray-600 mt-1",children:r("settings.subtitle")})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-4 gap-8",children:[e.jsx("div",{className:"lg:col-span-1",children:e.jsx("nav",{className:"space-y-1",children:fe.map(({type:n,label:p})=>{var V;const K=t===n,q=(V=B==null?void 0:B[n])==null?void 0:V.length;return e.jsxs("a",{href:`#${n}`,className:`w-full group flex items-center px-3 py-2 text-sm font-medium rounded-md transition-colors ${K?"bg-blue-50 text-blue-700":"text-gray-600 hover:bg-gray-50 hover:text-gray-900"}`,onClick:je=>{je.preventDefault(),window.location.hash=n;const z=document.getElementById(`config-${n}`);z&&z.scrollIntoView({behavior:"smooth",block:"start"})},children:[e.jsx("span",{className:`mr-3 flex-shrink-0 ${K?"text-blue-500":"text-gray-400 group-hover:text-gray-500"}`,children:Ss[n]}),e.jsx("span",{className:"flex-1 text-left",children:p}),q&&!U(n)&&e.jsx(P,{variant:"secondary",className:"bg-green-500 text-white dark:bg-blue-600",children:B[n].length})]},n)})})}),e.jsx("div",{className:"lg:col-span-3",children:e.jsxs("div",{id:`config-${t}`,className:"bg-white rounded-lg shadow-sm border",children:[e.jsx("div",{className:"px-6 py-4 border-b border-gray-200",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-medium text-gray-900",children:j(t)}),e.jsx("p",{className:"text-sm text-gray-600 mt-1",children:o[t]})]}),!U(t)&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsxs(M,{size:"sm",onClick:()=>a(!0),children:[e.jsx(Z,{className:"w-4 h-4 mr-2"}),r("settings.actions.create")]})})]})}),e.jsx("div",{className:"p-6",children:U(t)?e.jsx(ws,{}):F.length?e.jsx(ps,{configData:F,columns:ye,onEdit:xe,onDelete:pe}):e.jsxs("div",{className:"text-center py-12",children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:r("settings.empty.title",{type:j(t)})}),e.jsx("p",{className:"text-gray-600 mb-6",children:r("settings.empty.description")}),e.jsxs(M,{onClick:()=>a(!0),children:[e.jsx(Z,{className:"w-4 h-4 mr-2"}),r("settings.actions.create")]})]})})]})})]}),e.jsx(X,{open:h,onOpenChange:a,children:e.jsxs(D,{className:"max-w-2xl",children:[e.jsxs(ee,{children:[e.jsx(se,{children:r("settings.dialogs.create.title",{type:j(t)})}),e.jsx(te,{children:r("settings.dialogs.create.description",{type:j(t)})})]}),e.jsx("div",{className:"py-4",children:e.jsx(re,{configType:t,onSubmit:ue,isLoading:A.isPending})})]})}),e.jsx(X,{open:g,onOpenChange:s,children:e.jsxs(D,{className:"max-w-2xl",children:[e.jsxs(ee,{children:[e.jsx(se,{children:r("settings.dialogs.edit.title",{type:j(t)})}),e.jsx(te,{children:r("settings.dialogs.edit.description",{type:j(t)})})]}),e.jsx("div",{className:"py-4",children:l&&e.jsx(re,{configType:t,onSubmit:ge,initialData:l.value?{name:l.name,...t==="custom"?{config:l.value}:l.value}:{name:l.name},isLoading:H.isPending})})]})})]})})}export{Ks as component};
