import{a as o,j as t,F as S}from"./index-b983ad9b.js";/* empty css                *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              */import{r as a}from"./react-b0e0d18a.js";import{g as M}from"./KB-757eebe4.js";import{M as f}from"./MonoEventTrigger-c155a44e.js";/* empty css              */import{k,b as v,B as g,r as O,M as N,c as y,s as j,O as V,Q as A,E as T,m as h}from"./antd-8ca2e36c.js";import{s as w}from"./TriggerSetting-c8c5e754.js";/* empty css              */function D({open:m,onSubmit:u,onCancel:d}){const[n,r]=a.useState({}),[p,i]=a.useState({});return a.useEffect(()=>{let s=!0;return(async()=>{if(s){const l=await M();i(l)}})(),()=>{s=!1}},[]),o(k,{title:"添加指标",open:m,okButtonProps:{disabled:!n.key},onOk:()=>{u&&u(n),r({})},onCancel:()=>{d&&d(),r({})},children:[t("h4",{children:"指标"}),t("div",{className:"ant-input",children:p&&Object.entries(p).map(([s,l])=>t(v.CheckableTag,{checked:n.key===s,onChange:()=>{if(s===n.key)return;r({key:s})},children:l.title},s))})]})}const{confirm:I}=k;function Z({onChange:m,onDeleteItem:u}){const[d,n]=a.useState(!1),[r,p]=a.useState({}),[i,s]=a.useState([]);a.useEffect(()=>{let e=!0;return(async()=>e&&(await l(),await c()))(),()=>{e=!1}},[]);const l=async()=>{try{const e=await M();p(e)}catch{}},c=async()=>{try{const e=await f.getTriggers();s(e)}catch{}},E=()=>n(!0),b=async e=>{try{await f.addTrigger(e.key),await c(),a.startTransition(()=>{n(!1),h.success("操作成功")})}catch{h.warn("该环境指标已存在")}},x=async e=>{try{await f.updateTrigger(e.measurement,{enabled:!e.enabled}),await c()}catch{}},C=async e=>{try{await f.deleteTrigger(e.measurement),await c(),u(),a.startTransition(()=>{h.success("已删除")})}catch{}};return o(S,{children:[o("div",{className:w.sectionTitle,children:[t("span",{className:"title",children:"环境指标"}),t(g,{size:"small",shape:"circle",icon:t(O,{}),onClick:E}),t(D,{open:d,onSubmit:e=>b(e),onCancel:()=>n(!1)})]}),t("div",{className:w.sectionContent,children:i&&i.length?t(N,{mode:"vertical",onClick:({key:e})=>{m&&m(e)},items:i.map(e=>({key:e.measurement,label:o("div",{style:{display:"flex",flexDirection:"row",alignItems:"center"},children:[t("div",{style:{flex:1},children:t(y,{children:t("span",{className:"name",children:r[e.measurement].title})})}),o(y,{children:[t(j,{size:"small",defaultChecked:e.enabled,onChange:()=>x(e)}),t(g,{type:"text",danger:!0,onClick:()=>{I({title:"提示",icon:t(V,{}),content:"是否删除该环境指标？",okText:"确定",okType:"danger",cancelText:"取消",onOk(){C(e)},onCancel(){console.log("Cancel")}})},children:t(A,{})})]})]})}))}):t("div",{style:{height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:t(T,{image:T.PRESENTED_IMAGE_SIMPLE,description:""})})})]})}export{Z as default};
