import { Locator, Page, expect } from "@playwright/test";
import { WebAllLocators } from "../locator";

export class SellerProfileReviewByCustomer {
    readonly page: Page;
    readonly locators: WebAllLocators;

    constructor(page: Page) {
        this.page = page;
        this.locators = new WebAllLocators(page);
    }
    
    async sellerProfileReviewByCustomer(review_star: number, title: string, comments: string) {
        await this.locators.profileReviewTabButton.click();
        await this.page.waitForTimeout(2000);
        
        await this.locators.writeAReviewButton.click();

        await this.page.waitForTimeout(2000);
        await this.locators.reviewRating.nth(review_star).click();
        await this.page.waitForTimeout(2000);

        await this.locators.writeAReviewTitle.fill(title);

        await this.locators.writeAReviewComments.fill(comments);

        await this.locators.submitProfileReviewButton.click();

        await this.page.waitForTimeout(2000);

        const profile_review_already_given = await this.page.locator("text=You have already reviewed this seller").first();

        if (await profile_review_already_given.isVisible()) {
            await expect(profile_review_already_given).toBeVisible();
        } else {
            await expect(this.locators.profileReviewSuccessToast).toBeVisible(); 
        }
    }
}
