<script setup>
import { onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useSession } from 'src/composables/useSession';
import { useState } from 'src/composables/useState';
import { useStateStore } from 'stores/useStateStore';
import { useQuasar } from 'quasar';
import PinnedModules from './PinnedModules.vue';
import UserPanel from 'components/UserPanel.vue';
import VnBreadcrumbs from './common/VnBreadcrumbs.vue';

const { t } = useI18n();
const stateStore = useStateStore();
const quasar = useQuasar();
const state = useState();
const user = state.getUser();
const { getTokenMultimedia } = useSession();
const token = getTokenMultimedia();
const appName = 'Lilium';

onMounted(() => stateStore.setMounted());

const pinnedModulesRef = ref();
</script>

<template>
    <QHeader color="white" elevated>
        <QToolbar class="q-py-sm q-px-md">
            <QBtn @click="stateStore.toggleLeftDrawer()" icon="menu" round dense flat>
                <QTooltip bottom anchor="bottom right">
                    {{ t('globals.collapseMenu') }}
                </QTooltip>
            </QBtn>
            <RouterLink to="/">
                <QBtn color="primary" flat round v-if="!quasar.platform.is.mobile">
                    <QAvatar square size="md">
                        <QImg
                            src="~/assets/salix_icon.svg"
                            :alt="appName"
                            spinner-color="primary"
                        />
                    </QAvatar>
                    <QTooltip bottom>
                        {{ t('globals.backToDashboard') }}
                    </QTooltip>
                </QBtn>
            </RouterLink>
            <VnBreadcrumbs v-if="$q.screen.gt.sm" />
            <QSpace />
            <div id="searchbar" class="searchbar"></div>
            <QSpace />
            <div class="q-pl-sm q-gutter-sm row items-center no-wrap">
                <div id="actions-prepend"></div>
                <QBtn
                    flat
                    v-if="!quasar.platform.is.mobile"
                    @click="pinnedModulesRef.redirect($route.params.id)"
                    icon="more_up"
                >
                    <QTooltip>
                        {{ t('Go to Salix') }}
                    </QTooltip>
                </QBtn>
                <QBtn
                    :class="{ 'q-pa-none': quasar.platform.is.mobile }"
                    id="pinnedModules"
                    icon="apps"
                    flat
                    dense
                    rounded
                >
                    <QTooltip bottom>
                        {{ t('globals.pinnedModules') }}
                    </QTooltip>
                    <PinnedModules ref="pinnedModulesRef" />
                </QBtn>
                <QBtn
                    :class="{ 'q-pa-none': quasar.platform.is.mobile }"
                    rounded
                    dense
                    flat
                    no-wrap
                    id="user"
                >
                    <QAvatar size="lg">
                        <QImg
                            :src="`/api/Images/user/160x160/${user.id}/download?access_token=${token}`"
                            spinner-color="primary"
                        >
                        </QImg>
                    </QAvatar>
                    <QTooltip bottom>
                        {{ t('globals.userPanel') }}
                    </QTooltip>
                    <UserPanel />
                </QBtn>
                <div id="actions-append"></div>
            </div>
        </QToolbar>
        <VnBreadcrumbs v-if="$q.screen.lt.md" class="q-ml-md" />
    </QHeader>
</template>

<style lang="scss" scoped>
.searchbar {
    width: max-content;
}
.q-header {
    background-color: var(--vn-dark);
}
</style>
<i18n>
en:
    Go to Salix: Go to Salix
es:
    Go to Salix: Ir a Salix
</i18n>
