import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import { Link } from 'react-router-dom';
/**
 * Anchor tag that handles internal and external links
 * opens external links in a new window
 */

var A = function A(props) {
  var to = props.to,
      href = props.href,
      text = props.text,
      children = props.children,
      rest = _objectWithoutProperties(props, ["to", "href", "text", "children"]);

  var aProps;
  var Tag = 'a';

  if (href) {
    // is external link
    aProps = _objectSpread({}, rest, {
      href: href,
      target: '_blank'
    });
  } else {
    // is internal link
    aProps = _objectSpread({}, rest, {
      to: to
    });
    Tag = Link;
  }

  return React.createElement(Tag, aProps, text);
};

A.defaultProps = {
  to: '',
  href: ''
};
export default A;