import{r as d,a8 as _,u as y,s as C,j as a,B as w,a as g,E as j,a6 as S,F as D,Z as N}from"./index-ClCsMWbS.js";import{R as k,A as E}from"./RecallRemove-CnNFF1IW.js";import{D as F}from"./DevicePicker-0T64KBIx.js";import{E as A}from"./EndpointPicker-xjSURnYy.js";import{u as M,b as G}from"./useColumnCount-BIzxc4Aw.js";import{D as R}from"./DashboardFeatureWrapper-DSvHZUwh.js";import{D as q}from"./DeviceCard-C89jjCiz.js";import"./envs-CSqIi4cL.js";import"./Feature-C2pFQwpi.js";import"./DisplayValue-qZ7xyN8v.js";import"./isObject--vsEa_js.js";import"./_createCompounder-CDQ_1ElC.js";import"./isObjectLike-D4auEUP9.js";import"./index-CQLnbJQy.js";import"./InputField-CqTVHKf8.js";import"./SelectField-WiB6Edsu.js";import"./LastSeen-BOY7jIoe.js";import"./TimeAgo-55eetS_D.js";import"./Lqi-B1ebT_rM.js";import"./PowerSource--PK2quZc.js";import"./snakeCase-D0nOJtgb.js";import"./DeviceImage-Bs0M9j-k.js";import"./index-C8QGyin-.js";const z=d.memo(({sourceIdx:s,devices:i,group:t})=>{const[n,m]=d.useState(""),[o,u]=d.useState(""),v=d.useMemo(()=>_(i.find(e=>e.ieee_address===o)),[o,i]),{t:l}=y(["groups","zigbee"]),b=d.useCallback(e=>{u(e.ieee_address);const c=_(e);m(c.values().next().value)},[]),f=d.useCallback(async()=>await C(s,"bridge/request/group/members/add",{group:t.id.toString(),endpoint:n,device:o}),[s,t.id,n,o]);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:o,devices:i,onChange:b}),a.jsx(A,{label:l(e=>e.endpoint,{ns:"zigbee"}),values:v,value:n,onChange:e=>m(e),disabled:!o})]}),a.jsx(w,{onClick:f,className:"btn btn-primary",disabled:n==null||n===""||!o,children:l(e=>e.add_to_group)})]})}),B=({sourceIdx:s,device:i,deviceState:t,deviceAvailability:n,groupMember:m,lastSeenConfig:o,removeDeviceFromGroup:u,setDeviceState:v})=>{const{endpoint:l}=m,{t:b}=y(["groups","common"]),f=g(j(r=>r.deviceScenesFeatures[s][i.ieee_address]??[])),e=d.useCallback(async r=>await v(i.ieee_address,r),[i.ieee_address,v]),c=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 ${n==="offline"?"border-error/50":"border-base-300"}`,children:a.jsx(q,{sourceIdx:s,hideSourceDot:!0,features:f,device:i,endpoint:l,deviceState:t,onChange:e,featureWrapperClass:R,lastSeenConfig:o,children:a.jsx(S,{onClick:c,className:"btn btn-square btn-outline btn-error btn-sm",title:b(r=>r.remove_from_group),modalDescription:b(r=>r.dialog_confirmation_prompt,{ns:"common"}),modalCancelLabel:b(r=>r.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:t})=>{const n=g(e=>e.availability),m=g(e=>e.bridgeInfo),o=g(j(e=>e.deviceStates[s])),u=g(j(e=>e.bridgeInfo[s].config.advanced.last_seen)),v=M(),l=d.useCallback(async(e,c)=>await C(s,"bridge/request/group/members/remove",{device:e,endpoint:c,group:t.id.toString()}),[s,t.id]),b=d.useCallback(async(e,c)=>{await C(s,`${e}/set`,c)},[s]),f=d.useMemo(()=>{const e=[],c=m[s].config.availability.enabled;for(const r of t.members){const p=i.find(h=>h.ieee_address===r.ieee_address);if(p){let h="disabled";if(!p.disabled){const x=m[s].config.devices[p.ieee_address]?.availability;h=(x!=null?!!x:void 0)??c?n[s][p.friendly_name]?.state??"offline":"disabled"}e.push({sourceIdx:s,groupMember:r,device:p,deviceState:o[p.friendly_name]??{},deviceAvailability:h,lastSeenConfig:u,removeDeviceFromGroup:l,setDeviceState:b})}}return e.sort((r,p)=>r.device.ieee_address.localeCompare(p.device.ieee_address)),e},[s,t,i,u,o,m,n,l,b]);return a.jsx("div",{children:a.jsx(G,{useWindowScroll:!0,columnCount:v,data:f,ItemContent:T,className:"gap-3"},`groupmembers-${f.length}`)})});function ce({sourceIdx:s,group:i}){const t=g(j(n=>n.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:t,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(k,{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(E,{sourceIdx:s,target:i,deviceState:{}})})})]}),a.jsx(W,{sourceIdx:s,devices:t,group:i})]})}export{ce as default};
