export default class AMultiTag extends window.AObject {
    constructor(ele) {
        super();
        this.parent = ele;
        this.cItems = ele.querySelector(".input-content");
        this.itemEles = [];
        this.itemDatas = [];
        this.btnAdd = ele.querySelector(".btn-Add");
        this.btnAdd.addEventListener("click", ((e) => {
            this.parent.classList.add("active");
            this.trigger("btnAdd_Click", e);
        }).bind(this));
        if (window.AMultiTag == null) {
            this.initGlobalVar();
        }
    }
    initGlobalVar() {
        var f = function (ev) {
            if (ev.target.closest(".amultitag") || ev.target.closest(".c-aoverlay")) {
                return;
            } else {
                this.parent.classList.remove("active");
            }
        }.bind(this);
        document.body.addEventListener("mousedown", f, false);
        window.AMultiTag = true;
    }
    addItem(id, name, obj, action = null) {
        var ele = this.addItem(id, name, action);
        this.itemEles.push(ele);
        this.itemDatas.push(obj);
        this.cItems.appendChild(ele);
    }
    createItem(id, name, action) {
        var p = document.createElement("div");
        p.setAttribute("data-id", id);
        p.classList.add("item");
        var label = document.createElement("span");
        label.innerHTML = name;
        label.classList.add("name");
        if (action != null) {
            p.appendChild(action);
        }
        p.appendChild(label);
        return p;
    }
}