function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
// Styled elements
import * as React from 'react';
import { Link } from './styled-components';
import { withWrapper } from '../styles';
import { isFocusVisible, forkFocus, forkBlur } from '../utils/focusVisible';

function LinkFocus(props) {
  const [focusVisible, setFocusVisible] = React.useState(false);

  const handleFocus = event => {
    if (isFocusVisible(event)) {
      setFocusVisible(true);
    }
  };

  const handleBlur = event => {
    if (focusVisible !== false) {
      setFocusVisible(false);
    }
  };

  return props.children({
    focusVisible,
    handleFocus,
    handleBlur
  });
}

export const StyledLink = withWrapper(Link, Styled => function StyledLink({
  animateUnderline,
  ...restProps
}) {
  return /*#__PURE__*/React.createElement(LinkFocus, null, focusProps => /*#__PURE__*/React.createElement(Styled, _extends({
    "data-baseweb": "link",
    $isAnimateUnderline: animateUnderline,
    $isFocusVisible: focusProps.focusVisible,
    onFocus: forkFocus(restProps, focusProps.handleFocus),
    onBlur: forkBlur(restProps, focusProps.handleBlur)
  }, restProps)));
});
/** @deprecated To be removed in future versions.*/