import {CustomExpect} from "../../common-helpers/custom-expect";
import {browser, $, $$, expect} from '@wdio/globals'

/**
 * Check the text of a modal
 *                                  (alertbox, confirmbox or prompt)
 * @param  {String}   falseState    Whether to check if the text matches or not
 * @param  {String}   expectedText  The text to check against
 * @param ignoreCaseCheck
 */
// export default async function (modalType: 'alertbox' | 'confirmbox' | 'prompt', falseState: boolean, expectedText: string) {
export default async function (falseState: boolean, expectedText: string, ignoreCaseCheck = false) {
    try {
        /**
         * The text of the current modal
         * @type {String}
         */
        let modalText: string = await browser.getAlertText();
        if (ignoreCaseCheck) {
            modalText = modalText.toLowerCase();
            expectedText = expectedText.toLowerCase();
        }

        if (falseState) {
            CustomExpect.expectNotToEqual(modalText, expectedText, `Modal's expected text "${expectedText}" equals to actual text "${modalText}"`);
        } else {
            CustomExpect.expectToEqual(modalText, expectedText, `Modal's expected text "${expectedText}" is not equal to actual text "${modalText}"`);
        }
    } catch (e) {
        throw new Error(`An ALERT was not opened when it should have been opened`);
    }
};
