import { test, expect } from './helpers/fixtures.js'

test.describe('Member dashboard', () => {
  test('dashboard loads for authenticated user', async ({ adminPage }) => {
    await adminPage.goto('/member/dashboard')

    // Welcome heading includes the member's name (inside ClientOnly, may take time)
    await expect(adminPage.getByText('Welcome back')).toBeVisible({ timeout: 15000 })
  })

  test('shows navigation links', async ({ adminPage }) => {
    await adminPage.goto('/member/dashboard')

    // Wait for ClientOnly dashboard content to render
    await expect(adminPage.getByText('Welcome back')).toBeVisible({ timeout: 15000 })

    // Verify quick action links are present
    await expect(adminPage.getByText('Update your profile')).toBeVisible()
    await expect(adminPage.getByText('Browse members')).toBeVisible()
    await expect(adminPage.getByText('Manage account')).toBeVisible()
  })

  test('unauthenticated shows sign-in prompt', async ({ browser }) => {
    const context = await browser.newContext()
    const page = await context.newPage()

    await page.goto('/member/dashboard')

    // Should show the login modal or the page's sign-in required state
    await expect(
      page.locator('.modal-title').or(page.getByText('Sign in required')).first()
    ).toBeVisible({ timeout: 10000 })

    await context.close()
  })
})
