<script lang="ts">
	import { goto } from '$app/navigation';
	import { isAuthenticated } from '$lib/stores/auth';
	import { browser } from '$app/environment';
	import { page } from '$app/stores';
	import { onMount } from 'svelte';

	// Only redirect when actually on the root page, not during navigation
	onMount(() => {
		if (browser) {
			const unsubscribe = isAuthenticated.subscribe((authenticated) => {
				// Only redirect if we're actually on the root page
				if ($page.url.pathname === '/') {
					if (authenticated) {
						goto('/dashboard');
					} else {
						goto('/login');
					}
				}
			});
			return unsubscribe;
		}
	});
</script>

<div class="flex items-center justify-center min-h-screen">
	<div class="loading loading-spinner loading-lg text-primary"></div>
</div>
