import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
var SafeAnchor = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var _props$as = props.as,
      Component = _props$as === void 0 ? 'a' : _props$as,
      href = props.href,
      disabled = props.disabled,
      onClick = props.onClick,
      rest = _objectWithoutPropertiesLoose(props, ["as", "href", "disabled", "onClick"]);

  var handleClick = useCallback(function (event) {
    if (disabled) {
      event.preventDefault();
      event.stopPropagation();
      return;
    }

    onClick === null || onClick === void 0 ? void 0 : onClick(event);
  }, [onClick, disabled]);

  if (disabled) {
    rest.tabIndex = -1;
    rest['aria-disabled'] = true;
  }

  if (!href || href !== '#') {
    rest.role = rest.role || 'button';
  }

  return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
    href: href,
    ref: ref,
    onClick: handleClick
  }));
});
SafeAnchor.displayName = 'SafeAnchor';
SafeAnchor.propTypes = {
  disabled: PropTypes.bool,
  as: PropTypes.elementType
};
export default SafeAnchor;