/*!
 * Built by ShiftSoftware
 * Copyright (c)
 */
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
            t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { h } from "@stencil/core";
import cn from "../../global/lib/cn";
export function renderStructure(structure, elementMapper, generaProps, fields, currentStep) {
    // @ts-ignore
    if (currentStep !== -2 || (structure === null || structure === void 0 ? void 0 : structure.step) !== undefined) {
        if (currentStep === -1) {
            // @ts-ignore
            if ((structure === null || structure === void 0 ? void 0 : structure.step) !== undefined && (structure === null || structure === void 0 ? void 0 : structure.step) !== -1)
                return false;
            // @ts-ignore
        }
        else if (!!(structure === null || structure === void 0 ? void 0 : structure.step) && (structure === null || structure === void 0 ? void 0 : structure.step) !== currentStep)
            return false;
    }
    if (typeof structure === 'string') {
        if (typeof structure === 'string' && structure && elementMapper[structure]) {
            generaProps.props['name'] = structure;
            generaProps.props = Object.assign(Object.assign({}, generaProps.props), (fields && fields[structure] ? fields[structure] : {}));
            return elementMapper[structure](Object.assign(Object.assign({}, generaProps), (fields && fields[structure] ? fields[structure] : {})));
        }
    }
    else {
        const { tag, name, children, data, type } = structure, props = __rest(structure, ["tag", "name", "children", "data", "type"]);
        if (tag) {
            const Tag = tag;
            return (h(Tag, Object.assign({}, props, { part: cn(props === null || props === void 0 ? void 0 : props.id, props === null || props === void 0 ? void 0 : props.class, `element-${tag}`, tag) }), Array.isArray(children) && children.map(child => renderStructure(child, elementMapper, Object.assign({}, generaProps), fields, currentStep)), typeof children === 'object' && !Array.isArray(children) && children !== null && (children === null || children === void 0 ? void 0 : children[generaProps === null || generaProps === void 0 ? void 0 : generaProps.language])));
        }
        const newProps = Object.assign(Object.assign({}, generaProps), { props: Object.assign(Object.assign(Object.assign({}, props), (fields && fields[name] ? fields[name] : {})), { name, wrapperId: props === null || props === void 0 ? void 0 : props.id, form: generaProps.form, wrapperClass: props === null || props === void 0 ? void 0 : props.class, isLoading: generaProps.isLoading }) });
        if (((typeof name === 'string' && name) || (typeof type === 'string' && type)) && elementMapper[type || name])
            return elementMapper[type || name](newProps);
    }
    return false;
}
