"use strict";

Liferay.Loader.define("@frontend-taglib-clay$clayui/drop-down@3.58.0/lib/DropDownWithDrilldown", ['module', 'exports', 'require', 'frontend-taglib-clay$classnames', 'frontend-js-react-web$react', './DropDown', './drilldown'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.ClayDropDownWithDrilldown = void 0;

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

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

    var _DropDown = _interopRequireDefault(require("./DropDown"));

    var _drilldown = _interopRequireDefault(require("./drilldown"));

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

    function _toConsumableArray(arr) {
      return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
    }

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

    function _iterableToArray(iter) {
      if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
    }

    function _arrayWithoutHoles(arr) {
      if (Array.isArray(arr)) return _arrayLikeToArray(arr);
    }

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

    var ClayDropDownWithDrilldown = function ClayDropDownWithDrilldown(_ref) {
      var active = _ref.active,
          alignmentByViewport = _ref.alignmentByViewport,
          alignmentPosition = _ref.alignmentPosition,
          className = _ref.className,
          containerElement = _ref.containerElement,
          defaultActive = _ref.defaultActive,
          defaultActiveMenu = _ref.defaultActiveMenu,
          initialActiveMenu = _ref.initialActiveMenu,
          menuElementAttrs = _ref.menuElementAttrs,
          menuHeight = _ref.menuHeight,
          menuWidth = _ref.menuWidth,
          menus = _ref.menus,
          offsetFn = _ref.offsetFn,
          onActiveChange = _ref.onActiveChange,
          renderMenuOnClick = _ref.renderMenuOnClick,
          spritemap = _ref.spritemap,
          trigger = _ref.trigger;

      var _React$useState = _react.default.useState(defaultActiveMenu !== null && defaultActiveMenu !== void 0 ? defaultActiveMenu : initialActiveMenu),
          _React$useState2 = _slicedToArray(_React$useState, 2),
          activeMenu = _React$useState2[0],
          setActiveMenu = _React$useState2[1];

      var _React$useState3 = _react.default.useState(),
          _React$useState4 = _slicedToArray(_React$useState3, 2),
          direction = _React$useState4[0],
          setDirection = _React$useState4[1];

      var _React$useState5 = _react.default.useState([]),
          _React$useState6 = _slicedToArray(_React$useState5, 2),
          history = _React$useState6[0],
          setHistory = _React$useState6[1];

      var menuIds = Object.keys(menus);
      return (/*#__PURE__*/_react.default.createElement(_DropDown.default, {
          active: active,
          alignmentByViewport: alignmentByViewport,
          alignmentPosition: alignmentPosition,
          className: className,
          containerElement: containerElement,
          defaultActive: defaultActive,
          hasRightSymbols: true,
          menuElementAttrs: _objectSpread(_objectSpread({}, menuElementAttrs), {}, {
            className: (0, _classnames.default)(menuElementAttrs === null || menuElementAttrs === void 0 ? void 0 : menuElementAttrs.className, 'drilldown')
          }),
          menuHeight: menuHeight,
          menuWidth: menuWidth,
          offsetFn: offsetFn,
          onActiveChange: onActiveChange,
          renderMenuOnClick: renderMenuOnClick,
          trigger: trigger
        }, /*#__PURE__*/_react.default.createElement(_drilldown.default.Inner, null, menuIds.map(function (menuKey) {
          return (/*#__PURE__*/_react.default.createElement(_drilldown.default.Menu, {
              active: activeMenu === menuKey,
              direction: direction,
              header: activeMenu === menuKey && !!history.length ? history.slice(-1)[0].title : undefined,
              items: menus[menuKey],
              key: menuKey,
              onBack: function onBack() {
                var _history$slice = history.slice(-1),
                    _history$slice2 = _slicedToArray(_history$slice, 1),
                    parent = _history$slice2[0];

                setHistory(history.slice(0, history.length - 1));
                setDirection('prev');
                setActiveMenu(parent.id);
              },
              onForward: function onForward(title, childId) {
                setHistory([].concat(_toConsumableArray(history), [{
                  id: activeMenu,
                  title: title
                }]));
                setDirection('next');
                setActiveMenu(childId);
              },
              spritemap: spritemap
            })
          );
        })))
      );
    };

    exports.ClayDropDownWithDrilldown = ClayDropDownWithDrilldown;
    ClayDropDownWithDrilldown.displayName = 'ClayDropDownWithDrilldown';
  }
});
//# sourceMappingURL=DropDownWithDrilldown.js.map