"use strict";

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

exports.__esModule = true;
exports.default = void 0;

var _react = require("react");

var _useBreakpoint = require("@restart/hooks/useBreakpoint");

var _ramda = require("ramda");

var _ramdaExtension = require("ramda-extension");

var _useTheme2 = _interopRequireDefault(require("./useTheme"));

var getStaticPropsFromArray = (0, _ramda.ifElse)(_ramdaExtension.isArray, (0, _ramda.o)( // Removing both all indices and `length` property
(0, _ramda.reject)((0, _ramda.anyPass)([(0, _ramda.equals)('length'), (0, _ramda.test)(/[0-9]+/)])), Object.getOwnPropertyNames), _ramdaExtension.alwaysNull);
var DEFAULT_ALIASES = ['sm', 'md', 'lg', 'xl'];
var getAliases = (0, _ramda.o)((0, _ramda.when)(_ramdaExtension.isNilOrEmpty, (0, _ramda.always)(DEFAULT_ALIASES)), getStaticPropsFromArray);
/** Bridge between current theme (based on styled-system) and @rebass/hooks/useBreakpoint */

var useBreakpoint = function useBreakpoint() {
  var _useTheme = (0, _useTheme2.default)(),
      breakpoints = _useTheme.breakpoints;

  var aliases = getAliases(breakpoints); // Styled-system use alias `_` for the smallest breakpoint.

  var mapping = (0, _ramda.zipObj)(['_'].concat(aliases), [0].concat(breakpoints));
  var mappingHash = JSON.stringify(mapping); // eslint-disable-next-line

  var useBreakpoint = (0, _react.useMemo)(function () {
    return (0, _useBreakpoint.createBreakpointHook)(mapping);
  }, [mappingHash]);
  return useBreakpoint.apply(void 0, arguments);
};

var _default = useBreakpoint;
exports.default = _default;