import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "core-js/modules/es.array.concat.js";
import React from 'react';
import { breakpoints } from '@megafon/ui-helpers';
var MOBILE_MIDDLE_END = breakpoints.MOBILE_MIDDLE_END,
  MOBILE_BIG_START = breakpoints.MOBILE_BIG_START,
  MOBILE_BIG_END = breakpoints.MOBILE_BIG_END,
  DESKTOP_SMALL_START = breakpoints.DESKTOP_SMALL_START,
  DESKTOP_MIDDLE_START = breakpoints.DESKTOP_MIDDLE_START;
var useResolutions = function useResolutions() {
  var _React$useState = React.useState(false),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    isMobile = _React$useState2[0],
    setIsMobile = _React$useState2[1];
  var _React$useState3 = React.useState(false),
    _React$useState4 = _slicedToArray(_React$useState3, 2),
    isTablet = _React$useState4[0],
    setIsTablet = _React$useState4[1];
  var _React$useState5 = React.useState(false),
    _React$useState6 = _slicedToArray(_React$useState5, 2),
    isDesktop = _React$useState6[0],
    setIsDesktop = _React$useState6[1];
  var _React$useState7 = React.useState(false),
    _React$useState8 = _slicedToArray(_React$useState7, 2),
    isDesktopWide = _React$useState8[0],
    setIsDesktopWide = _React$useState8[1];
  React.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
  };
};
export default useResolutions;