<script lang="ts">
  import {BrowserOpenURL} from "../../wailsjs/runtime"

  export let id: string
  let url = ""
  let isAniList = false
  let isMAL = false
  let isSimkl = false
  let newId = id
  let re = /[ams]?-?(.*)/
  if (id !== undefined && id.length > 0) {
    isAniList = id.includes("a-")
    isMAL = id.includes("m-")
    isSimkl = id.includes("s-")
    newId = id.match(re)[1]
  }


  if (isAniList) url = `https://anilist.co/anime/${newId}`
  if (isMAL) url = `https://myanimelist.net/anime/${newId}`
  if (isSimkl) url = `https://simkl.com/anime/${newId}`
</script>

{#if url.length > 0}
  <button class="underline underline-offset-2 px-4 py-1" on:click={() => BrowserOpenURL(url)}>{newId}</button>
{:else}
  {id}
{/if}
