import { forwardRef, useCallback } from 'react';
import { clsx } from 'clsx';
import { jsx } from 'react/jsx-runtime';

const PrimitiveAnchor = /*#__PURE__*/forwardRef(({
  children,
  className,
  href,
  id,
  disabled = false,
  testId,
  onClick,
  onFocus,
  onBlur,
  onMouseEnter,
  onMouseLeave,
  onKeyDown,
  ...props
}, ref) => {
  const anchorClasses = clsx(className);
  const handleClick = useCallback(event => {
    if (disabled) {
      event.preventDefault();
    } else {
      onClick?.(event);
    }
  }, [disabled, onClick]);
  const handleFocus = useCallback(event => {
    onFocus?.(event);
  }, [onFocus]);
  const handleBlur = useCallback(event => {
    onBlur?.(event);
  }, [onBlur]);
  const handleMouseEnter = useCallback(event => {
    onMouseEnter?.(event);
  }, [onMouseEnter]);
  const handleMouseLeave = useCallback(event => {
    onMouseLeave?.(event);
  }, [onMouseLeave]);
  const handleKeyDown = 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 || undefined,
    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__*/jsx("a", {
    ...anchorProps,
    children: children
  });
});
PrimitiveAnchor.displayName = 'PrimitiveAnchor';

export { PrimitiveAnchor as default };
//# sourceMappingURL=PrimitiveAnchor.mjs.map
