import { expect, test } from "../../../../setup";
import { ProductCreation } from "../../../../pages/product";
import { CreateRules } from "../../../../pages/rules";

let generatedName: string;
generatedName = `Simple-${Date.now()}`;

test.beforeEach("should create simple product", async ({ adminPage }) => {
    const productCreation = new ProductCreation(adminPage);

    await productCreation.createProduct({
        type: "simple",
        sku: `SKU-${Date.now()}`,
        name: generatedName,
        shortDescription: "Short desc",
        description: "Full desc",
        price: 199,
        weight: 1,
        inventory: 199,
    });
});

test.describe("cart rules", () => {
    test.describe("product attribute conditions", () => {
        test("should apply coupon when visible individually product condition is -> is equal to (yes)", async ({
            page,
        }) => {
            const createRules = new CreateRules(page);
            await createRules.adminlogin();
            await createRules.cartRuleCreationFlow();
            await createRules.addCondition({
                attribute: "product|visible_individually",
                operator: "==",
                optionSelect: "1",
            });
            await createRules.saveCartRule();
            await createRules.applyCoupon();
            await createRules.deleteRuleAndProduct();
        });

        // test("should apply coupon when visible individually product condition is -> is equal to (no)", async ({
        //     page,
        // }) => {
        //     const createRules = new CreateRules(page);
        //     await createRules.adminlogin();
        //     await createRules.cartRuleCreationFlow();
        //     await createRules.addCondition({
        //         attribute: "product|visible_individually",
        //         operator: "==",
        //         optionSelect: "0",
        //     });
        //     await createRules.saveCartRule();
        //     await page.goto("admin/catalog/products");
        //     await page
        //         .locator("span.cursor-pointer.icon-sort-right")
        //         .nth(1)
        //         .click();
        //     await page.waitForLoadState("networkidle");
        //     await page.locator(".peer.h-5").nth(2).click();
        //     await page
        //         .locator('button:has-text("Save Product")')
        //         .first()
        //         .click();
        //     await expect(
        //         page.getByText("Product updated successfully").first(),
        //     ).toBeVisible();
        //     await createRules.applyCoupon();
        //     await createRules.deleteRuleAndProduct();
        // });

        // test("should apply coupon when visible individually product condition is -> is not equal to (yes)", async ({
        //     page,
        // }) => {
        //     const createRules = new CreateRules(page);
        //     await createRules.adminlogin();
        //     await createRules.cartRuleCreationFlow();
        //     await createRules.addCondition({
        //         attribute: "product|visible_individually",
        //         operator: "!=",
        //         optionSelect: "1",
        //     });
        //     await createRules.saveCartRule();
        //     await createRules.applyCoupon();
        //     await createRules.deleteRuleAndProduct();
        // });

        test("should apply coupon when visible individually product condition is -> is not equal to (no)", async ({
            page,
        }) => {
            const createRules = new CreateRules(page);
            await createRules.adminlogin();
            await createRules.cartRuleCreationFlow();
            await createRules.addCondition({
                attribute: "product|visible_individually",
                operator: "!=",
                optionSelect: "0",
            });
            await createRules.saveCartRule();
            await createRules.applyCoupon();
            await createRules.deleteRuleAndProduct();
        });
    });
});
