<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { api } from './api'
import { resolveLocale } from './i18n/locale'
import { setCurrency } from './taskui'
import type { UserInfo } from './types'
const route = useRoute()
const { t } = useI18n()
const user = ref<UserInfo | null>(null)
const navItems = computed(() => [
{ id: 'stack', label: t('nav.stack'), icon: 'ph-inbox', to: '/stack' },
{ id: 'tree', label: t('nav.tree'), icon: 'ph-tree-structure', to: '/tree' },
{ id: 'list', label: t('nav.list'), icon: 'ph-list-bullets', to: '/list' },
{ id: 'projects', label: t('nav.projects'), icon: 'ph-folders', to: '/projects' },
{ id: 'options', label: t('nav.options'), icon: 'ph-shuffle', to: '/options' },
{ id: 'settings', label: t('nav.settings'), icon: 'ph-gear-six', to: '/settings' },
])
const currentLabel = computed(() => {
const item = navItems.value.find((i) => i.to === route.path)
return item?.label ?? 'gntodo'
})
onMounted(async () => {
const res = await fetch('/auth/me')
if (res.ok) {
const data = await res.json()
user.value = data.user
}
// валюта и язык — глобальные настройки; язык без переопределения берётся из SSO
try {
const s = await api.getSettings()
setCurrency(s.currency)
resolveLocale(s.language, user.value?.locale)
} catch {
setCurrency('UAH')
resolveLocale(undefined, user.value?.locale)
}
})
</script>
<template>
<GnToastProvider>
<GnNavigationShell
brand="gntodo"
logo-src="/logo.svg"
:items="navItems"
:current="currentLabel"
:title="t('nav.sections')"
:subtitle="t('nav.subtitle')"
>
<template #current>
<a v-if="!user" href="/auth/login">{{ t('nav.signIn') }}</a>
<span v-else class="user-chip">
{{ user.email }}
<a href="/auth/logout">{{ t('nav.signOut') }}</a>
</span>
</template>
<template #content>
<div class="app-content">
<RouterView />
</div>
</template>
</GnNavigationShell>
</GnToastProvider>
</template>
<style>
.app-content {
max-width: 760px;
margin: 0 auto;
padding: 1.5rem 1rem 3rem;
}
/* У кита .card имеет intrinsic max-width: 340px / width: max-content — в наших видах
карточки должны заполнять колонку контента целиком (иначе обрезаются действия).
overflow отключаем, иначе dropdown-меню внутри карточки обрезается. */
.app-content .card {
max-width: 100%;
width: 100%;
overflow: visible;
}
.user-chip a {
margin-left: 0.5rem;
color: var(--muted);
}
</style>