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

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

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

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

  get descriptionInput() {
    return this.page.getByLabel("Description");
  }

  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; description?: string }) {
    if (fields.name) await this.nameInput.fill(fields.name);
    if (fields.description) await this.descriptionInput.fill(fields.description);
  }
}
