'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _themeGet = require('../../extensions/themeGet');

var _themeGet2 = _interopRequireDefault(_themeGet);

var _recompose = require('recompose');

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

var GridDiv = _styledComponents2.default.div.withConfig({
  displayName: 'Grid__GridDiv'
})(['display:grid;grid-auto-rows:min-content;grid-gap:', ';grid-template-columns:', ';& > *{grid-column:1 span;}'], function (_ref) {
  var gridGap = _ref.gridGap;
  return gridGap;
}, function (_ref2) {
  var columns = _ref2.columns,
      minSize = _ref2.minSize,
      maxSize = _ref2.maxSize;
  return 'repeat(' + columns + ', minmax(' + minSize + ', ' + maxSize + '))';
});

var Grid = function (_React$PureComponent) {
  (0, _inherits3.default)(Grid, _React$PureComponent);

  function Grid() {
    (0, _classCallCheck3.default)(this, Grid);
    return (0, _possibleConstructorReturn3.default)(this, (Grid.__proto__ || (0, _getPrototypeOf2.default)(Grid)).apply(this, arguments));
  }

  (0, _createClass3.default)(Grid, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          columns = _props.columns,
          minSize = _props.minSize,
          maxSize = _props.maxSize,
          gridGap = _props.gridGap,
          children = _props.children;

      return _react2.default.createElement(
        GridDiv,
        {
          columns: columns,
          minSize: minSize,
          maxSize: maxSize,
          gridGap: gridGap
        },
        children
      );
    }
  }]);
  return Grid;
}(_react2.default.PureComponent);

Grid.propTypes = {
  /**
   * The number of columns to use in the grid. Alternatively, provide "auto-fill"
   * or "auto-fit" to fit rows. See CSS grid for more details.
   */
  columns: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]),
  /**
   * Minimum column size.
   */
  minSize: _propTypes2.default.string,
  /**
   * Maximum column size. Usually does not need to be set.
   */
  maxSize: _propTypes2.default.string,
  /**
   * Gap size between grid items both horizontally and vertically.
   */
  gridGap: _propTypes2.default.string
};
Grid.defaultProps = {
  minSize: 'min-content',
  maxSize: '1fr',
  gridGap: (0, _themeGet2.default)('spacing.medium'),
  columns: 'auto-fit'
};


Grid.Small = (0, _recompose.defaultProps)({
  gridGap: (0, _themeGet2.default)('spacing.extraSmall'),
  minSize: '30px'
})(Grid);

exports.default = Grid;