import{proxyCustomElement,HTMLElement,createEvent,h}from"@stencil/core/internal/client";import{w as watchIcon,u as unwatchIcon,g as getIconLibrary}from"./library.js";const iconFiles=new Map,requestIcon=t=>{if(iconFiles.has(t))return iconFiles.get(t);{const e=fetch(t).then((async t=>{if(t.ok){const e=document.createElement("div");e.innerHTML=await t.text();const s=e.firstElementChild;return{ok:t.ok,status:t.status,svg:s&&"svg"===s.tagName.toLowerCase()?s.outerHTML:""}}return{ok:t.ok,status:t.status,svg:null}}));return iconFiles.set(t,e),e}},scIconCss=":host{--width:1em;--height:1em;display:inline-block;width:var(--width);height:var(--height);contain:strict;box-sizing:content-box !important}.icon,svg{display:block;height:100%;width:100%;stroke-width:var(--sc-icon-stroke-width, 2px)}",ScIconStyle0=scIconCss,LABEL_MAPPINGS={"chevron-down":wp.i18n.__("Open","surecart"),"chevron-up":wp.i18n.__("Close","surecart"),"chevron-right":wp.i18n.__("Next","surecart"),"chevron-left":wp.i18n.__("Previous","surecart"),"arrow-right":wp.i18n.__("Next","surecart"),"arrow-left":wp.i18n.__("Previous","surecart"),"arrow-down":wp.i18n.__("Down","surecart"),"arrow-up":wp.i18n.__("Up","surecart"),"alert-circle":wp.i18n.__("Alert","surecart")},parser=new DOMParser,ScIcon=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.scLoad=createEvent(this,"scLoad",7),this.svg="",this.name=void 0,this.src=void 0,this.label=void 0,this.library="default",this.mutate=!0}redraw(){this.setIcon()}componentWillLoad(){watchIcon(this),this.setIcon()}disconnectedCallback(){unwatchIcon(this)}getLabel(){let t="";return this.label?t=(null==LABEL_MAPPINGS?void 0:LABEL_MAPPINGS[this.label])||this.label:this.name?t=((null==LABEL_MAPPINGS?void 0:LABEL_MAPPINGS[this.name])||this.name).replace(/-/g," "):this.src&&(t=this.src.replace(/.*\//,"").replace(/-/g," ").replace(/\.svg/i,"")),t}async setIcon(){const t=getIconLibrary(this.library),e=this.getUrl();if(e)try{const s=await requestIcon(e);if(e!==this.getUrl())return;if(s.ok){const e=parser.parseFromString(s.svg,"text/html").body.querySelector("svg");e?(t&&t.mutator&&this.mutate&&t.mutator(e),this.svg=e.outerHTML,this.svg=this.svg.replace("<svg",'<svg part="svg" '),this.scLoad.emit()):(this.svg="",console.error({status:null==s?void 0:s.status}))}else this.svg="",console.error({status:null==s?void 0:s.status})}catch{console.error({status:-1})}else this.svg&&(this.svg="")}getUrl(){const t=getIconLibrary(this.library);return this.name&&t?t.resolver(this.name):this.src}render(){return h("div",{key:"87747ec5b82fcc260080b9c282c9556d97e885ef",part:"base",class:"icon",role:"img","aria-label":this.getLabel(),innerHTML:this.svg})}static get assetsDirs(){return["icon-assets"]}static get watchers(){return{name:["setIcon"],src:["setIcon"],library:["setIcon"]}}static get style(){return ScIconStyle0}},[1,"sc-icon",{name:[513],src:[1],label:[1],library:[1],mutate:[4],svg:[32]},void 0,{name:["setIcon"],src:["setIcon"],library:["setIcon"]}]);function defineCustomElement(){"undefined"!=typeof customElements&&["sc-icon"].forEach((t=>{"sc-icon"===t&&(customElements.get(t)||customElements.define(t,ScIcon))}))}export{ScIcon as S,defineCustomElement as d};