import{P as t,h as e,G as i,f as s,_ as n,k as o,e as r,I as a,E as c,F as h,T as l,q as u,i as d,n as p}from"./main-ef294d92.js";class v{constructor(t){v[" "](t),this.type=t&&t.type||"default",this.key=t&&t.key,t&&"value"in t&&(this.value=t.value)}get value(){var t=this.type,e=this.key;if(t&&e)return v.types[t]&&v.types[t][e]}set value(t){var e=this.type,i=this.key;e&&i&&(e=v.types[e]=v.types[e]||{},null==t?delete e[i]:e[i]=t)}get list(){if(this.type){var t=v.types[this.type];return t?Object.keys(t).map((function(t){return _[this.type][t]}),this):[]}}byKey(t){return this.key=t,this.value}}v[" "]=function(){},v.types={};var _=v.types;t({is:"iron-meta",properties:{type:{type:String,value:"default"},key:{type:String},value:{type:String,notify:!0},self:{type:Boolean,observer:"_selfChanged"},__meta:{type:Boolean,computed:"__computeMeta(type, key, value)"}},hostAttributes:{hidden:!0},__computeMeta:function(t,e,i){var s=new v({type:t,key:e});return void 0!==i&&i!==s.value?s.value=i:this.value!==s.value&&(this.value=s.value),s},get list(){return this.__meta&&this.__meta.list},_selfChanged:function(t){t&&(this.value=this)},byKey:function(t){return new v({type:this.type,key:t}).value}}),t({_template:e`
    <style>
      :host {
        @apply --layout-inline;
        @apply --layout-center-center;
        position: relative;

        vertical-align: middle;

        fill: var(--iron-icon-fill-color, currentcolor);
        stroke: var(--iron-icon-stroke-color, none);

        width: var(--iron-icon-width, 24px);
        height: var(--iron-icon-height, 24px);
        @apply --iron-icon;
      }

      :host([hidden]) {
        display: none;
      }
    </style>
`,is:"iron-icon",properties:{icon:{type:String},theme:{type:String},src:{type:String},_meta:{value:i.create("iron-meta",{type:"iconset"})}},observers:["_updateIcon(_meta, isAttached)","_updateIcon(theme, isAttached)","_srcChanged(src, isAttached)","_iconChanged(icon, isAttached)"],_DEFAULT_ICONSET:"icons",_iconChanged:function(t){var e=(t||"").split(":");this._iconName=e.pop(),this._iconsetName=e.pop()||this._DEFAULT_ICONSET,this._updateIcon()},_srcChanged:function(t){this._updateIcon()},_usesIconset:function(){return this.icon||!this.src},_updateIcon:function(){this._usesIconset()?(this._img&&this._img.parentNode&&s(this.root).removeChild(this._img),""===this._iconName?this._iconset&&this._iconset.removeIcon(this):this._iconsetName&&this._meta&&(this._iconset=this._meta.byKey(this._iconsetName),this._iconset?(this._iconset.applyIcon(this,this._iconName,this.theme),this.unlisten(window,"iron-iconset-added","_updateIcon")):this.listen(window,"iron-iconset-added","_updateIcon"))):(this._iconset&&this._iconset.removeIcon(this),this._img||(this._img=document.createElement("img"),this._img.style.width="100%",this._img.style.height="100%",this._img.draggable=!1),this._img.src=this.src,s(this.root).appendChild(this._img))}});const y=t=>(e,i)=>{if(e.constructor._observers){if(!e.constructor.hasOwnProperty("_observers")){const t=e.constructor._observers;e.constructor._observers=new Map,t.forEach((t,i)=>e.constructor._observers.set(i,t))}}else{e.constructor._observers=new Map;const t=e.updated;e.updated=function(e){t.call(this,e),e.forEach((t,e)=>{const i=this.constructor._observers.get(e);void 0!==i&&i.call(this,this[e],t)})}}e.constructor._observers.set(i,t)};function m(t){const e=t.language||"en";return t.translationMetadata.translations[e]&&t.translationMetadata.translations[e].isRTL||!1}function f(t){return m(t)?"rtl":"ltr"}const g=window;"customIconsets"in g||(g.customIconsets={});const w=g.customIconsets;function k(t){return new Promise((e,i)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>i(t.error)})}function b(t,e){const i=indexedDB.open(t);i.onupgradeneeded=()=>i.result.createObjectStore(e);const s=k(i);return(t,i)=>s.then(s=>i(s.transaction(e,t).objectStore(e)))}let I;function $(){return I||(I=b("keyval-store","keyval")),I}function C(t,e,i=$()){return i("readwrite",i=>(i.put(e,t),k(i.transaction)))}const N={version:"0",parts:[]},P=b("hass-icon-db","mdi-icon-store"),x=["mdi","hass","hassio","hademo"];let E=[];const S=t=>new Promise((e,i)=>{E.push([t,e,i]),E.length>1||((t,e)=>{const i=new Promise((e,i)=>{setTimeout(()=>{i(`Timed out in ${t} ms.`)},t)});return Promise.race([e,i])})(1e3,P("readonly",t=>{for(const[e,i,s]of E)k(t.get(e)).then(t=>i(t)).catch(t=>s(t));E=[]})).catch(t=>{for(const[,,e]of E)e(t);E=[]})}),j={},B={};(async()=>{const t=await function(t,e=$()){return e("readonly",e=>k(e.get(t)))}("_version",P);t?t!==N.version&&(await function(t=$()){return t("readwrite",t=>(t.clear(),k(t.transaction)))}(P),C("_version",N.version,P)):C("_version",N.version,P)})();const T=((t,e,i=!1)=>{let s;return(...n)=>{const o=i&&!s;clearTimeout(s),s=window.setTimeout(()=>{s=void 0,i||t(...n)},e),o&&t(...n)}})(()=>(async t=>{const e=Object.keys(t),i=await Promise.all(Object.values(t));P("readwrite",s=>{i.forEach((i,n)=>{Object.entries(i).forEach(([t,e])=>{s.put(e,t)}),delete t[e[n]]})})})(B),2e3),O={};n([p("ha-icon")],(function(t,e){class i extends e{constructor(...e){super(...e),t(this)}}return{F:i,d:[{kind:"field",decorators:[r()],key:"icon",value:void 0},{kind:"field",decorators:[a()],key:"_path",value:void 0},{kind:"field",decorators:[a()],key:"_viewBox",value:void 0},{kind:"field",decorators:[a()],key:"_legacy",value:()=>!1},{kind:"method",key:"willUpdate",value:function(t){c(h(i.prototype),"willUpdate",this).call(this,t),t.has("icon")&&(this._path=void 0,this._viewBox=void 0,this._loadIcon())}},{kind:"method",key:"render",value:function(){return this.icon?this._legacy?l`<iron-icon .icon=${this.icon}></iron-icon>`:l`<ha-svg-icon
      .path=${this._path}
      .viewBox=${this._viewBox}
    ></ha-svg-icon>`:l``}},{kind:"method",key:"_loadIcon",value:async function(){if(!this.icon)return;const[t,e]=this.icon.split(":",2);let i,s=e;if(!t||!s)return;if(!x.includes(t)){if(t in w){const e=w[t];return void(e&&this._setCustomPath(e(s)))}return void(this._legacy=!0)}if(this._legacy=!1,s in j){const e=j[s];let i;e.newName?(i=`Icon ${t}:${s} was renamed to ${t}:${e.newName}, please change your config, it will be removed in version ${e.removeIn}.`,s=e.newName):i=`Icon ${t}:${s} was removed from MDI, please replace this icon with an other icon in your config, it will be removed in version ${e.removeIn}.`,console.warn(i),u(this,"write_log",{level:"warning",message:i})}if(s in O)return void(this._path=O[s]);try{i=await S(s)}catch(t){i=void 0}if(i)return this._path=i,void(O[s]=i);const n=(t=>{let e;for(const i of N.parts){if(void 0!==i.start&&t<i.start)break;e=i}return e.file})(s);if(n in B)return void this._setPath(B[n],s);const o=fetch(`/static/mdi/${n}.json`).then(t=>t.json());B[n]=o,this._setPath(o,s),T()}},{kind:"method",key:"_setCustomPath",value:async function(t){const e=await t;this._path=e.path,this._viewBox=e.viewBox}},{kind:"method",key:"_setPath",value:async function(t,e){const i=await t;this._path=i[e],O[e]=i[e]}},{kind:"get",static:!0,key:"styles",value:function(){return d`
      :host {
        fill: currentcolor;
      }
    `}}]}}),o);export{v as I,m as a,f as c,y as o};
