import * as _vue from "vue";

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; }

import { inject } from 'vue';
import PropTypes from '../_util/vue-types';
import { filterEmpty, initDefaultProps } from '../_util/props-util';
import { ConfigConsumerProps } from '../config-provider';
export var SpaceSizeType = PropTypes.oneOfType([PropTypes.number, PropTypes.oneOf(['small', 'middle', 'large'])]);
var spaceSize = {
  small: 8,
  middle: 16,
  large: 24
};
export var SpaceProps = {
  prefixCls: PropTypes.string,
  size: SpaceSizeType,
  direction: PropTypes.oneOf(['horizontal', 'vertical']),
  align: PropTypes.oneOf(['start', 'end', 'center', 'baseline'])
};

var Space = function Space(props, _ref) {
  var _someSpaceClass;

  var slots = _ref.slots;
  var configProvider = inject('configProvider', ConfigConsumerProps);
  var align = props.align,
      size = props.size,
      direction = props.direction,
      customizePrefixCls = props.prefixCls;
  var getPrefixCls = configProvider.getPrefixCls;
  var prefixCls = getPrefixCls('space', customizePrefixCls);
  var items = filterEmpty(slots.default && slots.default());
  var len = items.length;

  if (len === 0) {
    return null;
  }

  var mergedAlign = align === undefined && direction === 'horizontal' ? 'center' : align;
  var someSpaceClass = (_someSpaceClass = {}, _defineProperty(_someSpaceClass, prefixCls, true), _defineProperty(_someSpaceClass, "".concat(prefixCls, "-").concat(direction), true), _defineProperty(_someSpaceClass, "".concat(prefixCls, "-align-").concat(mergedAlign), mergedAlign), _someSpaceClass);
  var itemClassName = "".concat(prefixCls, "-item");
  var marginDirection = 'marginRight'; // directionConfig === 'rtl' ? 'marginLeft' : 'marginRight';

  return _vue.createVNode("div", {
    "class": someSpaceClass
  }, [items.map(function (child, i) {
    return _vue.createVNode("div", {
      "class": itemClassName,
      "key": "".concat(itemClassName, "-").concat(i),
      "style": i === len - 1 ? {} : _defineProperty({}, direction === 'vertical' ? 'marginBottom' : marginDirection, typeof size === 'string' ? "".concat(spaceSize[size], "px") : "".concat(size, "px"))
    }, [child]);
  })]);
};

Space.props = initDefaultProps(SpaceProps, {
  size: 'small',
  direction: 'horizontal'
});
/* istanbul ignore next */

Space.install = function (app) {
  app.component('ASpace', Space);
};

export default Space;