import{t as _,z as E,A as M,r as u,j as e}from"./vendor-react.js";import{t as w}from"./main.js";import{u as W}from"./history-store.js";import{c as v}from"./config2.js";import{M as B}from"./MonacoEditor.js";import{B as l}from"./button.js";import{C as j,a as y,b as C,c as D}from"./card.js";import{S as n}from"./skeleton.js";import{D as P,a as $,b as z,c as F,e as G,d as J}from"./dialog.js";import{O as T,T as q}from"./vendor-icons.js";import"./vendor-monaco.js";import"./config.js";import"./vendor-ui.js";function ne(){const{t:s}=_(),N=E(),[c]=M(),i=c.get("dataId")||"",d=c.get("group")||"",x=c.get("nid")||"",h=c.get("namespace")||"",{currentHistory:a,detailLoading:R,fetchHistoryDetail:S,clearCurrentHistory:O}=W(),[U,m]=u.useState(!1),[f,k]=u.useState(!1);u.useEffect(()=>(x&&i&&d&&S(x,i,d),()=>{O()}),[x,i,d]);const g=()=>{N(`/historyRollback?dataId=${encodeURIComponent(i)}&group=${encodeURIComponent(d)}&namespace=${encodeURIComponent(h)}`)},H=t=>{switch(t?.trim()){case"I":return s("history.opInsert");case"U":return s("history.opUpdate");case"D":return s("history.opDelete");default:return t}},A=()=>{if(!a)return"";switch(a.opType?.trim()){case"I":return s("history.rollbackInsertWarn");case"U":return s("history.rollbackUpdateWarn");case"D":return s("history.rollbackDeleteWarn");default:return""}},L=async()=>{if(a){k(!0);try{if(a.opType?.trim()==="I")await v.delete({dataId:a.dataId,groupName:a.groupName,namespaceId:h});else{let r=a.type||"text",b="",I="";try{const o=JSON.parse(a.extInfo||"{}");o.type&&(r=o.type),o.config_tags&&(I=o.config_tags),o.c_desc&&(b=o.c_desc)}catch{}await v.publish({dataId:a.dataId,groupName:a.groupName,content:a.content,namespaceId:h,type:r,appName:a.appName,desc:b||void 0,configTags:I||void 0})}w.success(s("history.rollbackSuccess")),N("/configurationManagement")}catch{w.error(s("history.rollbackFailed"))}finally{k(!1),m(!1)}}},p=(t,r)=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:t}),e.jsx("span",{className:"text-sm font-medium",children:r||"-"})]});return R?e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(n,{className:"h-9 w-9"}),e.jsx(n,{className:"h-8 w-48"})]}),e.jsx(n,{className:"h-24 w-full"}),e.jsx(j,{children:e.jsx(y,{className:"p-6",children:e.jsx("div",{className:"grid grid-cols-3 gap-6",children:Array.from({length:4}).map((t,r)=>e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{className:"h-4 w-20"}),e.jsx(n,{className:"h-5 w-32"})]},r))})})}),e.jsx(n,{className:"h-[350px] w-full"})]}):a?e.jsxs("div",{className:"flex flex-col gap-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(l,{variant:"outline",size:"icon",onClick:g,children:e.jsx(T,{className:"h-4 w-4"})}),e.jsx("h1",{className:"text-2xl font-semibold",children:s("history.rollbackTitle")})]}),e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-yellow-200 bg-yellow-50 p-4 dark:border-yellow-900 dark:bg-yellow-950",children:[e.jsx(q,{className:"h-5 w-5 text-yellow-600 dark:text-yellow-400 shrink-0"}),e.jsx("p",{className:"text-sm text-yellow-800 dark:text-yellow-200",children:A()})]}),e.jsxs(j,{children:[e.jsx(C,{children:e.jsx(D,{children:s("history.rollbackTitle")})}),e.jsx(y,{className:"p-6 pt-0",children:e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[p(s("config.dataId"),a.dataId),p(s("config.group"),a.groupName),p(s("history.opType"),H(a.opType)),p(s("config.md5"),a.md5)]})})]}),e.jsxs(j,{children:[e.jsx(C,{children:e.jsx(D,{children:s("config.content")})}),e.jsx(y,{className:"p-6 pt-0",children:e.jsx(B,{value:a.content||"",language:a.type||"text",readOnly:!0,height:"350px"})})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(l,{variant:"outline",onClick:g,children:s("common.back")}),e.jsx(l,{onClick:()=>m(!0),children:s("history.rollback")})]}),e.jsx(P,{open:U,onOpenChange:m,children:e.jsxs($,{children:[e.jsxs(z,{children:[e.jsx(F,{children:s("history.rollback")}),e.jsx(G,{children:s("history.rollbackConfirm")})]}),e.jsxs("div",{className:"text-sm space-y-1",children:[e.jsxs("p",{children:["Data ID: ",e.jsx("span",{className:"font-medium",children:a.dataId})]}),e.jsxs("p",{children:["Group: ",e.jsx("span",{className:"font-medium",children:a.groupName})]})]}),e.jsxs(J,{children:[e.jsx(l,{variant:"outline",onClick:()=>m(!1),disabled:f,children:s("common.cancel")}),e.jsx(l,{onClick:L,disabled:f,children:s(f?"common.loading":"common.confirm")})]})]})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-[400px] gap-4",children:[e.jsx("p",{className:"text-muted-foreground",children:s("common.noData")}),e.jsxs(l,{variant:"outline",onClick:g,children:[e.jsx(T,{className:"h-4 w-4 mr-2"}),s("common.back")]})]})}export{ne as default};
