'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _airbnbPropTypes = require('airbnb-prop-types');

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

require('./style.css');

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

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

    var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));

    _this.handleMouseEnter = function () {
      _this.setState({ isActive: true });
      if (typeof _this.props.setActiveHover === 'function') {
        _this.props.setActiveHover(_this.props.id);
      }
    };

    _this.handleMouseLeave = function () {
      _this.setState({ isActive: false });
      if (typeof _this.props.clearActiveHover === 'function') {
        _this.props.clearActiveHover();
      }
    };

    _this.state = {
      isActive: false
    };
    if (process.env.NODE_ENV === 'development') {
      /* eslint-disable-next-line no-console */
      console.warn('This component is deprecated and will be archived in v10. Use the GenTeaser Organism instead.');
    }
    return _this;
  }

  Teaser.prototype.render = function render() {
    var _this2 = this;

    var primaryInfoClass = (0, _classnames2.default)({
      'ma__general-teaser__primaryinfo__details': this.props.left && !this.props.right,
      'ma__general-teaser__primaryinfo': !(this.props.left && !this.props.right)
    });
    var secondaryInfoClass = (0, _classnames2.default)({
      'ma__general-teaser__secondary': !this.props.left && this.props.right,
      'ma__general-teaser__secondary--border': !(!this.props.left && this.props.right)
    });
    var teaserClass = (0, _classnames2.default)({
      'ma__general-teaser': true,
      'ma__general-teaser--active': this.state.isActive
    });
    var sectionProps = {
      className: teaserClass,
      onMouseEnter: function onMouseEnter() {
        return _this2.handleMouseEnter();
      },
      onMouseLeave: function onMouseLeave() {
        return _this2.handleMouseLeave();
      }
    };
    return _react2.default.createElement(
      'section',
      sectionProps,
      _react2.default.createElement(
        'div',
        { className: 'ma__general-teaser__details' },
        this.props.title && _react2.default.createElement(
          'span',
          { className: 'ma__general-teaser__title' },
          this.props.title
        ),
        (this.props.right || this.props.left) && _react2.default.createElement(
          'div',
          { className: 'ma__general-teaser__moreinfo' },
          this.props.left && _react2.default.createElement(
            'div',
            { className: 'ma__general-teaser__primary' },
            this.props.left.map(function (info, infoKey) {
              return (
                /* eslint-disable-next-line react/no-array-index-key */
                _react2.default.createElement(
                  'div',
                  { key: infoKey, className: primaryInfoClass },
                  info
                )
              );
            })
          ),
          this.props.right && _react2.default.createElement(
            'div',
            { className: secondaryInfoClass },
            this.props.right.map(function (info, infoKey) {
              return _react2.default.createElement(
                'div',
                {
                  /* eslint-disable-next-line react/no-array-index-key */
                  key: infoKey,
                  className: 'ma__general-teaser__secondaryinfo'
                },
                info
              );
            })
          )
        )
      )
    );
  };

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

Teaser.propTypes = process.env.NODE_ENV !== "production" ? {
  /** A unique id for the teaser instance. */
  id: _propTypes2.default.number,
  /** A function that runs after the mouse is no longer hovering over the component. */
  clearActiveHover: _propTypes2.default.func,
  /** A function that runs when the mouse is hovering over the component. */
  setActiveHover: _propTypes2.default.func,
  /** A DecorativeLink used to display the title. */
  title: (0, _airbnbPropTypes.componentWithName)('DecorativeLink'),
  /** An array of components to be displayed under the title, on the left.
      Components that may be passed in the array: Link, ContactGroup. */
  left: _propTypes2.default.arrayOf(_propTypes2.default.oneOfType([(0, _airbnbPropTypes.componentWithName)('Link'), (0, _airbnbPropTypes.componentWithName)('ContactGroup')])),
  /** An array of components to be displayed under the title, on the right.
      If left is not set, this will display on the left side under the title instead.
      Components that may be passed in the array: DecorativeLink, OperationalHours, IconLink. */
  right: _propTypes2.default.arrayOf(_propTypes2.default.oneOfType([(0, _airbnbPropTypes.componentWithName)('DecorativeLink'), (0, _airbnbPropTypes.componentWithName)('OperationalHours'), (0, _airbnbPropTypes.componentWithName)('IconLink')]))
} : {};

exports.default = Teaser;
module.exports = exports['default'];