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

import React from 'react';
import PropTypes from 'prop-types';
import { componentWithName } from 'airbnb-prop-types';
import classNames from 'classnames';
import './style.css';

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 = classNames({
      'ma__general-teaser__primaryinfo__details': this.props.left && !this.props.right,
      'ma__general-teaser__primaryinfo': !(this.props.left && !this.props.right)
    });
    var secondaryInfoClass = classNames({
      'ma__general-teaser__secondary': !this.props.left && this.props.right,
      'ma__general-teaser__secondary--border': !(!this.props.left && this.props.right)
    });
    var teaserClass = classNames({
      '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 React.createElement(
      'section',
      sectionProps,
      React.createElement(
        'div',
        { className: 'ma__general-teaser__details' },
        this.props.title && React.createElement(
          'span',
          { className: 'ma__general-teaser__title' },
          this.props.title
        ),
        (this.props.right || this.props.left) && React.createElement(
          'div',
          { className: 'ma__general-teaser__moreinfo' },
          this.props.left && React.createElement(
            'div',
            { className: 'ma__general-teaser__primary' },
            this.props.left.map(function (info, infoKey) {
              return (
                /* eslint-disable-next-line react/no-array-index-key */
                React.createElement(
                  'div',
                  { key: infoKey, className: primaryInfoClass },
                  info
                )
              );
            })
          ),
          this.props.right && React.createElement(
            'div',
            { className: secondaryInfoClass },
            this.props.right.map(function (info, infoKey) {
              return React.createElement(
                'div',
                {
                  /* eslint-disable-next-line react/no-array-index-key */
                  key: infoKey,
                  className: 'ma__general-teaser__secondaryinfo'
                },
                info
              );
            })
          )
        )
      )
    );
  };

  return Teaser;
}(React.Component);

Teaser.propTypes = process.env.NODE_ENV !== "production" ? {
  /** A unique id for the teaser instance. */
  id: PropTypes.number,
  /** A function that runs after the mouse is no longer hovering over the component. */
  clearActiveHover: PropTypes.func,
  /** A function that runs when the mouse is hovering over the component. */
  setActiveHover: PropTypes.func,
  /** A DecorativeLink used to display the title. */
  title: 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: PropTypes.arrayOf(PropTypes.oneOfType([componentWithName('Link'), 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: PropTypes.arrayOf(PropTypes.oneOfType([componentWithName('DecorativeLink'), componentWithName('OperationalHours'), componentWithName('IconLink')]))
} : {};

export default Teaser;