Liferay.Loader.define("layout-content-page-editor-web@2.0.161/page_editor/app/reducers/defaultFragmentEntryLinksReducer", ['module', 'exports', 'require', '../actions/types', '../utils/getFragmentEntryLinkIdsFromItemId'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = defaultFragmentEntryLinksReducer;

    var _types = require("../actions/types");

    var _getFragmentEntryLinkIdsFromItemId = _interopRequireDefault(require("../utils/getFragmentEntryLinkIdsFromItemId"));

    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 _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
    }

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

    function _iterableToArray(iter) {
      if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) {
        for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
          arr2[i] = arr[i];
        }return arr2;
      }
    }

    function defaultFragmentEntryLinksReducer(state, action) {
      switch (action.type) {
        case _types.INIT:
          {
            var fragmentEntryLinks = state.fragmentEntryLinks,
                layoutData = state.layoutData;
            var deletedItemIds = layoutData.deletedItems.map(function (deletedItem) {
              return deletedItem.itemId;
            });
            var newFragmentEntryLinks = {};
            var deletedFragments = deletedItemIds.reduce(function (acc, deleteItemId) {
              return [].concat(_toConsumableArray(acc), _toConsumableArray((0, _getFragmentEntryLinkIdsFromItemId.default)({
                itemId: deleteItemId,
                layoutData: layoutData
              })));
            }, []);
            deletedFragments.forEach(function (deletedFragment) {
              newFragmentEntryLinks[deletedFragment] = _objectSpread(_objectSpread({}, fragmentEntryLinks[deletedFragment]), {}, {
                removed: true
              });
            });
            return _objectSpread(_objectSpread({}, state), {}, {
              fragmentEntryLinks: _objectSpread(_objectSpread({}, fragmentEntryLinks), newFragmentEntryLinks)
            });
          }

        default:
          return state;
      }
    }
    //# sourceMappingURL=defaultFragmentEntryLinksReducer.js.map
  }
});
//# sourceMappingURL=defaultFragmentEntryLinksReducer.js.map