"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let _parentNode;
class ClassList extends Array {
    constructor(parentNode) {
        super();
        _parentNode = parentNode;
    }
    __updateAttribute() {
        if (this.length > 0) {
            _parentNode.setAttribute("class", this.value);
        }
        else {
            _parentNode.removeAttribute("class");
        }
    }
    add(...classNames) {
        for (const className of classNames) {
            if (!this.includes(className)) {
                this.unshift(className);
            }
        }
        this.__updateAttribute();
    }
    remove(...classNames) {
        for (const className of classNames) {
            if (this.includes(className)) {
                this._splice(className);
            }
        }
        this.__updateAttribute();
    }
    toggle(className, force) {
        if (this.contains(className)) {
            if (force === true) {
                return true;
            }
            this.remove(className);
            return false;
        }
        else {
            if (force === false) {
                return false;
            }
            this.add(className);
            return true;
        }
    }
    _splice(element) {
        let index = this.indexOf(element);
        if (index > -1) {
            const newLength = this.length - 1;
            while (index < newLength) {
                this[index] = this[index + 1];
                ++index;
            }
            this.length = newLength;
            return [element];
        }
        return [];
    }
    get value() {
        return this.join(" ");
    }
    set value(value) {
        while (this.length > 0) {
            this.pop();
        }
        this.push(...value.split(" "));
        this.__updateAttribute();
    }
    contains(className) {
        return this.includes(className);
    }
}
exports.default = ClassList;
//# sourceMappingURL=classList.js.map