'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

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 }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

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) {
  _inherits(Grid, _React$PureComponent);

  function Grid() {
    _classCallCheck(this, Grid);

    return _possibleConstructorReturn(this, (Grid.__proto__ || Object.getPrototypeOf(Grid)).apply(this, arguments));
  }

  _createClass(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;