import{dq as d,de as _,dG as y,dx as j,dm as a,B as w,dB as g,dF as C,l as S,o as D,cT as N}from"./index-DjbVAZHL.js";import{R as E,A as k}from"./RecallRemove-7D_NDzYK.js";import{D as F}from"./DevicePicker-CtoMuVoS.js";import{E as A}from"./EndpointPicker-ByksWRBx.js";import{u as M,g as G}from"./useColumnCount-BxxtEcEj.js";import{D as R}from"./DashboardFeatureWrapper-O5P5TMzv.js";import{D as q}from"./DeviceCard-DKc-PXhO.js";import"./envs-CRUy-_iG.js";import"./startCase-SXH8nyJo.js";import"./DisplayValue-e_yVQGok.js";import"./isObject--vsEa_js.js";import"./_createCompounder-CI5okWsL.js";import"./isObjectLike-DlSfHoCn.js";import"./index-RfvTmd0Z.js";import"./InputField-D1U5kSs2.js";import"./extends-CF3RwP-h.js";import"./react-select.esm-189R5gw4.js";import"./defineProperty-CegpTSss.js";import"./floating-ui.dom-CFVCCol6.js";import"./SelectField-XDAy-a1R.js";import"./LastSeen-TlG8TNPK.js";import"./TimeAgo-B6rAagzx.js";import"./Lqi-_D0pWzA-.js";import"./PowerSource-DwoxK9gS.js";import"./snakeCase-Dg4N4ThO.js";import"./DeviceImage-Bsu1Hk6P.js";import"./index-BzinHeAr.js";const B=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 j(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)})]})}),T=({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(C(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})})})})},z=s=>s?.data?a.jsx(T,{...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(C(e=>e.deviceStates[s])),u=g(C(e=>e.bridgeInfo[s].config.advanced.last_seen)),v=M(),l=d.useCallback(async(e,b)=>await j(s,"bridge/request/group/members/remove",{device:e,endpoint:b,group:o.id.toString()}),[s,o.id]),m=d.useCallback(async(e,b)=>{await j(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:z,className:"gap-3"},`groupmembers-${f.length}`)})});function ue({sourceIdx:s,group:i}){const o=g(C(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(B,{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};
