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-a36IMXuN.js";import{R as E,A as k}from"./RecallRemove-DYqjMF_w.js";import{D as F}from"./DevicePicker-BzI6-dAt.js";import{E as A}from"./EndpointPicker-C6CQyxjG.js";import{u as M,g as G}from"./useColumnCount-BMdgoihj.js";import{D as R}from"./DashboardFeatureWrapper-DGHjt4Ah.js";import{D as q}from"./DeviceCard-vHwXtt-g.js";import"./envs-CRUy-_iG.js";import"./startCase-K7WbZvzP.js";import"./DisplayValue-D9Ja0Su_.js";import"./isObject--vsEa_js.js";import"./_createCompounder-BuXEc9F7.js";import"./isObjectLike-BQssIl0N.js";import"./index-CCf1BEwD.js";import"./InputField-IMyvy6Mz.js";import"./extends-CF3RwP-h.js";import"./react-select.esm-s6La4tfe.js";import"./defineProperty-CegpTSss.js";import"./floating-ui.dom-DbzrgdRQ.js";import"./SelectField-BQBsNhlB.js";import"./LastSeen-sm0titIc.js";import"./TimeAgo-DVPpOI6f.js";import"./Lqi-BErKiqkS.js";import"./PowerSource-CSWJpU_d.js";import"./snakeCase-BMb4_GjJ.js";import"./DeviceImage-DIhbuI22.js";import"./index-CsCgDwc5.js";const z=d.memo(({sourceIdx:s,devices:i,group:o})=>{const[r,c]=d.useState(""),[n,u]=d.useState(""),v=d.useMemo(()=>_(i.find(e=>e.ieee_address===n)),[n,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:o.id.toString(),endpoint:r,device:n}),[s,o.id,r,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:m}),a.jsx(A,{label:l(e=>e.endpoint,{ns:"zigbee"}),values:v,value:r,onChange:e=>c(e),disabled:!n})]}),a.jsx(w,{onClick:f,className:"btn btn-primary",disabled:r==null||r===""||!n,children:l(e=>e.add_to_group)})]})}),B=({sourceIdx:s,device:i,deviceState:o,deviceAvailability:r,groupMember:c,lastSeenConfig:n,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 ${r==="offline"?"border-error/50":"border-base-300"}`,children:a.jsx(q,{sourceIdx:s,hideSourceDot:!0,features:f,device:i,endpoint:l,deviceState:o,onChange:e,featureWrapperClass:R,lastSeenConfig:n,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:o})=>{const r=g(e=>e.availability),c=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,b)=>await C(s,"bridge/request/group/members/remove",{device:e,endpoint:b,group:o.id.toString()}),[s,o.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 o.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?r[s][p.friendly_name]?.state??"offline":"disabled"}e.push({sourceIdx:s,groupMember:t,device:p,deviceState:n[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,o,i,u,n,c,r,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 ue({sourceIdx:s,group:i}){const o=g(j(r=>r.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:o,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:o,group:i})]})}export{ue as default};
