import _join from "ramda/src/join";
import _insert from "ramda/src/insert";
import _split from "ramda/src/split";
import _pipe from "ramda/src/pipe";
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { useEffect, useState } from 'react';
import styled, { useTheme } from 'styled-components';
var negateMedia = _pipe(_split(' '), _insert(1, 'not all and'), _join(' '));
var StyledDiv = styled.div.withConfig({
  displayName: "Media__StyledDiv",
  componentId: "sc-1dic02p-0"
})(["", "{display:none !important;}"], function (p) {
  return negateMedia(typeof p.query === 'string' ? p.query : p.query(p.theme));
});
var useMedia = function useMedia(query) {
  var theme = useTheme();
  var _useState = useState(null),
    _useState2 = _slicedToArray(_useState, 2),
    matches = _useState2[0],
    setMatches = _useState2[1];
  var mediaQuery = (typeof query === 'string' ? query : query(theme)).replace('@media ', '');
  useEffect(function () {
    if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
      return undefined;
    }
    var media = window.matchMedia(mediaQuery);
    setMatches(media.matches);
    var handler = function handler(e) {
      return setMatches(e.matches);
    };
    media.addListener(handler);
    return function () {
      return media.removeListener(handler);
    };
  }, [mediaQuery]);
  return matches;
};
var Media = function Media(props) {
  var As = props.as || 'div';
  var matches = useMedia(props.query);
  if (matches === null) return React.createElement(StyledDiv, props);
  return matches ? React.createElement(As, null, props.children) : null;
};
export { Media, useMedia };