'use strict';

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

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _recordComponent = require('./record-component');

var _recordComponent2 = _interopRequireDefault(_recordComponent);

var _displayTest = require('./display-test');

var _displayTest2 = _interopRequireDefault(_displayTest);

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

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

    var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(TestRecorder).call(this));

    _this.state = {
      hovered: false
    };
    _this.hideTest = _this.hideTest.bind(_this);
    return _this;
  }

  _createClass(TestRecorder, [{
    key: 'onClick',
    value: function onClick(recordingStatus) {
      var _this2 = this;

      var click = recordingStatus ? this.props.stopRecord : this.props.startRecord;
      if (!recordingStatus) {
        this.interval = setInterval(function () {
          _this2.setState({
            hovered: !_this2.state.hovered
          });
        }, 500);
      } else {
        clearInterval(this.interval);
      }
      click();
      this.forceUpdate();
    }
  }, {
    key: 'hideTest',
    value: function hideTest() {
      this.props.hideTest();
      this.forceUpdate();
    }
  }, {
    key: 'onKeyPress',
    value: function onKeyPress(e) {
      if (this.props.shouldShowTest && e.keyCode === 27) {
        this.hideTest();
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var _this3 = this;

      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(_recordComponent2.default, {
          onClick: function onClick(recordingStatus) {
            return _this3.onClick(recordingStatus);
          },
          hovered: this.state.hovered,
          onMouseOver: function onMouseOver() {
            return _this3.setState({ hovered: true });
          },
          onMouseOut: function onMouseOut() {
            return _this3.setState({ hovered: false });
          },
          getRecordingStatus: this.props.getRecordingStatus
        }),
        _react2.default.createElement(_displayTest2.default, {
          getTest: this.props.getTest,
          shouldShowTest: this.props.shouldShowTest,
          onKeyPress: function onKeyPress(e) {
            return _this3.onKeyPress(e);
          },
          hideTest: this.hideTest
        })
      );
    }
  }]);

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

exports.default = TestRecorder;