'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactAddonsPureRenderMixin = require('react-addons-pure-render-mixin');

var _reactAddonsPureRenderMixin2 = _interopRequireDefault(_reactAddonsPureRenderMixin);

var _reactRedux = require('react-redux');

var _actions = require('../../actions');

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

/* eslint class-methods-use-this: 0 */

class CellCreatorButtons extends _react2.default.Component {

  constructor() {
    super();
    this.shouldComponentUpdate = _reactAddonsPureRenderMixin2.default.shouldComponentUpdate.bind(this);
    this.createCodeCell = this.createCell.bind(this, 'code');
    this.createTextCell = this.createCell.bind(this, 'markdown');
    this.createCell = this.createCell.bind(this);
    this.mergeCell = this.mergeCell.bind(this);
  }

  shouldComponentUpdate() {
    return false;
  }

  createCell(type) {
    if (!this.props.id) {
      this.context.store.dispatch((0, _actions.createCellAppend)(type));
      return;
    }

    if (this.props.above) {
      this.context.store.dispatch((0, _actions.createCellBefore)(type, this.props.id));
    } else {
      this.context.store.dispatch((0, _actions.createCellAfter)(type, this.props.id));
    }
  }

  mergeCell() {
    this.context.store.dispatch((0, _actions.mergeCellAfter)(this.props.id));
  }

  render() {
    const mergeButton = _react2.default.createElement(
      'button',
      { onClick: this.mergeCell, title: 'merge cells' },
      _react2.default.createElement('span', { className: 'octicon octicon-arrow-up' })
    );
    return _react2.default.createElement(
      'div',
      { className: 'cell-creator' },
      _react2.default.createElement(
        'button',
        { onClick: this.createTextCell, title: 'create text cell', className: 'add-text-cell' },
        _react2.default.createElement('span', { className: 'octicon octicon-markdown' })
      ),
      _react2.default.createElement(
        'button',
        { onClick: this.createCodeCell, title: 'create code cell', className: 'add-code-cell' },
        _react2.default.createElement('span', { className: 'octicon octicon-code' })
      ),
      this.props.above ? null : mergeButton
    );
  }

}

exports.CellCreatorButtons = CellCreatorButtons;
CellCreatorButtons.propTypes = {
  above: _react2.default.PropTypes.bool,
  id: _react2.default.PropTypes.string
};
CellCreatorButtons.contextTypes = {
  store: _react2.default.PropTypes.object
};
exports.default = (0, _reactRedux.connect)()(CellCreatorButtons);