import{r,W as y,C as _,a as o,b as C,Y as I,Z as P,$ as w,j as s,L as N,B as m,F as b,a0 as k,a1 as F,a2 as T}from"./index-BeDhuS24.js";import{T as v}from"./Table-CH7yonv3.js";import"./envs-DFlyG_dH.js";import"./DebouncedInput-jeSVRz3c.js";function A(){const{sendMessage:i}=r.useContext(y),a=_(),x=o(e=>e.touchlinkDevices),d=o(e=>e.devices),c=o(e=>e.touchlinkIdentifyInProgress),l=o(e=>e.touchlinkResetInProgress),h=o(e=>e.touchlinkScanInProgress),u=c||l,{t:n}=C(["touchlink","common","zigbee"]),p=r.useCallback(async()=>{a(I({inProgress:!0,devices:[]})),await i("bridge/request/touchlink/scan","")},[i,a]),f=r.useCallback(async e=>{a(P(!0)),await i("bridge/request/touchlink/identify",e)},[i,a]),g=r.useCallback(async e=>{a(w(!0)),await i("bridge/request/touchlink/factory_reset",e)},[i,a]),j=r.useMemo(()=>[{id:"ieee_address",header:n("zigbee:ieee_address"),accessorFn:e=>e.ieee_address,cell:({row:{original:e}})=>d.find(t=>t.ieee_address===e.ieee_address)?s.jsx(N,{to:`/device/${e.ieee_address}/info`,className:"link link-hover",children:e.ieee_address}):e.ieee_address,sortingFn:(e,t)=>e.original.ieee_address.localeCompare(t.original.ieee_address)},{id:"friendly_name",header:n("common:friendly_name"),accessorFn:e=>d.find(t=>t.ieee_address===e.ieee_address)?.friendly_name},{id:"channel",header:n("zigbee:channel"),accessorFn:e=>e.channel},{id:"actions",header:"",cell:({row:{original:e}})=>s.jsxs("div",{className:"join join-horizontal",children:[s.jsx(m,{disabled:u,item:e,title:n("identify"),className:"btn btn-square btn-outline btn-primary join-item",onClick:f,children:s.jsx(b,{icon:c?k:F,spin:c})}),s.jsx(m,{disabled:u,item:e,title:n("factory_reset"),className:"btn btn-square btn-outline btn-error join-item",onClick:g,children:s.jsx(b,{icon:l?k:T,spin:l})})]}),enableSorting:!1,enableColumnFilter:!1}],[c,l,u,d,n,f,g]);return h?s.jsx("div",{className:"flex flex-row justify-center items-center gap-2",children:s.jsx("span",{className:"loading loading-infinity loading-xl"})}):s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"flex flex-row flex-wrap justify-center items-center gap-2 mb-3",children:s.jsx(m,{className:"btn btn-primary",onClick:p,disabled:h,children:n("scan")})}),s.jsx(v,{id:"touchlink-devices",columns:j,data:x})]})}export{A as default};
