'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 _reactOnclickoutside = require('react-onclickoutside');

var _reactOnclickoutside2 = _interopRequireDefault(_reactOnclickoutside);

var _template = require('./template.js');

var _template2 = _interopRequireDefault(_template);

var _Icons = require('../Icons');

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

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

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

    _this.state = { displayed: false };
    _this.handleClick = _this.handleClick.bind(_this);
    _this.handleMouseEnter = _this.handleMouseEnter.bind(_this);
    _this.handleMouseLeave = _this.handleMouseLeave.bind(_this);
    return _this;
  }

  _createClass(TooltipContainer, [{
    key: 'handleClick',
    value: function handleClick() {
      this.setState({ displayed: !this.state.displayed });
    }
  }, {
    key: 'handleMouseEnter',
    value: function handleMouseEnter() {
      this.props.hover && this.setState({ displayed: true });
    }
  }, {
    key: 'handleMouseLeave',
    value: function handleMouseLeave() {
      this.props.hover && this.setState({ displayed: false });
    }
  }, {
    key: 'handleClickOutside',
    value: function handleClickOutside() {
      this.setState({ displayed: false });
    }
  }, {
    key: 'render',
    value: function render() {
      var icon = this.state.displayed ? _react2.default.createElement(_Icons.Icon, { name: 'close-in-circle' }) : _react2.default.createElement(_Icons.Icon, { name: 'question-in-circle' });

      return _react2.default.createElement(
        _template2.default,
        {
          icon: icon,
          width: this.props.width,
          left: this.props.left,
          label: this.props.label,
          displayed: this.state.displayed,
          handleClick: this.handleClick,
          handleMouseEnter: this.handleMouseEnter,
          handleMouseLeave: this.handleMouseLeave },
        this.props.children
      );
    }
  }]);

  return TooltipContainer;
}(_react2.default.PureComponent);

exports.default = (0, _reactOnclickoutside2.default)(TooltipContainer);