import{r as g,j as o,R as x,u as w,b as S}from"./index-42f456b7.js";import{A as P,a as v}from"./index-4552832e.js";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||"default");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 N=function(r){var e=r.decode,t=e===void 0?!0:e,n=r.crossOrigin,s=n===void 0?"":n;return function(u){return new Promise(function(l,f){var a=new Image;s&&(a.crossOrigin=s),a.onload=function(){t&&a.decode?a.decode().then(l).catch(f):l()},a.onerror=f,a.src=u})}};function y(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 d(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){L(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 _=function(e){return e.filter(function(t){return t})},D=function(e){return Array.isArray(e)?e:[e]},c={},I=function(e,t){var n=!1;return new Promise(function(s,u){var l=function(a){return t(a).then(function(){n=!0,s(a)})};e.reduce(function(f,a){return f.catch(function(){if(!n)return l(a)})},l(e.shift())).catch(u)})};function R(r){var e=r.srcList,t=r.imgPromise,n=t===void 0?N({decode:!0}):t,s=r.useSuspense,u=s===void 0?!0:s,l=g.useState(!1),f=l[1],a=_(D(e)),i=a.join("");if(c[i]||(c[i]={promise:I(a,n),cache:"pending",error:null}),c[i].cache==="resolved")return{src:c[i].src,isLoading:!1,error:null};if(c[i].cache==="rejected"){if(u)throw c[i].error;return{isLoading:!1,error:c[i].error,src:void 0}}if(c[i].promise.then(function(m){c[i]=d(d({},c[i]),{},{cache:"resolved",src:m}),u||f(i)}).catch(function(m){c[i]=d(d({},c[i]),{},{cache:"rejected",error:m}),u||f(i)}),u)throw c[i].promise;return{isLoading:!0,src:void 0,error:null}}function b(r){const{device:e,type:t,...n}=r,{src:s}=R({srcList:P.map(u=>u(e)).filter(Boolean)});return t==="svg"?o.jsx("image",{crossOrigin:"anonymous",...n,href:s}):o.jsx("img",{alt:"",crossOrigin:"anonymous",src:s})}class h extends x.Component{constructor(e){super(e),this.state={hasError:!1}}componentDidCatch(){this.setState({hasError:!0})}render(){return this.state.hasError?o.jsx(o.Fragment,{children:"ERROR"}):this.props.children}}function k(r){const{t:e}=w("zigbee"),{device:t={},disabled:n,deviceStatus:s,type:u="img",className:l,...f}=r;if(u==="svg")return o.jsx(g.Suspense,{fallback:o.jsx("image",{crossOrigin:"anonymous",...f,href:v}),children:o.jsx(h,{children:o.jsx(b,{type:"svg",device:t,...f})})});const i=((s==null?void 0:s.update)??{}).state==="updating"?o.jsx("i",{title:e("updating_firmware"),className:"fa fa-sync fa-spin position-absolute bottom-0 right-0"}):null,m=t.interviewing?o.jsx("i",{title:e("interviewing"),className:"fa fa-spinner fa-spin position-absolute bottom-0 right-0"}):null,j=!t.interviewing&&!t.interview_completed,O=n?o.jsx("i",{title:e("device_disabled"),className:"fa fa-ban position-absolute bottom-0 right-0"}):null;return o.jsxs("div",{className:S(l,"position-relative"),...f,children:[o.jsx(g.Suspense,{fallback:o.jsx("img",{alt:"",src:v}),children:o.jsx(h,{children:o.jsx(b,{device:t})})}),m,i,O,j&&o.jsx("i",{title:e("interview_failed"),className:"fa fa-exclamation-triangle position-absolute top-0 right-0 text-danger"})]})}export{k as D};
