"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.CustomFieldsViewWidgetContent = void 0;
var _designSystem = require("@wix/design-system");
var _react = _interopRequireDefault(require("react"));
var _CustomFieldsViewWidgetSection = require("./CustomFieldsViewWidgetSection");
var _mobxReactLite = require("mobx-react-lite");
var _react2 = require("@wix/bex-core/react");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/CustomFieldsWidget/CustomFieldsViewWidgetContent.tsx";
const _CustomFieldsViewWidgetContent = ({
  state,
  extendedFields,
  userFieldsTitle
}) => {
  const {
    translate: t
  } = (0, _react2.useWixPatternsContainer)();
  const getSections = () => {
    return state.dataExtension.allNamespaces.map(namespace => {
      var _extendedFields$names;
      const relevantCustomFields = state.getExtendedFieldsToDisplayForNamespace(namespace, extendedFields);
      if (relevantCustomFields.length === 0) {
        return null;
      }
      const title = namespace === state.userFieldsNamespace ? userFieldsTitle || t('cairo.customFields.entityPage.sectionTitle') : state.getAppName(namespace);
      return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
        marginBottom: "SP1",
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 38,
          columnNumber: 11
        }
      }, /*#__PURE__*/_react.default.createElement(_CustomFieldsViewWidgetSection.CustomFieldsViewWidgetSection, {
        title: title,
        customFields: relevantCustomFields,
        namespace: namespace,
        fieldValues: (extendedFields == null || (_extendedFields$names = extendedFields.namespaces) == null ? void 0 : _extendedFields$names[namespace]) || {},
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 39,
          columnNumber: 13
        }
      }));
    }).filter(Boolean);
  };
  const sectionsWithDividers = sections => {
    return sections.map((section, index) => /*#__PURE__*/_react.default.createElement(_react.default.Fragment, {
      key: index,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 57,
        columnNumber: 7
      }
    }, section, index < sections.length - 1 && /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
      marginTop: "SP4",
      marginBottom: "SP4",
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 60,
        columnNumber: 11
      }
    }, /*#__PURE__*/_react.default.createElement(_designSystem.Divider, {
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 61,
        columnNumber: 13
      }
    }))));
  };
  const renderCustomFields = () => {
    const sections = getSections();
    return sectionsWithDividers(sections);
  };
  return /*#__PURE__*/_react.default.createElement(_designSystem.Box, {
    direction: "vertical",
    dataHook: "fields-content",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 73,
      columnNumber: 5
    }
  }, renderCustomFields());
};
const CustomFieldsViewWidgetContent = exports.CustomFieldsViewWidgetContent = (0, _mobxReactLite.observer)(_CustomFieldsViewWidgetContent);
//# sourceMappingURL=CustomFieldsViewWidgetContent.js.map