'use strict';

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

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 _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _bowser = require('bowser');

var _bowser2 = _interopRequireDefault(_bowser);

var _sideGrid = require('kitten/components/grid/side-grid');

var _grid = require('kitten/components/grid/grid');

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

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 SideLayout = exports.SideLayout = function (_React$Component) {
  _inherits(SideLayout, _React$Component);

  function SideLayout(props) {
    _classCallCheck(this, SideLayout);

    var _this = _possibleConstructorReturn(this, (SideLayout.__proto__ || Object.getPrototypeOf(SideLayout)).call(this, props));

    _this.state = { needsFullHeight: false };
    return _this;
  }

  _createClass(SideLayout, [{
    key: 'needsFullHeight',
    value: function needsFullHeight() {
      return !!_bowser2.default.safari;
    }
  }, {
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.setState({
        needsFullHeight: this.needsFullHeight()
      });
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          className = _props.className,
          sideGridProps = _objectWithoutProperties(_props, ['className']);

      var hasFluidLayout = (className || '').search('k-VerticalGrid__fluid') != -1;
      var hasFullHeightLayout = hasFluidLayout && this.state.needsFullHeight;
      var sideLayoutClassName = (0, _classnames2.default)(className, {
        'k-VerticalGrid__fullHeight': hasFullHeightLayout
      });

      return _react2.default.createElement(
        _sideGrid.SideGrid,
        {
          className: sideLayoutClassName,
          containerClassName: 'k-VerticalGrid__container',
          rowClassName: 'k-VerticalGrid__element'
        },
        _react2.default.createElement(
          _sideGrid.SideGridContent,
          null,
          _react2.default.createElement(
            _grid.Grid,
            null,
            _react2.default.createElement(
              _grid.GridCol,
              { 'col-s': '12' },
              this.props.children
            )
          )
        ),
        _react2.default.createElement(
          _sideGrid.SideGridAside,
          { className: 'k-VerticalGrid__element' },
          this.props.sidebar
        )
      );
    }
  }]);

  return SideLayout;
}(_react2.default.Component);

SideLayout.defaultProps = {
  children: 'Children',
  // sidebar: renderOfWhatYouWant() // Content for aside grid
  // E.g: see assets/javascripts/kitten/karl/layout/side-layout.js
  sidebar: null
};