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

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

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

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

    async enableRMA() {
        await this.adminRMAConfigurationgoto();
        const status = await this.page.locator('label > div').first();
        if (!(await status.isChecked())) {
            await status.click();
        }
    }

    async fillRMAConfigurationDetails(
        policy_text: "Return Policy Text",
        return_window: string,
    ) {
        await this.enableRMA();
        await this.page.fill(
            'textarea[name="marketplace[rma][setting][policy_text]"]',
            policy_text
        );
        

        await this.page.click(
            '//button[contains(.," Save Configuration ")]'
        );

        await expect(this.page.getByText('Configuration saved successfully').first()).toBeVisible();
        // await this.page.waitForTimeout(2000);

        // await expect(this.page.locator('(//p[contains(.," Marketplace")])[1]')).toBeVisible();
    }
}
