import{a as E,I as $,r as o,s as R,j as e,u as P,F as y,aa as q,B,f as O}from"./index-VJpwYvBU.js";import{u as z,o as M,s as T,b as K,g as G,d as H,c as J,e as L,F as Q,f as U}from"./floating-ui.react-CjPmCA_-.js";import{g as V,i as W}from"./ClusterSinglePicker-nUKjaZbF.js";import{a as X,m as Y,R as w}from"./ReportingRow-EvLhObhq.js";import"./envs-CRUy-_iG.js";import"./floating-ui.dom-DbzrgdRQ.js";import"./react-select.esm-DM_HiCZr.js";import"./defineProperty-CegpTSss.js";import"./extends-CF3RwP-h.js";import"./InputField-B_6Ee4_m.js";const Z=t=>`${t.endpoint}-${t.cluster}-${t.attribute}-${t.minimum_report_interval}-${t.maximum_report_interval}`,I=o.memo(({endpointId:t,rules:a,device:r,sourceIdx:d,onApply:f,bridgeDefinitions:n})=>{const{t:i}=P(["zigbee","common"]),u=o.useRef(null),[l,m]=o.useState(!1),[g,b]=o.useState(null),{refs:p,floatingStyles:h,context:c}=z({open:l,onOpenChange:m,placement:"bottom-end",middleware:[M(8),T({padding:16,crossAxis:!0}),K({element:u})],strategy:"fixed",transform:!1}),_=G(c,{event:"click"}),A=H(c),N=J(c),{getReferenceProps:k,getFloatingProps:v}=L([_,A,N]);o.useEffect(()=>{b(l?Y(r.ieee_address,t):null)},[l,r.ieee_address,t]);const j=o.useCallback(async s=>{await f(s),s.isNew&&m(!1)},[f]),C=o.useCallback(async([s,x,D,F,S])=>{await R(s,"bridge/request/device/reporting/read",{id:x,endpoint:D,cluster:F,configs:[{attribute:S}]})},[]);return e.jsx("section",{className:"card bg-base-200 card-border border-base-200 shadow-sm",children:e.jsxs("div",{className:"card-body p-3",children:[e.jsxs("div",{className:"card-title flex flex-wrap gap-2 items-center justify-between",children:[i(s=>s.endpoint)," ",t,e.jsxs("button",{ref:p.setReference,type:"button",className:"btn btn-primary btn-outline btn-sm",...k(),children:[e.jsx(y,{icon:q}),e.jsx("span",{children:i(s=>s.add,{ns:"common"})})]})]}),a.length>0?a.map((s,x)=>e.jsx(w,{sourceIdx:d,rule:s,bridgeDefinitions:n,device:r,onApply:j,onSync:C,showDivider:x<a.length-1},Z(s))):e.jsx("p",{className:"text-sm opacity-70",children:i(s=>s.none,{ns:"common"})}),l&&g?e.jsx(Q,{children:e.jsxs("aside",{ref:p.setFloating,style:h,...v({className:"card bg-base-200 shadow-lg border border-base-300 w-[min(32rem,calc(100vw-2.5rem))] max-h-[90vh] z-11"}),children:[e.jsxs("div",{className:"card-body p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"card-title",children:[i(s=>s.add,{ns:"common"}),": ",i(s=>s.endpoint)," ",t]}),e.jsx(B,{onClick:()=>m(!1),className:"btn btn-ghost btn-square",children:e.jsx(y,{icon:O})})]}),e.jsx(w,{sourceIdx:d,rule:g,bridgeDefinitions:n,device:r,onApply:j,showDivider:!1})]}),e.jsx(U,{ref:u,context:c,className:"fill-base-200 [&>path:first-of-type]:stroke-base-300 [&>path:last-of-type]:stroke-base-300"})]})}):null]})})});function me({sourceIdx:t,device:a}){const r=E($(n=>n.bridgeDefinitions[t])),d=o.useMemo(()=>X(a),[a]),f=o.useCallback(async n=>{const{cluster:i,endpoint:u,attribute:l,minimum_report_interval:m,maximum_report_interval:g,reportable_change:b}=n,p=V(r,a.ieee_address,i,l),h=p==null||W(p),c={id:a.ieee_address,endpoint:u,cluster:i,attribute:l,minimum_report_interval:m,maximum_report_interval:g,option:{}};h&&(c.reportable_change=b),await R(t,"bridge/request/device/reporting/configure",c)},[t,a.ieee_address,r]);return e.jsx("div",{className:"flex flex-col w-full gap-3",children:d.map(n=>e.jsx(I,{...n,device:a,sourceIdx:t,onApply:f,bridgeDefinitions:r},n.endpointId))})}export{me as default};
