import Observe from '../modules/Observe';
import attrJoinVal from '../utils/attrJoinVal';
import deepMerge from '../utils/deepMerge';
import strToJson from '../utils/strToJson';
class CustomElem extends HTMLElement {
    constructor() {
        super();
        this.isCmpt = true;
        this.timestamp = Date.now();
        this.setAttribute('customized', '');
        this.reset = () => {
            this.ins.reset();
        };
        this.clear = () => {
            this.ins.clear();
        };
    }
    createObs() {
        this.properties = {};
        this.observer = new Observe(this.properties);
        this.propsProxy = this.observer.proxy;
        this.observer.ins.on('complete', () => {
            this.ins.update(this.properties);
        });
    }
    updateProxy(name, newVal, map) {
        let value;
        if (newVal === null) {
            this.propsProxy[name] = this.ins.dftOpts[name];
        }
        else {
            if (name === 'options') {
                value = strToJson(newVal);
            }
            else {
                value = attrJoinVal(name, newVal, map);
            }
            deepMerge(this.propsProxy, value, {});
        }
    }
}
window.customElements.define("ax-custom", CustomElem);
export default CustomElem;
