'use strict';

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

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 _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

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 FakeCodeTypingLine = function (_Component) {
  _inherits(FakeCodeTypingLine, _Component);

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

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

    _this.state = {
      opacity: false,
      border: true
    };
    return _this;
  }

  _createClass(FakeCodeTypingLine, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      var _this2 = this;

      var _props = this.props,
          duration = _props.duration,
          delay = _props.delay;

      this.opacityTimeout = setTimeout(function () {
        return _this2.setState({ opacity: 1 });
      }, delay * 1000);
      this.borderTimeout = setTimeout(function () {
        _this2.setState({ border: 0 });
      }, (duration + delay) * 1000);
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      clearTimeout(this.opacityTimeout);
      clearTimeout(this.borderTimeout);
    }
  }, {
    key: 'render',
    value: function render() {
      var _props2 = this.props,
          duration = _props2.duration,
          count = _props2.count,
          delay = _props2.delay,
          keepBorder = _props2.keepBorder,
          children = _props2.children;
      var opacity = this.state.opacity;


      var borderRight = this.state.border;
      borderRight = keepBorder ? true : borderRight;

      var animations = {
        opacity: opacity,
        borderRight: borderRight,
        WebkitAnimation: 'typing ' + duration + 's steps(' + count + ', end) forwards, blink 1s step-end 1s infinite',
        MozAnimation: 'typing ' + duration + 's steps(' + count + ', end) forwards, blink 1s step-end 1s infinite',
        animationDelay: delay + 's'
      };
      return _react2.default.createElement(
        'div',
        { className: 'fake-code-typing-line' },
        _react2.default.createElement('div', { style: animations, dangerouslySetInnerHTML: { __html: children } })
      );
    }
  }]);

  return FakeCodeTypingLine;
}(_react.Component);

FakeCodeTypingLine.propTypes = {
  duration: _propTypes2.default.number.isRequired,
  count: _propTypes2.default.number.isRequired,
  delay: _propTypes2.default.number.isRequired,
  keepBorder: _propTypes2.default.bool.isRequired,
  children: _propTypes2.default.oneOfType([_propTypes2.default.arrayOf(_propTypes2.default.node), _propTypes2.default.node]).isRequired
};

exports.default = FakeCodeTypingLine;