'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _DecorativeLink = require('../../atoms/links/DecorativeLink');

var _DecorativeLink2 = _interopRequireDefault(_DecorativeLink);

var _Icon = require('../../base/Icon');

var _Icon2 = _interopRequireDefault(_Icon);

require('./style.css');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var ContactGroup = function ContactGroup(contactGroup) {
  var icons = {
    SvgMarker: _react2.default.createElement(_Icon2.default, { name: 'marker' }), SvgPhone: _react2.default.createElement(_Icon2.default, { name: 'phone' }), SvgLaptop: _react2.default.createElement(_Icon2.default, { name: 'laptop' }), SvgFax: _react2.default.createElement(_Icon2.default, { name: 'fax' })
  };
  var Element = 'h' + (contactGroup.level ? contactGroup.level : 2);
  var createItems = function createItems(item) {
    switch (item.type) {
      case 'online':
        return _react2.default.createElement(_DecorativeLink2.default, item.link);
      case 'phone':
        return _react2.default.createElement(
          'a',
          { href: 'tel:' + item.link.href, className: 'ma__content-link ma__content-link--phone' },
          item.link.text
        );
      case 'email':
        return _react2.default.createElement(
          'a',
          { href: 'mailto:' + item.link.href, className: 'ma__content-link' },
          item.link.text
        );
      case 'address':
        return _react2.default.createElement(
          _react2.default.Fragment,
          null,
          _react2.default.createElement('div', { className: 'ma__contact-group__address', dangerouslySetInnerHTML: { __html: item.address } }),
          item.link.href && _react2.default.createElement(
            'div',
            { className: 'ma__contact-group__directions' },
            _react2.default.createElement(_DecorativeLink2.default, item.link)
          )
        );
      default:
        return _react2.default.createElement(
          'span',
          { className: 'ma__contact-group__value' },
          item.link.text
        );
    }
  };
  return _react2.default.createElement(
    'div',
    { className: 'ma__contact-group' },
    contactGroup.name && contactGroup.icon && _react2.default.createElement(
      Element,
      { className: 'ma__contact-group__name' },
      icons[contactGroup.icon],
      _react2.default.createElement(
        'span',
        null,
        contactGroup.name
      )
    ),
    contactGroup.items && contactGroup.items.map(function (item, itemIndex) {
      return (
        /* eslint-disable-next-line react/no-array-index-key */
        _react2.default.createElement(
          _react2.default.Fragment,
          { key: 'contactGroup.item.' + itemIndex },
          _react2.default.createElement(
            'div',
            { className: 'ma__contact-group__item' },
            item.label && _react2.default.createElement(
              'span',
              { className: 'ma__contact-group__label' },
              item.label
            ),
            createItems(item)
          ),
          item.details && _react2.default.createElement(
            'p',
            { className: 'ma__contact-group__details' },
            item.details
          )
        )
      );
    })
  );
};

ContactGroup.propTypes = process.env.NODE_ENV !== "production" ? {
  /** icon to pass to the contact group */
  icon: _propTypes2.default.oneOf(['SvgMarker', 'SvgPhone', 'SvgLaptop', 'SvgFax']),
  /** The heading text  */
  text: _propTypes2.default.string,
  /** The name of the contact info */
  name: _propTypes2.default.oneOf(['Phone', 'Online', 'Fax', 'Address']),
  /** The heading level, default is 2 */
  level: _propTypes2.default.number,
  /** A set of contact info items */
  items: _propTypes2.default.arrayOf(_propTypes2.default.shape({
    type: _propTypes2.default.oneOf(['phone', 'online', 'email', 'address']),
    label: _propTypes2.default.string,
    address: _propTypes2.default.string,
    link: _propTypes2.default.shape(_DecorativeLink2.default.props),
    details: _propTypes2.default.string
  }))
} : {};

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