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

<template>
  <UiSystemBar color="ot_danger" v-if="show">
    <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 {AnyStore} from "~/types/interfaces";
import {State} from "@vuex-orm/core";

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

    const url = `${baseLegacyUrl}/switch_user/${originalAccess.organization.id}/${originalAccess.id}/exit`

    return {
      show: originalAccess.isSuperAdminAccess,
      url
    }
  }
})
</script>

<style scoped>

</style>
