import _defineProperty from "@babel/runtime/helpers/defineProperty";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

import * as React from 'react';
import { createBEM } from '@zarm-design/bem';
import { ConfigContext } from '../config-provider';
import GridContext from './GridContext';

var GridItem = function GridItem(props) {
  var className = props.className,
      style = props.style,
      onClick = props.onClick,
      children = props.children;

  var _React$useContext = React.useContext(GridContext),
      columns = _React$useContext.columns,
      gutter = _React$useContext.gutter,
      bordered = _React$useContext.bordered,
      square = _React$useContext.square;

  var _React$useContext2 = React.useContext(ConfigContext),
      prefixCls = _React$useContext2.prefixCls;

  var bem = createBEM('grid-item', {
    prefixCls: prefixCls
  });
  var percent = "".concat(100 / +columns, "%");
  var mergedStyle = {
    flexBasis: percent,
    paddingTop: square ? percent : undefined
  };
  var horizontalGutter;
  var verticalGutter;

  if (!square && gutter && gutter[0] > 0) {
    horizontalGutter = gutter[0] / 2;
    mergedStyle.paddingTop = horizontalGutter;
    mergedStyle.paddingBottom = horizontalGutter;
  }

  if (!square && gutter && gutter[1] > 0) {
    verticalGutter = gutter[1] / 2;
    mergedStyle.paddingLeft = verticalGutter;
    mergedStyle.paddingRight = verticalGutter;
  }

  var cls = bem([{
    clickable: !!onClick,
    'horizontal-bordered': bordered && horizontalGutter > 0,
    'vertical-bordered': bordered && verticalGutter > 0
  }, className]);
  return /*#__PURE__*/React.createElement("div", {
    className: cls,
    style: _objectSpread(_objectSpread({}, mergedStyle), style),
    onClick: onClick
  }, /*#__PURE__*/React.createElement("div", {
    className: bem('content')
  }, children));
};

export default GridItem;