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

test.describe('Member profile page', () => {
  test('profile page loads', async ({ adminPage }) => {
    await adminPage.goto('/member/profile')
    await expect(adminPage.getByText('Edit Profile')).toBeVisible()
    await expect(adminPage.getByText('How you appear to other members')).toBeVisible()
  })

  test('form fields are present', async ({ adminPage }) => {
    await adminPage.goto('/member/profile')

    // Name input
    await expect(adminPage.locator('input[placeholder="Your name"]')).toBeVisible()

    // Bio textarea
    await expect(adminPage.locator('textarea[placeholder*="Share your background"]')).toBeVisible()

    // Save button
    await expect(adminPage.getByRole('button', { name: 'Save Profile' })).toBeVisible()
  })

  test('bio field accepts input', async ({ adminPage }) => {
    await adminPage.goto('/member/profile')

    const bio = adminPage.locator('textarea[placeholder*="Share your background"]')
    const saveBtn = adminPage.getByRole('button', { name: 'Save Profile' })

    // Save button should start disabled (no changes yet)
    await expect(saveBtn).toBeDisabled()

    // Clear and type new text
    await bio.clear()
    await bio.fill('Game designer exploring cooperative structures')

    // Save button should now be enabled
    await expect(saveBtn).toBeEnabled()
  })

  test('pronouns field editable', async ({ adminPage }) => {
    await adminPage.goto('/member/profile')

    const pronouns = adminPage.locator('input[placeholder="e.g., she/her, they/them"]')
    await expect(pronouns).toBeVisible()

    await pronouns.clear()
    await pronouns.fill('they/them')

    await expect(pronouns).toHaveValue('they/them')
  })
})
