import createEl from '../utils/createEl';
import getAttrBool from '../utils/getAttrBool';
import PlainElem from './PlainElem';
class FlagElem extends PlainElem {
    constructor() {
        super();
        super.createObs();
        this.getRawData();
        this.fillWrap(this.propsProxy);
    }
    static get observedAttributes() {
        return ['label', ...this.custAttrs, ...this.boolAttrs];
    }
    attributeChangedCallback(name, oldVal, newVal) {
        this.propsProxy[name] = FlagElem.boolAttrs.includes(name) ? getAttrBool(newVal) : newVal;
        if (name === 'label') {
            this.labelEl.innerHTML = newVal;
        }
    }
    connectedCallback() {
        this.render();
        this.initialized = true;
        this.listen({ name: 'init' });
    }
    getRawData() {
        [...FlagElem.custAttrs, ...FlagElem.lazyAttrs].forEach((k) => {
            this.propsRaw[k] = this.getAttribute(k);
        });
        FlagElem.boolAttrs.forEach((k) => {
            this.propsRaw[k] = getAttrBool(this.getAttribute(k));
        });
        this.propsRaw.label = this.textContent?.trim() || this.getAttribute('label');
        for (let k in this.propsRaw) {
            this.propsProxy[k] = this.propsRaw[k];
        }
        this.innerHTML = '';
    }
    fillWrap(data) {
        this.wrapEl = createEl('span', { role: 'wrap' });
        this.labelEl = createEl('i', { role: 'label' }, data.label);
        this.wrapEl.appendChild(this.labelEl);
    }
    render(data) {
        this.appendChild(this.wrapEl);
    }
}
FlagElem.lazyAttrs = ['stor-name'];
FlagElem.custAttrs = [
    'class',
    'type', 'theme', 'placement',
    'on-init', 'on-reset', 'on-set',
];
FlagElem.boolAttrs = [];
window.customElements.define("ax-flag", FlagElem);
export default FlagElem;
