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

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

  async gotoCreate() {
    await this.page.goto("/user-management/user/create");
  }

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

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

  get passwordInput() {
    return this.page.getByLabel("Password");
  }

  get roleSelect() {
    return this.page.getByLabel(/role/i);
  }

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

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

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