package cz.moneta.test.dsl.forte.pages.branches;

import cz.moneta.test.dsl.forte.FortePageFlow;
import cz.moneta.test.dsl.forte.components.BranchesMenu;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.forte.pages.branches.DocumentsListPage.PAGE_TITLE;

@Wait(PAGE_TITLE)
public interface DocumentsListPage extends FortePageFlow<DocumentsListPage>, BranchesMenu {

    String PAGE_TITLE = CONTENT_DIV + "//h3[starts-with(text(), 'Přehled dokumentů pobočky')]";
    String ADD_PHOTO_OR_DOCUMENT_LINK = CONTENT_DIV + "//a[@title='Vytvořit nový záznam']//span[@class='icon-container']";
    String NEW_FORM = "//form[@id='frm-newItemForm-newItemForm']";
    String NEW_RECORD_NAME_INPUT = NEW_FORM + "//input[@name='name']";
    String NEW_RECORD_ADD_BUTTON = NEW_FORM + "//input[@name='add']";
    String NEW_RECORD_FILE_UPLOAD = NEW_FORM + "//input[@name='file']";
    String DOCUMENT_NAME = CONTENT_DIV + "//table[@class='datagrid']//tbody//tr//span[text()='%s']";
    String REMOVE_LAST_DOCUMENT_LINK = "//table[@class='datagrid']//tr[last()]//a[@title='Smazat záznam']//span[@class='icon-container']";

    String YES_BUTTON = "//form[@id='frm-confirmForm-confirmationDialogForm']//button[@name='yes']";

    @Click(value = ADD_PHOTO_OR_DOCUMENT_LINK, andWait = @Wait(NEW_RECORD_NAME_INPUT))
    DocumentsListPage clickAddNewPhotoDocument();

    @TypeInto(NEW_RECORD_NAME_INPUT)
    DocumentsListPage fillRecordName(String name);

    @FileUpload(NEW_RECORD_FILE_UPLOAD)
    DocumentsListPage uploadDocument(String documentPath);

    @Click(value = NEW_RECORD_ADD_BUTTON, andWait = @Wait(value = SPINNER, until = Until.GONE, by = Lookup.ID))
    DocumentsListPage clickAddButton();

    @CheckElementPresent(value = DOCUMENT_NAME, isStringDynamicXpath = true)
    DocumentsListPage checkDocumentPresence(String documentName);

    @Click(value = REMOVE_LAST_DOCUMENT_LINK, andWait = @Wait(YES_BUTTON))
    DocumentsListPage clickRemoveLastDocument();

    @Click(value = YES_BUTTON, andWait = @Wait(value = SPINNER, until = Until.GONE, by = Lookup.ID))
    DocumentsListPage clickYes();

}