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

test.describe('visual regression', () => {
    test('home page matches snapshot', async ({ page }) => {
        await page.goto('/');
        await expect(page).toHaveTitle(/mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('home.png', { fullPage: true });
    });

    test('services page matches snapshot', async ({ page }) => {
        await page.goto('/services');
        await expect(page).toHaveTitle(/SaaS Architecture Services | mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/services');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('services.png', { fullPage: true });
    });

    test('services/hands-on-saas-architecture-consultant page matches snapshot', async ({ page }) => {
        await page.goto('/services/hands-on-saas-architecture-consultant');
        await expect(page).toHaveTitle(/SaaS Product Architecture Consultant | mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('#faq')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/services/hands-on-saas-architecture-consultant');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('services-hands-on-saas-architecture-consultant.png', { fullPage: true });
    });

    test('services/mvp-architecture-and-launch page matches snapshot', async ({ page }) => {
        await page.goto('/services/mvp-architecture-and-launch');
        await expect(page).toHaveTitle(/MVP Architecture & Launch Consultant | mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('#faq')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/services/mvp-architecture-and-launch');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('services-mvp-architecture-and-launch.png', { fullPage: true });
    });

    test('services/fractional-cto-for-early-stage-saas page matches snapshot', async ({ page }) => {
        await page.goto('/services/fractional-cto-for-early-stage-saas');
        await expect(page).toHaveTitle(/Fractional CTO for Early-Stage SaaS | mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('#faq')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/services/fractional-cto-for-early-stage-saas');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('services-fractional-cto-for-early-stage-saas.png', { fullPage: true });
    });

    test('services/stage-aligned-infrastructure page matches snapshot', async ({ page }) => {
        await page.goto('/services/stage-aligned-infrastructure');
        await expect(page).toHaveTitle(/Startup Infrastructure Strategy | mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('#faq')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/services/stage-aligned-infrastructure');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('services-stage-aligned-infrastructure.png', { fullPage: true });
    });

    test('privacy policy page matches snapshot', async ({ page }) => {
        await page.goto('/privacy-policy');
        await expect(page).toHaveTitle(/Privacy Policy | mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/privacy-policy');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('privacy-policy.png', { fullPage: true });
    });

    test('terms of service page matches snapshot', async ({ page }) => {
        await page.goto('/terms-of-service');
        await expect(page).toHaveTitle(/Terms of Service | mifi Ventures/);
        await expect(page.locator('h1')).toBeVisible();
        await expect(page.locator('#main')).toBeVisible();
        await expect(page.locator('.footer')).toBeVisible();
        await expect(page.locator('#cookie-banner')).toBeVisible();

        await page.evaluate(() => {
            localStorage.setItem('mifi-ventures-cookie-consent', 'reject');
        });

        await page.goto('/terms-of-service');
        await expect(page.locator('#cookie-banner')).not.toBeVisible();
        await expect(page).toHaveScreenshot('terms-of-service.png', { fullPage: true });
    });

    test('404 page matches snapshot', async ({ page }) => {
        await page.goto('/404');
        await expect(page).toHaveTitle(/404 | mifi Ventures/);
        await expect(page).toHaveScreenshot('404.png', { fullPage: true });
    });

    test('410 page matches snapshot', async ({ page }) => { 
        await page.goto('/410');
        await expect(page).toHaveTitle(/410 | mifi Ventures/);
        await expect(page).toHaveScreenshot('410.png', { fullPage: true });
    });
});
