import{b as R,h as E,r as t,j as e,s as r}from"./main.js";import{d as L,B as m}from"./button-D4VgS8ri.js";import{I as o}from"./input-CbL6Bfs6.js";import{L as i}from"./label-Bemsalkj.js";import{T as D}from"./textarea-CJcz8Fvt.js";import{C as M,b as k,c as q,a as G}from"./card-D6OLc_JP.js";import{S as P,a as V,b as _,c as B,d as H}from"./select-BNSL7nj6.js";import{M as O}from"./MonacoEditor-CkW-kZUy.js";import{c as U}from"./config-C5ccHKCm.js";import{C as z}from"./config-CPAyKrGO.js";import{A as Y}from"./arrow-left-j3vPbhKI.js";import"./index-hZlSoXYO.js";import"./Combination-B6GbgrNn.js";import"./index-DArTFRYQ.js";import"./check-VUVUvqaV.js";const v=/[@#$%^&*\s]+/g;function oe(){const p=R(),{t:s}=L(),{currentNamespace:N}=E(),[n,C]=t.useState(""),[c,S]=t.useState("DEFAULT_GROUP"),[g,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 U.publish({dataId:n.trim(),groupName:c.trim(),content:d,desc:g.trim(),configTags:h.trim(),type:l,appName:u.trim(),namespaceId:N});a.data.code===0?(r.success(s("config.publishSuccess")),p("/configurationManagement")):r.error(a.data.message||s("config.publishFailed"))}catch{r.error(s("config.publishFailed"))}finally{x(!1)}}},j=()=>{p("/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:g,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(P,{value:l,onValueChange:a=>F(a),children:[e.jsx(V,{id:"type",className:"w-full md:w-[280px]",children:e.jsx(_,{})}),e.jsx(B,{children:z.map(a=>e.jsx(H,{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(O,{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{oe as default};
