/* eslint-disable no-param-reassign */
// @ts-nocheck
import { __assign } from "tslib";
import './Article.css';
import './old-content.css';
import React from 'react';
import parse, { domToReact } from 'html-react-parser';
import { cn } from '../../utils/bem';
import { renderReference } from '../../utils/renderReference';
import { SiteBlock } from '../SiteBlock/SiteBlock';
import { Tooltip } from '../Tooltip/Tooltip';
import { renderContentBanner, renderContentClients, renderContentListLinks, renderContentMembers, renderContentPartners, renderContentPosts, renderContentPostsSecondary, renderContentSlider, renderContentVacancy, } from './helpers/contents';
export var cnArticle = cn('Article');
export var Article = React.forwardRef(function (props, ref) {
    var content = props.content, className = props.className, size = props.size, contentPostsPath = props.contentPostsPath, contentPosts = props.contentPosts, team = props.team, links = props.links, posts = props.posts, landing = props.landing, clients = props.clients, partners = props.partners, vacancy = props.vacancy, references = props.references, slider = props.slider, chatTooltips = props.chatTooltips;
    var contentBody = function () {
        return parse(content, {
            replace: function (domNode) {
                var _a, _b, _c, _d, _e;
                if (domNode.children &&
                    domNode.children[0] &&
                    domNode.children[0].name &&
                    domNode.children[0].name === 'iframe' &&
                    !domNode.children[0].attribs["class"].includes('da-quiz')) {
                    return (React.createElement("div", { className: "iframe-container" }, domToReact(domNode.children, domNode.options)));
                }
                if (((_a = domNode.attribs) === null || _a === void 0 ? void 0 : _a.id) && references && references.items && references.path) {
                    var code_1 = (_b = domNode.attribs) === null || _b === void 0 ? void 0 : _b.id;
                    var item = references.items.find(function (w) { return w.textCode === code_1; });
                    if (item) {
                        var Tag = domNode.name;
                        var Item = renderReference(item, references.path);
                        return (React.createElement("div", { className: "Article-SideItemWrapper" },
                            React.createElement(Tag, __assign({}, domNode.attribs), domToReact(domNode.children, domNode.options)),
                            Item && (
                            // <Mq query="--tablet-max">
                            React.createElement("div", { className: "Article-SideItemInner" },
                                React.createElement(SiteBlock, { useMargin: true, topGap: "xxl", bottomGap: "xxl", className: "Article-SideItem" }, Item))
                            // </Mq>
                            )));
                    }
                }
                if (((_c = domNode.attribs) === null || _c === void 0 ? void 0 : _c.id) && chatTooltips) {
                    var code_2 = (_d = domNode.attribs) === null || _d === void 0 ? void 0 : _d.id;
                    var item = chatTooltips.find(function (w) { return w.code === code_2; });
                    if (item) {
                        var Tag = domNode.name;
                        return (React.createElement("div", { className: "Article-SideItemWrapper" },
                            React.createElement(Tag, __assign({}, domNode.attribs), domToReact(domNode.children, domNode.options)),
                            React.createElement("div", { className: "Article-SideItemInner" },
                                React.createElement(SiteBlock, { useMargin: true, topGap: "m", bottomGap: "2xl", className: "Article-SideItem" },
                                    React.createElement(Tooltip, { staticPosition: true, directionPosition: "upStartLeft" }, item.text)))));
                    }
                }
                if (domNode.data) {
                    if (domNode.data.includes('{{contentPosts}}') && contentPostsPath && contentPosts) {
                        domNode.parent.name = 'div';
                        return renderContentPosts(contentPosts, contentPostsPath);
                    }
                    if (domNode.data.includes(slider === null || slider === void 0 ? void 0 : slider.code)) {
                        domNode.parent.name = 'div';
                        return renderContentSlider(slider);
                    }
                    if (domNode.data.includes(team === null || team === void 0 ? void 0 : team.code)) {
                        domNode.parent.name = 'div';
                        return renderContentMembers(team);
                    }
                    if (domNode.data.includes(links === null || links === void 0 ? void 0 : links.code)) {
                        domNode.parent.name = 'div';
                        return renderContentListLinks(links);
                    }
                    if (domNode.data.includes(clients === null || clients === void 0 ? void 0 : clients.length)) {
                        domNode.parent.name = 'div';
                        return renderContentClients(clients);
                    }
                    if (domNode.data.includes(posts === null || posts === void 0 ? void 0 : posts.code)) {
                        domNode.parent.name = 'div';
                        return renderContentPostsSecondary(posts);
                    }
                    if (domNode.data.includes(landing === null || landing === void 0 ? void 0 : landing.code)) {
                        domNode.parent.name = 'div';
                        return renderContentBanner(landing);
                    }
                    if (domNode.data.includes(partners === null || partners === void 0 ? void 0 : partners.code)) {
                        domNode.parent.name = 'div';
                        return renderContentPartners(partners);
                    }
                    if (domNode.data.includes(vacancy === null || vacancy === void 0 ? void 0 : vacancy.code)) {
                        domNode.parent.name = 'div';
                        if (!((_e = vacancy.items) === null || _e === void 0 ? void 0 : _e.length)) {
                            domNode.data = domNode.data.replace(vacancy.code, '');
                        }
                        return renderContentVacancy(vacancy);
                    }
                }
            }
        });
    };
    return (React.createElement(React.Fragment, null, content && (React.createElement("article", { className: cnArticle({ size: size }, [className]), ref: ref }, contentBody()))));
});
