"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var MooBase = /** @class */ (function () {
    function MooBase(upperEle) {
        this._listeners = {};
        this._render(upperEle);
    }
    MooBase.prototype._render = function (upperEle) {
        this._ele = this._createElement();
        if (upperEle) {
            upperEle.appendChild(this._ele);
        }
    };
    Object.defineProperty(MooBase.prototype, "ele", {
        get: function () {
            if (this._ele) {
                return this._ele;
            }
            else {
                throw new Error('there is no element in the base.');
            }
        },
        enumerable: true,
        configurable: true
    });
    MooBase.prototype._helloListener = function (eventType, callback, subject) {
        if (subject) {
            this._listeners[eventType] = { evtListener: callback, evtTarget: subject };
            subject.addEventListener(eventType, callback);
        }
        else {
            var ele = this._ele;
            if (ele) {
                this._listeners[eventType] = { evtListener: callback, evtTarget: this.ele };
                ele.addEventListener(eventType, callback);
            }
            else {
                throw new Error('You added an event listener but there was no element.');
            }
        }
    };
    MooBase.prototype._byeListeners = function () {
        var evts = Object.keys(this._listeners);
        var len = evts.length;
        for (var i = 0; i < len; i++) {
            var listenerCom = this._listeners[evts[i]];
            listenerCom.evtTarget.removeEventListener(evts[i], listenerCom.evtListener);
            delete this._listeners[evts[i]];
        }
    };
    MooBase.prototype.eliminate = function () {
        var _a;
        var ele = this._ele;
        if (ele) {
            (_a = ele.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(ele);
        }
        this._byeListeners();
        this._ele = null;
    };
    return MooBase;
}());
exports.MooBase = MooBase;
