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

import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
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.main.DOK001_S001_SelectionOfSubmittedDocumentsPage.DOCUMENTS_CHECK_BUTTON;
import static cz.moneta.test.dsl.ufo.banka.pages.main.DOK001_S001_SelectionOfSubmittedDocumentsPage.DOK001_S001_PAGE_LABEL_XPATH;

@Wait(value = DOK001_S001_PAGE_LABEL_XPATH, waitSecondsForElement = 60, by = Lookup.XPATH)
@Wait(DOCUMENTS_CHECK_BUTTON)
public interface DOK001_S001_SelectionOfSubmittedDocumentsPage extends WebFlow<DOK001_S001_SelectionOfSubmittedDocumentsPage>, DOK001_S001_SelectionOfSubmittedDocumentsTransitions, StoreAccessor {

    String DOK001_S001_PAGE_LABEL_XPATH = "//div[text()='DOK001_S001']";
    String ID_CARD_RADIO = "DOK001_S001_G001-0";
    String PASSPORT_RADIO = "DOK001_S001_G002-0";
    String DRIVER_LICENSE_RADIO = "DOK001_S001_G002-1";
    String DOCUMENTS_CHECK_BUTTON = "DOK001_S001_B004";
    String ENABLED_CONTINUE_BUTTON_XPATH = "//button[@id='DOK001_S001_B001' and not(@disabled)]";
    String CONTINUE_BUTTON = "DOK001_S001_B001";
    String EDIT_CIF_BUTTON = "DOK001_S001_B002";

    @Click(ID_CARD_RADIO)
    DOK001_S001_SelectionOfSubmittedDocumentsPage selectIdCardRadio();

    @Click(value = PASSPORT_RADIO, andWait = @Wait(value = DOCUMENTS_CHECK_BUTTON, until = Until.CLICKABLE))
    DOK001_S001_SelectionOfSubmittedDocumentsPage selectPassportRadio();

    @Click(value = DRIVER_LICENSE_RADIO, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    DOK001_S001_SelectionOfSubmittedDocumentsPage selectDriverLicenceRadio();

    @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE)
    @Click(value = DOCUMENTS_CHECK_BUTTON, jsClick = true, andWait = @Wait(value = ENABLED_CONTINUE_BUTTON_XPATH, by = Lookup.XPATH))
    DOK001_S001_SelectionOfSubmittedDocumentsPage clickDocumentsCheckButton();

    @Wait(CONTINUE_BUTTON)
    @Click(value = CONTINUE_BUTTON, jsClick = true)
    DOK001_S001_SelectionOfSubmittedDocumentsTransitions clickContinue();

    @CustomAction
    default DOK001_S001_SelectionOfSubmittedDocumentsTransitions clickDocumentsCheckAndContinue() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(30, Lookup.CLASSNAME, Until.GONE, SharedElements.LOAD_IMG_DIV_CLASS);
        endpoint.click(() -> DOCUMENTS_CHECK_BUTTON);
        endpoint.waitForElementsToLoad(30, Lookup.CLASSNAME, Until.GONE, SharedElements.LOAD_IMG_DIV_CLASS);
        endpoint.waitForElementsToLoad(45, Until.VISIBLE, CONTINUE_BUTTON);
        endpoint.checkElementContent(DOCUMENTS_CHECK_BUTTON, "Kontrola OK");
        endpoint.click(() -> CONTINUE_BUTTON);
        return null;
    }
}
