import{z as R,t as E,r as t,j as e}from"./vendor-react.js";import{c as L,t as r}from"./main.js";import{B as m}from"./button.js";import{I as o}from"./input.js";import{L as i}from"./label.js";import{T as D}from"./textarea.js";import{C as M,b as k,c as q,a as G}from"./card.js";import{S as O,a as P,b as V,c as _,d as z}from"./select.js";import{M as B}from"./MonacoEditor.js";import{c as H}from"./config2.js";import{C as U}from"./config.js";import{O as Y}from"./vendor-icons.js";import"./vendor-monaco.js";import"./vendor-ui.js";const v=/[@#$%^&*\s]+/g;function ce(){const g=R(),{t:s}=E(),{currentNamespace:N}=L(),[n,C]=t.useState(""),[c,S]=t.useState("DEFAULT_GROUP"),[p,y]=t.useState(""),[u,I]=t.useState(""),[h,b]=t.useState(""),[l,F]=t.useState("text"),[d,w]=t.useState(""),[f,x]=t.useState(!1),T=()=>n.trim()?c.trim()?d.trim()?v.test(n)?(r.error(s("config.noSpecialChars")),!1):v.test(c)?(r.error(s("config.noSpecialChars")),!1):!0:(r.error(s("config.contentRequired")),!1):(r.error(s("config.groupRequired")),!1):(r.error(s("config.dataIdRequired")),!1),A=async()=>{if(T()){x(!0);try{const a=await H.publish({dataId:n.trim(),groupName:c.trim(),content:d,desc:p.trim(),configTags:h.trim(),type:l,appName:u.trim(),namespaceId:N});a.data.code===0?(r.success(s("config.publishSuccess")),g("/configurationManagement")):r.error(a.data.message||s("config.publishFailed"))}catch{r.error(s("config.publishFailed"))}finally{x(!1)}}},j=()=>{g("/configurationManagement")};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(m,{variant:"outline",size:"icon",onClick:j,children:e.jsx(Y,{className:"h-4 w-4"})}),e.jsx("h1",{className:"text-2xl font-semibold",children:s("config.newConfig")})]}),e.jsxs(M,{children:[e.jsx(k,{children:e.jsx(q,{children:s("config.newConfig")})}),e.jsxs(G,{className:"space-y-6 pt-0",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(i,{htmlFor:"dataId",children:[s("config.dataId"),e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(o,{id:"dataId",value:n,onChange:a=>C(a.target.value),placeholder:s("config.dataId")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(i,{htmlFor:"group",children:[s("config.group"),e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(o,{id:"group",value:c,onChange:a=>S(a.target.value),placeholder:s("config.group")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"desc",children:s("config.description")}),e.jsx(D,{id:"desc",value:p,onChange:a=>y(a.target.value),placeholder:s("config.description"),rows:2})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"appName",children:s("config.appName")}),e.jsx(o,{id:"appName",value:u,onChange:a=>I(a.target.value),placeholder:s("config.appName")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"tags",children:s("config.tags")}),e.jsx(o,{id:"tags",value:h,onChange:a=>b(a.target.value),placeholder:"tag1,tag2,tag3"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{htmlFor:"type",children:s("config.type")}),e.jsxs(O,{value:l,onValueChange:a=>F(a),children:[e.jsx(P,{id:"type",className:"w-full md:w-[280px]",children:e.jsx(V,{})}),e.jsx(_,{children:U.map(a=>e.jsx(z,{value:a.value,children:a.label},a.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(i,{htmlFor:"content",children:[s("config.content"),e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(B,{value:d,onChange:w,language:l,height:"400px"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-end gap-4",children:[e.jsx(m,{variant:"outline",onClick:j,children:s("common.cancel")}),e.jsx(m,{onClick:A,disabled:f,children:s(f?"common.loading":"config.publish")})]})]})}export{ce as default};
