package cz.moneta.test.dsl.ufo.banka.pages.fon;

import cz.moneta.test.dsl.ufo.banka.pages.income.PIM001_S001_IncomeEditPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.banka.pages.fon.CRS001_S001_CommonReportingStatusPage.CONTINUE_BUTTON;
import static cz.moneta.test.dsl.ufo.banka.pages.fon.CRS001_S001_CommonReportingStatusPage.CRS001_S001_PAGE_ID_LABEL_XPATH;
import static cz.moneta.test.dsl.ufo.banka.pages.fon.CRS001_S001_CommonReportingStatusPage.CRS_CZECH_TAX_DOMICIL_BUTTON;

@Wait(value = CRS001_S001_PAGE_ID_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
@Wait(value = {CRS_CZECH_TAX_DOMICIL_BUTTON, CONTINUE_BUTTON}, waitSecondsForElement = 60)
public interface CRS001_S001_CommonReportingStatusPage extends WebFlow<CRS001_S001_CommonReportingStatusPage>, StoreAccessor {
    String CRS001_S001_PAGE_ID_LABEL_XPATH = "//div[text()='CRS001_S001']";

    String CONTINUE_BUTTON = "CRS001_S001_B002";
    String CZECH_TAX_RESIDENCY_CELL = "//table[@id='CRS001_S001_G001_UfoTable']//td[text()='Česká republika']";
    String CRS_CZECH_TAX_DOMICIL_BUTTON = "CRS001_S001_B006";

    @Click(
            value = CRS_CZECH_TAX_DOMICIL_BUTTON,
            andWait = @Wait(value = CZECH_TAX_RESIDENCY_CELL, by = Lookup.XPATH, waitSecondsForElement = 80)
    )
    CRS001_S001_CommonReportingStatusPage confirmCzech();

    @CustomAction
    default PIM001_S001_IncomeEditPage clickContinueAndAcceptAlert() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> CONTINUE_BUTTON);
        if (endpoint.isAlertPresent(3)) {
            endpoint.acceptAlert(3);
        }
        return null;
    }
}