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.CheckElementPresent;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Wait;

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

@Wait({DOCUMENTS_TITLE_XPATH, FILTER_BTN_XPATH})
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']";
    String CLOSE_BTN_XPATH = "//button[@data-testid='close-documents-button']";

    @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();
}
