Liferay.Loader.define("app-builder-web@1.0.76/js/pages/apps/edit/settings/ProductMenuSettings.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/drop-down', '@frontend-taglib-clay$clayui/form', '@frontend-taglib-clay$clayui/layout', 'frontend-js-react-web$classnames', 'data-engine-taglib', 'frontend-js-react-web$react', '../../../../utils/client.es', '../EditAppContext.es'], 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 = void 0;

    var _dropDown = _interopRequireWildcard(require("@frontend-taglib-clay$clayui/drop-down"));

    var _form = require("@frontend-taglib-clay$clayui/form");

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

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

    var _dataEngineTaglib = require("data-engine-taglib");

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

    var _client = require("../../../../utils/client.es");

    var _EditAppContext = _interopRequireWildcard(require("../EditAppContext.es"));

    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 _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 Divider = _dropDown.default.Divider,
        Item = _dropDown.default.Item,
        ItemList = _dropDown.default.ItemList;
    var SCOPES = [{
      label: Liferay.Language.get('applications'),
      value: ['applications_menu.applications']
    }, {
      label: Liferay.Language.get('site-menu'),
      value: ['site_administration.content']
    }, {
      label: Liferay.Language.get('applications-and-site-menu'),
      value: ['applications_menu.applications', 'site_administration.content']
    }];

    var _default = function _default() {
      var _useContext = (0, _react.useContext)(_EditAppContext.default),
          dispatch = _useContext.dispatch,
          appDeployments = _useContext.state.app.appDeployments;

      var _useState = (0, _react.useState)([]),
          _useState2 = _slicedToArray(_useState, 2),
          sites = _useState2[0],
          setSites = _useState2[1];

      var _useState3 = (0, _react.useState)(false),
          _useState4 = _slicedToArray(_useState3, 2),
          active = _useState4[0],
          setActive = _useState4[1];

      var _useState5 = (0, _react.useState)(''),
          _useState6 = _slicedToArray(_useState5, 2),
          searchText = _useState6[0],
          setSearchText = _useState6[1];

      var filteredSites = sites.filter(function (item) {
        if (!searchText) {
          return true;
        }

        var regex = new RegExp(searchText, 'ig');
        return regex.test(item.name);
      });
      (0, _react.useEffect)(function () {
        (0, _client.getItem)('/o/headless-admin-user/v1.0/my-user-account/sites').then(function (_ref) {
          var _ref$items = _ref.items,
              sites = _ref$items === void 0 ? [] : _ref$items;
          return setSites(sites);
        });
      }, []);

      var onSiteIdsChange = function onSiteIdsChange(siteId) {
        dispatch({
          siteId: parseInt(siteId, 10),
          type: _EditAppContext.TOGGLE_SETTINGS_SITE_ID
        });
      };

      var _appDeployments$find = appDeployments.find(function (appDeployment) {
        return appDeployment.type === _EditAppContext.PRODUCT_MENU;
      }),
          _appDeployments$find$ = _appDeployments$find.settings,
          scope = _appDeployments$find$.scope,
          _appDeployments$find$2 = _appDeployments$find$.siteIds,
          siteIds = _appDeployments$find$2 === void 0 ? [] : _appDeployments$find$2;

      var sitesNames = siteIds.map(function (siteId) {
        if (siteId === _EditAppContext.SITE_ID_ALL) {
          return Liferay.Language.get('all-sites');
        }

        var site = sites.find(function (site) {
          return site.id === siteId;
        });

        if (site) {
          return site.name;
        } else {
          return '';
        }
      }).join(', ');
      return (/*#__PURE__*/_react.default.createElement(_layout.default.ContentRow, {
          className: "pl-4 pr-4"
        }, /*#__PURE__*/_react.default.createElement(_layout.default.ContentCol, {
          expand: true
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "form-group"
        }, /*#__PURE__*/_react.default.createElement("label", {
          htmlFor: "scope"
        }, Liferay.Language.get('place-it-in-the')), /*#__PURE__*/_react.default.createElement("select", {
          className: "form-control",
          id: "scope",
          onChange: function onScopeChange(event) {
            var scope = event.target.value;
            dispatch({
              scope: scope.split(','),
              type: _EditAppContext.UPDATE_SETTINGS_SCOPE
            });
          },
          value: scope
        }, SCOPES.map(function (_ref2, index) {
          var label = _ref2.label,
              value = _ref2.value;
          return (/*#__PURE__*/_react.default.createElement("option", {
              key: index,
              value: value
            }, label)
          );
        })))), scope.includes('site_administration.content') && /*#__PURE__*/_react.default.createElement(_layout.default.Col, {
          md: "6"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "form-group"
        }, /*#__PURE__*/_react.default.createElement("label", {
          htmlFor: "site"
        }, Liferay.Language.get('site')), /*#__PURE__*/_react.default.createElement(_dropDown.default, {
          active: active,
          alignmentPosition: _dropDown.Align.BottomLeft,
          onActiveChange: function onActiveChange(newVal) {
            return setActive(newVal);
          },
          trigger: /*#__PURE__*/_react.default.createElement("button", {
            "aria-label": Liferay.Language.get('choose-sites'),
            className: (0, _classnames.default)('form-control', 'form-control-select', 'select-site', 'text-truncate'),
            id: "site"
          }, sitesNames ? sitesNames : "".concat(Liferay.Language.get('choose-sites'), "..."))
        }, /*#__PURE__*/_react.default.createElement(ItemList, null, /*#__PURE__*/_react.default.createElement(Item, {
          key: 'search'
        }, /*#__PURE__*/_react.default.createElement(_dataEngineTaglib.SearchInput, {
          onChange: function onChange(searchText) {
            return setSearchText(searchText);
          }
        })), /*#__PURE__*/_react.default.createElement(Item, {
          key: _EditAppContext.SITE_ID_ALL
        }, /*#__PURE__*/_react.default.createElement(_form.ClayCheckbox, {
          checked: siteIds.includes(_EditAppContext.SITE_ID_ALL),
          label: Liferay.Language.get('all-sites'),
          onChange: function onChange() {
            return onSiteIdsChange(_EditAppContext.SITE_ID_ALL);
          }
        })), /*#__PURE__*/_react.default.createElement(Divider, null), filteredSites.map(function (_ref3) {
          var id = _ref3.id,
              name = _ref3.name;
          return (/*#__PURE__*/_react.default.createElement(Item, {
              disabled: siteIds.includes(_EditAppContext.SITE_ID_ALL),
              key: id
            }, /*#__PURE__*/_react.default.createElement(_form.ClayCheckbox, {
              checked: siteIds.includes(id) || siteIds.includes(_EditAppContext.SITE_ID_ALL),
              disabled: siteIds.includes(_EditAppContext.SITE_ID_ALL),
              label: name,
              onChange: function onChange() {
                return onSiteIdsChange(id);
              }
            }))
          );
        }))))))
      );
    };

    exports.default = _default;
    //# sourceMappingURL=ProductMenuSettings.es.js.map
  }
});
//# sourceMappingURL=ProductMenuSettings.es.js.map