"use strict";

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

var _breakpoints = require("../../breakpoints");

var getStackeeOptions = function getStackeeOptions(_ref) {
  var grow = _ref.grow,
      shrink = _ref.shrink,
      basis = _ref.basis;
  var rules = [];

  if (grow != null) {
    rules.push("flex-grow: ".concat(grow, ";"));
  }

  if (shrink != null) {
    rules.push("flex-shrink: ".concat(shrink, ";"));
  }

  if (basis != null) {
    rules.push("flex-basis: ".concat(basis, "px;"));
  }

  return rules.join(' ');
};

var getStackeeRules = function getStackeeRules(stackeeProps) {
  var rules = [];
  var globalOptions = {
    grow: typeof stackeeProps.grow === 'number' ? stackeeProps.grow : undefined,
    shrink: typeof stackeeProps.shrink === 'number' ? stackeeProps.shrink : undefined,
    basis: typeof stackeeProps.basis === 'number' ? stackeeProps.basis : undefined
  };
  rules.push(getStackeeOptions(globalOptions));

  var optionsByBreakpoint = _breakpoints.breakPoints.reduce(function (acc, bp) {
    var _stackeeProps$grow, _stackeeProps$shrink, _stackeeProps$basis;

    if (stackeeProps.grow instanceof Object && (_stackeeProps$grow = stackeeProps.grow) !== null && _stackeeProps$grow !== void 0 && _stackeeProps$grow[bp] || stackeeProps.shrink instanceof Object && (_stackeeProps$shrink = stackeeProps.shrink) !== null && _stackeeProps$shrink !== void 0 && _stackeeProps$shrink[bp] || stackeeProps.basis instanceof Object && (_stackeeProps$basis = stackeeProps.basis) !== null && _stackeeProps$basis !== void 0 && _stackeeProps$basis[bp]) {
      var _stackeeProps$grow2, _stackeeProps$shrink2, _stackeeProps$basis2;

      acc[bp] = {
        grow: stackeeProps.grow instanceof Object ? (_stackeeProps$grow2 = stackeeProps.grow) === null || _stackeeProps$grow2 === void 0 ? void 0 : _stackeeProps$grow2[bp] : undefined,
        shrink: stackeeProps.shrink instanceof Object ? (_stackeeProps$shrink2 = stackeeProps.shrink) === null || _stackeeProps$shrink2 === void 0 ? void 0 : _stackeeProps$shrink2[bp] : undefined,
        basis: stackeeProps.basis instanceof Object ? (_stackeeProps$basis2 = stackeeProps.basis) === null || _stackeeProps$basis2 === void 0 ? void 0 : _stackeeProps$basis2[bp] : undefined
      };
    }

    return acc;
  }, {});

  if (optionsByBreakpoint.sm) {
    rules.push("@media (max-width: ".concat(_breakpoints.bpMedium, ") {").concat(getStackeeOptions(optionsByBreakpoint.sm), "}"));
  }

  if (optionsByBreakpoint.md) {
    rules.push("@media (min-width: ".concat(_breakpoints.bpMedium, ") {").concat(getStackeeOptions(optionsByBreakpoint.md), "}"));
  }

  if (optionsByBreakpoint.lg) {
    rules.push("@media (min-width: ".concat(_breakpoints.bpLarge, ") {").concat(getStackeeOptions(optionsByBreakpoint.lg), "}"));
  }

  if (optionsByBreakpoint.xl) {
    rules.push("@media (min-width: ".concat(_breakpoints.bpXLarge, ") {").concat(getStackeeOptions(optionsByBreakpoint.xl), "}"));
  }

  return rules.join('\n');
};

exports.getStackeeRules = getStackeeRules;