"use strict";
/* eslint-disable no-param-reassign */
// @ts-nocheck
exports.__esModule = true;
exports.Article = exports.cnArticle = void 0;
var tslib_1 = require("tslib");
require("./Article.css");
require("./old-content.css");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var html_react_parser_1 = (0, tslib_1.__importStar)(require("html-react-parser"));
var bem_1 = require("../../utils/bem");
var renderReference_1 = require("../../utils/renderReference");
var SiteBlock_1 = require("../SiteBlock/SiteBlock");
var Tooltip_1 = require("../Tooltip/Tooltip");
var contents_1 = require("./helpers/contents");
exports.cnArticle = (0, bem_1.cn)('Article');
exports.Article = react_1["default"].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 (0, html_react_parser_1["default"])(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_1["default"].createElement("div", { className: "iframe-container" }, (0, html_react_parser_1.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 = (0, renderReference_1.renderReference)(item, references.path);
                        return (react_1["default"].createElement("div", { className: "Article-SideItemWrapper" },
                            react_1["default"].createElement(Tag, (0, tslib_1.__assign)({}, domNode.attribs), (0, html_react_parser_1.domToReact)(domNode.children, domNode.options)),
                            Item && (
                            // <Mq query="--tablet-max">
                            react_1["default"].createElement("div", { className: "Article-SideItemInner" },
                                react_1["default"].createElement(SiteBlock_1.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_1["default"].createElement("div", { className: "Article-SideItemWrapper" },
                            react_1["default"].createElement(Tag, (0, tslib_1.__assign)({}, domNode.attribs), (0, html_react_parser_1.domToReact)(domNode.children, domNode.options)),
                            react_1["default"].createElement("div", { className: "Article-SideItemInner" },
                                react_1["default"].createElement(SiteBlock_1.SiteBlock, { useMargin: true, topGap: "m", bottomGap: "2xl", className: "Article-SideItem" },
                                    react_1["default"].createElement(Tooltip_1.Tooltip, { staticPosition: true, directionPosition: "upStartLeft" }, item.text)))));
                    }
                }
                if (domNode.data) {
                    if (domNode.data.includes('{{contentPosts}}') && contentPostsPath && contentPosts) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.renderContentPosts)(contentPosts, contentPostsPath);
                    }
                    if (domNode.data.includes(slider === null || slider === void 0 ? void 0 : slider.code)) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.renderContentSlider)(slider);
                    }
                    if (domNode.data.includes(team === null || team === void 0 ? void 0 : team.code)) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.renderContentMembers)(team);
                    }
                    if (domNode.data.includes(links === null || links === void 0 ? void 0 : links.code)) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.renderContentListLinks)(links);
                    }
                    if (domNode.data.includes(clients === null || clients === void 0 ? void 0 : clients.length)) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.renderContentClients)(clients);
                    }
                    if (domNode.data.includes(posts === null || posts === void 0 ? void 0 : posts.code)) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.renderContentPostsSecondary)(posts);
                    }
                    if (domNode.data.includes(landing === null || landing === void 0 ? void 0 : landing.code)) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.renderContentBanner)(landing);
                    }
                    if (domNode.data.includes(partners === null || partners === void 0 ? void 0 : partners.code)) {
                        domNode.parent.name = 'div';
                        return (0, contents_1.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 (0, contents_1.renderContentVacancy)(vacancy);
                    }
                }
            }
        });
    };
    return (react_1["default"].createElement(react_1["default"].Fragment, null, content && (react_1["default"].createElement("article", { className: (0, exports.cnArticle)({ size: size }, [className]), ref: ref }, contentBody()))));
});
