Liferay.Loader.define("app-builder-web@1.0.58/js/pages/form-view/useDeleteDefinitionFieldModal.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button/lib/Button', '@frontend-taglib-clay$clayui/modal', '@frontend-taglib-clay$clayui/panel', 'data-engine-taglib', 'frontend-js-react-web$react', '../../utils/client.es', '../../utils/lang.es', './FormViewContext.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"] = void 0;

    var _Button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button/lib/Button"));

    var _modal = require("@frontend-taglib-clay$clayui/modal");

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

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

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

    var _client = require("../../utils/client.es");

    var _lang = require("../../utils/lang.es");

    var _FormViewContext = _interopRequireDefault(require("./FormViewContext.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 _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var _default = function _default(callback) {
      var _useContext = (0, _react.useContext)(_FormViewContext["default"]),
          _useContext2 = _slicedToArray(_useContext, 1),
          _useContext2$ = _useContext2[0],
          dataDefinition = _useContext2$.dataDefinition,
          dataDefinitionId = _useContext2$.dataDefinitionId,
          fieldTypes = _useContext2$.fieldTypes;

      var _useContext3 = (0, _react.useContext)(_modal.Context),
          _useContext4 = _slicedToArray(_useContext3, 2),
          onClose = _useContext4[0].onClose,
          dispatchModal = _useContext4[1];

      return function (event) {
        var _DataDefinitionUtils$ = _dataEngineTaglib.DataDefinitionUtils.getDataDefinitionField(dataDefinition, event.fieldName),
            ddmStructureId = _DataDefinitionUtils$.customProperties.ddmStructureId,
            fieldType = _DataDefinitionUtils$.fieldType,
            label = _DataDefinitionUtils$.label;

        var _fieldTypes$find = fieldTypes.find(function (_ref) {
          var name = _ref.name;
          return name === fieldType;
        }),
            fieldTypeLabel = _fieldTypes$find.label;

        if (fieldType === 'fieldset' && ddmStructureId) {
          fieldTypeLabel = Liferay.Language.get('fieldset');
        }

        return (0, _client.getItem)("/o/data-engine/v2.0/data-definitions/".concat(dataDefinitionId, "/data-definition-field-links?fieldName=").concat(event.fieldName)).then(function (_ref2) {
          var items = _ref2.items;

          var _ref3 = items[0] || {},
              _ref3$dataDefinition = _ref3.dataDefinition,
              dataDefinition = _ref3$dataDefinition === void 0 ? {} : _ref3$dataDefinition,
              _ref3$dataLayouts = _ref3.dataLayouts,
              dataLayouts = _ref3$dataLayouts === void 0 ? [] : _ref3$dataLayouts,
              _ref3$dataListViews = _ref3.dataListViews,
              dataListViews = _ref3$dataListViews === void 0 ? [] : _ref3$dataListViews;

          dispatchModal({
            payload: {
              body: _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_panel["default"], {
                className: "remove-object-field-panel",
                displayTitle: Liferay.Language.get('field'),
                displayType: "secondary"
              }, _react["default"].createElement(_panel["default"].Body, null, _react["default"].createElement("div", null, _react["default"].createElement("label", null, Liferay.Language.get('name'), ":"), _react["default"].createElement("span", null, event.fieldName)), _react["default"].createElement("div", null, _react["default"].createElement("label", null, Liferay.Language.get('label'), ":"), _react["default"].createElement("span", null, label[themeDisplay.getLanguageId()])), _react["default"].createElement("div", null, _react["default"].createElement("label", null, Liferay.Language.get('type'), ":"), _react["default"].createElement("span", null, fieldTypeLabel)))), _react["default"].createElement("p", {
                className: "remove-object-field-message"
              }, dataLayouts.length === 0 && dataListViews.length === 0 ? Liferay.Language.get('delete-definition-field-confirmation') : Liferay.Language.get('delete-definition-field-warning')), dataLayouts.length > 0 && _react["default"].createElement(_panel["default"], {
                className: "remove-object-field-panel",
                displayTitle: Liferay.Language.get('form-views'),
                displayType: "secondary"
              }, _react["default"].createElement(_panel["default"].Body, null, dataLayouts.map(function (_ref4, index) {
                var name = _ref4.name;
                return _react["default"].createElement("label", {
                  className: "d-block",
                  key: index
                }, "".concat(index + 1, ". ").concat((0, _lang.getLocalizedValue)(dataDefinition.defaultLanguageId, name)));
              }))), dataListViews.length > 0 && _react["default"].createElement(_panel["default"], {
                className: "remove-object-field-panel",
                displayTitle: Liferay.Language.get('table-views'),
                displayType: "secondary"
              }, _react["default"].createElement(_panel["default"].Body, null, dataListViews.map(function (_ref5, index) {
                var name = _ref5.name;
                return _react["default"].createElement("label", {
                  className: "d-block",
                  key: index
                }, "".concat(index + 1, ". ").concat((0, _lang.getLocalizedValue)(dataDefinition.defaultLanguageId, name)));
              })))),
              footer: [_react["default"].createElement(_react["default"].Fragment, null), _react["default"].createElement(_react["default"].Fragment, null), _react["default"].createElement(_Button["default"].Group, {
                key: 0,
                spaced: true
              }, _react["default"].createElement(_Button["default"], {
                displayType: "secondary",
                key: 1,
                onClick: onClose
              }, Liferay.Language.get('cancel')), _react["default"].createElement(_Button["default"], {
                key: 2,
                onClick: function onClick() {
                  callback(event);
                  onClose();
                }
              }, Liferay.Language.get('delete')))],
              header: Liferay.Language.get('delete-from-object'),
              size: 'md',
              status: 'warning'
            },
            type: 1
          });
        });
      };
    };

    exports["default"] = _default;
    //# sourceMappingURL=useDeleteDefinitionFieldModal.es.js.map
  }
});
//# sourceMappingURL=useDeleteDefinitionFieldModal.es.js.map