<template>
  <vab-icon :class="className" icon="refresh-line" @click="refreshRoute" />
</template>

<script setup>
defineOptions({
  name: 'VabRefresh',
})

const className = ref('')

const rotate = () => {
  className.value = 'rotate'
  setTimeout(() => {
    className.value = ''
  }, 500)
}

const refreshRoute = () => {
  $pub('reload-router-view')
  rotate()
}

onBeforeMount(() => {
  $sub('refresh-rotate', () => {
    rotate()
  })
})
</script>
