var _getThemedSpacing = function(space, theme) {
  if (theme.spacing.hasOwnProperty(space)) {
    return theme.spacing[space];
  }
  return space;
};
var _getValueUnitGap = function(gap) {
  var numericalPart = parseFloat(gap);
  var numericalValue = isNaN(numericalPart) ? 0 : numericalPart;
  var numericalString = isNaN(numericalPart) ? "" : numericalPart.toString();
  var unitPart = gap.substring(numericalString.toString().length);
  return {
    value: numericalValue,
    unit: unitPart || "px"
  };
};
var parseGap = function(gap, theme) {
  if (gap === void 0 || gap === "") {
    return {
      rowGap: {
        value: 0,
        unit: "px"
      },
      columnGap: {
        value: 0,
        unit: "px"
      }
    };
  }
  if (typeof gap === "number") {
    return {
      rowGap: {
        value: gap,
        unit: "px"
      },
      columnGap: {
        value: gap,
        unit: "px"
      }
    };
  }
  var splitGap = gap.split(" ");
  if (splitGap.length > 2) {
    return {
      rowGap: {
        value: 0,
        unit: "px"
      },
      columnGap: {
        value: 0,
        unit: "px"
      }
    };
  }
  if (splitGap.length === 2) {
    return {
      rowGap: _getValueUnitGap(_getThemedSpacing(splitGap[0], theme)),
      columnGap: _getValueUnitGap(_getThemedSpacing(splitGap[1], theme))
    };
  }
  var calculatedGap = _getValueUnitGap(_getThemedSpacing(gap, theme));
  return {
    rowGap: calculatedGap,
    columnGap: calculatedGap
  };
};
var parsePadding = function(padding, theme) {
  if (padding === void 0 || typeof padding === "number" || padding === "") {
    return padding;
  }
  var paddingValues = padding.split(" ");
  if (paddingValues.length < 2) {
    return _getThemedSpacing(padding, theme);
  }
  return paddingValues.reduce(function(padding1, padding2) {
    return _getThemedSpacing(padding1, theme) + " " + _getThemedSpacing(padding2, theme);
  });
};

export { parseGap, parsePadding };
