import React, { AnchorHTMLAttributes, forwardRef } from "react";
import classNames from "classnames";
import { useConfig } from "../_util/config-context";

export interface ExternalLinkProps
  extends AnchorHTMLAttributes<HTMLAnchorElement> {
  /**
   * 不显示为高亮色
   * @default false
   */
  weak?: boolean;
}

export const ExternalLink = forwardRef<HTMLAnchorElement, ExternalLinkProps>(
  ({ className, weak, children, ...props }: ExternalLinkProps, ref) => {
    const { classPrefix } = useConfig();
    return (
      <a
        target="_blank"
        {...props}
        ref={ref}
        className={classNames(
          `${classPrefix}-link-external`,
          {
            [`${classPrefix}-link-external--black`]: weak,
          },
          className
        )}
      >
        {children}
      </a>
    );
  }
);

ExternalLink.displayName = "ExternalLink";
