
/*
* infoGet 扩展 
* Date  : 2024-10-24
* author: lith

 */

; (function (infoGet) {


    class InfoGet extends HTMLElement {

        ig_attr;
        jq
        widget;

        constructor() {
            // Always call super first in constructor
            super();
            //console.log("[CustomElement] constructor"); 
        }

        connectedCallback() {

            this.ig_attr = getIgAttrFromJe(this);

            let html = infoGet.buildHtml(this.ig_attr);
            this.jq = $(html);
            let elem = this.jq[0];
            //this.innerHTML = html;

            // Attach the created elements to the shadow dom
            this.appendChild(elem);

            this.widget = infoGet.getWidget(elem);

            //console.log("[CustomElement] connectedCallback");
        }


        disconnectedCallback() {
            //console.log("[CustomElement] disconnectedCallback");
        }

        adoptedCallback() {
            //console.log("[CustomElement] adoptedCallback");
        }

        attributeChangedCallback(name, oldValue, newValue) {
            //console.log(`[CustomElement] Attribute ${name} has changed.`);
        }
    }


    customElements.define("info-get", InfoGet);

    function getIgAttrFromJe(elem) {
        function getAttrEval(value) {
            try {
                if (value)
                    return eval('(' + value + ')');
            } catch (e) {
                infoGet.errorList.push(e);
                console.log(e);
            }
            return null;
        }

        var igAttr = {
            'ig_class': elem.getAttribute('ig-class'),
            'ig_id': elem.getAttribute('ig-id'),
            'ig_param': getAttrEval(elem.getAttribute('ig-param')) || {}
        };

        return igAttr;
    };



    infoGet.buildElementHtml = function (igAttr) {

        let attrs = {
            'ig-class': igAttr.ig_class,
            'ig-id': igAttr.ig_id,
            'ig-param': igAttr.ig_param,
        };
        var html = '<info-get  ';
        html += infoGet.getHtmlCtrl_attr(attrs);
        html += ' />';
        return html;
    };



})(window.infoGet || (window.infoGet = {}));