package cz.moneta.test.dsl.ufo.operations.shared;

import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
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.operations.shared.PrintAppPage.APPLICATION_LOADER;
import static cz.moneta.test.dsl.ufo.operations.shared.PrintAppPage.EDITOR_PAGE_DIV;
import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

@Wait(EDITOR_PAGE_DIV)
@Wait(value = APPLICATION_LOADER, until = Until.GONE)
public interface PrintAppPage extends WebFlow<PrintAppPage>, StoreAccessor {

    String EDITOR_PAGE_DIV = "editor-page";
    String OK_BUTTON = "approveButton";
    String APPLICATION_LOADER = "application_loader";
    String COMPLETED_DIV_XPATH = "//div[@class='bb-app-header-btn-title bb-titleForActionButtonLeftPaddingStyle bb-titleForActionButtonRightPaddingStyle bb-titleSmallFontStyle bb-titleStyleSemiBold' and text()='Dokončeno']";
    String HISTORY_DIV = "approval-history";

    @Click(value = OK_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    PrintAppPage clickOk();

    @Click(value = COMPLETED_DIV_XPATH, by = Lookup.XPATH, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    PrintAppPage clickComplete();

    @CheckElementContent(HISTORY_DIV)
    PrintAppPage assertHistory(String history);

    @CustomAction
    default STS701_S002_ClientDetailPage switchToModalWindowByTitle(String title) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.closeCurrentWindow();
        endpoint.switchToWindowByTitle(title);
        return null;
    }
}