package cz.moneta.test.dsl.ib.welcome;

import cz.moneta.test.dsl.ib.IbPageFlow;
import cz.moneta.test.dsl.ib.doidentifikace.ConfirmPageAnotherPerson;
import cz.moneta.test.dsl.ib.doidentifikace.IdentityCardPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.IbEndpoint;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.ib.welcome.LoginToBankModalPage.CLOSE_ICON;
import static cz.moneta.test.dsl.ib.welcome.LoginToBankModalPage.MODAL_WINDOW_ID;
import static cz.moneta.test.harness.support.web.Until.VISIBLE;

@Wait(value = {MODAL_WINDOW_ID, CLOSE_ICON}, until = VISIBLE)
public interface LoginToBankModalPage extends IbPageFlow<LoginToBankModalPage>, StoreAccessor {
    String MODAL_WINDOW_ID = "//div[@testid='safety-rules-container']";
    String CLOSE_ICON = "//div[@testid='close-icon']";
    String CLOSE_AND_HIDE_BUTTON = "//span[@testid='close-and-hide-button']";
    String CHECKBOX_PERSON = "//div[@aria-checked]";
    String CONFIRM_BUTTON = "//button[@testid='handle-agree-button']";
    String NEED_HELP_TEXT_SPAN = "//span[contains(text(), 'Potřebujete poradit?')]"; //FIXME
    String ANOTHER_PERSON_BUTTON = "//span[contains(text(), 'Jsem někdo jiný')]"; //FIXME
    String GO_DASHBOARD_BUTTON = "//span[@testid='go-to-dashboard-button']";

    @Click(value = CLOSE_ICON, jsClick = true)
    @Click(value = CLOSE_AND_HIDE_BUTTON, andWait = @Wait(value = MODAL_WINDOW_ID, until = Until.GONE))
    WelcomePage closeModal();

    @CustomAction
    default IdentityCardPage clickCheckboxAndConfirm() {
        IbEndpoint endpoint = getEndpoint(IbEndpoint.class);
        endpoint.moveToElement(NEED_HELP_TEXT_SPAN);
        endpoint.click(() -> CHECKBOX_PERSON);
        endpoint.click(() -> CONFIRM_BUTTON);
        return null;
    }

    @CustomAction
    default ConfirmPageAnotherPerson clickAnotherPerson() {
        IbEndpoint endpoint = getEndpoint(IbEndpoint.class);
        endpoint.moveToElement(NEED_HELP_TEXT_SPAN);
        endpoint.click(() -> ANOTHER_PERSON_BUTTON);
        //endpoint.click(() -> GO_DASHBOARD_BUTTON);
        return null;
    }
}
