"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.NavLink = NavLink;

var _react = _interopRequireDefault(require("react"));

var _reactRouterDom = require("react-router-dom");

var _classnames = _interopRequireDefault(require("classnames"));

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function NavLink(_ref) {
  var text = _ref.text,
      path = _ref.path,
      type = _ref.type,
      _ref$active = _ref.active,
      active = _ref$active === void 0 ? false : _ref$active,
      _ref$attentionNeeded = _ref.attentionNeeded,
      attentionNeeded = _ref$attentionNeeded === void 0 ? false : _ref$attentionNeeded,
      target = _ref.target,
      external = _ref.external;
  var commonLinkProps = {
    className: (0, _classnames.default)('usa-nav__link', {
      'usa-current': active
    }),
    to: path,
    target: target
  };

  var LinkEl = function LinkEl(_ref2) {
    var children = _ref2.children;
    return /*#__PURE__*/_react.default.createElement(_reactRouterDom.Link, commonLinkProps, children);
  };

  if (external) {
    LinkEl = function LinkEl(_ref3) {
      var children = _ref3.children;
      return /*#__PURE__*/_react.default.createElement("a", _extends({}, commonLinkProps, {
        href: path,
        rel: "noopener noreferrer"
      }), children);
    };
  }

  switch (type) {
    case 'primary':
      return /*#__PURE__*/_react.default.createElement("li", {
        className: "usa-nav__primary-item"
      }, /*#__PURE__*/_react.default.createElement(LinkEl, null, /*#__PURE__*/_react.default.createElement("span", null, text, attentionNeeded && /*#__PURE__*/_react.default.createElement("span", {
        className: "attention-needed"
      }, "\xA0\u2022", /*#__PURE__*/_react.default.createElement("span", {
        className: "usa-sr-only"
      }, " (attention needed)")))));

    case 'secondary':
      return /*#__PURE__*/_react.default.createElement("li", {
        className: "usa-nav__secondary-item"
      }, /*#__PURE__*/_react.default.createElement(LinkEl, null, text));
  }
}