import EuiDialogPage from "../pages/v10/eui-dialog.po.js"
import ElementsActions from "./element-actions.js"

export default class EuiDialogActions {

    static async openDialog() {
        let euiDialogPage = new EuiDialogPage();
        let openDialogButton = await euiDialogPage.openDialogButtonCO.element();
        await ElementsActions.checkElementExistsAndIsDisplayed(openDialogButton, 'Eui dialog', 'Open dialog button');
        await ElementsActions.clickElement(openDialogButton, 'Eui dialog', 'Open dialog button');
        await expect(await euiDialogPage.euiDialogCO.element()).toBeExisting({ wait: 1000, message: 'Eui dialog is not existing' });
        await expect(await euiDialogPage.euiDialogCO.element()).toBeDisplayed({ wait: 1000, message: 'Eui dialog is not displayed' });
    }
    static async verifyCancelButtonTranslation(language) {
        let euiDialogPage = new EuiDialogPage();
        let cancelButtonTranslated = euiDialogPage.translate('cancelBtn', language);
        let cancelButton = await euiDialogPage.euiDialogCO.dismissButton.element();
        await ElementsActions.checkElementExistsAndIsDisplayed(cancelButton, 'Eui dialog', 'Cancel dialog button');
        await expect(cancelButton).toHaveTextContaining(cancelButtonTranslated, { message: 'Cancel button is not translated' })
    }
    static async closeDialog() {
        let euiDialogPage = new EuiDialogPage();
        let cancelButton = await euiDialogPage.euiDialogCO.dismissButton.element();
        await ElementsActions.checkElementExistsAndIsDisplayed(cancelButton, 'Eui dialog', 'Cancel dialog button');
        await ElementsActions.clickElement(cancelButton, 'Eui dialog', 'Cancel dialog button');
        await expect(await euiDialogPage.euiDialogCO.element()).not.toBeDisabled({ wait: 1000, message: 'Eui dialog is displayed' });
    }
}