import { test, expect } from '@playwright/test';
import { BASE_URL, ADMIN, USER, loginAs } from '../helpers';

test.describe('WFBO Access', () => {

    test('non-admin cannot see WFBO dashboard content', async ({ page }) => {
        await loginAs(page, USER.mobile, USER.password);
        await page.goto(`${BASE_URL}/wfbo`);

        // Authenticated user without ROLE_ADMIN gets a 403 — sidebar must not appear
        await expect(page.locator('[data-testid="wfbo-sidebar"]')).not.toBeVisible();
    });

    test('admin can access WFBO dashboard', async ({ page }) => {
        await loginAs(page, ADMIN.mobile, ADMIN.password);
        await page.goto(`${BASE_URL}/wfbo`);

        await expect(page).toHaveURL(`${BASE_URL}/wfbo`);
        await expect(page.locator('[data-testid="wfbo-sidebar"]')).toBeVisible();
        await expect(page.locator('[data-testid="wfbo-page-title"]')).toBeVisible();
    });

    test('WFBO sidebar has key nav links', async ({ page }) => {
        await loginAs(page, ADMIN.mobile, ADMIN.password);
        await page.goto(`${BASE_URL}/wfbo`);

        await expect(page.locator('[data-testid="wfbo-nav-dashboard"]')).toBeVisible();
        await expect(page.locator('[data-testid="wfbo-nav-users"]')).toBeVisible();
        await expect(page.locator('[data-testid="wfbo-nav-deposits"]')).toBeVisible();
    });

    test('WFBO dashboard shows stat cards', async ({ page }) => {
        await loginAs(page, ADMIN.mobile, ADMIN.password);
        await page.goto(`${BASE_URL}/wfbo`);

        await expect(page.locator('[data-testid="stat-total-users"]')).toBeVisible();
        await expect(page.locator('[data-testid="stat-pending-deposits"]')).toBeVisible();
    });

    test('navbar shows WFBO link for admin', async ({ page }) => {
        await loginAs(page, ADMIN.mobile, ADMIN.password);
        await page.click('[data-testid="navbar-user-menu"]');
        await expect(page.locator('[data-testid="nav-link-wfbo"]')).toBeVisible();
    });

});
