import{j as i,F as d,ap as h,r as l,u as w,aj as b,b4 as S,aB as O,b5 as P,a5 as N,c as _}from"./index-CE-9RlbR.js";import{g as D}from"./index-CDoSh7QA.js";const x=""+new URL("generic-zigbee-device-Dj-9sUqG.png",import.meta.url).href;function I({error:r,children:e}){return r?i.jsx(d,{icon:h,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 L(r){var e=E(r,"string");return p(e)=="symbol"?e:e+""}function A(r,e,t){return(e=L(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(a,s){var u=new Image;t&&(u.crossOrigin=t),u.onload=function(){u.decode?u.decode().then(a).catch(s):a()},u.onerror=s,u.src=n})}});function y(r,e){var t=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);e&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(r,a).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?y(Object(t),!0).forEach(function(n){A(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):y(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})},z=function(e){return Array.isArray(e)?e:[e]},f={},B=function(e,t){var n=!1;return new Promise(function(a,s){var u=function(o){return t(o).then(function(){n=!0,a(o)})};e.reduce(function(m,o){return m.catch(function(){if(!n)return u(o)})},u(e.shift())).catch(s)})};function T(r){var e=r.srcList,t=r.imgPromise,n=t===void 0?$({}):t,a=r.useSuspense,s=a===void 0?!0:a,u=l.useState(!1),m=u[1],o=F(z(e)),c=o.join("");if(f[c]||(f[c]={promise:B(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(s)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}),s||m(c)}).catch(function(v){f[c]=g(g({},f[c]),{},{cache:"rejected",error:v}),s||m(c)}),s)throw f[c].promise;return{isLoading:!0,src:void 0,error:null}}const j=l.memo(({device:r={},className:e})=>{const t=r.definition?.icon,n=D(r),a=t?[t]:[];n&&a.push(...n),a.push(x);const{src:s}=T({srcList:a});return i.jsx("img",{alt:r.ieee_address,src:s,className:`object-contain ${e??""}`})}),K=l.memo(r=>{const{t:e}=w(["zigbee","common"]),{device:t={},disabled:n,otaState:a,className:s,noIndicator:u}=r,m=l.useMemo(()=>t.interview_state===b.InProgress?i.jsx("span",{title:e(o=>o.interviewing),children:i.jsx(d,{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(d,{icon:h,beat:!0,className:"indicator-item indicator-bottom indicator-end text-error"})}):t.definition?.source==="generated"?i.jsx("span",{title:e(o=>o[t.definition.source]),children:i.jsx(d,{icon:O,className:"indicator-item indicator-bottom indicator-end text-accent"})}):t.definition?.source==="external"?i.jsx("span",{title:e(o=>o[t.definition.source]),children:i.jsx(d,{icon:P,className:"indicator-item indicator-bottom indicator-end text-info"})}):null,[t.interview_state,t.definition,e]);return i.jsx(l.Suspense,{fallback:i.jsx("img",{alt:t.ieee_address,src:x}),children:i.jsx(I,{children:u?i.jsx(j,{device:t,className:`grid place-items-center${s?` ${s}`:""}`}):i.jsxs("div",{className:"indicator w-full",children:[a==="updating"&&i.jsx("span",{title:e(o=>o.updating_firmware),children:i.jsx(d,{icon:N,spin:!0,className:"indicator-item indicator-top indicator-end text-info"})}),m,n&&i.jsx("span",{title:e(o=>o.disabled,{ns:"common"}),children:i.jsx(d,{icon:_,className:"indicator-item indicator-middle indicator-center text-error",size:"2xl"})}),i.jsx(j,{device:t,className:`grid place-items-center${s?` ${s}`:""}`})]})})})});export{K as D};
