package cz.moneta.test.dsl.ufo.banka.pages.main.client.settings;

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.banka.pages.main.client.settings.VDB001_S001_SecondBankerJoiningPage.PAGE_LAYOUT_DIV;
import static cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.VDB001_S001_SecondBankerJoiningPage.VDB001_S001_PAGE_LABEL_XPATH;
import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;
import static cz.moneta.test.harness.support.web.Lookup.XPATH;

@Wait(value = VDB001_S001_PAGE_LABEL_XPATH, by = XPATH, waitSecondsForElement = 60)
@Wait(value = PAGE_LAYOUT_DIV, waitSecondsForElement = 60)
public interface VDB001_S001_SecondBankerJoiningPage extends WebFlow<VDB001_S001_SecondBankerJoiningPage>, StoreAccessor {
    String VDB001_S001_PAGE_LABEL_XPATH = "//div[text()='VDB001_S001']";
    String PAGE_LAYOUT_DIV = "VDB001_S001_X003";
    String SURNAME_INPUT = "VDB001_S001_E002";
    String SEARCH_BANKER_BUTTON = "VDB001_S001_P002";
    String BANKER_LIST_LAYOUT_DIV = "VDB001_S001_X001";
    String BANKER_GENERAL_RADIO_BY_USERNAME_XPATH = "//table[@id='VDB001_S001_G001_UfoTable']//td[contains(text(), '%s')]//ancestor::tr//input[@name='VDB001_S001_G001']";
    String CONTINUE_BUTTON = "VDB001_S001_B001";
    String FIRST_NAME_RADIO = "VDB001_S001_G001-0";

    @TypeInto(SURNAME_INPUT)
    VDB001_S001_SecondBankerJoiningPage fillSurnameInput(String surname);

    @Click(value = SEARCH_BANKER_BUTTON, andWait = @Wait(BANKER_LIST_LAYOUT_DIV))
    VDB001_S001_SecondBankerJoiningPage clickSearchButton();

    @CustomAction
    default VDB001_S001_SecondBankerJoiningPage selectBankerByLogin(String bankerUsername) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> String.format(BANKER_GENERAL_RADIO_BY_USERNAME_XPATH, bankerUsername), XPATH);
        return null;
    }

    @Click(value = SEARCH_BANKER_BUTTON,
            andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    VDB001_S001_SecondBankerJoiningPage clickSearch();

    @Click(value = FIRST_NAME_RADIO, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    VDB001_S001_SecondBankerJoiningPage selectFirstName();

    @Click(CONTINUE_BUTTON)
    VDB001_S001_SecondBankerJoiningPageTransitions clickContinue();

}
