<!--
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, useContext } from '@nuxtjs/composition-api'

export default defineComponent({
  setup () {
    const { $config, store } = useContext()
    const baseLegacyUrl:string = $config.baseURL_adminLegacy
    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>
