---
import type { HTMLAttributes } from "astro/types";

interface Props extends HTMLAttributes<"a"> {
  href: string;
}

const { href, ...rest } = Astro.props;

const isExternal =
  /^(https?:)?\/\//.test(href) ||
  href.startsWith("mailto:") ||
  href.startsWith("tel:");
---

<a
  href={href}
  target={isExternal ? "_blank" : "_self"}
  rel={isExternal ? "noopener noreferrer" : undefined}
  {...rest}
>
  <slot />
</a>
