Liferay.Loader.define("app-builder-web@1.0.73/js/pages/entry/utils.es", ['module', 'exports', 'require', 'frontend-js-react-web$react', 'app-builder-web$react-router-dom', '../../hooks/useQuery.es', './FieldPreview.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.buildEntries = buildEntries;
    exports.navigateToEditPage = navigateToEditPage;

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

    var _reactRouterDom = require("app-builder-web$react-router-dom");

    var _useQuery = require("../../hooks/useQuery.es");

    var _FieldPreview = require("./FieldPreview.es");

    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;
    }

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    function buildEntries(_ref) {
      var dataDefinition = _ref.dataDefinition,
          _ref$fieldNames = _ref.fieldNames,
          fieldNames = _ref$fieldNames === void 0 ? [] : _ref$fieldNames,
          permissions = _ref.permissions,
          query = _ref.query;
      return function (_ref2, index) {
        var _ref2$dataRecordValue = _ref2.dataRecordValues,
            dataRecordValues = _ref2$dataRecordValue === void 0 ? {} : _ref2$dataRecordValue,
            entry = _objectWithoutProperties(_ref2, ["dataRecordValues"]);

        var entryIndex = query.pageSize * (query.page - 1) + index + 1;
        var viewURL = "/entries/".concat(entryIndex, "?").concat((0, _useQuery.toQueryString)(_objectSpread(_objectSpread({}, query), {}, {
          backURL: window.location.href
        })));
        var displayedDataRecordValues = {};
        fieldNames.forEach(function (fieldName, columnIndex) {
          var fieldValuePreview = /*#__PURE__*/_react.default.createElement(_FieldPreview.FieldValuePreview, {
            dataDefinition: dataDefinition,
            dataRecordValues: dataRecordValues,
            displayType: "list",
            fieldName: fieldName
          });

          if (columnIndex === 0 && permissions.view) {
            fieldValuePreview = /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, {
              to: viewURL
            }, fieldValuePreview);
          }

          displayedDataRecordValues['dataRecordValues/' + fieldName] = fieldValuePreview;
        });
        return _objectSpread(_objectSpread(_objectSpread({}, displayedDataRecordValues), entry), {}, {
          viewURL: viewURL
        });
      };
    }

    function navigateToEditPage(basePortletURL) {
      var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
      Liferay.Util.navigate(Liferay.Util.PortletURL.createRenderURL(basePortletURL, _objectSpread({
        dataRecordId: 0,
        mvcPath: '/edit_entry.jsp'
      }, params)));
    }
    //# sourceMappingURL=utils.es.js.map
  }
});
//# sourceMappingURL=utils.es.js.map