export default class AOverlay extends window.AObject {
    constructor(p) {
        super();
        this.parent = p;
        this.IsActive = false;
        this.isClose = true;
    }
    createOverlay() {
        var c = document.createElement("div");
        c.classList.add("c-aoverlay");
        this.parent.appendChild(c);
        this.overlay = c;
        var f = function (e) {
                this.onOverlay_click.call(this, e);
        }.bind(this);
        c.addEventListener("click", f, false);

    }
    setIndex(i) {
        this.overlay.style.zIndex = i;
    }
    showOverlay() {
        this.overlay.classList.add("show");
        this.IsActive = true;
    }
    isCloseOverlay(flag) {
        this.isClose = flag;
    }
    addChildNode(childNode) {
        this.overlay.appendChild(childNode);
    }

    removeOverlay() {
        this.trigger("before_close");
        var f = function (e) {
            this.IsActive = false;
            this.trigger("after_close");
            this.overlay.removeEventListener("transitionend", f, false);
        }.bind(this);
        this.overlay.addEventListener("transitionend", f, false);
        this.overlay.classList.remove("show");

    }
    onOverlay_click(e) {
        if ((e.target.classList.contains("modal-con") || e.target.classList.contains("c-aoverlay") )&& this.isClose) {
            this.removeOverlay();
        }
    }


}
