/**
 * Copyright 2019 Penn State University
 * @license Apache-2.0, see License.md for full text.
 */
import{css as e}from"../../lit/index.js";import{SimplePicker as t}from"../simple-picker/simple-picker.js";import"../simple-icon/lib/simple-icon-lite.js";import"../simple-icon/lib/simple-icons.js";import{SimpleIconsetStore as i}from"../simple-icon/lib/simple-iconset.js";class SimpleIconPicker extends t{static get styles(){return[super.styles,e`
        simple-picker-option {
          --simple-picker-option-size: 32px;
        }
      `]}static get properties(){return{...super.properties,allowNull:{type:Boolean},icons:{type:Array},includeSets:{type:Array,attribute:"include-sets"},excludeSets:{type:Array,attribute:"exclude-sets"},exclude:{type:Array,attribute:"exclude"},value:{type:String,reflect:!0},optionsPerRow:{type:Number},__iconList:{type:Array}}}static get tag(){return"simple-icon-picker"}constructor(){super(),this.hideOptionLabels=!0,this.allowNull=!0,this.icons=[],this.value=null,this.options=[],this.optionsPerRow=6}updated(e){super.updated&&super.updated(e),e.forEach(((e,t)=>{["optionsPerRow","icons","allowNull","__iconList"].includes(t)&&(clearTimeout(this.__rebuild),this.__rebuild=setTimeout((()=>{this._getOptions()}),0)),"value"==t&&this.dispatchEvent(new CustomEvent("value-changed",{detail:{value:this[t]}}))}))}firstUpdated(e){super.firstUpdated&&super.firstUpdated(e)}_getStoredIcons(){let e=i&&i.iconlist?i.iconlist:[],t=!!(this.includeSets&&this.includeSets.length>0)&&("object"!=typeof this.includeSets?JSON.parse(this.includeSets):this.includeSets),s=!!(this.excludeSets&&this.excludeSets.length>0)&&("object"!=typeof this.excludeSets?JSON.parse(this.excludeSets):this.excludeSets),l=!!(this.exclude&&this.exclude.length>0)&&("object"!=typeof this.exclude?JSON.parse(this.exclude):this.exclude);return(t||s||l)&&(e=e.filter((e=>{let i=e,o=e,r=!0;return i=i.replace(/:.*/,""),o.replace("icons:",""),l&&(l.includes(e)||l.includes(`icons:${o}`))&&(r=!1),t&&!t.includes(i)&&(r=!1),s&&s.includes(i)&&(r=!1),r}))),e}_getOptions(){let e="string"==typeof this.icons?JSON.parse(this.icons):this.icons,t=this.optionsPerRow;0===e.length&&(e=this._getStoredIcons());let i=!1===this.allowNull?[]:[[{alt:"null",value:null}]],s=!1===this.allowNull?0:1;t=Math.sqrt(e.length+s)<=this.optionsPerRow?Math.ceil(Math.sqrt(e.length+s)):this.optionsPerRow;for(let l=0;l<e.length;l++){let o=s+l,r=Math.floor(o/t),n=o-r*t;void 0!==i[r]&&null!==i[r]||(i[r]=[]),i[r][n]={alt:e[l],icon:e[l],value:e[l]}}this.options=i}_setSelectedOption(){this.options.length>1&&super._setSelectedOption()}}customElements.define(SimpleIconPicker.tag,SimpleIconPicker);export{SimpleIconPicker};