import { test, expect } from '@playwright/test';

test.describe('Navigation and Authentication Flow', () => {
	test.describe('Landing page (/)', () => {
		test('shows landing page when not authenticated', async ({ page }) => {
			// Clear any existing session
			await page.context().clearCookies();

			await page.goto('/');

			// Should show the landing page with login button
			await expect(page.getByRole('button', { name: /se connecter/i })).toBeVisible();
			await expect(page.getByText(/bienvenue sur/i)).toBeVisible();
		});

		test('shows Score Serenite feature on landing page', async ({ page }) => {
			await page.context().clearCookies();
			await page.goto('/');

			await expect(page.getByText(/score serenite/i)).toBeVisible();
		});

		test('login button navigates to login page', async ({ page }) => {
			await page.context().clearCookies();
			await page.goto('/');

			await page.getByRole('button', { name: /se connecter/i }).click();

			await expect(page).toHaveURL(/\/login/);
		});
	});

	test.describe('Post-login redirect', () => {
		// This is already tested in login.spec.ts with proper test user setup
		// See: login.spec.ts > "logs in successfully and redirects to dashboard"
		test.skip('redirects to dashboard after successful login', async ({ page: _page }) => {
			// Covered by login.spec.ts which creates test users via Docker
		});
	});

	test.describe('Dashboard access', () => {
		test('dashboard is accessible in demo mode (no auth required for placeholder)', async ({ page }) => {
			await page.context().clearCookies();
			await page.goto('/dashboard');

			// Dashboard shows demo content without requiring auth
			// This is intentional for the placeholder story (1.9)
			await expect(page).toHaveURL(/\/dashboard/);
			// Role switcher visible (shows demo banner)
			await expect(page.getByText(/Démo - Changer de rôle/i)).toBeVisible();
		});
	});

	test.describe('Header navigation consistency', () => {
		// These tests require authentication - skip if no test user available
		test.skip('dashboard header has correct navigation links', async ({ page }) => {
			// Would need authenticated session
			await page.goto('/dashboard');

			await expect(page.getByRole('link', { name: /tableau de bord/i })).toBeVisible();
			await expect(page.getByRole('link', { name: /parametres/i })).toBeVisible();
			await expect(page.getByRole('button', { name: /deconnexion/i })).toBeVisible();
		});

		test.skip('settings header has correct navigation links', async ({ page }) => {
			// Would need authenticated session
			await page.goto('/settings');

			await expect(page.getByRole('link', { name: /tableau de bord/i })).toBeVisible();
			await expect(page.getByRole('link', { name: /parametres/i })).toBeVisible();
			await expect(page.getByRole('button', { name: /deconnexion/i })).toBeVisible();
		});

		test.skip('clicking logo navigates to dashboard', async ({ page }) => {
			// Would need authenticated session
			await page.goto('/settings');

			await page.getByText('Classeo').click();

			await expect(page).toHaveURL(/\/dashboard/);
		});
	});
});

test.describe('Dashboard Demo Features', () => {
	test.describe('Role switcher (demo mode)', () => {
		test.skip('can switch between roles', async ({ page }) => {
			// Would need authenticated session
			await page.goto('/dashboard');

			// Check role switcher is visible
			await expect(page.getByText(/demo.*changer de role/i)).toBeVisible();

			// Switch to teacher
			await page.getByRole('button', { name: /enseignant/i }).click();
			await expect(page.getByText(/tableau de bord enseignant/i)).toBeVisible();

			// Switch to student
			await page.getByRole('button', { name: /eleve/i }).click();
			await expect(page.getByText(/mon espace/i)).toBeVisible();

			// Switch to admin
			await page.getByRole('button', { name: /admin/i }).click();
			await expect(page.getByText(/administration/i)).toBeVisible();

			// Switch back to parent
			await page.getByRole('button', { name: /parent/i }).click();
			await expect(page.getByText(/score serenite/i)).toBeVisible();
		});
	});

	test.describe('Serenity Score Preview', () => {
		test.skip('displays demo badge', async ({ page }) => {
			// Would need authenticated session
			await page.goto('/dashboard');

			await expect(page.getByText(/donnees de demonstration/i)).toBeVisible();
		});

		test.skip('opens explainer modal on click', async ({ page }) => {
			// Would need authenticated session
			await page.goto('/dashboard');

			// Click on serenity score card
			await page.getByRole('button', { name: /score serenite/i }).click();

			// Modal should appear
			await expect(page.getByText(/comment fonctionne le score serenite/i)).toBeVisible();
		});
	});
});
