"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

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

var _vue = _interopRequireWildcard(require("vue"));

var _vueTypes = _interopRequireDefault(require("../_util/vue-types"));

var _propsUtil = require("../_util/props-util");

var _configProvider = require("../config-provider");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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 SpaceSizeType = _vueTypes.default.oneOfType([_vueTypes.default.number, _vueTypes.default.oneOf(['small', 'middle', 'large'])]);

exports.SpaceSizeType = SpaceSizeType;
var spaceSize = {
  small: 8,
  middle: 16,
  large: 24
};
var SpaceProps = {
  prefixCls: _vueTypes.default.string,
  size: SpaceSizeType,
  direction: _vueTypes.default.oneOf(['horizontal', 'vertical']),
  align: _vueTypes.default.oneOf(['start', 'end', 'center', 'baseline'])
};
exports.SpaceProps = SpaceProps;

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

  var slots = _ref.slots;
  var configProvider = (0, _vue.inject)('configProvider', _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 = (0, _propsUtil.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 = (0, _propsUtil.initDefaultProps)(SpaceProps, {
  size: 'small',
  direction: 'horizontal'
});
/* istanbul ignore next */

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

var _default = Space;
exports.default = _default;