package cz.moneta.test.dsl.hypos.pages.hypokalkulacka;

import cz.moneta.test.dsl.hypos.pages.HyposPageFlow;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.TypeInto;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.hypos.pages.hypokalkulacka.HypokalkulackaAddressPage.ALL_ADDRESSES_EQUAL_CHECKBOX;
import static cz.moneta.test.dsl.hypos.pages.hypokalkulacka.HypokalkulackaAddressPage.SAVE_ADDRESS_BUTTON;

@Wait(value = {ALL_ADDRESSES_EQUAL_CHECKBOX, SAVE_ADDRESS_BUTTON}, until = Until.VISIBLE)
public interface HypokalkulackaAddressPage extends HyposPageFlow<HypokalkulackaAddressPage> {
    String ADDRESS_DIV_XPATH = "//div[@id='address-input']";
    String STREET_INPUT = ADDRESS_DIV_XPATH + "//input[@name='address_street']";
    String DESCRIPTIVE_NUMBER_INPUT = ADDRESS_DIV_XPATH + "//input[@name='address_descriptive_number']";
    String ORIENTATION_NUMBER_INPUT = ADDRESS_DIV_XPATH + "//input[@name='address_orientation_number']";
    String CITY_INPUT = ADDRESS_DIV_XPATH + "//input[@name='address_town']";
    String ZIP_INPUT = ADDRESS_DIV_XPATH + "//input[@name='address_post_code']";
    String ALL_ADDRESSES_EQUAL_CHECKBOX = ADDRESS_DIV_XPATH + "//input[@id='address-all-eq']";
    String SAVE_ADDRESS_BUTTON = ADDRESS_DIV_XPATH + "//input[@value='Uložit']";
    String ADDRESS_LOADER_IMG = ADDRESS_DIV_XPATH + "//img[@class='addressLoading']";
    String ZIP_LOADER_IMG = ADDRESS_DIV_XPATH + "//span[@id='address-client-name']/../..//img[@class='zipLoading' and contains(@style,'display: inline')]";
    String WHISPER_INPUT = ADDRESS_DIV_XPATH + "//input[@id='whisper']";
    String WHISPER_LOADER_IMG = "//input[@id='whisper']/following-sibling::img[contains(@style,'display: inline')]";
    String SELECT_ADDRESS_WHISPER_LINK = "(//tbody[contains(@class,'selectAddress') and not(contains(@style,'display: none'))]//a)[1]";

    @Click(value = ALL_ADDRESSES_EQUAL_CHECKBOX, andWait = @Wait(value = ADDRESS_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage clickAllAddressesEqual();

    @TypeInto(value = STREET_INPUT, clear = true, andWait = @Wait(value = ADDRESS_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage fillStreet(String street);

    @TypeInto(value = CITY_INPUT, clear = true, andWait = @Wait(value = ADDRESS_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage fillCity(String city);

    @TypeInto(value = DESCRIPTIVE_NUMBER_INPUT, clear = true, andWait = @Wait(value = ADDRESS_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage fillDescriptiveNumber(String descriptiveNumber);

    @TypeInto(value = ORIENTATION_NUMBER_INPUT, clear = true, andWait = @Wait(value = ADDRESS_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage fillOrientationNumber(String orientationNumber);

    @TypeInto(value = ZIP_INPUT, clear = true, andWait = @Wait(value = ZIP_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage fillZip(String zip);

    @TypeInto(value = WHISPER_INPUT, clear = true, andWait = @Wait(value = WHISPER_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage fillAddressWhisper(String whisperInput);

    @Wait(value = SELECT_ADDRESS_WHISPER_LINK, until = Until.CLICKABLE)
    HypokalkulackaAddressPage waitForAddressFromWhisper();

    @Click(value = SELECT_ADDRESS_WHISPER_LINK, andWait = @Wait(value = ZIP_LOADER_IMG, until = Until.GONE))
    HypokalkulackaAddressPage selectAddressFromWhisper();

    @Click(value = SAVE_ADDRESS_BUTTON, jsClick = true)
    HypokalkulackaPage clickSaveAddressButton();
}