Liferay.Loader.define("layout-content-page-editor-web@2.0.162/page_editor/plugins/experience/components/ExperienceToolbarSection", ['module', 'exports', 'require', 'frontend-js-react-web$react', '../../../app/actions/togglePermission', '../../../app/config/index', '../../../app/store/index', './ExperienceSelector'], 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 = ExperienceToolbarSection;

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

    var _togglePermission = _interopRequireDefault(require("../../../app/actions/togglePermission"));

    var _index = require("../../../app/config/index");

    var _index2 = require("../../../app/store/index");

    var _ExperienceSelector = _interopRequireDefault(require("./ExperienceSelector"));

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

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

    // TODO: show how to colocate CSS with plugins (may use loaders)
    function ExperienceToolbarSection(_ref) {
      var selectId = _ref.selectId;
      var availableSegmentsExperiences = (0, _index2.useSelector)(function (state) {
        return state.availableSegmentsExperiences;
      });
      var dispatch = (0, _index2.useDispatch)();
      var segmentsExperienceId = (0, _index2.useSelector)(function (state) {
        return state.segmentsExperienceId;
      });
      var experiences = (0, _react.useMemo)(function () {
        return Object.values(availableSegmentsExperiences).sort(function (a, b) {
          return b.priority - a.priority;
        }).map(function (experience, _, experiences) {
          var segmentsEntryName = _index.config.availableSegmentsEntries[experience.segmentsEntryId].name;
          var firstExperience = experiences.find(function (exp) {
            return exp.segmentsEntryId === experience.segmentsEntryId || exp.segmentsEntryId === _index.config.defaultSegmentsEntryId;
          });
          return _objectSpread(_objectSpread({}, experience), {}, {
            active: firstExperience.segmentsExperienceId === experience.segmentsExperienceId,
            segmentsEntryName: segmentsEntryName
          });
        });
      }, [availableSegmentsExperiences]);
      var segments = (0, _react.useMemo)(function () {
        return Object.values(_index.config.availableSegmentsEntries);
      }, []);
      var selectedExperience = availableSegmentsExperiences[segmentsExperienceId];
      (0, _react.useEffect)(function () {
        dispatch((0, _togglePermission.default)('LOCKED_SEGMENTS_EXPERIMENT', selectedExperience.hasLockedSegmentsExperiment));
      }, [dispatch, selectedExperience.hasLockedSegmentsExperiment]);
      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "mr-2 page-editor__toolbar-experience"
        }, /*#__PURE__*/_react.default.createElement("label", {
          className: "d-lg-block d-none mr-2",
          htmlFor: selectId
        }, Liferay.Language.get('experience')), /*#__PURE__*/_react.default.createElement(_ExperienceSelector.default, {
          editSegmentsEntryURL: _index.config.editSegmentsEntryURL,
          experiences: experiences,
          segments: segments,
          selectId: selectId,
          selectedExperience: selectedExperience
        }))
      );
    }
    //# sourceMappingURL=ExperienceToolbarSection.js.map
  }
});
//# sourceMappingURL=ExperienceToolbarSection.js.map