import{dB as E,dF as $,dq as o,dx as R,dm as e,dG as q,o as j,c8 as B,B as P,aN as O}from"./index-DjbVAZHL.js";import{e as z,o as M,s as T,b as G,u as K,d as H,g as J,f as L,a as Q,F as U}from"./floating-ui.react-B9Qqkq_g.js";import{g as V,i as W}from"./ClusterSinglePicker-BRdWNtCr.js";import{a as X,m as Y,R as w}from"./ReportingRow-CTB2BXDo.js";import"./envs-CRUy-_iG.js";import"./floating-ui.dom-CFVCCol6.js";import"./react-select.esm-189R5gw4.js";import"./defineProperty-CegpTSss.js";import"./extends-CF3RwP-h.js";import"./InputField-D1U5kSs2.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:p,onApply:f,bridgeDefinitions:n})=>{const{t:i}=q(["zigbee","common"]),g=o.useRef(null),[l,m]=o.useState(!1),[u,b]=o.useState(null),{refs:d,floatingStyles:x,context:c}=z({open:l,onOpenChange:m,placement:"bottom-end",middleware:[M(8),T({padding:16,crossAxis:!0}),G({element:g})],strategy:"fixed",transform:!1}),_=K(c,{event:"click"}),N=H(c),A=J(c),{getReferenceProps:k,getFloatingProps:v}=L([_,N,A]);o.useEffect(()=>{b(l?Y(r.ieee_address,t):null)},[l,r.ieee_address,t]);const y=o.useCallback(async s=>{await f(s),s.isNew&&m(!1)},[f]),C=o.useCallback(async([s,h,D,F,S])=>{await R(s,"bridge/request/device/reporting/read",{id:h,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:d.setReference,type:"button",className:"btn btn-primary btn-outline btn-sm",...k(),children:[e.jsx(j,{icon:B}),e.jsx("span",{children:i(s=>s.add,{ns:"common"})})]})]}),a.length>0?a.map((s,h)=>e.jsx(w,{sourceIdx:p,rule:s,bridgeDefinitions:n,device:r,onApply:y,onSync:C,showDivider:h<a.length-1},Z(s))):e.jsx("p",{className:"text-sm opacity-70",children:i(s=>s.none,{ns:"common"})}),l&&u?e.jsx(Q,{children:e.jsxs("aside",{ref:d.setFloating,style:x,...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(P,{onClick:()=>m(!1),className:"btn btn-ghost btn-square",children:e.jsx(j,{icon:O})})]}),e.jsx(w,{sourceIdx:p,rule:u,bridgeDefinitions:n,device:r,onApply:y,showDivider:!1})]}),e.jsx(U,{ref:g,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])),p=o.useMemo(()=>X(a),[a]),f=o.useCallback(async n=>{const{cluster:i,endpoint:g,attribute:l,minimum_report_interval:m,maximum_report_interval:u,reportable_change:b}=n,d=V(r,a.ieee_address,i,l),x=d==null||W(d),c={id:a.ieee_address,endpoint:g,cluster:i,attribute:l,minimum_report_interval:m,maximum_report_interval:u,option:{}};x&&(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:p.map(n=>e.jsx(I,{...n,device:a,sourceIdx:t,onApply:f,bridgeDefinitions:r},n.endpointId))})}export{me as default};
