<!--
Super Admin bar : Barre qui s'affiche lorsque l'utilisateur est un super admin en mode switch
-->

<template>
  <UiSystemBar v-if="show" color="ot_danger">
    <template #bar.text>
      <v-icon small>
        fas fa-exclamation-triangle
      </v-icon>
      <span>{{ $t('super_admin_switch_account') }}</span>
      <a :href="url" class="ot_black--text text-decoration-none"><strong>{{ $t('click_here') }}</strong></a>
    </template>
  </UiSystemBar>
</template>

<script lang="ts">
import { defineComponent, useStore, useContext } from '@nuxtjs/composition-api'
import { State } from '@vuex-orm/core'
import { AnyStore } from '~/types/interfaces'

export default defineComponent({
  setup () {
    const { $config } = useContext()
    const baseLegacyUrl:string = $config.baseURL_adminLegacy
    const store:AnyStore = useStore<State>()
    const originalAccess = store.state.profile.access.originalAccess
    let show = false
    let url = ''

    if (originalAccess !== null) {
      show = originalAccess.isSuperAdminAccess
      url = `${baseLegacyUrl}/switch_user/${originalAccess.organization.id}/${originalAccess.id}/exit`
    }

    return { show, url }
  }
})
</script>

<style scoped>

</style>
