"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getStyle = getStyle;

var React = _interopRequireWildcard(require("react"));

var _index = require("./index");

require("@testing-library/jest-dom/extend-expect");

var _Box = _interopRequireWildcard(require("../Box/Box"));

var _Box2 = require("../Box/Box.styled");

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var testText = 'Hello World';
var classes = (0, _index.getClasses)(_Box2.styles, _Box.name);

function getStyle(props) {
  var _render = (0, _index.render)(React.createElement(_Box["default"], props, testText)),
      sheets = _render.sheets;

  var result = sheets.registry[0].rules.index.reduce(function (acc, cur) {
    var rule = cur;

    if (rule.at === 'media') {
      if (Object.keys(rule.rules.index[0].style).length) {
        return _objectSpread({}, acc, _defineProperty({}, rule.key, rule.rules.index[0].style));
      }
    } else if (classes.system.includes(rule.id) && !!Object.keys(rule.style).length) {
      return _objectSpread({}, acc, {}, rule.style);
    }

    return acc;
  }, {});
  return result;
}