Liferay.Loader.define("layout-content-page-editor-web@2.0.162/page_editor/plugins/page-design-options/components/PageDesignOptionsSidebar", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/alert', '@frontend-taglib-clay$clayui/card', '@frontend-taglib-clay$clayui/icon', '@frontend-taglib-clay$clayui/link', '@frontend-taglib-clay$clayui/tabs', 'frontend-js-react-web$classnames', 'frontend-js-react-web$react', '../../../app/config/constants/layoutTypes', '../../../app/config/index', '../../../app/services/LayoutService', '../../../app/store/index', '../../../app/thunks/changeMasterLayout', '../../../app/utils/useId', '../../../common/components/SidebarPanelContent', '../../../common/components/SidebarPanelHeader', '../hooks/useStyleBook'], 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 = PageDesignOptionsSidebar;

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

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

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

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

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

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

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

    var _layoutTypes = require("../../../app/config/constants/layoutTypes");

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

    var _LayoutService = _interopRequireDefault(require("../../../app/services/LayoutService"));

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

    var _changeMasterLayout = _interopRequireDefault(require("../../../app/thunks/changeMasterLayout"));

    var _useId = require("../../../app/utils/useId");

    var _SidebarPanelContent = _interopRequireDefault(require("../../../common/components/SidebarPanelContent"));

    var _SidebarPanelHeader = _interopRequireDefault(require("../../../common/components/SidebarPanelHeader"));

    var _useStyleBook = require("../hooks/useStyleBook");

    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 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 _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 OPTIONS_TYPES = {
      master: 'master',
      styleBook: 'styleBook'
    };

    function PageDesignOptionsSidebar() {
      var dispatch = (0, _index2.useDispatch)();
      var selectedStyleBook = (0, _useStyleBook.useStyleBook)();
      var setSelectedStyleBook = (0, _useStyleBook.useSetStyleBook)();

      var _useState = (0, _react.useState)({
        imagePreviewURL: _index.config.defaultStyleBookEntryImagePreviewURL,
        name: _index.config.defaultStyleBookEntryName
      }),
          _useState2 = _slicedToArray(_useState, 2),
          defaultStyleBook = _useState2[0],
          setDefaultStyleBook = _useState2[1];

      var masterLayoutPlid = (0, _index2.useSelector)(function (state) {
        var _state$masterLayout;

        return (_state$masterLayout = state.masterLayout) === null || _state$masterLayout === void 0 ? void 0 : _state$masterLayout.masterLayoutPlid;
      });
      var onSelectMasterLayout = (0, _react.useCallback)(function (masterLayout) {
        dispatch((0, _changeMasterLayout.default)({
          masterLayoutPlid: masterLayout.masterLayoutPlid
        })).then(function (_ref) {
          var styleBook = _ref.styleBook;
          var defaultStyleBookEntryImagePreviewURL = styleBook.defaultStyleBookEntryImagePreviewURL,
              defaultStyleBookEntryName = styleBook.defaultStyleBookEntryName,
              styleBookEntryId = styleBook.styleBookEntryId,
              tokenValues = styleBook.tokenValues;
          setDefaultStyleBook({
            imagePreviewURL: defaultStyleBookEntryImagePreviewURL,
            name: defaultStyleBookEntryName
          }); // Changing the master layout should only affect the selected stylebook
          // only if styleBookEntryId is equal to 0 which means that the stylebook is
          // inherited

          if (styleBookEntryId === '0') {
            setSelectedStyleBook({
              styleBookEntryId: styleBookEntryId,
              tokenValues: tokenValues
            });
          }
        });
      }, [dispatch, setSelectedStyleBook]);
      var onSelectStyleBook = (0, _react.useCallback)(function (styleBookEntryId) {
        _LayoutService.default.changeStyleBookEntry({
          onNetworkStatus: function onNetworkStatus() {},
          styleBookEntryId: styleBookEntryId
        }).then(function (_ref2) {
          var tokenValues = _ref2.tokenValues;
          setSelectedStyleBook({
            styleBookEntryId: styleBookEntryId,
            tokenValues: tokenValues
          });
        });
      }, [setSelectedStyleBook]);
      (0, _react.useEffect)(function () {
        if (selectedStyleBook && document.documentElement) {
          Object.values(selectedStyleBook.tokenValues).forEach(function (token) {
            document.documentElement.style.setProperty("--".concat(token.cssVariable), token.value);
          });
        }
      }, [selectedStyleBook]);
      var tabs = (0, _react.useMemo)(function () {
        return getTabs(masterLayoutPlid, selectedStyleBook, defaultStyleBook, onSelectMasterLayout, onSelectStyleBook);
      }, [defaultStyleBook, masterLayoutPlid, onSelectMasterLayout, onSelectStyleBook, selectedStyleBook]);

      var _useState3 = (0, _react.useState)(0),
          _useState4 = _slicedToArray(_useState3, 2),
          activeTabId = _useState4[0],
          setActiveTabId = _useState4[1];

      var tabIdNamespace = (0, _useId.useId)();

      var getTabId = function getTabId(tabId) {
        return "".concat(tabIdNamespace, "tab").concat(tabId);
      };

      var getTabPanelId = function getTabPanelId(tabId) {
        return "".concat(tabIdNamespace, "tabPanel").concat(tabId);
      };

      return (/*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_SidebarPanelHeader.default, {
          className: "justify-content-between"
        }, Liferay.Language.get('page-design-options'), /*#__PURE__*/_react.default.createElement(_link.default, {
          className: "font-weight-normal",
          href: _index.config.lookAndFeelURL
        }, Liferay.Language.get('more'))), /*#__PURE__*/_react.default.createElement(_SidebarPanelContent.default, null, /*#__PURE__*/_react.default.createElement(_tabs.default, {
          className: "page-editor__sidebar__page-design-options__tabs",
          modern: true
        }, tabs.map(function (tab, index) {
          return (/*#__PURE__*/_react.default.createElement(_tabs.default.Item, {
              active: activeTabId === index,
              innerProps: {
                'aria-controls': getTabPanelId(index),
                id: getTabId(index)
              },
              key: index,
              onClick: function onClick() {
                return setActiveTabId(index);
              }
            }, tab.label)
          );
        })), /*#__PURE__*/_react.default.createElement(_tabs.default.Content, {
          activeIndex: activeTabId,
          fade: true
        }, tabs.map(function (_ref3, index) {
          var icon = _ref3.icon,
              options = _ref3.options,
              type = _ref3.type;
          return (/*#__PURE__*/_react.default.createElement(_tabs.default.TabPane, {
              "aria-labelledby": getTabId(index),
              id: getTabPanelId(index),
              key: index
            }, /*#__PURE__*/_react.default.createElement(OptionList, {
              icon: icon,
              options: options,
              type: type
            }))
          );
        }))))
      );
    }

    var OptionList = function OptionList(_ref4) {
      var _ref4$options = _ref4.options,
          options = _ref4$options === void 0 ? [] : _ref4$options,
          icon = _ref4.icon,
          type = _ref4.type;

      if (type === OPTIONS_TYPES.styleBook && !_index.config.styleBookEnabled) {
        return (/*#__PURE__*/_react.default.createElement(_alert.default, {
            className: "mt-3",
            displayType: "info"
          }, Liferay.Language.get('this-page-is-using-a-different-theme-than-the-one-set-for-public-pages'))
        );
      }

      return (/*#__PURE__*/_react.default.createElement("ul", {
          className: "list-unstyled mt-3"
        }, options.map(function (_ref5, index) {
          var imagePreviewURL = _ref5.imagePreviewURL,
              isActive = _ref5.isActive,
              name = _ref5.name,
              _onClick = _ref5.onClick,
              subtitle = _ref5.subtitle;
          return (/*#__PURE__*/_react.default.createElement("li", {
              key: index
            }, /*#__PURE__*/_react.default.createElement(_card.default, {
              "aria-label": name,
              className: (0, _classnames.default)({
                'page-editor__sidebar__design-options__tab-card--active': isActive
              }),
              displayType: "file",
              onClick: function onClick() {
                if (!isActive) {
                  _onClick();
                }
              },
              selectable: true
            }, /*#__PURE__*/_react.default.createElement(_card.default.AspectRatio, {
              className: "card-item-first",
              containerAspectRatio: "16/9"
            }, imagePreviewURL ? /*#__PURE__*/_react.default.createElement("img", {
              alt: "thumbnail",
              className: "aspect-ratio-item aspect-ratio-item-center-middle aspect-ratio-item-fluid",
              src: imagePreviewURL
            }) : /*#__PURE__*/_react.default.createElement("div", {
              className: "aspect-ratio-item aspect-ratio-item-center-middle aspect-ratio-item-fluid card-type-asset-icon"
            }, /*#__PURE__*/_react.default.createElement(_icon.default, {
              symbol: icon
            }))), /*#__PURE__*/_react.default.createElement(_card.default.Body, null, /*#__PURE__*/_react.default.createElement(_card.default.Row, null, /*#__PURE__*/_react.default.createElement("div", {
              className: "autofit-col autofit-col-expand"
            }, /*#__PURE__*/_react.default.createElement("section", {
              className: "autofit-section"
            }, /*#__PURE__*/_react.default.createElement(_card.default.Description, {
              displayType: "title"
            }, name), subtitle && /*#__PURE__*/_react.default.createElement(_card.default.Description, {
              displayType: "subtitle"
            }, subtitle)))))))
          );
        }))
      );
    };

    function getTabs(masterLayoutPlid, selectedStyleBook, defaultStyleBook, onSelectMasterLayout, onSelectStyleBook) {
      var styleBooks = [{
        imagePreviewURL: defaultStyleBook.imagePreviewURL,
        name: _index.config.layoutType === _layoutTypes.LAYOUT_TYPES.master ? Liferay.Language.get('default-style-book') : Liferay.Language.get('inherited-from-master'),
        styleBookEntryId: '0',
        subtitle: defaultStyleBook.name || Liferay.Language.get('provided-by-theme')
      }].concat(_toConsumableArray(_index.config.styleBooks));
      var tabs = [];

      if (_index.config.layoutType !== _layoutTypes.LAYOUT_TYPES.master) {
        tabs.push({
          icon: 'page',
          label: Liferay.Language.get('master'),
          options: _index.config.masterLayouts.map(function (masterLayout) {
            return _objectSpread(_objectSpread({}, masterLayout), {}, {
              isActive: masterLayoutPlid === masterLayout.masterLayoutPlid,
              onClick: function onClick() {
                return onSelectMasterLayout(masterLayout);
              }
            });
          }),
          type: OPTIONS_TYPES.master
        });
      }

      tabs.push({
        icon: 'magic',
        label: Liferay.Language.get('style-book'),
        options: styleBooks.map(function (styleBook) {
          return _objectSpread(_objectSpread({}, styleBook), {}, {
            isActive: selectedStyleBook.styleBookEntryId === styleBook.styleBookEntryId,
            onClick: function onClick() {
              return onSelectStyleBook(styleBook.styleBookEntryId);
            }
          });
        }),
        type: OPTIONS_TYPES.styleBook
      });
      return tabs;
    }
    //# sourceMappingURL=PageDesignOptionsSidebar.js.map
  }
});
//# sourceMappingURL=PageDesignOptionsSidebar.js.map