"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
require("core-js/modules/es.array.concat.js");
var _react = _interopRequireDefault(require("react"));
var _uiHelpers = require("@megafon/ui-helpers");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var MOBILE_MIDDLE_END = _uiHelpers.breakpoints.MOBILE_MIDDLE_END,
  MOBILE_BIG_START = _uiHelpers.breakpoints.MOBILE_BIG_START,
  MOBILE_BIG_END = _uiHelpers.breakpoints.MOBILE_BIG_END,
  DESKTOP_SMALL_START = _uiHelpers.breakpoints.DESKTOP_SMALL_START,
  DESKTOP_MIDDLE_START = _uiHelpers.breakpoints.DESKTOP_MIDDLE_START;
var useResolutions = function useResolutions() {
  var _React$useState = _react["default"].useState(false),
    _React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
    isMobile = _React$useState2[0],
    setIsMobile = _React$useState2[1];
  var _React$useState3 = _react["default"].useState(false),
    _React$useState4 = (0, _slicedToArray2["default"])(_React$useState3, 2),
    isTablet = _React$useState4[0],
    setIsTablet = _React$useState4[1];
  var _React$useState5 = _react["default"].useState(false),
    _React$useState6 = (0, _slicedToArray2["default"])(_React$useState5, 2),
    isDesktop = _React$useState6[0],
    setIsDesktop = _React$useState6[1];
  var _React$useState7 = _react["default"].useState(false),
    _React$useState8 = (0, _slicedToArray2["default"])(_React$useState7, 2),
    isDesktopWide = _React$useState8[0],
    setIsDesktopWide = _React$useState8[1];
  _react["default"].useEffect(function () {
    if (typeof window === 'undefined') {
      return undefined;
    }
    var _window = window,
      matchMedia = _window.matchMedia;
    var mobileQuery = matchMedia("(max-width: ".concat(MOBILE_MIDDLE_END, "px)"));
    var tabletQuery = matchMedia("(min-width: ".concat(MOBILE_BIG_START, "px) and (max-width: ").concat(MOBILE_BIG_END, "px)"));
    var desktopQuery = matchMedia("(min-width: ".concat(DESKTOP_SMALL_START, "px)"));
    var desktopWideQuery = matchMedia("(min-width: ".concat(DESKTOP_MIDDLE_START, "px)"));
    var handleResize = function handleResize() {
      setIsMobile(mobileQuery.matches);
      setIsTablet(tabletQuery.matches);
      setIsDesktop(desktopQuery.matches);
      setIsDesktopWide(desktopWideQuery.matches);
    };
    handleResize();
    mobileQuery.addEventListener('change', handleResize);
    tabletQuery.addEventListener('change', handleResize);
    desktopQuery.addEventListener('change', handleResize);
    desktopWideQuery.addEventListener('change', handleResize);
    return function () {
      mobileQuery.removeEventListener('change', handleResize);
      tabletQuery.removeEventListener('change', handleResize);
      desktopQuery.removeEventListener('change', handleResize);
      desktopWideQuery.addEventListener('change', handleResize);
    };
  }, []);
  return {
    isDesktopWide: isDesktopWide,
    isDesktop: isDesktop,
    isMobile: isMobile,
    isTablet: isTablet
  };
};
var _default = exports["default"] = useResolutions;