export default class AbstractNode {
    constructor(arena, id, attributes) {
        this.arena = arena;
        this.id = id;
        this.hasParent = false;
        this.hasChildren = false;
        this.hasText = false;
        this.inline = false;
        this.single = false;
        this.attributes = {};
        this.attributes = attributes || {};
    }
    get parent() {
        if (!this._parent) {
            throw Error('parrent not set');
        }
        return this._parent;
    }
    // Child node methods
    getId() {
        return this.id;
    }
    getIndex() {
        // if (!this.parent) {
        //   return 0;
        // }
        return this.parent.children.indexOf(this);
    }
    isFirstChild() {
        return this.getIndex() === 0;
    }
    isLastChild() {
        return this.getIndex() === this.parent.children.length - 1;
    }
    getGlobalIndex() {
        if (!this._parent) {
            return '0';
        }
        return `${this.parent.getGlobalIndex()}.${this.getIndex().toString()}`;
    }
    getOpenTag() {
        return this.arena.getOpenTag(this.attributes);
    }
    getCloseTag() {
        return this.arena.getCloseTag();
    }
    getParent() {
        return { node: this.parent, offset: this.getIndex() };
    }
    setParent(parent) {
        this._parent = parent;
    }
    // TODO deprecate
    getUnprotectedParent() {
        if (this.parent) {
            if (this.parent.arena.protected) {
                if (this.parent.hasParent) {
                    return this.parent.getUnprotectedParent();
                }
                return undefined;
            }
            return { node: this.parent, offset: this.getIndex() };
        }
        return undefined;
    }
    remove() {
        return this.parent.removeChild(this.getIndex());
    }
    // Attributes methods
    setAttribute(name, value) {
        this.attributes[name] = value;
    }
    setAttributes(attrs) {
        Object.entries(attrs).forEach(([name, value]) => this.setAttribute(name, value));
    }
    getAttribute(name) {
        return this.attributes[name] || '';
    }
}
//# sourceMappingURL=AbstractNode.js.map