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

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

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

    async sellerProductSectionGoto() {
        await this.page.goto("seller/products");
    }

    async adminProductApprovalgoto() {
        await this.page.goto("admin/marketplace/products");
    }

    async adminMarketplaceConfigurationgoto() {
        await this.page.goto("admin/configuration/marketplace/settings");
    }

    async SellerProductSearchOnFront() {
        const sellerProductdetails = JSON.parse(
            fs.readFileSync("seller-simple-product-details.json", "utf-8")
        );

        await this.page.goto("");
        await this.locators.searchProductOnFront.fill(
            sellerProductdetails.product_name
        );
        await this.locators.searchProductOnFront.press("Enter");
        
        await this.page.waitForSelector(
            '//div[contains(@class, "mt-8 grid ")]/div[1]'
        );

        await this.locators.clickFirstProductOnsearchResult.click();

        await this.page.waitForTimeout(2000);
    }
}
