<script setup lang="ts">
// Simple page to clear session and redirect to Keycloak logout
const router = useRouter();

onMounted(async () => {
  try {
    console.log('🧹 Clearing session...');
    
    const response = await $fetch('/api/auth/clear-session', {
      method: 'POST'
    });
    
    console.log('✅ Session cleared, redirecting to Keycloak logout...');
    
    // Redirect to Keycloak logout URL
    if (response.logoutUrl) {
      window.location.href = response.logoutUrl;
    } else {
      // Fallback to login page
      router.push('/LoginPage?logout=success');
    }
  } catch (error) {
    console.error('❌ Error clearing session:', error);
    // On error, just go to login page
    router.push('/LoginPage?error=logout_failed');
  }
});
</script>

<template>
  <div class="flex items-center justify-center min-h-screen">
    <div class="text-center">
      <v-progress-circular indeterminate color="primary" size="64"></v-progress-circular>
      <p class="mt-4 text-lg">Clearing session and logging out...</p>
    </div>
  </div>
</template>
