import{j as i,F as l,ai as x,r as m,u as w,aV as b,aX as S,c$ as O,d0 as P,a2 as N,c as _}from"./index-ClCsMWbS.js";import{g as D,a as y}from"./index-C8QGyin-.js";function I({error:r,children:e}){return r?i.jsx(l,{icon:x,size:"3x",className:"text-error"}):e}function p(r){"@babel/helpers - typeof";return p=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},p(r)}function E(r,e){if(p(r)!="object"||!r)return r;var t=r[Symbol.toPrimitive];if(t!==void 0){var n=t.call(r,e);if(p(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(r)}function A(r){var e=E(r,"string");return p(e)=="symbol"?e:e+""}function L(r,e,t){return(e=A(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}var $=(function(r){var e=r.crossOrigin,t=e===void 0?"":e;return function(n){return new Promise(function(s,a){var u=new Image;t&&(u.crossOrigin=t),u.onload=function(){u.decode?u.decode().then(s).catch(a):s()},u.onerror=a,u.src=n})}});function j(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(s){return Object.getOwnPropertyDescriptor(r,s).enumerable})),t.push.apply(t,n)}return t}function g(r){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?j(Object(t),!0).forEach(function(n){L(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):j(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}var F=function(e){return e.filter(function(t){return t})},T=function(e){return Array.isArray(e)?e:[e]},f={},z=function(e,t){var n=!1;return new Promise(function(s,a){var u=function(o){return t(o).then(function(){n=!0,s(o)})};e.reduce(function(d,o){return d.catch(function(){if(!n)return u(o)})},u(e.shift())).catch(a)})};function B(r){var e=r.srcList,t=r.imgPromise,n=t===void 0?$({}):t,s=r.useSuspense,a=s===void 0?!0:s,u=m.useState(!1),d=u[1],o=F(T(e)),c=o.join("");if(f[c]||(f[c]={promise:z(o,n),cache:"pending",error:null}),f[c].cache==="resolved")return{src:f[c].src,isLoading:!1,error:null};if(f[c].cache==="rejected"){if(a)throw f[c].error;return{isLoading:!1,error:f[c].error,src:void 0}}if(f[c].promise.then(function(v){f[c]=g(g({},f[c]),{},{cache:"resolved",src:v}),a||d(c)}).catch(function(v){f[c]=g(g({},f[c]),{},{cache:"rejected",error:v}),a||d(c)}),a)throw f[c].promise;return{isLoading:!0,src:void 0,error:null}}const h=m.memo(({device:r={},className:e})=>{const t=r.definition?.icon,n=D(r),s=[];t&&s.push(t),n&&s.push(n),n!==y&&s.push(y);const{src:a}=B({srcList:s});return i.jsx("img",{alt:r.ieee_address,src:a,className:e})}),K=m.memo(r=>{const{t:e}=w(["zigbee","common"]),{device:t={},disabled:n,otaState:s,className:a,noIndicator:u}=r,d=m.useMemo(()=>t.interview_state===b.InProgress?i.jsx("span",{title:e(o=>o.interviewing),children:i.jsx(l,{icon:S,spin:!0,className:"indicator-item indicator-bottom indicator-end text-info"})}):t.interview_state===b.Failed?i.jsx("span",{title:e(o=>o.interview_failed),children:i.jsx(l,{icon:x,beat:!0,className:"indicator-item indicator-bottom indicator-end text-error"})}):t.definition?.source==="generated"?i.jsx("span",{title:e(o=>o.unsupported),children:i.jsx(l,{icon:O,beat:!0,className:"indicator-item indicator-bottom indicator-end text-warning"})}):t.definition?.source==="external"?i.jsx("span",{title:e(o=>o.unsupported),children:i.jsx(l,{icon:P,className:"indicator-item indicator-bottom indicator-end text-info"})}):null,[t.interview_state,t.definition,e]);return i.jsx(m.Suspense,{fallback:i.jsx("img",{alt:t.ieee_address,src:y}),children:i.jsx(I,{children:u?i.jsx(h,{device:t,className:`grid place-items-center${a?` ${a}`:""}`}):i.jsxs("div",{className:"indicator w-full",children:[s==="updating"&&i.jsx("span",{title:e(o=>o.updating_firmware),children:i.jsx(l,{icon:N,spin:!0,className:"indicator-item indicator-top indicator-end text-info"})}),d,n&&i.jsx("span",{title:e(o=>o.disabled,{ns:"common"}),children:i.jsx(l,{icon:_,className:"indicator-item indicator-middle indicator-center text-error",size:"2xl"})}),i.jsx(h,{device:t,className:`grid place-items-center${a?` ${a}`:""}`})]})})})});export{K as D};
