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