UNPKG

infinity-forge

Version:
67 lines 3.49 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDynamicSection = useDynamicSection; var jsx_runtime_1 = require("react/jsx-runtime"); var router_1 = require("next/router"); var ui_1 = require("../../../../../ui/index.js"); var context_1 = require("../context.js"); var edit_section_1 = require("./edit-section.js"); function useDynamicSection(props) { var router = (0, router_1.useRouter)(); var locale = router.locale || 'pt-BR'; var refSectionID = (0, ui_1.generateRef)(props.refSection, router, props.isGlobal); var _a = (0, context_1.useAtena)(), sections = _a.sections, hasPermission = _a.hasPermission; var languages = (0, ui_1.useI18n)().languages; var findSection = (sections === null || sections === void 0 ? void 0 : sections.find(function (section) { return section.ref === refSectionID; })) || {}; function Section(_a) { var children = _a.children; var propsEditSectionComponent = { refSection: refSectionID, section: findSection, fields: props.fields, }; if (!hasPermission) { return children; } if ((!findSection.enabled && router.query.showPreview !== 'true') || props.editModeIsOutside) { return (0, jsx_runtime_1.jsx)(edit_section_1.EditSectionComponent, __assign({}, propsEditSectionComponent, { dynamicSectionProps: props })); } return ((0, jsx_runtime_1.jsx)(edit_section_1.EditSectionComponent, __assign({}, propsEditSectionComponent, { dynamicSectionProps: props, children: children }))); } var initialDataSection = { enabled: false, images: [{ url: '/images/default-image.webp' }], linkUrl: '', videoUrl: '', i18n: languages === null || languages === void 0 ? void 0 : languages.reduce(function (reducer, language) { var _a; return (__assign(__assign({}, reducer), (_a = {}, _a[language.symbol] = { title: '', subtitle: '', description: '', linkText: '', }, _a))); }, {}), }; if (findSection && Object.keys(findSection).length > 0) { var desestrureI18n_1 = (locale && findSection['i18n'] && findSection['i18n'][locale]) || {}; var desestrureInitialI18n = (locale && initialDataSection['i18n'] && initialDataSection['i18n'][locale]) || {}; return __assign(__assign(__assign(__assign(__assign({}, initialDataSection), desestrureInitialI18n), findSection), desestrureI18n_1), { images: findSection.images && findSection.images.length > 0 ? findSection.images : [{ url: '/images/default-image.webp' }], Section: Section, jsonContent: (0, ui_1.parseJSON)(findSection === null || findSection === void 0 ? void 0 : findSection.jsonContent) }); } var desestrureI18n = (locale && initialDataSection['i18n'] && initialDataSection['i18n'][locale]) || {}; return __assign(__assign({ Section: Section }, initialDataSection), desestrureI18n); } //# sourceMappingURL=index.js.map