'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createMatchMediaWithin = exports.createMatchMediaMax = exports.createMatchMediaMin = exports.createMatchMedia = exports.getJoinedQueries = exports.getMaxQuery = exports.getMinQuery = undefined;

var _screenConfig = require('kitten/constants/screen-config');

var getMinQuery = exports.getMinQuery = function getMinQuery(num) {
  return '(min-width: ' + num + 'px)';
};
var getMaxQuery = exports.getMaxQuery = function getMaxQuery(num) {
  return '(max-width: ' + num + 'px)';
};

var getJoinedQueries = exports.getJoinedQueries = function getJoinedQueries(queries) {
  return queries.filter(function (q) {
    return q;
  }).join(' and ');
};

var createMatchMedia = exports.createMatchMedia = function createMatchMedia(mediaQueryString) {
  if (typeof window === 'undefined' || !mediaQueryString) return;

  return window.matchMedia(mediaQueryString);
};

var createMatchMediaMin = exports.createMatchMediaMin = function createMatchMediaMin(configName) {
  var screenConfig = _screenConfig.ScreenConfig[configName];

  if (!screenConfig) return;

  return createMatchMedia(getMinQuery(screenConfig.min));
};

var createMatchMediaMax = exports.createMatchMediaMax = function createMatchMediaMax(configName) {
  var screenConfig = _screenConfig.ScreenConfig[configName];

  if (!screenConfig) return;

  return createMatchMedia(getMaxQuery(screenConfig.max));
};

var createMatchMediaWithin = exports.createMatchMediaWithin = function createMatchMediaWithin(configName) {
  var screenConfig = _screenConfig.ScreenConfig[configName];

  if (!screenConfig) return;

  var minQuery = screenConfig.min ? getMinQuery(screenConfig.min) : null;
  var maxQuery = screenConfig.max ? getMaxQuery(screenConfig.max) : null;
  var query = getJoinedQueries([minQuery, maxQuery]);

  return createMatchMedia(query);
};