import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
var _excluded = ["prefixCls", "className", "selected", "onSelectChange", "cornerPlacement"];
import React, { useContext, useEffect, useRef, useState } from 'react';
import classNames from 'classnames';
import noop from 'lodash/noop';
import ConfigContext from '../config-provider/ConfigContext';

var Grid = function Grid(props) {
  var _useState = useState('xl'),
      _useState2 = _slicedToArray(_useState, 2),
      size = _useState2[0],
      setSize = _useState2[1];

  var gridRef = useRef(null);
  useEffect(function () {
    if (gridRef && gridRef.current && gridRef.current.offsetHeight <= 50) {
      setSize('xs');
    }
  }, []);

  var customizePrefixCls = props.prefixCls,
      className = props.className,
      selected = props.selected,
      _props$onSelectChange = props.onSelectChange,
      onSelectChange = _props$onSelectChange === void 0 ? noop : _props$onSelectChange,
      cornerPlacement = props.cornerPlacement,
      others = _objectWithoutProperties(props, _excluded);

  var _useContext = useContext(ConfigContext),
      getPrefixCls = _useContext.getPrefixCls;

  var prefixCls = getPrefixCls('card', customizePrefixCls);
  var selectedPrefixCls = "".concat(prefixCls, "-grid-selected");
  var classString = classNames("".concat(prefixCls, "-grid"), className, _defineProperty({}, "".concat(selectedPrefixCls, " ").concat(selectedPrefixCls, "-").concat(cornerPlacement, " ").concat(selectedPrefixCls, "-").concat(size), selected));
  return /*#__PURE__*/React.createElement("div", _extends({}, others, {
    className: classString,
    ref: gridRef,
    onClick: function onClick() {
      return onSelectChange(!selected);
    }
  }));
};

Grid.displayName = 'CardGrid';
Grid.defaultProps = {
  cornerPlacement: 'bottomRight'
};
export default Grid;
//# sourceMappingURL=Grid.js.map
