'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _reactAddonsPureRenderMixin2 = _interopRequireDefault(_reactAddonsPureRenderMixin);

var _reactJupyterDisplayArea = require('react-jupyter-display-area');

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _inputs = require('./inputs');

var _inputs2 = _interopRequireDefault(_inputs);

var _editor = require('./editor');

var _editor2 = _interopRequireDefault(_editor);

var _latex = require('../latex');

var _latex2 = _interopRequireDefault(_latex);

var _pager = require('./pager');

var _pager2 = _interopRequireDefault(_pager);

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

class CodeCell extends _react2.default.Component {

  constructor(props) {
    super(props);
    this.shouldComponentUpdate = _reactAddonsPureRenderMixin2.default.shouldComponentUpdate.bind(this);
  }

  isOutputHidden() {
    return this.props.cellStatus.get('outputHidden');
  }

  isInputHidden() {
    return this.props.cellStatus.get('inputHidden');
  }

  render() {
    return _react2.default.createElement(
      'div',
      null,
      !this.isInputHidden() ? _react2.default.createElement(
        'div',
        { className: 'input-container' },
        _react2.default.createElement(_inputs2.default, {
          executionCount: this.props.cell.get('execution_count'),
          running: this.props.running
        }),
        _react2.default.createElement(_editor2.default, {
          id: this.props.id,
          input: this.props.cell.get('source'),
          language: this.props.language,
          focused: this.props.focused,
          getCompletions: this.props.getCompletions,
          theme: this.props.theme,
          focusAbove: this.props.focusAbove,
          focusBelow: this.props.focusBelow
        })
      ) : null,
      this.props.pagers && !this.props.pagers.isEmpty() ? _react2.default.createElement(
        'div',
        { className: 'pagers' },
        this.props.pagers.map((pager, key) => _react2.default.createElement(_pager2.default, {
          className: 'pager',
          displayOrder: this.props.displayOrder,
          transforms: this.props.transforms,
          pager: pager,
          key: key
        }))
      ) : null,
      _react2.default.createElement(
        _latex2.default,
        null,
        _react2.default.createElement(
          'div',
          { className: 'outputs' },
          _react2.default.createElement(_reactJupyterDisplayArea.TogglableDisplay, {
            className: 'outputs-display',
            outputs: this.props.cell.get('outputs'),
            isHidden: this.isOutputHidden(),
            displayOrder: this.props.displayOrder,
            transforms: this.props.transforms
          })
        )
      )
    );
  }
}

CodeCell.propTypes = {
  cell: _react2.default.PropTypes.instanceOf(_immutable2.default.Map).isRequired,
  displayOrder: _react2.default.PropTypes.instanceOf(_immutable2.default.List).isRequired,
  cellStatus: _react2.default.PropTypes.instanceOf(_immutable2.default.Map).isRequired,
  getCompletions: _react2.default.PropTypes.func,
  id: _react2.default.PropTypes.string,
  language: _react2.default.PropTypes.string,
  theme: _react2.default.PropTypes.string,
  transforms: _react2.default.PropTypes.instanceOf(_immutable2.default.Map),
  focused: _react2.default.PropTypes.bool,
  pagers: _react2.default.PropTypes.instanceOf(_immutable2.default.List),
  running: _react2.default.PropTypes.bool,
  focusAbove: _react2.default.PropTypes.func,
  focusBelow: _react2.default.PropTypes.func
};
CodeCell.defaultProps = {
  pagers: new _immutable2.default.List(),
  running: false
};
exports.default = CodeCell;