import {Given, When} from "@cucumber/cucumber";
import setWindowSize from "../helpers/framework-helpers/action/setWindowSize";
import closeAllButFirstTab from "../helpers/framework-helpers/action/closeAllButFirstTab";
import closeLastOpenedWindow from "../helpers/framework-helpers/action/closeLastOpenedWindow";
import focusLastOpenedWindow from "../helpers/framework-helpers/action/focusLastOpenedWindow";
// import {sleep} from "@wdio/utils";
import refreshPage from "../helpers/framework-helpers/action/refreshPage";
import {browser} from "@wdio/globals";

Given(/^I have a screen that is ([\d]+) by ([\d]+) pixels$/, async (screenWidth: string, screenHeight: string) => {
    console.log(`I have a screen that is : ${screenWidth} and Height : ${screenHeight}`);
    await setWindowSize(screenWidth, screenHeight);
});

Given(/^I have closed all except the first (?:window|tab)$/, async () => {
    console.log(`I have closed all except first (window|tab)`);
    await closeAllButFirstTab();
});

When(/^I close the last opened (?:window|tab)$/, async () => {
    console.log(`I close the last opened (window|tab)`);
    await closeLastOpenedWindow();
});

When(/^I focus on the last opened (?:window|tab)$/, async () => {
    console.log(`I focus on the last opened (window|tab)`);
    await focusLastOpenedWindow();
});

When(/^I wait "([^"]*)" seconds?$/, async (waitSeconds: string) => {
    console.log(`I wait ${waitSeconds} seconds`);
    // await sleep(parseInt(waitSeconds, 10) * 1000);
    await browser.pause(parseInt(waitSeconds, 10) * 1000);
});

When(/^I refresh the page$/, async () => {
    console.log(`I refresh the page`);
    await refreshPage();
});
