import{dG as A,dB as y,dF as N,dq as l,dx as h,dm as e,l as B,o as x,cU as C,c8 as v,B as P,aN as $}from"./index-D_pphaE2.js";import{e as O,o as z,s as L,b as M,u as T,d as U,g as G,f as K,a as H,F as J}from"./floating-ui.react-T-WLCbGi.js";import{b as Q,g as V,m as W,B as k}from"./BindRow-BySpAw-J.js";import"./envs-CRUy-_iG.js";import"./floating-ui.dom-CFVCCol6.js";import"./react-select.esm-OUcOCR-x.js";import"./defineProperty-CegpTSss.js";import"./extends-CF3RwP-h.js";import"./DevicePicker-CfFlp6BC.js";import"./EndpointPicker-DHX3IgJS.js";import"./SelectField-J0vaqEIK.js";const X=n=>`${n.isNew}-${n.source.endpoint}-${n.source.ieee_address}-${"ieee_address"in n.target?n.target.ieee_address:n.target.id}-${n.clusters.join("-")}`,Y=l.memo(({endpointId:n,rules:t,devices:o,groups:d,sourceIdx:m,device:f,onApply:b})=>{const{t:c}=A(["common","zigbee","scene"]),s=l.useRef(null),[i,r]=l.useState(!1),[p,j]=l.useState(null),{refs:_,floatingStyles:R,context:g}=O({open:i,onOpenChange:r,placement:"bottom-end",middleware:[z(8),L({padding:16,crossAxis:!0}),M({element:s})],strategy:"fixed",transform:!1}),D=T(g,{event:"click"}),F=U(g),E=G(g),{getReferenceProps:S,getFloatingProps:q}=K([D,F,E]);l.useEffect(()=>{j(i?W(f.ieee_address,n):null)},[i,f.ieee_address,n]);const w=l.useCallback(async([a,u])=>{await b([a,u]),u.isNew&&r(!1)},[b]);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:[c(a=>a.source_endpoint,{ns:"common"})," ",n,e.jsxs("button",{ref:_.setReference,type:"button",className:"btn btn-primary btn-outline btn-sm",...S(),children:[e.jsx(x,{icon:v}),e.jsx("span",{children:c(a=>a.add,{ns:"common"})})]})]}),t.length>0?t.map((a,u)=>e.jsx(k,{rule:a,sourceIdx:m,groups:d,device:f,devices:o,showDivider:u<t.length-1,onApply:w},X(a))):e.jsx("p",{className:"text-sm opacity-70",children:c(a=>a.none,{ns:"common"})}),i&&p?e.jsx(H,{children:e.jsxs("aside",{ref:_.setFloating,style:R,...q({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 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"card-title",children:[c(a=>a.add,{ns:"common"}),": ",c(a=>a.source_endpoint,{ns:"common"})," ",n]}),e.jsx(P,{onClick:()=>r(!1),className:"btn btn-ghost btn-square",children:e.jsx(x,{icon:$})})]}),e.jsx(k,{rule:p,sourceIdx:m,groups:d,device:f,devices:o,showDivider:!1,onApply:w})]}),e.jsx(J,{ref:s,context:g,className:"fill-base-200 [&>path:first-of-type]:stroke-base-300 [&>path:last-of-type]:stroke-base-300"})]})}):null]})})});function cs({sourceIdx:n,device:t}){const{t:o}=A("common"),d=y(N(s=>s.devices[n])),m=y(N(s=>s.groups[n])),f=l.useMemo(()=>Q(t),[t]),b=l.useCallback(async([s,i])=>{const r=V(i.target,d,m);if(!r)return;const p={from:t.ieee_address,from_endpoint:i.source.endpoint,to:r.to,to_endpoint:r.toEndpoint,clusters:i.clusters};s==="Bind"?await h(n,"bridge/request/device/bind",p):await h(n,"bridge/request/device/unbind",p)},[n,t,d,m]),c=l.useCallback(async([s,i,r])=>{await h(s,"bridge/request/device/binds/clear",{target:i,ieee_list:r})},[]);return e.jsxs("div",{className:"flex flex-col w-full gap-3",children:[e.jsxs("div",{className:"flex flex-row flex-wrap gap-3",children:[e.jsxs(B,{className:"btn btn-outline btn-error join-item",item:[n,t.ieee_address,[t.ieee_address]],onClick:c,title:o(s=>s.clear_self_as_source),modalDescription:o(s=>s.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:o(s=>s.cancel,{ns:"common"}),children:[e.jsx(x,{icon:C}),o(s=>s.clear_self_as_source)]}),e.jsxs(B,{className:"btn btn-outline btn-error join-item",item:[n,t.ieee_address,["0xffffffffffffffff"]],onClick:c,title:o(s=>s.clear_all),modalDescription:o(s=>s.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:o(s=>s.cancel,{ns:"common"}),children:[e.jsx(x,{icon:C}),o(s=>s.clear_all)]})]}),f.map(s=>e.jsx(Y,{...s,devices:d,groups:m,sourceIdx:n,device:t,onApply:b},s.endpointId))]})}export{cs as default};
