import{dq as l,dG as D,dm as n,B as R,o as d,aE as E,l as g,an as S,ak as L,cD as B,aq as y}from"./index-D_pphaE2.js";import{a as F,i as M,C as V,A as z}from"./ClusterSinglePicker-BVz2htML.js";import{I as j}from"./InputField-B0SBdaHi.js";const K=(a,i)=>({isNew:a,reportable_change:0,minimum_report_interval:60,maximum_report_interval:3600,endpoint:i,cluster:"",attribute:""}),Q=a=>{const i=[];for(const r in a.endpoints){const c=a.endpoints[r].configured_reportings.map(b=>({...b,endpoint:r}));i.push({endpointId:r,rules:c})}return i},P=(a,i,r)=>!(a==null||a===""||Number.isNaN(a)||i==null||i===""||Number.isNaN(i)||r===""||Number.isNaN(r)||a>i&&!(i===0&&a===65535&&r===0)),T=a=>a.endpoint===void 0||a.endpoint===""||a.cluster===void 0||a.cluster===""||a.attribute===void 0||a.attribute===""?!1:P(a.minimum_report_interval,a.maximum_report_interval,a.reportable_change),U=l.memo(({sourceIdx:a,rule:i,bridgeDefinitions:r,device:m,onApply:c,onSync:b,showDivider:C,showOnlyApply:p=!1})=>{const[t,_]=l.useState(i),[x,h]=l.useState(null),{t:s}=D(["zigbee","common"]);l.useEffect(()=>{_(i);const e=F(r,m.ieee_address,i.cluster);h(e[i.attribute]??null)},[i,r,m.ieee_address]);const w=l.useCallback(e=>{_(o=>({...o,cluster:e}))},[]),v=l.useCallback((e,o)=>{_(u=>({...u,attribute:e})),h(o)},[]),N=l.useCallback(e=>{_(o=>({...o,[e.target.name]:e.target.value?e.target.valueAsNumber:""}))},[]),k=l.useMemo(()=>{const e=new Set,o=new Set;t.cluster&&o.add(t.cluster);const u=m.endpoints[Number.parseInt(t.endpoint,10)];if(u){for(const f of u.clusters.output)o.add(f);for(const f of u.clusters.input)o.has(f)||e.add(f)}return[{name:"available",clusters:o},{name:"possible",clusters:e}]},[m.endpoints,t.endpoint,t.cluster]),q=l.useMemo(()=>x==null||M(x),[x]),A=l.useMemo(()=>T(t),[t]);return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex flex-row flex-wrap gap-2",children:[n.jsx(V,{label:s(e=>e.cluster),disabled:!t.endpoint||!t.isNew,clusters:k,value:t.cluster,onChange:w,required:!0}),n.jsx(z,{sourceIdx:a,label:s(e=>e.attribute),disabled:!t.cluster||!t.isNew,value:t.attribute,cluster:t.cluster,device:m,onChange:v,required:!0}),n.jsx(j,{name:"minimum_report_interval",label:s(e=>e.min_rep_interval),type:"number",value:t.minimum_report_interval??"",onChange:N,required:!0,className:"input validator w-48",min:0,max:65535}),n.jsx(j,{name:"maximum_report_interval",label:s(e=>e.max_rep_interval),type:"number",value:t.maximum_report_interval??"",onChange:N,required:!0,className:"input validator w-48",min:0,max:65535}),q?n.jsx(j,{name:"reportable_change",label:s(e=>e.min_rep_change),type:"number",value:t.reportable_change??"",onChange:N,className:"input validator w-48",required:!0}):n.jsxs("fieldset",{className:"fieldset",children:[n.jsx("legend",{className:"fieldset-legend",children:s(e=>e.min_rep_change)}),n.jsx("p",{className:"label w-48",children:"N/A"})]}),n.jsxs("fieldset",{className:"fieldset ml-auto",children:[n.jsx("legend",{className:"fieldset-legend",children:s(e=>e.actions)}),n.jsxs("div",{className:"join join-horizontal",children:[n.jsx(R,{title:s(e=>e.apply,{ns:"common"}),className:"btn btn-square btn-primary btn-outline join-item",item:t,onClick:c,disabled:!A,children:n.jsx(d,{icon:E})}),!p&&b!==void 0&&!t.isNew?n.jsx(g,{className:"btn btn-square btn-outline btn-accent join-item",item:[a,m.ieee_address,i.endpoint,i.cluster,i.attribute],onClick:b,title:s(e=>e.sync,{ns:"common"}),modalDescription:s(e=>e.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:s(e=>e.cancel,{ns:"common"}),children:n.jsx(d,{icon:S})}):null,!p&&!t.isNew?n.jsx(g,{title:s(e=>e.reset,{ns:"common"}),className:"btn btn-square btn-warning btn-outline join-item",onClick:async()=>{await c({...t,minimum_report_interval:65535,maximum_report_interval:0,reportable_change:0})},modalDescription:s(e=>e.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:s(e=>e.cancel,{ns:"common"}),children:n.jsx(d,{icon:L})}):null,!p&&!t.isNew?n.jsx(g,{title:s(e=>e.reset,{ns:"common"}),className:"btn btn-square btn-error btn-outline join-item",onClick:async()=>{await c({...t,minimum_report_interval:0,maximum_report_interval:0})},modalDescription:s(e=>e.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:s(e=>e.cancel,{ns:"common"}),children:n.jsx(d,{icon:B})}):null,!p&&!t.isNew?n.jsx(g,{title:s(e=>e.terminate,{ns:"common"}),className:"btn btn-square btn-error btn-outline join-item",onClick:async()=>{await c({...t,minimum_report_interval:0,maximum_report_interval:65535,reportable_change:0})},modalDescription:s(e=>e.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:s(e=>e.cancel,{ns:"common"}),children:n.jsx(d,{icon:y})}):null]})]})]}),C?n.jsx("div",{className:"divider my-0"}):null]})});export{U as R,Q as a,P as i,K as m};
