"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParsedNgElement = void 0;
const interface_1 = require("./interface");
class ParsedNgElement {
    constructor(node, parent, componentMeta, index, directiveMeta) {
        this.node = node;
        this.parent = parent;
        this.componentMeta = componentMeta;
        this.index = index;
        this.directiveMeta = directiveMeta;
        this.children = [];
        this.attributeObject = {};
        this.kind = interface_1.NgNodeKind.Element;
        this.inputs = [];
        this.outputs = [];
        this.singleClosedTag = false;
    }
    analysis() {
        this.getTagName();
        this.node.attributes
            .filter((item) => item.name !== 'class' && item.name !== 'style')
            .forEach((item) => {
            this.attributeObject[item.name] = item.value;
        });
        this.node.inputs.forEach((input) => {
            if (input.type === 0) {
                this.inputs.push(input.name);
            }
        });
        this.node.outputs.forEach((output) => {
            this.outputs.push(output.name);
        });
        if (!this.node.endSourceSpan ||
            this.node.startSourceSpan.end.offset ===
                this.node.endSourceSpan.end.offset) {
            this.singleClosedTag = true;
        }
    }
    getTagName() {
        const originTagName = this.node.name;
        this.tagName = originTagName;
        if (/^(div|p|h1|h2|h3|h4|h5|h6|span)$/.test(originTagName)) {
            this.tagName = 'view';
        }
        else if (originTagName === 'ng-container') {
            this.tagName = 'block';
        }
    }
    appendNgNodeChild(child) {
        this.children.push(child);
    }
    getNodeMeta() {
        this.analysis();
        return {
            kind: interface_1.NgNodeKind.Element,
            tagName: this.tagName,
            children: this.children.map((child) => child.getNodeMeta()),
            inputs: this.inputs,
            outputs: this.outputs,
            attributes: this.attributeObject,
            singleClosedTag: this.singleClosedTag,
            componentMeta: this.componentMeta,
            index: this.index,
            directiveMeta: this.directiveMeta,
        };
    }
}
exports.ParsedNgElement = ParsedNgElement;
