"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _one = require("remax/one");

var _common = require("./../common");

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var prefixCls = (0, _common.getPrefixCls)('space');

var renderItems = function renderItems(children, size, direction) {
  var itemStyle = undefined;

  if (typeof size === 'number') {
    itemStyle = direction === 'vertical' ? {
      marginBottom: size
    } : {
      marginRight: size
    };
  }

  var items = [];

  _react.default.Children.forEach(children, function (child, index) {
    var itemCn = (0, _classnames.default)("".concat(prefixCls, "-item"), _defineProperty({}, "".concat(prefixCls, "-").concat(direction, "-").concat(size), typeof size === 'string' && size));

    if (child === undefined || child === null) {
      return;
    }

    items.push( /*#__PURE__*/_react.default.createElement(_one.View, {
      key: index,
      className: itemCn,
      style: itemStyle
    }, child));
  });

  return items;
};

var Space = function Space(props) {
  var _classNames2;

  var _props$size = props.size,
      size = _props$size === void 0 ? 'small' : _props$size,
      _props$direction = props.direction,
      direction = _props$direction === void 0 ? 'horizontal' : _props$direction,
      _props$align = props.align,
      align = _props$align === void 0 ? direction === 'horizontal' ? 'center' : undefined : _props$align,
      justify = props.justify,
      style = props.style,
      className = props.className,
      children = props.children;
  var cn = (0, _classnames.default)(prefixCls, "".concat(prefixCls, "-").concat(direction), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-align-").concat(align), align), _defineProperty(_classNames2, "".concat(prefixCls, "-justify-").concat(justify), justify), _classNames2), className);
  return /*#__PURE__*/_react.default.createElement(_one.View, {
    className: cn,
    style: style
  }, renderItems(children, size, direction));
};

var _default = Space;
exports.default = _default;