"use strict";

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

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

var JUSTIFY_CONTENT_MAP = {
  start: 'flex-start',
  end: 'flex-end',
  center: 'center',
  'space-between': 'space-between',
  'space-around': 'space-around',
  'space-evenly': 'space-evenly'
};
var DEFAULT_ALIGN = 'stretch';
var DEFAULT_JUSTIFY = 'flex-start';
var ALIGN_CONTENT_MAP = {
  start: 'flex-start',
  end: 'flex-end',
  center: 'center',
  stretch: 'stretch'
};

var getStackedOptions = function getStackedOptions(_ref) {
  var stacked = _ref.stacked,
      justify = _ref.justify,
      align = _ref.align,
      wrap = _ref.wrap;

  if (!stacked) {
    return '';
  }

  var rules = ['display: flex;', "flex-direction: ".concat(stacked === 'column' ? 'column' : 'row', ";"), "justify-content: ".concat(justify ? JUSTIFY_CONTENT_MAP[justify] : DEFAULT_JUSTIFY, ";"), "align-items: ".concat(align ? ALIGN_CONTENT_MAP[align] : DEFAULT_ALIGN, ";")];

  if (wrap) {
    rules.push('flex-wrap: wrap');
  }

  return rules.join(' ');
};

var getStackedRules = function getStackedRules(stackedProps) {
  var rules = [];
  var globalOptions = {
    stacked: typeof stackedProps.stacked === 'string' ? stackedProps.stacked : undefined,
    align: typeof stackedProps.align === 'string' ? stackedProps.align : undefined,
    justify: typeof stackedProps.justify === 'string' ? stackedProps.justify : undefined,
    wrap: Array.isArray(stackedProps.wrap) ? undefined : stackedProps.wrap
  };
  rules.push(getStackedOptions(globalOptions));

  var optionsByBreakpoint = _breakpoints.breakPoints.reduce(function (acc, bp) {
    var _stackedProps$stacked, _stackedProps$align, _stackedProps$justify;

    acc[bp] = {
      stacked: stackedProps.stacked instanceof Object ? (_stackedProps$stacked = stackedProps.stacked) === null || _stackedProps$stacked === void 0 ? void 0 : _stackedProps$stacked[bp] : undefined,
      align: stackedProps.align instanceof Object ? (_stackedProps$align = stackedProps.align) === null || _stackedProps$align === void 0 ? void 0 : _stackedProps$align[bp] : undefined,
      justify: stackedProps.justify instanceof Object ? (_stackedProps$justify = stackedProps.justify) === null || _stackedProps$justify === void 0 ? void 0 : _stackedProps$justify[bp] : undefined,
      wrap: Array.isArray(stackedProps.wrap) ? stackedProps.wrap.includes(bp) : undefined
    };
    return acc;
  }, {});

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

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

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

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

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

exports.getStackedRules = getStackedRules;