"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _react = require("react");
var _utils = require("../../utils");
var _constants = require("../../constants");
var _OnDarkContext = _interopRequireDefault(require("../OnDarkContext"));
var _utils2 = require("../utils");
var _Icon = _interopRequireDefault(require("../Icon"));
var _jsxRuntime = require("react/jsx-runtime");
// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

/**
 * `Link` is used for navigation purposes.
 * @since 1.9.0
 */
const Link = _ref => {
  let {
    baseClassName = `${_constants.CLS_PREFIX}link`,
    className,
    onClick,
    disabled = false,
    pseudo = false,
    component,
    children,
    ...other
  } = _ref;
  const Tag = component || 'a';
  const onDark = (0, _react.useContext)(_OnDarkContext.default);
  const props = {
    ...other,
    onClick,
    className: (0, _classnames.default)(baseClassName, className, {
      [`${baseClassName}--disabled`]: disabled,
      [`${baseClassName}--pseudo`]: pseudo,
      [`${baseClassName}--on-dark`]: onDark
    })
  };
  const {
    target
  } = other;
  const external = !pseudo && target === '_blank';
  if (external && !props.rel) {
    props.rel = 'noopener noreferrer';
  }
  if (disabled) {
    props.onClick = e => e.preventDefault();
    props.tabIndex = -1;
  }
  // accessibility
  if (onClick) {
    props.tabIndex = props.tabIndex || 0;
    props.onKeyDown = (0, _utils2.wrapFunction)(props.onKeyDown, e => {
      if (e.key === 'Enter') {
        e.preventDefault();
        e.currentTarget.click();
      }
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Tag, {
    ...props,
    children: [children, external && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
      flipHorizontal: (0, _utils.isRtl)(),
      name: "arrow-diagonal-out",
      className: `${baseClassName}__external-icon`
    })]
  });
};
var _default = exports.default = Link;