"use strict";

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

function _jsxRuntime() {
  const data = require("react/jsx-runtime");

  _jsxRuntime = function () {
    return data;
  };

  return data;
}

function _react() {
  const data = _interopRequireDefault(require("react"));

  _react = function () {
    return data;
  };

  return data;
}

function _clsx() {
  const data = _interopRequireDefault(require("clsx"));

  _clsx = function () {
    return data;
  };

  return data;
}

var _ConfigProviderContext = _interopRequireDefault(require("../config-provider/ConfigProviderContext"));

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

const formatGap = gap => typeof gap === 'number' ? `${gap}px` : gap;

const Space = props => {
  const {
    wrap,
    block,
    direction,
    align,
    justify
  } = props;

  const {
    prefixCls,
    createNamespace
  } = _react().default.useContext(_ConfigProviderContext.default);

  const [bem] = createNamespace('space', prefixCls);

  const style = _react().default.useMemo(() => {
    if (props.gap) {
      if (Array.isArray(props.gap)) {
        const [gapH, gapV] = props.gap;
        return Object.assign(Object.assign({}, props.style), {
          '--gap-vertical': formatGap(gapV),
          '--gap-horizontal': formatGap(gapH)
        });
      }

      return Object.assign(Object.assign({}, props.style), {
        '--gap': formatGap(props.gap)
      });
    }

    return props.style;
  }, [props.style, props.gap]);

  return (0, _jsxRuntime().jsx)("div", Object.assign({
    className: (0, _clsx().default)(props.className, bem({
      wrap,
      block,
      [`${direction}`]: !!direction,
      [`align-${align}`]: !!align,
      [`justify-${justify}`]: !!justify
    })),
    style: style,
    onClick: props.onClick
  }, {
    children: _react().default.Children.map(props.children, child => {
      return child !== null && child !== undefined && (0, _jsxRuntime().jsx)("div", Object.assign({
        className: (0, _clsx().default)(bem('item'))
      }, {
        children: child
      }));
    })
  }));
};

Space.defaultProps = {
  direction: 'horizontal'
};
var _default = Space;
exports.default = _default;