import { type Page } from '@playwright/test';

/**
 * Walk the guided creation wizard and land on the new character's sheet.
 * Uses the default class; selects the minimum required trained skills.
 */
export async function createCharacter(page: Page, name: string): Promise<void> {
  await page.getByRole('button', { name: '+ New character' }).first().click();
  await page.getByLabel('Name').fill(name);
  await page.getByRole('button', { name: 'Next' }).click(); // → Abilities (standard array is valid by default)
  await page.getByRole('button', { name: 'Next' }).click(); // → Skills

  const next = page.getByRole('button', { name: 'Next' });
  const boxes = page.locator('input[type="checkbox"]');
  const count = await boxes.count();
  for (let i = 0; i < count; i++) {
    if (!(await next.isDisabled())) break;
    await boxes.nth(i).check();
  }
  await next.click(); // → Review
  await page.getByRole('button', { name: 'Create character' }).click();
}
