<template>
  <div class="admin-dashboard">
    <div class="admin-header">
      <h1>Административная панель</h1>
      <div class="admin-user-info">
        <span>{{ user?.name || 'Администратор' }}</span>
        <button @click="logout" class="logout-btn">Выйти</button>
      </div>
    </div>
    
    <div class="admin-content">
      <div class="admin-sidebar">
        <nav>
          <router-link :to="{ name: 'AdminUsers' }" active-class="active">Пользователи</router-link>
          <router-link :to="{ name: 'AdminConversations' }" active-class="active">Диалоги</router-link>
          <router-link :to="{ name: 'AdminStatistics' }" active-class="active">Статистика</router-link>
        </nav>
      </div>
      
      <div class="admin-main-content">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import { useAuth } from '../../auth';
import { useRouter } from 'vue-router';
import { computed } from 'vue';

export default {
  name: 'AdminDashboard',
  setup() {
    const { user, logout: authLogout } = useAuth();
    const router = useRouter();
    
    const logout = async () => {
      try {
        await authLogout();
        router.push({ name: 'Login' });
      } catch (error) {
        console.error('Ошибка при выходе:', error);
      }
    };
    
    return {
      user: computed(() => user.value),
      logout
    };
  }
}
</script>

<style scoped>
.admin-dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background-color: #f5f5f5;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  background-color: #ff3e68;
  color: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.admin-header h1 {
  font-size: 1.5rem;
  margin: 0;
}

.admin-user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logout-btn {
  padding: 0.4rem 1rem;
  background-color: white;
  color: #ff3e68;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}

.admin-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.admin-sidebar {
  width: 200px;
  background-color: white;
  box-shadow: 1px 0 3px rgba(0,0,0,0.1);
  overflow-y: auto;
}

.admin-sidebar nav {
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.admin-sidebar a {
  padding: 0.75rem 1.5rem;
  color: #333;
  text-decoration: none;
  transition: background-color 0.3s;
}

.admin-sidebar a:hover {
  background-color: #f0f0f0;
}

.admin-sidebar a.active {
  background-color: #ff3e68;
  color: white;
}

.admin-main-content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}
</style>