package cz.moneta.test.dsl.ufo.banka.pages.main.savings.account;

import cz.moneta.test.dsl.ufo.banka.pages.fon.TIS050_S001_SignerSelectionPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import java.util.Arrays;
import java.util.List;

import static cz.moneta.test.dsl.ufo.banka.pages.main.savings.account.SPU021_S001_SavingsAccountCreatePage.CONTINUE_BUTTON;
import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

@Wait(CONTINUE_BUTTON)
public interface SPU021_S001_SavingsAccountCreatePage extends WebFlow<SPU021_S001_SavingsAccountCreatePage>, StoreAccessor {

    String SU_SPORENI = "Spoření H";
    String SU_GENIUS_CAPS = "SÚ GENIUS";
    String SU_GENIUS = "SÚ Genius";

    String CONTINUE_BUTTON = "SPU021_S001_B001";
    String FEE_PLAN_COMBO = "SPU021_S001_C001";
    String ACCOUNT_TITLE_INPUT = "SPU021_S001_E001";
    String DISPOSITION_RIGHTS_YES_RADIO = "SPU021_S001_R002_1";
    String DISPOSITION_RIGHTS_NO_RADIO = "SPU021_S001_R002_0";
    List<String> FEE_PLAN_SELECT_VALUE_PARTS = Arrays.asList(SU_SPORENI, SU_GENIUS_CAPS);
    String INTEREST_PLAN_XPATH = "//*[@id='SPU021_S001_L006' and (contains(text(),'" + SU_SPORENI + "') or contains(text(),'" + SU_GENIUS + "'))]";

    @Wait(value = INTEREST_PLAN_XPATH, by = Lookup.XPATH)
    @Wait(CONTINUE_BUTTON)
    @Click(CONTINUE_BUTTON)
    TIS050_S001_SignerSelectionPage submitPage();

    @CustomAction
    default SPU021_S001_SavingsAccountCreatePage selectFeePlan(String feePlan) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.selectByVisibleText(FEE_PLAN_COMBO, feePlan);
        endpoint.waitForElementsToLoad(2, Lookup.CLASSNAME, Until.GONE, LOAD_IMG_DIV_CLASS);
        return null;
    }

    @TypeInto(ACCOUNT_TITLE_INPUT)
    SPU021_S001_SavingsAccountCreatePage fillAccountTitle(String accountTitle);

    @Click(value = DISPOSITION_RIGHTS_YES_RADIO, jsClick = true)
    SPU021_S001_SavingsAccountCreatePage selectDispositionRadioYes();

    @Click(DISPOSITION_RIGHTS_NO_RADIO)
    SPU021_S001_SavingsAccountCreatePage clickDispositionRadioNo();

    @CustomAction
    default SPU021_S001_SavingsAccountCreatePage selectFeePlanCombo() {
        UfoEndpoint ufoEndpoint = getEndpoint(UfoEndpoint.class);
        ufoEndpoint.selectByContainingTexts(FEE_PLAN_COMBO, FEE_PLAN_SELECT_VALUE_PARTS);
        return null;
    }
}