'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactHtmlParser = require('react-html-parser');

var _reactHtmlParser2 = _interopRequireDefault(_reactHtmlParser);

require('./style.css');

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

var formatPhoneNumber = function formatPhoneNumber(number) {
  var clean = number.replace(/\D/g, '');
  var match = clean.match(/^(1|)?(\d{3})(\d{3})(\d{4})$/);
  if (match) {
    var intlCode = match[1] ? '+1 ' : '';
    return [intlCode, '(', match[2], ') ', match[3], '-', match[4]].join('');
  }
  return null;
};

var PhoneNumber = function PhoneNumber(props) {
  var number = props.number,
      details = props.details;

  var display = formatPhoneNumber(number);
  return _react2.default.createElement(
    'span',
    { className: 'ma__phone-number' },
    _react2.default.createElement(
      'a',
      { href: 'tel:' + number, className: 'ma__phone-number__number' },
      display
    ),
    details && _react2.default.createElement(
      'p',
      { className: 'ma__contact__details' },
      (0, _reactHtmlParser2.default)(details)
    )
  );
};

PhoneNumber.propTypes = process.env.NODE_ENV !== "production" ? {
  /** The phone number. Expect the following +16174659898 or 6174659898 */
  number: _propTypes2.default.string.isRequired,
  /** Details around contacting the provided phone number */
  details: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object])
} : {};

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