'use strict';

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

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _FlowItemContainer = require('./FlowItemContainer');

var _FlowItemContainer2 = _interopRequireDefault(_FlowItemContainer);

var _constants = require('../constants');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var BaseStyles = _styledComponents2.default.div.withConfig({
  displayName: 'FlowRowStyles__BaseStyles'
})(['display:flex;flex-direction:row;']);

var grow = function grow(alignment) {
  return ['left', 'right', 'center'].includes(alignment) ? 0 : 1;
};
var basis = function basis(alignment) {
  return ['left', 'right', 'center'].includes(alignment) ? 'auto' : 0;
};

var justification = function justification(alignment) {
  switch (alignment) {
    case 'left':
      return 'flex-start';
    case 'right':
      return 'flex-end';
    case 'center':
      return 'center';
    default:
      return 'space-between';
  }
};

var generateSizes = function generateSizes(sizes) {
  return sizes.map(function (size, idx) {
    return size !== undefined && size !== null ? (0, _styledComponents.css)(['& > ', ',& > ', '{&:nth-child(', '){flex-grow:', ';}}'], _FlowItemContainer2.default, BaseStyles, idx + 1, size) : '';
  });
};

// immediately extend via wrap so that we can do nested Flows

exports.default = (0, _styledComponents2.default)(BaseStyles).withConfig({
  displayName: 'FlowRowStyles'
})(['justify-content:', ';& > ', ',& > ', '{flex-grow:', ';flex-shrink:0;margin-left:', 'px;margin-right:', 'px;flex-basis:', ';&:first-child{margin-left:0;}&:last-child{margin-right:0;}}', ' & .FlowItem-label{', ';}'], function (_ref) {
  var alignment = _ref.alignment;
  return justification(alignment);
}, _FlowItemContainer2.default, BaseStyles, function (_ref2) {
  var alignment = _ref2.alignment;
  return grow(alignment);
}, _constants.HORIZONTAL_SPACING / 2, _constants.HORIZONTAL_SPACING / 2, function (_ref3) {
  var alignment = _ref3.alignment;
  return basis(alignment);
}, function (_ref4) {
  var sizes = _ref4.sizes;
  return generateSizes(sizes);
}, function (_ref5) {
  var suppressLabels = _ref5.suppressLabels;
  return suppressLabels && 'display: none;';
});