import{r as d,ab as _,u as y,s as C,j as a,B as w,a as g,I as j,a9 as S,F as D,a0 as N}from"./index-CE-9RlbR.js";import{R as E,A as k}from"./RecallRemove-DFcPL08D.js";import{D as F}from"./DevicePicker-D9pe3MS2.js";import{E as A}from"./EndpointPicker-WNk50fpC.js";import{u as M,g as G}from"./useColumnCount-CdMiuwHk.js";import{D as R}from"./DashboardFeatureWrapper-BAseHpKP.js";import{D as q}from"./DeviceCard-DkDt8Vgs.js";import"./envs-CRUy-_iG.js";import"./startCase-BwzMWzGM.js";import"./DisplayValue-eLtXORWe.js";import"./isObject--vsEa_js.js";import"./_createCompounder-pwnXEtry.js";import"./isObjectLike-BsEMHB57.js";import"./InputField-DRmYNLGX.js";import"./react-select.esm-CxImRSNQ.js";import"./floating-ui.dom-D02yrJtw.js";import"./SelectField-BPXpeItQ.js";import"./LastSeen-D1je17I0.js";import"./TimeAgo-D_O5nVVz.js";import"./Lqi-0GAOTPeK.js";import"./PowerSource-Ch5TptQq.js";import"./snakeCase-WwJ9QoNs.js";import"./DeviceImage-Bcp15E0n.js";import"./index-CDoSh7QA.js";const z=d.memo(({sourceIdx:s,devices:i,group:n})=>{const[o,c]=d.useState(""),[r,u]=d.useState(""),v=d.useMemo(()=>_(i.find(e=>e.ieee_address===r)),[r,i]),{t:l}=y(["groups","zigbee"]),m=d.useCallback(e=>{u(e.ieee_address);const t=_(e).values().next().value;c(t??"")},[]),f=d.useCallback(async()=>await C(s,"bridge/request/group/members/add",{group:n.id.toString(),endpoint:o,device:r}),[s,n.id,o,r]);return a.jsxs(a.Fragment,{children:[a.jsx("h2",{className:"text-lg font-semibold",children:l(e=>e.add_to_group_header)}),a.jsxs("div",{className:"mb-3",children:[a.jsx(F,{label:l(e=>e.device,{ns:"zigbee"}),value:r,devices:i,onChange:m}),a.jsx(A,{label:l(e=>e.endpoint,{ns:"zigbee"}),values:v,value:o,onChange:e=>c(e),disabled:!r})]}),a.jsx(w,{onClick:f,className:"btn btn-primary",disabled:o==null||o===""||!r,children:l(e=>e.add_to_group)})]})}),B=({sourceIdx:s,device:i,deviceState:n,deviceAvailability:o,groupMember:c,lastSeenConfig:r,removeDeviceFromGroup:u,setDeviceState:v})=>{const{endpoint:l}=c,{t:m}=y(["groups","common"]),f=g(j(t=>t.deviceScenesFeatures[s][i.ieee_address]??[])),e=d.useCallback(async t=>await v(i.ieee_address,t),[i.ieee_address,v]),b=d.useCallback(async()=>await u(i.ieee_address,l),[i.ieee_address,l,u]);return a.jsx("div",{className:`mb-3 card card-border bg-base-200 rounded-box shadow-md ${o==="offline"?"border-error/50":"border-base-300"}`,children:a.jsx(q,{sourceIdx:s,hideSourceDot:!0,features:f,device:i,endpoint:l,deviceState:n,onChange:e,featureWrapperClass:R,lastSeenConfig:r,children:a.jsx(S,{onClick:b,className:"btn btn-square btn-outline btn-error btn-sm",title:m(t=>t.remove_from_group),modalDescription:m(t=>t.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:m(t=>t.cancel,{ns:"common"}),children:a.jsx(D,{icon:N})})})})},T=s=>s?.data?a.jsx(B,{...s.data}):null,W=d.memo(({sourceIdx:s,devices:i,group:n})=>{const o=g(e=>e.availability),c=g(e=>e.bridgeInfo),r=g(j(e=>e.deviceStates[s])),u=g(j(e=>e.bridgeInfo[s].config.advanced.last_seen)),v=M(),l=d.useCallback(async(e,b)=>await C(s,"bridge/request/group/members/remove",{device:e,endpoint:b,group:n.id.toString()}),[s,n.id]),m=d.useCallback(async(e,b)=>{await C(s,`${e}/set`,b)},[s]),f=d.useMemo(()=>{const e=[],b=c[s].config.availability.enabled;for(const t of n.members){const p=i.find(h=>h.ieee_address===t.ieee_address);if(p){let h="disabled";if(!p.disabled){const x=c[s].config.devices[p.ieee_address]?.availability;h=(x!=null?!!x:void 0)??b?o[s][p.friendly_name]?.state??"offline":"disabled"}e.push({sourceIdx:s,groupMember:t,device:p,deviceState:r[p.friendly_name]??{},deviceAvailability:h,lastSeenConfig:u,removeDeviceFromGroup:l,setDeviceState:m})}}return e.sort((t,p)=>t.device.ieee_address.localeCompare(p.device.ieee_address)),e},[s,n,i,u,r,c,o,l,m]);return a.jsx("div",{children:a.jsx(G,{useWindowScroll:!0,columnCount:v,data:f,ItemContent:T,className:"gap-3"},`groupmembers-${f.length}`)})});function me({sourceIdx:s,group:i}){const n=g(j(o=>o.devices[s]));return a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex flex-row flex-wrap gap-4 mb-4 w-full",children:[a.jsx("div",{className:"card card-border bg-base-200 border-base-300 rounded-box shadow-md flex-1",children:a.jsx("div",{className:"card-body p-4",children:a.jsx(z,{sourceIdx:s,devices:n,group:i})})}),a.jsx("div",{className:"card card-border bg-base-200 border-base-300 rounded-box shadow-md flex-1",children:a.jsx("div",{className:"card-body p-4",children:a.jsx(E,{sourceIdx:s,target:i})})}),a.jsx("div",{className:"card card-border bg-base-200 border-base-300 rounded-box shadow-md flex-1",children:a.jsx("div",{className:"card-body p-4",children:a.jsx(k,{sourceIdx:s,target:i,deviceState:{}})})})]}),a.jsx(W,{sourceIdx:s,devices:n,group:i})]})}export{me as default};
