<script setup lang="ts">
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import AppIcon from '@/components/ui/AppIcon.vue'

const auth = useAuthStore()
const route = useRoute()

const navItems = computed(() => {
  const role = auth.user?.activeRole ?? 'student'
  if (role === 'teacher')
    return [
      { label: 'Дашборд', icon: 'chart-bar', to: '/teacher' },
      { label: 'Лекции', icon: 'book-2', to: '/teacher/lectures' },
      { label: 'Аналитика', icon: 'chart-line', to: '/teacher/analytics' },
    ]
  if (role === 'admin')
    return [
      { label: 'Дашборд', icon: 'shield', to: '/admin' },
      { label: 'Юзеры', icon: 'users', to: '/admin/users' },
      { label: 'Лекции', icon: 'books', to: '/admin/lectures' },
      { label: 'Отзывы', icon: 'message-circle', to: '/admin/reviews' },
    ]
  return [
    { label: 'Главная', icon: 'home', to: '/' },
    { label: 'Лекции', icon: 'books', to: '/catalog' },
    { label: 'Мои', icon: 'clipboard-list', to: '/my-lectures' },
  ]
})

function isActive(to: string) {
  if (to === '/' || to === '/teacher' || to === '/admin') return route.path === to
  return route.path.startsWith(to)
}
</script>

<template>
  <nav class="bottom-nav">
    <RouterLink
      v-for="item in navItems"
      :key="item.to"
      :to="item.to"
      class="bottom-nav-item"
      :class="{ active: isActive(item.to) }"
    >
      <AppIcon class="bottom-nav-icon" :icon="item.icon" :size="20" />
      <span class="bottom-nav-label">{{ item.label }}</span>
    </RouterLink>
  </nav>
</template>

<style scoped>
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: var(--color-white-a90);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--color-border-glass);
  display: none;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--color-text-secondary);
  text-decoration: none;
  flex: 1;
  padding: 4px 0;
  transition: color 0.2s;
}
.bottom-nav-item.active {
  color: var(--color-primary-dark);
}
.bottom-nav-icon {
  color: currentColor;
}
.bottom-nav-label {
  font-size: 10px;
  font-weight: 600;
}

@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
  }
}
</style>
