import { Locator, Page, expect } from "@playwright/test";
import { WebAllLocators } from "../locator";
import { sellerProductSearchonFront } from "../../pageObjects/seller/seller-product-search";

export class ToCheckSellerProductReview {
    readonly page: Page;
    readonly locators: WebAllLocators;
    readonly sellerProductSearch: sellerProductSearchonFront;

    constructor(page: Page) {
        this.page = page;
        this.locators = new WebAllLocators(page);
        this.sellerProductSearch = new sellerProductSearchonFront(page);
    }

    async SellerProductReviewSectionGoto() {
        await this.page.goto("seller/product-reviews");
    }

    async CheckSellerProductReview(
        product_name: string,
        customer_email: string
    ) {
        await this.SellerProductReviewSectionGoto();
        await this.page.waitForTimeout(2000);

        await this.locators.searchInput.fill(product_name);
        await this.locators.searchInput.press("Enter");

        await this.page.waitForTimeout(2000);

        const product_name_visible = await this.page
            .locator(`//p[contains(., "${product_name}")]`)
            .nth(0);
        if (await product_name_visible.isVisible()) {
            await expect(product_name_visible).toBeVisible();
        } else {
            await expect(product_name_visible).not.toBeVisible();
        }
    }
}
