'use strict';

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

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 _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

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

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

    _this.handleResize = _this.handleResize.bind(_this);
    return _this;
  }

  // Component lifecycle.

  _createClass(TourPopover, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.props.onPopoverPosition(this.refs.popover);
      window.addEventListener('resize', this.handleResize);
    }
  }, {
    key: 'componentDidUpdate',
    value: function componentDidUpdate(prevProps) {
      if (this.shouldUpdatePosition(prevProps)) {
        this.props.onPopoverPosition(this.refs.popover);
      }
    }
  }, {
    key: 'componentWillUnmount',
    value: function componentWillUnmount() {
      window.removeEventListener('resize', this.handleResize);
    }

    // Component listener callbacks.

  }, {
    key: 'handleResize',
    value: function handleResize() {
      this.props.onPopoverPosition(this.refs.popover);
    }

    // Component methods.

  }, {
    key: 'shouldUpdatePosition',
    value: function shouldUpdatePosition(prevProps) {
      return prevProps.name != this.props.name;
    }

    // Component rendering.

  }, {
    key: 'renderNextButton',
    value: function renderNextButton() {
      var isDisabled = !this.props.buttons.next.active;
      var buttonClassName = (0, _classnames2.default)('k-Tour__popover__button', 'k-Tour__popover__button--right', 'k-Button', 'k-Button--tiny', 'k-Button--icon', 'k-Button--iconRight', {
        'k-Button--helium': !isDisabled,
        'k-Button--hydrogen': isDisabled
      });

      return _react2.default.createElement(
        'button',
        {
          onClick: isDisabled ? null : this.props.onNextClick,
          title: this.props.buttons.next.title,
          className: buttonClassName,
          disabled: isDisabled
        },
        this.props.buttons.next.label,
        _react2.default.createElement(
          'svg',
          {
            className: 'k-Button__icon',
            xmlns: 'http://www.w3.org/2000/svg',
            viewBox: '0 0 6 6'
          },
          _react2.default.createElement('path', { d: 'M6 0H0v6h2V2h4z' })
        )
      );
    }
  }, {
    key: 'renderPrevButton',
    value: function renderPrevButton() {
      var isDisabled = !this.props.buttons.prev.active;
      var buttonClassName = (0, _classnames2.default)('k-Tour__popover__button', 'k-Button', 'k-Button--tiny', 'k-Button--icon', {
        'k-Button--helium': !isDisabled,
        'k-Button--hydrogen': isDisabled
      });

      return _react2.default.createElement(
        'button',
        {
          onClick: isDisabled ? null : this.props.onPrevClick,
          title: this.props.buttons.prev.title,
          className: buttonClassName,
          disabled: isDisabled
        },
        _react2.default.createElement(
          'svg',
          {
            className: 'k-Button__icon--tiny',
            xmlns: 'http://www.w3.org/2000/svg',
            viewBox: '0 0 6 6',
            fill: '#fff'
          },
          _react2.default.createElement('path', { d: 'M6 0H0v6h2V2h4z' })
        ),
        this.props.buttons.prev.label
      );
    }
  }, {
    key: 'renderCloseButton',
    value: function renderCloseButton() {
      return _react2.default.createElement(
        'button',
        {
          title: this.props.buttons.close.label,
          'aria-label': this.props.buttons.close.label,
          onClick: this.props.onCloseClick,
          className: 'k-ButtonIcon k-ButtonIcon--hydrogen k-ButtonIcon--tiny'
        },
        _react2.default.createElement(
          'svg',
          {
            className: 'k-ButtonIcon__svg k-ButtonIcon__svgRotate',
            xmlns: 'http://www.w3.org/2000/svg',
            viewBox: '-11 -4 125 105'
          },
          _react2.default.createElement('path', { d: 'M91.968 21.407l-70.56 70.56-13.44-13.44 70.56-70.56z' }),
          _react2.default.createElement('path', { d: 'M91.968 78.527l-13.44 13.44-70.56-70.56 13.44-13.44z' })
        )
      );
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        {
          ref: 'popover',
          className: 'k-Popover k-Tour__popover',
          role: 'dialog',
          'aria-hidden': 'true',
          'aria-labelledby': 'dialogtitle',
          style: this.props.style
        },
        _react2.default.createElement(
          'div',
          { className: 'k-Popover__container k-Tour__popover__container' },
          _react2.default.createElement(
            'div',
            { className: 'k-Tour__popover__illustration' },
            this.props.illustration
          ),
          _react2.default.createElement(
            'div',
            { className: 'k-Tour__popover__content' },
            _react2.default.createElement(
              'p',
              { id: 'dialogtitle', className: 'k-Tour__popover__title' },
              this.props.title
            ),
            _react2.default.createElement(
              'p',
              { className: 'k-Tour__popover__text' },
              this.props.content
            ),
            _react2.default.createElement(
              'div',
              { className: 'k-Tour__popover__navigation' },
              _react2.default.createElement(
                'p',
                { className: 'k-Tour__popover__numbering' },
                this.props.progress
              ),
              _react2.default.createElement(
                'div',
                { className: 'k-Tour__popover__buttons' },
                this.renderPrevButton(),
                this.renderNextButton()
              )
            )
          ),
          _react2.default.createElement(
            'div',
            { className: 'k-Popover__close' },
            this.renderCloseButton()
          )
        )
      );
    }
  }]);

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

// DEPRECATED: do not use default export.


exports.default = TourPopover;