"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

exports.__esModule = true;
exports.useHideMobileDrawer = exports.MobileMenu = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

var _react = _interopRequireWildcard(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _router = require("next/router");

var _lib = require("@sentecacommerce-theme/lib");

var _Icons = require("../../../Common/Icons");

var _SupportButtons = require("./SupportButtons");

var _AuthButtons = require("./AuthButtons");

var _User = require("./User");

var _MobileMenuItem = require("./MobileMenuItem");

var _AnimatedDrawer = require("./AnimatedDrawer");

var _templateObject;

var MobileMenu = function MobileMenu(_ref) {
  var data = _ref.data,
      handleClose = _ref.handleClose,
      mobileMenu = _ref.mobileMenu;

  var _useConfigState = (0, _lib.useConfigState)(),
      views = _useConfigState.views;

  var _useIsAuthenticated = (0, _lib.useIsAuthenticated)(),
      isAuthenticated = _useIsAuthenticated.isAuthenticated;

  var router = (0, _router.useRouter)();

  var _useUIFunctions = (0, _lib.useUIFunctions)(),
      enqueueView = _useUIFunctions.enqueueView;

  var _useState = (0, _react.useState)(null),
      slideLeft = _useState[0],
      setSlideLeft = _useState[1];

  return /*#__PURE__*/_react["default"].createElement(_AnimatedDrawer.AnimatedDrawer, {
    isLeft: slideLeft,
    showBackdrop: true,
    showCloseIcon: true,
    handleClose: handleClose
  }, /*#__PURE__*/_react["default"].createElement(HideMobileMenuProvider, {
    hideMenu: handleClose
  }, /*#__PURE__*/_react["default"].createElement(_lib.OverflowHidden, null), isAuthenticated && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(ElementWrapper, {
    className: "pb-4 mb-2",
    onClick: function onClick() {
      return router.push('/profile');
    }
  }, /*#__PURE__*/_react["default"].createElement(_User.User, null), /*#__PURE__*/_react["default"].createElement(_Icons.ArrowRight, null))), /*#__PURE__*/_react["default"].createElement("ul", null, data == null ? void 0 : data.map(function (menu) {
    return /*#__PURE__*/_react["default"].createElement(_MobileMenuItem.MobileMenuItem, {
      data: menu,
      key: "Menu__" + menu._id,
      onItemClick: handleClose,
      slideLeft: function slideLeft() {
        return setSlideLeft(true);
      },
      reset: function reset() {
        return setSlideLeft(false);
      }
    });
  })), !isAuthenticated && /*#__PURE__*/_react["default"].createElement(_AuthButtons.AuthButtons, {
    handleModal: function handleModal() {
      handleClose();
      enqueueView(views.auth);
    }
  }), /*#__PURE__*/_react["default"].createElement(_SupportButtons.SupportButtons, {
    data: mobileMenu || []
  })));
};

exports.MobileMenu = MobileMenu;

var HideMobileMenuContext = /*#__PURE__*/_react["default"].createContext({
  hideMenu: function hideMenu() {}
});

var HideMobileMenuProvider = function HideMobileMenuProvider(_ref2) {
  var hideMenu = _ref2.hideMenu,
      children = _ref2.children;
  return /*#__PURE__*/_react["default"].createElement(HideMobileMenuContext.Provider, {
    value: {
      hideMenu: hideMenu
    }
  }, children);
};

var useHideMobileDrawer = function useHideMobileDrawer() {
  var _React$useContext;

  return (_React$useContext = _react["default"].useContext(HideMobileMenuContext)) == null ? void 0 : _React$useContext.hideMenu;
};

exports.useHideMobileDrawer = useHideMobileDrawer;

var ElementWrapper = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  align-items: center;\n  width: 100%;\n  display: flex;\n"])));
//# sourceMappingURL=index.js.map