<template>
  <div class="dashboard-router">
    <v-container v-if="loading" class="fill-height">
      <v-row justify="center" align="center">
        <v-col cols="auto" class="text-center">
          <v-progress-circular 
            indeterminate 
            color="primary" 
            size="64"
            width="6"
          />
          <p class="mt-4 text-h6">Loading your dashboard...</p>
        </v-col>
      </v-row>
    </v-container>
  </div>
</template>

<script setup lang="ts">
definePageMeta({
  middleware: 'auth',
  layout: 'dashboard'
});

const { user, userTier } = useAuth();
const loading = ref(true);

// Route to tier-specific dashboard - auth middleware ensures user is authenticated
onMounted(() => {
  console.log('🔄 Dashboard mounted, routing to tier-specific page...');
  
  // Auth middleware has already verified authentication - just route to tier page
  if (user.value && userTier.value) {
    const tierRoute = `/dashboard/${userTier.value}`;
    console.log('🔄 Routing to tier-specific dashboard:', tierRoute);
    navigateTo(tierRoute, { replace: true });
  } else {
    console.warn('❌ No user or tier found - this should not happen after auth middleware');
    // Fallback - middleware should have caught this
    navigateTo('/login');
  }
  
  loading.value = false;
});
</script>

<style scoped>
.dashboard-router {
  min-height: 100vh;
}

.v-progress-circular {
  margin-bottom: 1rem;
}
</style>
