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

export class UserEditFormPage {
  private page: Page;
  constructor(page: Page) {
    this.page = page;
  }

  async goto(id: string) {
    await this.page.goto(`/user-management/user/${id}/edit`);
  }

  get nameInput() {
    return this.page.getByLabel("Name");
  }

  get emailInput() {
    return this.page.getByLabel("Email");
  }

  get submitButton() {
    return this.page.getByRole("button", { name: /save|update/i });
  }

  get cancelButton() {
    return this.page.getByRole("button", { name: /cancel/i });
  }

  async fill(fields: { name?: string; email?: string }) {
    if (fields.name) await this.nameInput.fill(fields.name);
    if (fields.email) await this.emailInput.fill(fields.email);
  }
}
