"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemplatesBlock = void 0;
var tslib_1 = require("tslib");
var react_1 = tslib_1.__importStar(require("react"));
var react_router_dom_1 = require("react-router-dom");
var v_eris_1 = require("v-eris");
var icons_extend_1 = require("../../icons/icons.extend");
exports.TemplatesBlock = (0, react_1.memo)(function (props) {
    var section = props.section, subsection = props.subsection, dynamic = props.dynamic, qs = props.qs, data = props.data, alone = props.alone, selected = props.selected, token = props.token, rest = tslib_1.__rest(props, ["section", "subsection", "dynamic", "qs", "data", "alone", "selected", "token"]);
    var lang = (0, react_1.useContext)(v_eris_1.LangContext);
    var location = (0, react_router_dom_1.useLocation)();
    var nav = (0, react_router_dom_1.useNavigate)();
    var sectionElements = (0, react_1.useMemo)(function () {
        var array = (section ? (section.children || []) : []).map(function (item) {
            return { value: item.key || item.name, title: lang.get(item.name), length: "", widgets: item.list };
        });
        if (array.length < 2)
            return react_1.default.createElement("div", { key: "sections" });
        return (react_1.default.createElement("div", { key: "sections" },
            react_1.default.createElement(v_eris_1.Select, { stretch: true, headerless: true, row: true, value: qs.subsection, onSelect: function (v) {
                    nav(v_eris_1.Common.setQuery(location, { section: qs.section, subsection: v.value, token: token }));
                }, list: array }),
            react_1.default.createElement(v_eris_1.Divider, null)));
    }, [section, qs]);
    var widgetsElements = (0, react_1.useMemo)(function () {
        var array = subsection && subsection.list ? subsection.list : [];
        var n = 0;
        return array.map(function (item) {
            n++;
            return (react_1.default.createElement("div", { key: item.name },
                item.title ? (react_1.default.createElement("div", { className: "eris-templates-header" },
                    react_1.default.createElement("div", null, lang.get(item.title)),
                    react_1.default.createElement(v_eris_1.Space, null))) : null,
                react_1.default.createElement(item.module, tslib_1.__assign(tslib_1.__assign({}, item.props), { data: data })),
                n >= array.length ? (null) : (react_1.default.createElement(v_eris_1.Divider, null))));
        });
    }, [sectionElements, qs.subsection, dynamic.list]);
    var elements = (0, react_1.useMemo)(function () {
        if (!section.headerParams) {
            return (react_1.default.createElement("div", null));
        }
        ;
        if (Array.isArray(section.headerParams)) {
            return section.headerParams.map(function (name) {
                var value = data[name];
                return react_1.default.createElement(v_eris_1.Row, { className: "eris-templates-item", key: name },
                    react_1.default.createElement(v_eris_1.Text, { className: "eris-templates-item-key" },
                        lang.get("AeroInfo::" + name) || name,
                        ": "),
                    react_1.default.createElement(v_eris_1.Text, { className: "eris-templates-item-value" }, value));
            });
        }
        ;
        return (react_1.default.createElement("div", null, react_1.default.createElement(section.headerParams.module, tslib_1.__assign(tslib_1.__assign({}, section.headerParams.props), { data: data }))));
    }, [data, section.headerParams]);
    return (react_1.default.createElement("div", { className: v_eris_1.Props.className("eris-templates-block", { selected: selected, alone: alone }) },
        react_1.default.createElement("div", { className: "eris-templates-back", onClick: function () {
                nav(v_eris_1.Common.setQuery(location, { section: qs.section, subsection: qs.subsection, token: undefined }));
            } },
            react_1.default.createElement(icons_extend_1.Icons.exit, null),
            lang.get("TemplatesModuleBlock::Back")),
        elements,
        react_1.default.createElement(v_eris_1.Space, null),
        react_1.default.createElement("div", { className: "eris-templates-select", onClick: function () {
                nav(v_eris_1.Common.setQuery(location, { section: qs.section, subsection: qs.subsection, token: token }));
            } },
            react_1.default.createElement(icons_extend_1.Icons.info, null),
            lang.get("TemplatesModuleBlock::More")),
        selected || alone ? ([sectionElements, widgetsElements]) : (null),
        react_1.default.createElement(v_eris_1.Divider, null)));
});
//# sourceMappingURL=templates.block.js.map