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

export class ToCheckSellerProfileReview {
    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 SellerReviewSectionGoto() {
        await this.page.goto("seller/seller-reviews");
    }

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

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

        await this.page.waitForTimeout(2000);

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