package cz.moneta.test.dsl.monetaportal.savings.childbuildingsavings;

import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.monetaportal.savings.childbuildingsavings.PersonalAddressPage.PAGE_HEADER;
import static cz.moneta.test.dsl.monetaportal.savings.childbuildingsavings.PersonalAddressPage.EMAIL_WITH_VALUE;

@Waits({@Wait(PAGE_HEADER), @Wait(EMAIL_WITH_VALUE)})
public interface PersonalAddressPage extends ChildBuildingSavingsPageFlow<PersonalAddressPage> {
    String PAGE_HEADER = "//h2[text()='Máme správně Vaše kontaktní údaje?']";
    String EMAIL_WITH_VALUE = "//input[@id='email' and string-length(@value) > 0]";
    String CONTACT_SAME_AS_PERMANENT = "//*[@id='contactSameAsPermanent']";

    @CustomAction
    default PersonalAddressPage setContactSameAsPermanent(boolean isContactSameAsPermanent) {
        NewIbEndpoint ep = getEndpoint(NewIbEndpoint.class);
        boolean isChecked = ep.getAttribute(CONTACT_SAME_AS_PERMANENT, "value").equals("true");
        if (isContactSameAsPermanent != isChecked) ep.jsClick(() -> CONTACT_SAME_AS_PERMANENT, Lookup.XPATH);
        return null;
    }

    @Click(CONTINUE_BUTTON)
    ContinueOnMobilePage clickContinue();
}
