package cz.moneta.test.dsl.newib.documents;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.mainpage.DashboardPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.newib.documents.DocumentsModalPage.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Wait(value = {DOCUMENTS_TITLE_XPATH, FILTER_BTN_XPATH, LOAD_MORE_DOCUMENTS_BUTTON_XPATH, DOWNLOAD_BUTTON_XPATH, INFO_TEXT_XPATH}, waitSecondsForElement = 30)
public interface DocumentsModalPage extends NewIbPageFlow<DocumentsModalPage>, StoreAccessor {

    String DOCUMENTS_TITLE_XPATH = "//h1[@class='t-title t-title--h3 u-mb--0'][text()='Dokumenty']";
    String FILTER_BTN_XPATH = "//button[@data-testid='show-filter-button' and text()='Podrobné hledání']";
    String CLOSE_BTN_XPATH = "//button[@data-testid='close-documents-button']";
    String DOCUMENT_NAME_XPATH = "//span[@data-testid='TextComponent' and text()='%s']";
    String LOAD_MORE_DOCUMENTS_BUTTON_XPATH = "//button[@data-testid='load-more-documents' and text()='Zobrazit 10 dalších dokumentů']";
    String DOWNLOAD_BUTTON_XPATH = "//button[@data-testid='Button' and text()='Stáhnout']";
    String INFO_TEXT_XPATH = "//p[@data-testid='TextComponent' and contains(., 'Základní Produktové podmínky, speciální Produktové podmínky, Sazebník, Úrokový lístek, Reklamační řád a ') and contains(., 'další smluvní dokumenty najdete na našem webu')]";
    String LINK_XPATH = "//a[@href='https://www.moneta.cz/dokumenty-ke-stazeni']";
    String OPEN_DOCUMENT_TITLE_XPATH = "//h1[@class='t-title t-title--h3 u-mb--0' and text()='Záznam o podané reklamaci/stížnosti']";
    String PRINT_BUTTON_XPATH = "//button[@aria-label='Vytisknout']";
    String OPEN_DOCUMENT_DOWNLOAD_BUTTON_XPATH = "//button[@aria-label='Stáhnout']";

    @CheckElementPresent(DOCUMENTS_TITLE_XPATH)
    DocumentsModalPage checkDocumentsTitleIsPresent();

    @CheckElementPresent(FILTER_BTN_XPATH)
    DocumentsModalPage checkFilterBtnIsPresent();

    @CheckElementPresent(CLOSE_BTN_XPATH)
    DocumentsModalPage checkCloseBtnIsPresent();

    @CustomAction
    default DocumentsModalPage checkUrl() {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        String actualUrl = newIbEndpoint.getCurrentUrl();
        String urlContains = "modal/documents";
        assertTrue(actualUrl.contains(urlContains));
        return null;
    }

    @Click(CLOSE_BTN_XPATH)
    DashboardPage closeDocumentsModal();

    @CheckElementPresent(value = DOCUMENT_NAME_XPATH, isStringDynamicXpath = true)
    DocumentsModalPage checkDocumentName(String documentName);

    @Click(LINK_XPATH)
    DocumentsModalPage clickOnLink();

    @Click(value = DOCUMENT_NAME_XPATH, isStringDynamicXpath = true)
    DocumentsModalPage clickOnDocument(String documentName);

    @CheckElementPresent(OPEN_DOCUMENT_TITLE_XPATH)
    DocumentsModalPage checkOpenDocumentTitle();

    @CheckElementPresent(PRINT_BUTTON_XPATH)
    DocumentsModalPage checkPrintButton();

    @CheckElementPresent(OPEN_DOCUMENT_DOWNLOAD_BUTTON_XPATH)
    DocumentsModalPage checkDownloadButton();
}
