import NextLink, { LinkProps as NextLinkProps } from "next/link";
import React from "react";

type Props = Omit<NextLinkProps, "href"> & {
  href: string;
  className?: string;
};

export const CustomButton: React.FC<Props> = (props) => {
  const { children, className, ...otherProps } = props;
  const { href } = otherProps;

  const isExternal = href.includes("http://") || href.includes("https://");

  return isExternal ? (
    <a
      className={className}
      href={href}
      target="_blank"
      rel="noopener noreferrer"
    >
      {children}
    </a>
  ) : (
    <NextLink {...otherProps}>
      <a className={className}>{children}</a>
    </NextLink>
  );
};
