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