Liferay.Loader.define("app-builder-workflow-web@1.0.42/js/pages/apps/edit/sidebar/DataAndViewsTab.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/alert', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/tooltip', 'app-builder-web/js/pages/apps/SelectObjectsDropDown.es', 'app-builder-web/js/pages/apps/edit/EditAppContext.es', 'app-builder-web/js/utils/lang.es', 'app-builder-web/js/utils/utils.es', 'frontend-js-react-web$classnames', 'data-engine-taglib', 'frontend-js-react-web$react', '../../../../components/select-dropdown/SelectDropdown.es', '../configReducer.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = DataAndViewsTab;

    var _alert = _interopRequireDefault(require("@frontend-taglib-clay$clayui/alert"));

    var _button = _interopRequireWildcard(require("@frontend-taglib-clay$clayui/button"));

    var _form = require("@frontend-taglib-clay$clayui/form");

    var _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

    var _tooltip = require("@frontend-taglib-clay$clayui/tooltip");

    var _SelectObjectsDropDown = _interopRequireDefault(require("app-builder-web/js/pages/apps/SelectObjectsDropDown.es"));

    var _EditAppContext = require("app-builder-web/js/pages/apps/edit/EditAppContext.es");

    var _lang = require("app-builder-web/js/utils/lang.es");

    var _utils = require("app-builder-web/js/utils/utils.es");

    var _classnames = _interopRequireDefault(require("frontend-js-react-web$classnames"));

    var _dataEngineTaglib = require("data-engine-taglib");

    var _react = _interopRequireDefault(require("frontend-js-react-web$react"));

    var _SelectDropdown = _interopRequireDefault(require("../../../../components/select-dropdown/SelectDropdown.es"));

    var _configReducer = require("../configReducer.es");

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var NoObjectEmptyState = function NoObjectEmptyState() {
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "taglib-empty-result-message"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "text-center"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "taglib-empty-result-message-header"
        }), /*#__PURE__*/_react.default.createElement("h3", null, Liferay.Language.get('no-object-selected')), /*#__PURE__*/_react.default.createElement("p", {
          className: "empty-message-color taglib-empty-result-message-description"
        }, Liferay.Language.get('select-a-data-object-to-start-gathering-business-data'))))
      );
    };

    var SelectFormView = function SelectFormView(props) {
      props = _objectSpread(_objectSpread({}, props), {}, {
        emptyResultMessage: Liferay.Language.get('no-form-views-were-found-with-this-name-try-searching-again-with-a-different-name'),
        label: Liferay.Language.get('select-a-form-view'),
        stateProps: {
          emptyProps: {
            label: Liferay.Language.get('there-are-no-form-views-yet')
          },
          loadingProps: {
            label: Liferay.Language.get('retrieving-all-form-views')
          }
        }
      });
      return (/*#__PURE__*/_react.default.createElement(_SelectDropdown.default, props)
      );
    };

    var SelectTableView = function SelectTableView(props) {
      props = _objectSpread(_objectSpread({}, props), {}, {
        emptyResultMessage: Liferay.Language.get('no-table-views-were-found-with-this-name-try-searching-again-with-a-different-name'),
        label: Liferay.Language.get('select-a-table-view'),
        stateProps: {
          emptyProps: {
            label: Liferay.Language.get('there-are-no-table-views-yet')
          },
          loadingProps: {
            label: Liferay.Language.get('retrieving-all-table-views')
          }
        }
      });
      return (/*#__PURE__*/_react.default.createElement(_SelectDropdown.default, props)
      );
    };

    function DataAndViewsTab(_ref) {
      var _ref$config = _ref.config,
          currentStep = _ref$config.currentStep,
          dataObject = _ref$config.dataObject,
          formView = _ref$config.formView,
          _ref$config$listItems = _ref$config.listItems,
          fetching = _ref$config$listItems.fetching,
          formViews = _ref$config$listItems.formViews,
          tableViews = _ref$config$listItems.tableViews,
          stepIndex = _ref$config.stepIndex,
          tableView = _ref$config.tableView,
          dispatch = _ref.dispatch,
          dispatchConfig = _ref.dispatchConfig;
      var _currentStep$appWorkf = currentStep.appWorkflowDataLayoutLinks,
          stepFormViews = _currentStep$appWorkf === void 0 ? [] : _currentStep$appWorkf,
          _currentStep$errors = currentStep.errors;
      _currentStep$errors = _currentStep$errors === void 0 ? {} : _currentStep$errors;
      var _currentStep$errors$f = _currentStep$errors.formViews;
      _currentStep$errors$f = _currentStep$errors$f === void 0 ? {} : _currentStep$errors$f;
      var _currentStep$errors$f2 = _currentStep$errors$f.duplicatedFields,
          duplicatedFields = _currentStep$errors$f2 === void 0 ? [] : _currentStep$errors$f2,
          _currentStep$errors$f3 = _currentStep$errors$f.errorIndexes,
          errorIndexes = _currentStep$errors$f3 === void 0 ? [] : _currentStep$errors$f3;
      var availableFormViews = formViews.map(function (form) {
        return _objectSpread(_objectSpread({}, form), {}, {
          disabled: stepFormViews.findIndex(function (_ref2) {
            var dataLayoutId = _ref2.dataLayoutId;
            return dataLayoutId === form.id;
          }) > -1
        });
      });

      var removeStepFormView = function removeStepFormView(index) {
        dispatchConfig({
          index: index,
          type: _configReducer.REMOVE_STEP_FORM_VIEW
        });
      };

      var updateStepFormView = function updateStepFormView(formView, index) {
        dispatchConfig({
          formView: formView,
          index: index,
          type: _configReducer.UPDATE_STEP_FORM_VIEW
        });
      };

      var updateStepFormViewReadOnly = function updateStepFormViewReadOnly(readOnly, index) {
        dispatchConfig({
          index: index,
          readOnly: readOnly,
          type: _configReducer.UPDATE_STEP_FORM_VIEW_READONLY
        });
      };

      var duplicatedFieldsMessage = duplicatedFields.length === 1 ? Liferay.Language.get('the-field-x-is-present-in-multiple-form-views') : Liferay.Language.get('the-fields-x-are-present-in-multiple-form-views');
      var fieldsLabels = duplicatedFields.map(function (field) {
        return _dataEngineTaglib.DataDefinitionUtils.getFieldLabel(dataObject, field);
      });
      var parsedFieldsLabels = fieldsLabels.slice(0, 5).map(function (label) {
        return "\"".concat(label, "\"");
      });

      if (fieldsLabels.length > 5) {
        parsedFieldsLabels.push("others*");
      }

      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, stepIndex > 0 ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, duplicatedFields.length > 0 && /*#__PURE__*/_react.default.createElement(_alert.default, {
          className: "fields-alert-container mt-2",
          displayType: "danger",
          title: "".concat(Liferay.Language.get('error'), ":")
        }, "".concat((0, _lang.sub)(duplicatedFieldsMessage, [(0, _utils.concatValues)(parsedFieldsLabels)]), " "), duplicatedFields.length > 5 && /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, {
          delay: "0"
        }, /*#__PURE__*/_react.default.createElement("a", {
          className: "text-primary",
          "data-tooltip-align": "bottom",
          title: fieldsLabels.slice(5, fieldsLabels.length).join('\n')
        }, '*', Liferay.Language.get('see-other-fields')))), stepFormViews.map(function (_ref3, index) {
          var dataLayoutId = _ref3.dataLayoutId,
              name = _ref3.name,
              readOnly = _ref3.readOnly;
          return (/*#__PURE__*/_react.default.createElement("div", {
              className: (0, _classnames.default)('step-form-view', errorIndexes.includes(index) && 'border-error'),
              key: index
            }, /*#__PURE__*/_react.default.createElement("label", {
              id: "form-view-label"
            }, Liferay.Language.get('form-view')), /*#__PURE__*/_react.default.createElement(SelectFormView, {
              ariaLabelId: "form-view-label",
              items: availableFormViews,
              onSelect: function onSelect(formView) {
                return updateStepFormView(formView, index);
              },
              selectedValue: name
            }), /*#__PURE__*/_react.default.createElement("div", {
              className: "d-flex justify-content-between mt-2"
            }, /*#__PURE__*/_react.default.createElement(_form.ClayRadioGroup, {
              className: "pt-1",
              inline: true,
              onSelectedValueChange: function onSelectedValueChange(readOnly) {
                return updateStepFormViewReadOnly(readOnly, index);
              },
              selectedValue: readOnly
            }, /*#__PURE__*/_react.default.createElement(_form.ClayRadio, {
              disabled: !dataLayoutId,
              label: Liferay.Language.get('editable'),
              value: false
            }), /*#__PURE__*/_react.default.createElement(_form.ClayRadio, {
              disabled: !dataLayoutId,
              label: Liferay.Language.get('read-only'),
              value: true
            })), stepFormViews.length > 1 && /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, null, /*#__PURE__*/_react.default.createElement(_button.ClayButtonWithIcon, {
              borderless: true,
              "data-tooltip-align": "bottom",
              "data-tooltip-delay": "0",
              displayType: "secondary",
              onClick: function onClick() {
                return removeStepFormView(index);
              },
              small: true,
              symbol: "trash",
              title: Liferay.Language.get('remove')
            }))))
          );
        }), /*#__PURE__*/_react.default.createElement(_button.default, {
          className: "mt-3 w-100",
          displayType: "secondary",
          onClick: function addStepFormView() {
            dispatchConfig({
              type: _configReducer.ADD_STEP_FORM_VIEW
            });
          }
        }, /*#__PURE__*/_react.default.createElement("span", {
          className: "text-secondary"
        }, Liferay.Language.get('add-new-form-view')))) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
          className: "main-section"
        }, /*#__PURE__*/_react.default.createElement("label", {
          id: "select-object-label"
        }, Liferay.Language.get('main-data-object')), /*#__PURE__*/_react.default.createElement(_tooltip.ClayTooltipProvider, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
          className: "ml-2 text-muted tooltip-icon",
          "data-tooltip-align": "top",
          "data-tooltip-delay": "0",
          symbol: "question-circle-full",
          title: Liferay.Language.get('a-data-object-stores-your-business-data-and-is-composed-by-data-fields')
        })), /*#__PURE__*/_react.default.createElement(_SelectObjectsDropDown.default, {
          label: Liferay.Language.get('select-object'),
          onSelect: function updateDataObject(newDataObject) {
            if (newDataObject.id !== dataObject.id) {
              dispatchConfig({
                dataObject: newDataObject,
                type: _configReducer.UPDATE_DATA_OBJECT
              });
              dispatch({
                app: {
                  dataDefinitionId: newDataObject.id,
                  dataLayoutId: null,
                  dataListViewId: null
                },
                type: _EditAppContext.UPDATE_APP
              });
            }
          },
          selectedValue: dataObject
        })), dataObject.name ? /*#__PURE__*/_react.default.createElement("div", {
          className: "py-3"
        }, /*#__PURE__*/_react.default.createElement("h5", {
          className: "text-secondary text-uppercase"
        }, Liferay.Language.get('gather-data')), /*#__PURE__*/_react.default.createElement("label", {
          id: "form-view-label"
        }, Liferay.Language.get('form-view')), /*#__PURE__*/_react.default.createElement(SelectFormView, {
          ariaLabelId: "form-view-label",
          isLoading: fetching,
          items: formViews,
          onSelect: function updateFormView(formView) {
            dispatchConfig({
              formView: formView,
              type: _configReducer.UPDATE_FORM_VIEW
            });
            dispatch(_objectSpread(_objectSpread({}, formView), {}, {
              type: _EditAppContext.UPDATE_DATA_LAYOUT_ID
            }));
          },
          selectedValue: formView.name
        }), /*#__PURE__*/_react.default.createElement("h5", {
          className: "mt-3 text-secondary text-uppercase"
        }, Liferay.Language.get('display-data')), /*#__PURE__*/_react.default.createElement("label", {
          id: "table-view-label"
        }, Liferay.Language.get('table-view')), /*#__PURE__*/_react.default.createElement(SelectTableView, {
          ariaLabelId: "table-view-label",
          isLoading: fetching,
          items: tableViews,
          onSelect: function updateTableView(tableView) {
            dispatchConfig({
              tableView: tableView,
              type: _configReducer.UPDATE_TABLE_VIEW
            });
            dispatch(_objectSpread(_objectSpread({}, tableView), {}, {
              type: _EditAppContext.UPDATE_DATA_LIST_VIEW_ID
            }));
          },
          selectedValue: tableView.name
        })) : /*#__PURE__*/_react.default.createElement(NoObjectEmptyState, null)))
      );
    }
    //# sourceMappingURL=DataAndViewsTab.es.js.map
  }
});
//# sourceMappingURL=DataAndViewsTab.es.js.map