import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import { Icon } from './Icon';
export var ExternalLink =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(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;

    _defineProperty(_assertThisInitialized(_this), "onClick", function (e) {
      if (_.isFunction(_this.props.onClick)) {
        _this.props.onClick(e);
      }

      return false;
    });

    _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (e) {
      if (_.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.createElement(Icon, {
      name: "link"
    }) : null;
    return React.createElement("li", {
      id: id,
      role: "presentation",
      "data-test-automation-id": id
    }, React.createElement("a", {
      href: href,
      role: role,
      tabIndex: tabIndex,
      onClick: this.onClick,
      onKeyDown: this.onKeyDown,
      target: "_blank",
      className: "link-item"
    }, title, icon));
  };

  return ExternalLink;
}(React.Component);

_defineProperty(ExternalLink, "propTypes", {
  tabIndex: PropTypes.number,
  id: PropTypes.string.isRequired,
  title: PropTypes.string.isRequired,
  href: PropTypes.string.isRequired,
  role: PropTypes.string,
  onClick: PropTypes.func,
  onKeyDown: PropTypes.func,
  withIcon: PropTypes.bool
});

_defineProperty(ExternalLink, "defaultProps", {
  tabIndex: -1,
  onClick: null,
  onKeyDown: null,
  role: null,
  withIcon: false
});