"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.ExternalLink = void 0;

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _lodash = _interopRequireDefault(require("lodash"));

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _Icon = require("./Icon");

var ExternalLink =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(ExternalLink, _React$Component);

  function ExternalLink() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onClick", function (e) {
      if (_lodash.default.isFunction(_this.props.onClick)) {
        _this.props.onClick(e);
      }

      return false;
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onKeyDown", function (e) {
      if (_lodash.default.isFunction(_this.props.onKeyDown)) {
        _this.props.onKeyDown(e);
      }
    });
    return _this;
  }

  var _proto = ExternalLink.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        id = _this$props.id,
        href = _this$props.href,
        tabIndex = _this$props.tabIndex,
        title = _this$props.title,
        role = _this$props.role,
        withIcon = _this$props.withIcon;
    var icon = withIcon ? _react.default.createElement(_Icon.Icon, {
      name: "link"
    }) : null;
    return _react.default.createElement("li", {
      id: id,
      role: "presentation",
      "data-test-automation-id": id
    }, _react.default.createElement("a", {
      href: href,
      role: role,
      tabIndex: tabIndex,
      onClick: this.onClick,
      onKeyDown: this.onKeyDown,
      target: "_blank",
      className: "link-item"
    }, title, icon));
  };

  return ExternalLink;
}(_react.default.Component);

exports.ExternalLink = ExternalLink;
(0, _defineProperty2.default)(ExternalLink, "propTypes", {
  tabIndex: _propTypes.default.number,
  id: _propTypes.default.string.isRequired,
  title: _propTypes.default.string.isRequired,
  href: _propTypes.default.string.isRequired,
  role: _propTypes.default.string,
  onClick: _propTypes.default.func,
  onKeyDown: _propTypes.default.func,
  withIcon: _propTypes.default.bool
});
(0, _defineProperty2.default)(ExternalLink, "defaultProps", {
  tabIndex: -1,
  onClick: null,
  onKeyDown: null,
  role: null,
  withIcon: false
});