import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { CDataTag } from '../../components/CDataTag';
import { CommentTag } from '../../components/CommentTag';
import { DeclarationTag } from '../../components/DeclarationTag';
import { Tag } from '../../components/Tag';
import { TextElement } from '../../components/TextElement';
import { ATTRIBUTE_CDATA, ATTRIBUTE_COMMENT, ATTRIBUTE_TEXT, DECLARATION_TAG } from '../../constants';
import { useXMLViewerContext } from '../../context/xml-viewer-context';
import { getIndentationString, getTagProps, isInlineTextElement } from '../../helpers';
export function Elements(props) {
    const { elements, level = 0, isText = true } = props;
    const { indentSize } = useXMLViewerContext();
    if (!Array.isArray(elements) || elements.length === 0) {
        return null;
    }
    return (_jsx(_Fragment, { children: elements.map((element, index) => {
            const { tagKey, attributes, subElements, type } = getTagProps(element);
            const hasSiblings = elements.length > 1;
            const indentation = getIndentationString(indentSize, level);
            const key = `${level}-${index}`;
            const isInline = isInlineTextElement(subElements);
            switch (type) {
                case ATTRIBUTE_TEXT:
                    return (_jsx(TextElement, { text: subElements, indentation: indentation, hasSiblings: hasSiblings, isText: isText }, key));
                case ATTRIBUTE_COMMENT:
                    return (_jsx(CommentTag, { isInline: isInline, indentation: indentation, level: level, children: _jsx(Elements, { elements: subElements, level: level + 1, isText: false }) }, key));
                case ATTRIBUTE_CDATA:
                    return (_jsx(CDataTag, { indentation: indentation, isInline: isInline, children: _jsx(Elements, { elements: subElements, level: level + 1, isText: false }) }, key));
                case DECLARATION_TAG:
                    return (_jsx(DeclarationTag, { indentation: indentation, tagKey: tagKey, attributes: attributes }, key));
                default:
                    return (_jsx(Tag, { indentation: indentation, tagKey: tagKey, attributes: attributes, isInline: isInline, hasChildren: subElements.length > 0, level: level, children: _jsx(Elements, { elements: subElements, level: level + 1 }) }, key));
            }
        }) }));
}
//# sourceMappingURL=index.js.map