"use strict";

Liferay.Loader.define("@frontend-taglib-clay$clayui/drop-down@3.58.0/lib/DropDown", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/shared', 'frontend-taglib-clay$classnames', 'frontend-js-react-web$react', './Action', './Caption', './Divider', './Group', './Help', './Item', './ItemList', './Menu', './Search', './Section'], 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
    });
    Object.defineProperty(exports, "Align", {
      enumerable: true,
      get: function get() {
        return _Menu.Align;
      }
    });
    exports.default = void 0;

    var _shared = require("@frontend-taglib-clay$clayui/shared");

    var _classnames = _interopRequireDefault(require("frontend-taglib-clay$classnames"));

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

    var _Action = _interopRequireDefault(require("./Action"));

    var _Caption = _interopRequireDefault(require("./Caption"));

    var _Divider = _interopRequireDefault(require("./Divider"));

    var _Group = _interopRequireDefault(require("./Group"));

    var _Help = _interopRequireDefault(require("./Help"));

    var _Item = _interopRequireDefault(require("./Item"));

    var _ItemList = _interopRequireDefault(require("./ItemList"));

    var _Menu = _interopRequireWildcard(require("./Menu"));

    var _Search = _interopRequireDefault(require("./Search"));

    var _Section = _interopRequireDefault(require("./Section"));

    var _excluded = ["active", "alignmentByViewport", "alignmentPosition", "children", "className", "closeOnClickOutside", "containerElement", "defaultActive", "hasLeftSymbols", "hasRightSymbols", "menuElementAttrs", "menuHeight", "menuWidth", "offsetFn", "onActiveChange", "renderMenuOnClick", "trigger"];

    function _getRequireWildcardCache(nodeInterop) {
      if (typeof WeakMap !== "function") return null;var cacheBabelInterop = new WeakMap();var cacheNodeInterop = new WeakMap();return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) {
        return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
      })(nodeInterop);
    }

    function _interopRequireWildcard(obj, nodeInterop) {
      if (!nodeInterop && obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache(nodeInterop);if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (key !== "default" && 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 _extends() {
      _extends = Object.assign || function (target) {
        for (var i = 1; i < arguments.length; i++) {
          var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
              target[key] = source[key];
            }
          }
        }return target;
      };return _extends.apply(this, arguments);
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
    }

    function _unsupportedIterableToArray(o, minLen) {
      if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(o);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
    }

    function _arrayLikeToArray(arr, len) {
      if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {
        arr2[i] = arr[i];
      }return arr2;
    }

    function _iterableToArrayLimit(arr, i) {
      var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];if (_i == null) return;var _arr = [];var _n = true;var _d = false;var _s, _e;try {
        for (_i = _i.call(arr); !(_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;
    }

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    var ClayDropDown = function ClayDropDown(_ref) {
      var active = _ref.active,
          alignmentByViewport = _ref.alignmentByViewport,
          alignmentPosition = _ref.alignmentPosition,
          children = _ref.children,
          className = _ref.className,
          closeOnClickOutside = _ref.closeOnClickOutside,
          _ref$containerElement = _ref.containerElement,
          ContainerElement = _ref$containerElement === void 0 ? 'div' : _ref$containerElement,
          _ref$defaultActive = _ref.defaultActive,
          defaultActive = _ref$defaultActive === void 0 ? false : _ref$defaultActive,
          hasLeftSymbols = _ref.hasLeftSymbols,
          hasRightSymbols = _ref.hasRightSymbols,
          menuElementAttrs = _ref.menuElementAttrs,
          menuHeight = _ref.menuHeight,
          menuWidth = _ref.menuWidth,
          offsetFn = _ref.offsetFn,
          onActiveChange = _ref.onActiveChange,
          _ref$renderMenuOnClic = _ref.renderMenuOnClick,
          renderMenuOnClick = _ref$renderMenuOnClic === void 0 ? false : _ref$renderMenuOnClic,
          trigger = _ref.trigger,
          otherProps = _objectWithoutProperties(_ref, _excluded);

      var triggerElementRef = _react.default.useRef(null);

      var menuElementRef = _react.default.useRef(null);

      var _React$useState = _react.default.useState(!renderMenuOnClick),
          _React$useState2 = _slicedToArray(_React$useState, 2),
          initialized = _React$useState2[0],
          setInitialized = _React$useState2[1];

      var _useInternalState = (0, _shared.useInternalState)({
        defaultName: 'defaultActive',
        defaultValue: defaultActive,
        handleName: 'onActiveChange',
        name: 'active',
        onChange: onActiveChange,
        value: active
      }),
          _useInternalState2 = _slicedToArray(_useInternalState, 2),
          internalActive = _useInternalState2[0],
          setInternalActive = _useInternalState2[1];

      var handleFocus = function handleFocus(event) {
        var _menuElementRef$curre, _menuElementRef$curre2, _triggerElementRef$cu;

        if (!((_menuElementRef$curre = menuElementRef.current) !== null && _menuElementRef$curre !== void 0 && (_menuElementRef$curre2 = _menuElementRef$curre.parentElement) !== null && _menuElementRef$curre2 !== void 0 && _menuElementRef$curre2.contains(event.target)) && !((_triggerElementRef$cu = triggerElementRef.current) !== null && _triggerElementRef$cu !== void 0 && _triggerElementRef$cu.contains(event.target))) {
          setInternalActive(false);
        }
      };

      _react.default.useEffect(function () {
        document.addEventListener('focus', handleFocus, true);
        return function () {
          document.removeEventListener('focus', handleFocus, true);
        };
      }, [handleFocus]);

      return (/*#__PURE__*/_react.default.createElement(_shared.FocusScope, null, /*#__PURE__*/_react.default.createElement(ContainerElement, _extends({}, otherProps, {
          className: (0, _classnames.default)('dropdown', className),
          onKeyUp: function handleKeyUp(event) {
            if (event.key === _shared.Keys.Esc) {
              setInternalActive(!internalActive);
            }
          }
        }), /*#__PURE__*/_react.default.cloneElement(trigger, {
          className: (0, _classnames.default)('dropdown-toggle', trigger.props.className),
          onClick: function onClick() {
            if (!initialized) {
              setInitialized(true);
            }

            setInternalActive(!internalActive);
          },
          ref: function ref(node) {
            if (node) {
              triggerElementRef.current = node; // Call the original ref, if any.

              var ref = trigger.ref;

              if (typeof ref === 'function') {
                ref(node);
              }
            }
          }
        }), initialized && /*#__PURE__*/_react.default.createElement(_Menu.default, _extends({}, menuElementAttrs, {
          active: internalActive,
          alignElementRef: triggerElementRef,
          alignmentByViewport: alignmentByViewport,
          alignmentPosition: alignmentPosition,
          closeOnClickOutside: closeOnClickOutside,
          hasLeftSymbols: hasLeftSymbols,
          hasRightSymbols: hasRightSymbols,
          height: menuHeight,
          offsetFn: offsetFn,
          onSetActive: setInternalActive,
          ref: menuElementRef,
          width: menuWidth
        }), children)))
      );
    };

    ClayDropDown.Action = _Action.default;
    ClayDropDown.Caption = _Caption.default;
    ClayDropDown.Divider = _Divider.default;
    ClayDropDown.Group = _Group.default;
    ClayDropDown.Help = _Help.default;
    ClayDropDown.Menu = _Menu.default;
    ClayDropDown.Item = _Item.default;
    ClayDropDown.ItemList = _ItemList.default;
    ClayDropDown.Search = _Search.default;
    ClayDropDown.Section = _Section.default;
    var _default = ClayDropDown;
    exports.default = _default;
  }
});
//# sourceMappingURL=DropDown.js.map