import{r as g,j as o,R as j,u as O,b as P}from"./index-d7144f09.js";import{A as x,a as v}from"./index-46206196.js";var N=(r=>(r[r.NONE=0]="NONE",r[r.ACCESS_STATE=1]="ACCESS_STATE",r[r.ACCESS_WRITE=2]="ACCESS_WRITE",r[r.ACCESS_READ=4]="ACCESS_READ",r))(N||{}),y=(r=>(r.PENDING="PENDING",r.IN_PROGRESS="IN_PROGRESS",r.SUCCESSFUL="SUCCESSFUL",r.FAILED="FAILED",r))(y||{});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 _(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 w(r){var e=_(r,"string");return p(e)=="symbol"?e:e+""}function C(r,e,t){return(e=w(e))in r?Object.defineProperty(r,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):r[e]=t,r}var R=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 S(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?S(Object(t),!0).forEach(function(n){C(r,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(t)):S(Object(t)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(t,n))})}return r}var A=function(e){return e.filter(function(t){return t})},D=function(e){return Array.isArray(e)?e:[e]},c={},L=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 I(r){var e=r.srcList,t=r.imgPromise,n=t===void 0?R({decode:!0}):t,s=r.useSuspense,u=s===void 0?!0:s,l=g.useState(!1),f=l[1],a=A(D(e)),i=a.join("");if(c[i]||(c[i]={promise:L(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}=I({srcList:x.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 j.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 B(r){const{t:e}=O("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.interview_state===y.IN_PROGRESS?o.jsx("i",{title:e("interviewing"),className:"fa fa-spinner fa-spin position-absolute bottom-0 right-0"}):null,E=n?o.jsx("i",{title:e("device_disabled"),className:"fa fa-ban position-absolute bottom-0 right-0"}):null;return o.jsxs("div",{className:P(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,E,t.interview_state===y.FAILED&&o.jsx("i",{title:e("interview_failed"),className:"fa fa-exclamation-triangle position-absolute top-0 right-0 text-danger"})]})}export{B as D,N as F};
