<template>
  <transition name="fade">
    <div class="sw-new-version" v-if="newVersion">
      <button @click="reload">
        <img src="@/assets/reload.svg" alt="reload" />
      </button>
    </div>
  </transition>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { addEventBusListener } from 'retrobus'

const newVersion = ref(false)

onMounted(() => {
  addEventBusListener('new-version', () => (newVersion.value = true), {
    retro: true,
    once: true
  })
})

const reload = () => location.reload()
</script>

<style lang="scss" scoped>
$size: 25px;

.sw-new-version {
  position: absolute;
  top: 1rem;
  right: 1rem;

  button {
    padding: 0.5rem;
    img {
      width: $size;
      height: $size;
    }
  }
}
</style>
