import {Then, When} from "@cucumber/cucumber";
import handleModal from "../helpers/framework-helpers/action/handleModal";
import setPromptText from "../helpers/framework-helpers/action/setPromptText";
import checkModal from "../helpers/framework-helpers/check/checkModal";
import checkModalText from "../helpers/framework-helpers/check/checkModalText";

When(/^I (accept|dismiss) the (alertbox|confirmbox|prompt)$/, async (action: 'accept' | 'dismiss', modalType: 'alertbox' | 'confirmbox' | 'prompt') => {
    console.log(`I ${action} the ${modalType}`);
    await handleModal(action);
});

When(/^I enter "([^"]*)?" into the alert prompt$/, async (promptText: string) => {
    console.log(`I enter ${promptText} into the alert prompt`);
    await setPromptText(promptText);
});

Then(/^I expect that a (alertbox|confirmbox|prompt) is( not)? opened$/, async (modalType: 'alertbox' | 'confirmbox' | 'prompt', falseCase: boolean) => {
    console.log(`I expect that a ${modalType} is ${falseCase ? 'not' : ''} opened `);
    await checkModal(falseCase);
});

Then(/^I expect that a (alertbox|confirmbox|prompt)( not)? contains the text "([^"]*)?"( ignoring-case)?$/, async (modalType: 'alertbox' | 'confirmbox' | 'prompt', falseCase: boolean, expectedText: string, ignoreCase: boolean) => {
    console.log(`I expect that a ${modalType} ${falseCase ? 'not' : ''} contains the text ${ignoreCase ? 'ignoring case' : ''}`);
    await checkModalText(falseCase, expectedText, ignoreCase);
});
