package cz.moneta.test.dsl.ufo.banka.pages.cards.debit;

import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
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.auto.smartauto.shared.CommonElements.LOADER_DIV;
import static cz.moneta.test.dsl.ufo.banka.pages.cards.debit.PLK003_S002_BlockMenu.BLOCK_MENU_PAGE_LABEL_XPATH;

@Wait(value = BLOCK_MENU_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
public interface PLK003_S002_BlockMenu extends WebFlow<PLK003_S002_BlockMenu>, StoreAccessor {

    String BLOCK_MENU_PAGE_LABEL_XPATH = "//div[text()='PLK003_S002']";
    String TEMPORARILY_BLOCK_RADIO = "PLK003_S002_R001_25";
    String OWNER_OF_CARD_RADIO = "PLK003_S002_R002_1";
    String BLOCK_DATE_INPUT = "PLK003_S002_E002";
    String BLOCK_TIME_INPUT = "PLK003_S002_E004";
    String TELL_NUM_INPUT = "PLK003_S002_E006";
    String PRINT_BUTTON = "PLK003_S002_B002";
    String SAVE_BUTTON = "PLK003_S002_B003";
    String REAL_DATE = "XXX001_T001_L002";
    String LOST_REPORT = "PLK003_S002_R001_13";
    String DESCRIPTION = "PLK003_S002_V004";
    String CITY = "PLK003_S002_E005";

    @Click(TEMPORARILY_BLOCK_RADIO)
    PLK003_S002_BlockMenu clickTemporarilyBLock();

    @Click(LOST_REPORT)
    PLK003_S002_BlockMenu clickLostReport();

    @Click(OWNER_OF_CARD_RADIO)
    PLK003_S002_BlockMenu clickOwner();

    @CustomAction
    default PLK003_S002_BlockMenu fillDate() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.type(() -> BLOCK_DATE_INPUT, endpoint.getText(REAL_DATE), false);
        return null;
    }

    @TypeInto(BLOCK_TIME_INPUT)
    PLK003_S002_BlockMenu fillTime(String time);

    @TypeInto(CITY)
    PLK003_S002_BlockMenu fillCity(String city);

    @TypeInto(DESCRIPTION)
    PLK003_S002_BlockMenu fillDescription(String description);

    @TypeInto(value = TELL_NUM_INPUT, andWait = @Wait(value = LOADER_DIV, by = Lookup.XPATH, until = Until.GONE))
    PLK003_S002_BlockMenu fillTellNum(String tellNum);

    @CustomAction
    default PLK003_S002_BlockMenuTransitions clickPrintToSignerPageWithPossibleAlert() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> PRINT_BUTTON);
        if (endpoint.isAlertPresent(3)) {
            endpoint.acceptAlert(3);
            endpoint.waitForElementsToLoad(5, Lookup.CLASSNAME, Until.GONE, SharedElements.LOAD_IMG_DIV_CLASS);
            endpoint.click(() -> PRINT_BUTTON);
        }
        return null;
    }

    @Click(SAVE_BUTTON)
    @DismissAlert(waitSecondsForAlert = 3)
    HPO009_S001_DebitCardDetailPage clickSave();
}
