import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import { useMemo } from 'react';
import { createBreakpointHook } from '@restart/hooks/useBreakpoint';
import { always, anyPass, equals, ifElse, o, reject, test, when, zipObj } from 'ramda';
import { alwaysNull, isArray, isNilOrEmpty } from 'ramda-extension';
import useTheme from './useTheme';
var getStaticPropsFromArray = ifElse(isArray, o( // Removing both all indices and `length` property
reject(anyPass([equals('length'), test(/[0-9]+/)])), Object.getOwnPropertyNames), alwaysNull);
var DEFAULT_ALIASES = ['sm', 'md', 'lg', 'xl'];
var getAliases = o(when(isNilOrEmpty, always(DEFAULT_ALIASES)), getStaticPropsFromArray);
/**
 * Bridge between current theme (based on styled-system) and
 * @rebass/hooks/useBreakpoint
 */

var useBreakpoint = function useBreakpoint() {
  var _useTheme = useTheme(),
      breakpoints = _useTheme.breakpoints;

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

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

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

export default useBreakpoint;