import{a as E,D as $,r as o,s as R,j as e,u as P,F as y,a6 as B,B as O,f as q}from"./index-KAtljJVt.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-Dfxk0AMB.js";import{b as V,g as W,a as X,m as Y}from"./ClusterSinglePicker-BzLo1Dsb.js";import{R as w}from"./ReportingRow-BaRNUqpb.js";import"./envs-CSqIi4cL.js";import"./floating-ui.dom-I8hrORoS.js";import"./react-select.esm-DL84IisZ.js";import"./defineProperty-CegpTSss.js";import"./extends-CF3RwP-h.js";import"./InputField-D4fq1Htu.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"]),g=o.useRef(null),[l,m]=o.useState(!1),[u,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:g})],strategy:"fixed",transform:!1}),_=G(c,{event:"click"}),A=H(c),N=J(c),{getReferenceProps:k,getFloatingProps:D}=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]),v=o.useCallback(async([s,x,C,F,S])=>{await R(s,"bridge/request/device/reporting/read",{id:x,endpoint:C,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:B}),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:v,showDivider:x<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:p.setFloating,style:h,...D({className:"card bg-base-200 shadow-lg border border-base-300 w-[min(32rem,calc(100vw-2.5rem))] max-h-[80vh] 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(O,{onClick:()=>m(!1),className:"btn btn-ghost btn-sm",children:e.jsx(y,{icon:q})})]}),e.jsx(w,{sourceIdx:d,rule:u,bridgeDefinitions:n,device:r,onApply:j,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])),d=o.useMemo(()=>V(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,p=W(r,a.ieee_address,i,l),h=p==null||X(p),c={id:a.ieee_address,endpoint:g,cluster:i,attribute:l,minimum_report_interval:m,maximum_report_interval:u,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};
