import{u as I}from"./scene.1703796278973.js";import{d as l,s as _,k,j as T}from"./vue.1703796278973.js";import{a as g}from"./product.17037962789737.js";import{k as x}from"./instance.1703796278973.js";import{n as C}from"./config.17037962789732.js";import{n as S}from"./template.1703796278973.js";import{F as q}from"./index.17037962789732.js";import{b as R,E as w}from"./util.17037962789736.js";const E=l({name:"ActionCheckItem"}),P=l({...E,props:{branchesName:{type:Number,default:0},thenName:{type:Number,default:0},name:{type:Number,default:0}},setup(d){const e=d,p=I(),{data:a}=_(p),b=q.useInjectFormItemContext(),f=k(),r=()=>{b.onFieldChange()},v=async()=>{var s,c,o,u;const t=a.value.branches[e.branchesName].then[e.thenName].actions[e.name].device,n=await g({terms:[{terms:[{column:"id",termType:"eq",value:t.productId}]}]});if(n.success&&((s=n.result)==null?void 0:s.total)===0&&t&&t.productId){a.value.branches[e.branchesName].then[e.thenName].actions[e.name].device.productId=void 0,r();return}if((t==null?void 0:t.selector)==="fixed"){const m=((c=t.selectorValues)==null?void 0:c.map(y=>y.value))||[],h=await x({terms:[{terms:[{column:"id",termType:"in",value:m.toString()}]}]});if(h.success&&((o=h.result)==null?void 0:o.total)<(((u=t.selectorValues)==null?void 0:u.length)||0)){a.value.branches[e.branchesName].then[e.thenName].actions[e.name].device.selectorValues=void 0,r();return}}if(console.log(t.source,e.name),t.source==="upper")if(e.name===0){a.value.branches[e.branchesName].then[e.thenName].actions[e.name].device.upperKey=void 0,r();return}else{const m=a.value.branches[e.branchesName].then[e.thenName].actions[e.name-1].device;if((m==null?void 0:m.productId)!==(t==null?void 0:t.productId)){a.value.branches[e.branchesName].then[e.thenName].actions[e.name].device.upperKey=void 0,r();return}}},N=async()=>{var c,o;const t=a.value.branches[e.branchesName].then[e.thenName].actions[e.name].notify,n=await C.list({terms:[{terms:[{column:"id",termType:"eq",value:t.notifierId}]}]});if(n.success&&((c=n.result)==null?void 0:c.total)===0){a.value.branches[e.branchesName].then[e.thenName].actions[e.name].notify.notifierId="",r();return}const s=await S.list({terms:[{terms:[{column:"id",termType:"eq",value:t.templateId}]}]});if(s.success&&((o=s.result)==null?void 0:o.total)===0){a.value.branches[e.branchesName].then[e.thenName].actions[e.name].notify.templateId="",r();return}},i=()=>{var n,s,c;const t=(n=a.value.branches[e.branchesName].then[e.thenName].actions[e.name])==null?void 0:n.executor;t==="device"&&((s=a.value.branches[e.branchesName].then[e.thenName].actions[e.name])!=null&&s.device)?v():t==="notify"&&((c=a.value.branches[e.branchesName].then[e.thenName].actions[e.name])!=null&&c.notify)&&N()};return(()=>{const t=R({branch:e.branchesName,branchGroup:e.thenName,action:e.name});f.value=w.subscribe(t,i)})(),i(),(t,n)=>T(t.$slots,"default")}});export{P as _};
