import{G as d,j as a,a as m,L as u,_ as v}from"./index-b983ad9b.js";import{r as c}from"./react-b0e0d18a.js";/* empty css                *//* empty css              *//* empty css              */import{R as b,a as h,m as f}from"./antd-8ca2e36c.js";const l=new Map;class n{constructor(e){this.setData(e)}setData(e){Object.assign(this,e)}delete(){return n.deleteTrigger(this.id)}async parent(){return n.getTrigger(this.parentId)}async modify({type:e,targetId:i,...r}){if(this.id)if(e!==this.type)if(this.type!=="global")if(this.parentId){const t=await this.parent();return await this.delete(),t}else{const t={type:"global",targetId:void 0,enabled:!0,...r};return this.id?await n.updateTrigger(this.id,t):await n.addTrigger(t)}else return n.addTrigger({type:e,targetId:i,parentId:this.id,enabled:!1,...r});else{const t={...r};return this.id?await n.updateTrigger(this.id,t):await n.addTrigger(t)}else return await n.addTrigger({type:e,targetId:i,...r})}static async getTriggers(e){const i=d(),{items:r}=await i.get({path:"api/v1/event-triggers",query:e});return r==null?void 0:r.map(t=>new n(t))}static async getTrigger(e){let i=l.get(e);if(i===void 0){const t=await d().get(`api/v1/event-trigger/${e}`);t&&(i=new n(t),l.set(e,i))}return i}static async addTrigger(e){const r=await d().post("api/v1/event-trigger",e),t=new n(r);return l.set(t.id,t),t}static async updateTrigger(e,i){if(!e)return;const t=await d().patch(`api/v1/event-trigger/${e}`,i),o=new n(t);return l.set(o.id,o),o}static async deleteTrigger(e){if(!e)return;await d().delete(`api/v1/event-trigger/${e}`),l.delete(e)}}const _=n,x="_page_hm0gl_1",I={page:x},N=c.lazy(()=>v(()=>import("./index-3a6ab207.js"),["./index-3a6ab207.js","./index-b983ad9b.js","./react-b0e0d18a.js","./antd-8ca2e36c.js","./index-a8abcf49.css","./Room-7ae51b0a.js","./Room-74d2f679.css","./TimeoutItem-6cca4419.js","./index-154ab312.css","./default-76b7cd8d.css","./index-9368394d.css","./index-804d7e9f.css","./index-d63cb525.css","./index-8777399d.css","./index-3c2820ea.css"],import.meta.url)),L=c.lazy(()=>v(()=>import("./DeviceList-f68fe8ed.js"),["./DeviceList-f68fe8ed.js","./index-b983ad9b.js","./react-b0e0d18a.js","./antd-8ca2e36c.js","./index-a8abcf49.css","./Device-e8d48614.js","./default-76b7cd8d.css","./index-50ebf7c8.css","./index-2e40ceaa.css"],import.meta.url)),D=c.lazy(()=>v(()=>import("./TriggerList-1fda2874.js"),["./TriggerList-1fda2874.js","./index-b983ad9b.js","./react-b0e0d18a.js","./antd-8ca2e36c.js","./index-a8abcf49.css","./default-76b7cd8d.css","./index-93ee9d26.css","./index-abe611e6.css","./index-804d7e9f.css","./index-50ebf7c8.css","./index-2e40ceaa.css","./index-764a06d4.css","./index-8777399d.css","./index-cbca5443.css"],import.meta.url)),R=c.lazy(()=>v(()=>import("./TriggerForm-be955af1.js"),["./TriggerForm-be955af1.js","./index-b983ad9b.js","./react-b0e0d18a.js","./antd-8ca2e36c.js","./index-a8abcf49.css","./KB-757eebe4.js","./TriggerForm-9518fe5f.css","./default-76b7cd8d.css","./index-67061e3d.css","./index-8777399d.css","./index-2e40ceaa.css","./index-9368394d.css","./index-804d7e9f.css","./index-029e7fc6.css","./index-abe611e6.css","./index-3c2820ea.css","./index-11c46f0a.css","./index-97cb01cf.css","./index-764a06d4.css"],import.meta.url));function O(){const[y,e]=c.useState(),[i,r]=c.useState(),[t,o]=c.useState(),[T,g]=c.useReducer(s=>s+1,0);return a("div",{className:I.page,children:m(b,{children:[m(h,{className:"room-list",children:[a("div",{className:"section-title",children:"地点"}),a("div",{className:"section-content",style:{maxWidth:240},children:a(c.Suspense,{fallback:a(u,{}),children:a(N,{withAll:!0,value:i,onChange:s=>{s!==i&&(r(s),o(void 0),e(void 0),g())}})})})]}),m(h,{flex:"200px",className:"device-list",children:[a("div",{className:"section-title",children:"设备列表"}),a("div",{className:"section-content",children:a(c.Suspense,{fallback:a(u,{}),children:a(L,{roomId:i,onChange:s=>{s!==t&&(o(s),e(void 0),g())}})})})]}),a(h,{flex:"200px",className:"trigger-list",children:a(c.Suspense,{fallback:a(u,{}),children:a(D,{refreshSeed:T,type:t?"device":"room",targetId:t||i,onChange:async s=>{if(s!==0){const p=await _.getTrigger(s);e(p)}else e(new _({type:t?"device":"room",targetId:t||i}))}})})}),m(h,{flex:"auto",className:"trigger-form",children:[a("div",{className:"section-title",children:y&&!y.id?"规则添加":"规则详情"}),a("div",{className:"section-content",style:{padding:12},children:a(c.Suspense,{fallback:a(u,{}),children:a(R,{trigger:y,target:{type:t?"device":"room",id:t||i||0},onUpdate:async(s,{global:p,...S})=>{try{const w=await s.modify({type:p?"global":t?"device":"room",targetId:p?void 0:t||i,...S});w&&w.id!==s.id&&e(w),g(),f.success("已保存")}catch{f.error("保存失败")}},onDelete:async s=>{try{await s.delete(),e(void 0),g(),f.success("已删除")}catch{f.error("删除失败")}}})})})]})]})})}const V=Object.freeze(Object.defineProperty({__proto__:null,default:O},Symbol.toStringTag,{value:"Module"}));export{_ as E,V as i};
