import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "className", "element", "onMouseUp", "onMouseLeave"];
import React, { forwardRef, useRef, useImperativeHandle } from 'react';
import cx from 'classnames';
import Box from '../box';
import theme from './theme.css';
import uiUtilities from '@teamleader/ui-utilities';
var MarketingLink = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var children = _ref.children,
      _ref$className = _ref.className,
      className = _ref$className === void 0 ? '' : _ref$className,
      _ref$element = _ref.element,
      element = _ref$element === void 0 ? 'a' : _ref$element,
      onMouseUp = _ref.onMouseUp,
      onMouseLeave = _ref.onMouseLeave,
      others = _objectWithoutProperties(_ref, _excluded);

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

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

    if (currentLinkRef !== null && currentLinkRef !== void 0 && 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'], className);
  return /*#__PURE__*/React.createElement(Box, _extends({
    element: element,
    ref: linkRef,
    className: classNames,
    "data-teamleader-ui": "marketing-link",
    onMouseUp: handleMouseUp,
    onMouseLeave: handleMouseLeave
  }, others), children);
});
MarketingLink.displayName = 'MarketingLink';
export default MarketingLink;