<script lang="ts">
  let { href, text }: { href: string; text: string } = $props();
  let safeHref = $derived.by(() => {
    try {
      let url = new URL(href);

      switch (url.protocol) {
        case 'javascript:':
          return '#';

        default:
          return href;
      }
    } catch (error) {
      return '#';
    }
  });
</script>

<a href={safeHref} target="_blank">{text}</a>
