'use strict';

var React = require('react');
var clsx = require('clsx');
var jsxRuntime = require('react/jsx-runtime');

const PrimitiveAnchor = /*#__PURE__*/React.forwardRef(({
  children,
  className,
  href,
  id,
  disabled = false,
  testId,
  onClick,
  onFocus,
  onBlur,
  onMouseEnter,
  onMouseLeave,
  onKeyDown,
  ...props
}, ref) => {
  const anchorClasses = clsx.clsx('wds-Anchor', {
    'wds-Anchor--disabled': disabled
  }, className);
  const handleClick = React.useCallback(event => {
    if (disabled) {
      event.preventDefault();
    } else {
      onClick?.(event);
    }
  }, [disabled, onClick]);
  const handleFocus = React.useCallback(event => {
    onFocus?.(event);
  }, [onFocus]);
  const handleBlur = React.useCallback(event => {
    onBlur?.(event);
  }, [onBlur]);
  const handleMouseEnter = React.useCallback(event => {
    onMouseEnter?.(event);
  }, [onMouseEnter]);
  const handleMouseLeave = React.useCallback(event => {
    onMouseLeave?.(event);
  }, [onMouseLeave]);
  const handleKeyDown = React.useCallback(event => {
    onKeyDown?.(event);
  }, [onKeyDown]);
  /**
   * The following props are set to handle the `disabled` state for the link:
   *
   * - `aria-disabled`: Exposes the link as disabled to assistive technologies.
   * - `href`: Removed when `disabled` is true to prevent navigation.
   * - `role`: Set to 'link' when `disabled` is true to ensure the element
   *    is still exposed as a link.
   *
   * For more details, refer to Scott O'Hara's article on disabling links:
   * https://www.scottohara.me/blog/2021/05/28/disabled-links.html
   */
  const anchorProps = {
    'aria-disabled': disabled,
    className: anchorClasses,
    'data-testid': testId,
    href: disabled ? undefined : href,
    id,
    ref,
    role: disabled ? 'link' : undefined,
    rel: props.target === '_blank' ? 'noopener noreferrer' : undefined,
    onClick: handleClick,
    onFocus: handleFocus,
    onBlur: handleBlur,
    onMouseEnter: handleMouseEnter,
    onMouseLeave: handleMouseLeave,
    onKeyDown: handleKeyDown,
    ...props
  };
  return /*#__PURE__*/jsxRuntime.jsx("a", {
    ...anchorProps,
    children: children
  });
});
PrimitiveAnchor.displayName = 'PrimitiveAnchor';

module.exports = PrimitiveAnchor;
//# sourceMappingURL=PrimitiveAnchor.js.map
