Liferay.Loader.define("layout-content-page-editor-web@2.0.166/page_editor/app/components/undo/getItemNameFromAction", ['module', 'exports', 'require', '../../utils/getLayoutDataItemLabel'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.getItemNameFromAction = getItemNameFromAction;

    var _getLayoutDataItemLabel = _interopRequireDefault(require("../../utils/getLayoutDataItemLabel"));

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

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */

    /**
     * Obtain the name associated to the undo action,
     * for those cases where there is not name associated, returns null
     *
     * @param {object} options
     * @param {object} options.action
     * @param {object} options.state
     * @return {string|null}
     */
    function getItemNameFromAction(_ref) {
      var _state$layoutData, _action$layoutData, _state$layoutData$ite, _state$layoutData2, _action$layoutData$it, _action$layoutData2;

      var action = _ref.action,
          state = _ref.state;
      var fragmentEntryLinks = action.fragmentEntryLinks ? Object.values(action.fragmentEntryLinks).reduce(function (acc, fragmentEntryLink) {
        acc[fragmentEntryLink.fragmentEntryLinkId] = fragmentEntryLink;
        return acc;
      }, {}) : state.fragmentEntryLinks;
      var item = ((_state$layoutData = state.layoutData) === null || _state$layoutData === void 0 ? void 0 : _state$layoutData.items[action.itemId]) || ((_action$layoutData = action.layoutData) === null || _action$layoutData === void 0 ? void 0 : _action$layoutData.items[action.itemId]) || Object.values((_state$layoutData$ite = (_state$layoutData2 = state.layoutData) === null || _state$layoutData2 === void 0 ? void 0 : _state$layoutData2.items) !== null && _state$layoutData$ite !== void 0 ? _state$layoutData$ite : {}).find(function (item) {
        return item.config.fragmentEntryLinkId === action.fragmentEntryLinkId;
      }) || Object.values((_action$layoutData$it = (_action$layoutData2 = action.layoutData) === null || _action$layoutData2 === void 0 ? void 0 : _action$layoutData2.items) !== null && _action$layoutData$it !== void 0 ? _action$layoutData$it : {}).find(function (item) {
        return item.config.fragmentEntryLinkId === action.fragmentEntryLinkId;
      });

      if (!item) {
        return null;
      }

      return (0, _getLayoutDataItemLabel.default)(item, fragmentEntryLinks);
    }
    //# sourceMappingURL=getItemNameFromAction.js.map
  }
});
//# sourceMappingURL=getItemNameFromAction.js.map