package cz.moneta.test.dsl.hypos.pages.contract.documents;

import cz.moneta.test.dsl.hypos.components.Menu;
import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.hypos.pages.contract.documents.DocumentsPage.PAGE_TITLE;
import static cz.moneta.test.dsl.hypos.pages.contract.documents.DocumentsPage.DOCUMENT_LIST;

@Wait({PAGE_TITLE, DOCUMENT_LIST})
public interface DocumentsPage extends HyposPageFlow<DocumentsPage>, Menu {
    String PAGE_TITLE = "//h3[text()='Dokumenty']";
    String DOCUMENT_LIST = "//tbody[@id='doc-list-whatever']";
    String IMPORT_DOCUMENT_BUTTON = "//a[text()='IMPORT']";
    String GENERATE_LOAN_CONTRACT_LINK = "//td[text()='Úvěrová smlouva']//following::td[1]/a[text()='Volby generování']";
    String LOAN_CONTRACT_DOCUMENTS_TABLE = "//tbody[@id='doc-list-whatever']//tr[@rel='1']";
    String EXPAND_LOAN_CONTRACT_DOCUMENTS_SPAN = LOAN_CONTRACT_DOCUMENTS_TABLE + "//span[contains(text(),'Úvěrová smlouva')]";
    String SIGN_LOAN_CONTRACT_DOCUMENTS_BUTTON = LOAN_CONTRACT_DOCUMENTS_TABLE + "//following::input[@value='Podepsat']";
    String HYPOKALKULACKA_DOCUMENTS_BUTTON = "//form//span[contains(text(), 'Hypokalkulačka')]";
    String DOC_DRAFT_SELECTED_CHECKBOX = "//a[contains(text(),'%s')]//following::input[contains(@class,'selectedDocs')][1]";
    String DELETE_SELECTED_BUTTON = "//button[@id='deleteConfirm']";
    String DELETE_SELECTED_CONFIRM_BUTTON = "//div[@id='deleteComment']//button[text()='Smazat']";

    @Click(IMPORT_DOCUMENT_BUTTON)
    DocumentImportPage clickImportDocuments();

    @Click(HYPOKALKULACKA_DOCUMENTS_BUTTON)
    DocumentsPage clickHypokalkulackaDocuments();

    @Click(GENERATE_LOAN_CONTRACT_LINK)
    DocumentGeneratePage clickGenerateLoanContractLink();

    @Click(EXPAND_LOAN_CONTRACT_DOCUMENTS_SPAN)
    DocumentsPage expandLoanContractDocuments();

    @Wait(SIGN_LOAN_CONTRACT_DOCUMENTS_BUTTON)
    @Click(SIGN_LOAN_CONTRACT_DOCUMENTS_BUTTON)
    DocumentSignPage clickSignContractDocuments();

    @Click(value = DOC_DRAFT_SELECTED_CHECKBOX, isStringDynamicXpath = true)
    DocumentsPage selectDraftDocument(String document);

    @Click(DELETE_SELECTED_BUTTON)
    DocumentsPage clickDeleteSelectedDocument();

    @Click(value = DELETE_SELECTED_CONFIRM_BUTTON, andWait = @Wait(value = LOADER, until = Until.GONE))
    DocumentsPage clickDeleteSelectedDocumentConfirm();
}