'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 _H = require('../H');

var _H2 = _interopRequireDefault(_H);

var _TableControlsContainer = require('./styles/TableControlsContainer');

var _TableControlsContainer2 = _interopRequireDefault(_TableControlsContainer);

var _TableControlsRow = require('./styles/TableControlsRow');

var _TableControlsRow2 = _interopRequireDefault(_TableControlsRow);

var _TableControlsIcons = require('./styles/TableControlsIcons');

var _TableControlsIcons2 = _interopRequireDefault(_TableControlsIcons);

var _Anchor = require('../Anchor');

var _Anchor2 = _interopRequireDefault(_Anchor);

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

var TableControls = function (_React$Component) {
  (0, _inherits3.default)(TableControls, _React$Component);

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

  (0, _createClass3.default)(TableControls, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          title = _props.title,
          enableDelete = _props.enableDelete,
          enableAdd = _props.enableAdd,
          enableSearch = _props.enableSearch,
          children = _props.children,
          onDelete = _props.onDelete,
          onAdd = _props.onAdd,
          id = _props.id,
          className = _props.className,
          onSearch = _props.onSearch,
          Container = _props.Container,
          ControlsRow = _props.ControlsRow,
          ControlsIcons = _props.ControlsIcons,
          Anchor = _props.Anchor;


      if (!title && !enableAdd && !enableDelete && !enableSearch && !children) {
        return null;
      }

      return _react2.default.createElement(
        Container,
        null,
        _react2.default.createElement(
          ControlsRow,
          { id: id, className: className },
          _react2.default.createElement(
            _H2.default,
            null,
            title
          ),
          _react2.default.createElement(
            ControlsIcons,
            null,
            enableAdd ? _react2.default.createElement(Anchor, { onClick: onAdd, icon: 'plusMath' }) : null,
            enableSearch ? _react2.default.createElement(Anchor, { onClick: onSearch, icon: 'search' }) : null,
            enableDelete ? _react2.default.createElement(Anchor, { onClick: onDelete, icon: 'delete3' }) : null
          )
        ),
        children
      );
    }
  }]);
  return TableControls;
}(_react2.default.Component);

TableControls.propTypes = {
  /**
   * Show a delete button.
   */
  enableDelete: _propTypes2.default.bool,
  /**
   * Show an add button.
   */
  enableAdd: _propTypes2.default.bool,
  /**
   * Show a search button.
   */
  enableSearch: _propTypes2.default.bool,
  /**
   * A title to give for the table (optional).
   */
  title: _propTypes2.default.string,
  /**
   * Any other things you'd like to render below the title and the main controls.
   */
  children: _propTypes2.default.node,
  /**
   * Called when the user clicks the delete button.
   */
  onDelete: _propTypes2.default.func,
  /**
   * Called when the user clicks the add button.
   */
  onAdd: _propTypes2.default.func,
  /**
   * Called when the user clicks the search button.
   */
  onSearch: _propTypes2.default.func,
  /**
   * Adds a class name to the container element.
   */
  className: _propTypes2.default.string,
  /**
   * Adds an id to the container element.
   */
  id: _propTypes2.default.string,
  /**
   * A component to render the containing element
   */
  Container: _propTypes2.default.func,
  /**
   * A component to render the controls row, including header and icons
   */
  ControlsRow: _propTypes2.default.func,
  /**
   * A component to render the container for icons. Mainly controls font size.
   */
  ControlsIcons: _propTypes2.default.func,
  /**
   * A component to render an Anchor, defaults to library Anchor
   */
  Anchor: _propTypes2.default.func
};
TableControls.defaultProps = {
  enableDelete: false,
  enableAdd: false,
  enableSearch: false,
  title: null,
  children: null,
  onDelete: function onDelete() {
    return null;
  },
  onAdd: function onAdd() {
    return null;
  },
  onSearch: function onSearch() {
    return null;
  },
  className: null,
  id: null,
  Container: _TableControlsContainer2.default,
  ControlsRow: _TableControlsRow2.default,
  ControlsIcons: _TableControlsIcons2.default,
  Anchor: _Anchor2.default
};
exports.default = TableControls;