text: "use strict";
  
  exports.__esModule = true;
  exports.css = void 0;
  
  var _utils = require("@chakra-ui/utils");
  
  var _parser = require("./parser");
  
  var _pseudo = require("./pseudo");
  
  function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } it = o[Symbol.iterator](); return it.next.bind(it); }
  
  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; }
  
  var cache = {
    themeBreakpoints: [],
    breakpoints: [],
    breakpointValues: [],
    mediaQueries: []
  };
  
  /**
   *
   */
  var calculateBreakpointAndMediaQueries = function calculateBreakpointAndMediaQueries(themeBreakpoints) {
    if (themeBreakpoints === void 0) {
      themeBreakpoints = [];
    }
  
    // caching here reduces execution time by factor 4-6x
    var isCached = cache.themeBreakpoints === themeBreakpoints;
  
    if (isCached) {
      return cache;
    }
  
    var _Object$entries$filte = Object.entries(themeBreakpoints).filter(function (_ref) {
      var key = _ref[0];
      return (0, _utils.isCustomBreakpoint)(key);
    }).reduce(function (carry, _ref2) {
      var breakpoint = _ref2[0],
          value = _ref2[1];
      carry.breakpoints.push(breakpoint);
      carry.breakpointValues.push(value);
      return carry;
    }, {
      breakpoints: [],
      breakpointValues: []
    }),
        breakpoints = _Object$entries$filte.breakpoints,
        breakpointValues = _Object$entries$filte.breakpointValues;
  
    var mediaQueries = [null].concat(breakpointValues.map(function (bp) {
      return "@media screen and (min-width: " + bp + ")";
    }).slice(1));
    cache.themeBreakpoints = themeBreakpoints;
    cache.mediaQueries = mediaQueries;
    cache.breakpointValues = breakpointValues;
    cache.breakpoints = breakpoints;
    return {
      breakpoints: breakpoints,
      mediaQueries: mediaQueries
    };
  };
  
  var responsive = function responsive(styles) {
    return function (theme) {
      var computedStyles = {};
  
      var _calculateBreakpointA = calculateBreakpointAndMediaQueries(theme.breakpoints),
          breakpoints = _calculateBreakpointA.breakpoints,
          mediaQueries = _calculateBreakpointA.mediaQueries;
  
      for (var key in styles) {
        var value = (0, _utils.runIfFn)(styles[key], theme);
  
        if (value == null) {
          continue;
        }
  
        value = (0, _utils.isResponsiveObjectLike)(value, breakpoints) ? (0, _utils.objectToArrayNotation)(value, breakpoints) : value;
  
        if (!(0, _utils.isArray)(value)) {
          computedStyles[key] = value;
          continue;
        }
  
        var queries = value.slice(0, mediaQueries.length).length;
  
        for (var index = 0; index < queries; index += 1) {
          var media = mediaQueries[index];
  
          if (!media) {
            computedStyles[key] = value[index];
            continue;
          }
  
          computedStyles[media] = computedStyles[media] || {};
  
          if (value[index] == null) {
            continue;
          }
  
          computedStyles[media][key] = value[index];
        }
      }
  
      return computedStyles;
    };
  };
  
  var css = function css(args) {
    if (args === void 0) {
      args = {};
    }
  
    return function (props) {
      if (props === void 0) {
        props = {};
      }
  
      var theme = "theme" in props ? props.theme : props;
      var computedStyles = {};
      var styleObject = (0, _utils.runIfFn)(args, theme);
      var styles = responsive(styleObject)(theme);
  
      for (var k in styles) {
        var _config$transform;
  
        var x = styles[k];
        var val = (0, _utils.runIfFn)(x, theme);
        var key = k in _pseudo.pseudoSelectors ? _pseudo.pseudoSelectors[k] : k;
        var config = _parser.parser.config[key];
  
        if (key === "apply") {
          var apply = css((0, _utils.memoizedGet)(theme, val))(theme);
          computedStyles = (0, _utils.mergeWith)({}, computedStyles, apply);
          continue;
        }
  
        if ((0, _utils.isObject)(val)) {
          computedStyles[key] = css(val)(theme);
          continue;
        }
  
        var scale = (0, _utils.memoizedGet)(theme, config == null ? void 0 : config.scale, {});
        var value = (_config$transform = config == null ? void 0 : config.transform == null ? void 0 : config.transform(val, scale)) != null ? _config$transform : (0, _utils.memoizedGet)(scale, val, val);
  
        if (config == null ? void 0 : config.properties) {
          for (var _iterator = _createForOfIteratorHelperLoose(config.properties), _step; !(_step = _iterator()).done;) {
            var property = _step.value;
            computedStyles[property] = value;
          }
  
          continue;
        }
  
        if (config == null ? void 0 : config.property) {
          computedStyles[config.property] = value;
          continue;
        }
  
        computedStyles[key] = value;
      }
  
      return computedStyles;
    };
  };
  
  exports.css = css;
  //# sourceMappingURL=css.js.map