'use strict';

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

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

var parseFlexChar = function parseFlexChar(char) {
  if (char === '0') {
    return 'flex: 0 0 auto !important;';
  }

  return 'flex: ' + char + ' 0 0 !important;';
};

exports.default = function (flex) {
  var itemIdx = 0;
  return flex.split('').reduce(function (lines, char, idx) {
    if (char === ' ') {
      return lines;
    }

    if (flex[idx - 1] === ' ' && flex[idx + 1] === ' ') {
      lines.push('& > *:nth-child(' + (itemIdx + 1) + ') {\n        margin-left: auto !important;\n        margin-right: auto !important;\n        ' + parseFlexChar(char) + '\n      }');
    } else if (flex[idx - 1] === ' ') {
      lines.push('& > *:nth-child(' + (itemIdx + 1) + ') {\n        margin-left: auto !important;\n        margin-right: 15px !important;\n        ' + parseFlexChar(char) + '\n      }');
    } else if (flex[idx + 1] === ' ') {
      lines.push('& > *:nth-child(' + (itemIdx + 1) + ') {\n        margin-right: auto !important;\n        margin-left: 15px !important;\n        ' + parseFlexChar(char) + '\n      }');
    } else {
      lines.push('& > *:nth-child(' + (itemIdx + 1) + ') {\n        margin-right: 15px !important;\n        margin-left: 15px !important;\n        ' + parseFlexChar(char) + '\n      }');
    }

    if (idx === 0) {
      lines.push('& > *:nth-child(' + (itemIdx + 1) + ') { margin-left: 0 !important; }');
    }

    if (idx === flex.length - 1) {
      lines.push('& > *:nth-child(' + (itemIdx + 1) + ') { margin-right: 0 !important; }');
    }

    itemIdx = itemIdx + 1;
    return lines;
  }, []).join('\n');
};