import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "className", "disabled", "element", "inherit", "inverse", "selected", "onMouseUp", "onMouseLeave"];
import uiUtilities from '@teamleader/ui-utilities';
import cx from 'classnames';
import PropTypes from 'prop-types';
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
import Box from '../box';
import theme from './theme.css';
/** @type {React.ComponentType<any>} */

var Link = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var _cx;

  var children = _ref.children,
      className = _ref.className,
      disabled = _ref.disabled,
      element = _ref.element,
      inherit = _ref.inherit,
      inverse = _ref.inverse,
      selected = _ref.selected,
      onMouseUp = _ref.onMouseUp,
      onMouseLeave = _ref.onMouseLeave,
      others = _objectWithoutProperties(_ref, _excluded);

  var linkRef = useRef();
  useImperativeHandle(ref, function () {
    return linkRef.current;
  });

  var blur = function blur() {
    var currentLinkRef = linkRef.current;

    if (currentLinkRef.blur) {
      currentLinkRef.blur();
    }
  };

  var handleMouseUp = function handleMouseUp(event) {
    blur();
    onMouseUp && onMouseUp(event);
  };

  var handleMouseLeave = function handleMouseLeave(event) {
    blur();
    onMouseLeave && onMouseLeave(event);
  };

  var classNames = cx(uiUtilities['reset-font-smoothing'], theme['link'], (_cx = {}, _defineProperty(_cx, theme['is-disabled'], disabled), _defineProperty(_cx, theme['is-inherit'], inherit), _defineProperty(_cx, theme['is-inverse'], inverse), _defineProperty(_cx, theme['is-selected'], selected), _cx), className);
  return /*#__PURE__*/React.createElement(Box, _extends({
    element: element,
    ref: linkRef,
    className: classNames,
    "data-teamleader-ui": "link",
    onMouseUp: handleMouseUp,
    onMouseLeave: handleMouseLeave
  }, others), children);
});
Link.defaultProps = {
  className: '',
  disabled: false,
  element: 'a',
  inherit: true,
  inverse: false
};
Link.displayName = 'Link';
export default Link;