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-VJpwYvBU.js";import{R as k,A as E}from"./RecallRemove-B8kK-jlT.js";import{D as F}from"./DevicePicker-BQE6PtnK.js";import{E as A}from"./EndpointPicker-DlYDImDR.js";import{u as M,g as G}from"./useColumnCount-BNJ8FuYE.js";import{D as R}from"./DashboardFeatureWrapper-C5cTX2Yd.js";import{D as q}from"./DeviceCard-Jno_2bki.js";import"./envs-CRUy-_iG.js";import"./startCase-DNIChZAc.js";import"./DisplayValue-BX0bcoSg.js";import"./isObject--vsEa_js.js";import"./_createCompounder-JrZUBxnL.js";import"./isObjectLike-CKrHmw-v.js";import"./index-C1LTvZEM.js";import"./InputField-B_6Ee4_m.js";import"./extends-CF3RwP-h.js";import"./react-select.esm-DM_HiCZr.js";import"./defineProperty-CegpTSss.js";import"./floating-ui.dom-DbzrgdRQ.js";import"./SelectField-BkTP72p-.js";import"./LastSeen-YOzeyMXj.js";import"./TimeAgo-CeXmHrG4.js";import"./Lqi-BLanrDho.js";import"./PowerSource-B4Kn6y4z.js";import"./snakeCase-BPMTuOlK.js";import"./DeviceImage-DAL8fj7m.js";import"./index-RbRX26AQ.js";const z=d.memo(({sourceIdx:s,devices:i,group:t})=>{const[o,m]=d.useState(""),[n,u]=d.useState(""),v=d.useMemo(()=>_(i.find(e=>e.ieee_address===n)),[n,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:o,device:n}),[s,t.id,o,n]);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:n,devices:i,onChange:b}),a.jsx(A,{label:l(e=>e.endpoint,{ns:"zigbee"}),values:v,value:o,onChange:e=>m(e),disabled:!n})]}),a.jsx(w,{onClick:f,className:"btn btn-primary",disabled:o==null||o===""||!n,children:l(e=>e.add_to_group)})]})}),B=({sourceIdx:s,device:i,deviceState:t,deviceAvailability:o,groupMember:m,lastSeenConfig:n,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 ${o==="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:n,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 o=g(e=>e.availability),m=g(e=>e.bridgeInfo),n=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?o[s][p.friendly_name]?.state??"offline":"disabled"}e.push({sourceIdx:s,groupMember:r,device:p,deviceState:n[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,n,m,o,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 ue({sourceIdx:s,group:i}){const t=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: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{ue as default};
