<script setup lang="ts">
import type { mastodon } from 'masto'

const { tag } = defineProps<{
  tag: mastodon.v1.Tag
}>()

const emit = defineEmits<{
  (event: 'change'): void
}>()

const masto = useMasto()

const toggleFollowTag = async () => {
  if (tag.following)
    await masto.v1.tags.unfollow(tag.name)
  else
    await masto.v1.tags.follow(tag.name)

  emit('change')
}
</script>

<template>
  <button
    rounded group focus:outline-none
    hover:text-primary focus-visible:text-primary
    :aria-label="tag.following ? $t('tag_unfollow_label', { tag: tag.name }) : $t('tag_follow_label', { tag: tag.name })"
    @click="toggleFollowTag()"
  >
    <CommonTooltip placement="bottom" :content="tag.following ? $t('tag_unfollow') : $t('tag_follow')">
      <div rounded-full p2 group-hover="bg-orange/10" group-focus-visible="bg-orange/10" group-focus-visible:ring="2 current">
        <div :class="[tag.following ? 'i-ri:star-fill' : 'i-ri:star-line']" />
      </div>
    </CommonTooltip>
  </button>
</template>
