package cz.moneta.test.dsl.newib.settings.payments.trustedcontacts;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.components.HorizontalMainMenu;
import cz.moneta.test.dsl.newib.components.VerticalMainMenu;
import cz.moneta.test.dsl.newib.settings.SettingsModalPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Wait(value = {TrustedContactsPage.TRUSTED_CONTACTS_TITLE_XPATH}, waitSecondsForElement = 30)
public interface TrustedContactsPage extends NewIbPageFlow<TrustedContactsPage>, HorizontalMainMenu, VerticalMainMenu, StoreAccessor {

    String TRUSTED_CONTACTS_TITLE_XPATH = "//h2[@class='t-title t-title--h3'][text()='Důvěryhodní příjemci']";
    String SHOW_MORE_TRUSTED_CONTACTS_XPATH = "//button[@data-testid='show-more-accounts'][text()='Zobrazit další příjemce']";
    String BACK_TO_SETTINGS_BTN_XPATH = "//button[@data-testid='back-to-settings-crossroad']";
    String CLOSE_BTN_XPATH = "//button[@data-testid='settings_modal-close']";
    String INFO_TEXT_COMPONENT_XPATH = "//p[@data-testid='TextComponent'][text()='Účet příjemce si můžete uložit mezi důvěryhodné při zadávání platebního příkazu. K potvrzení transakcí pak nebudete potřebovat mobilní klíč. Účet můžete ze seznamu kdykoliv smazat.']";
    String ACCOUNT_COMPONENT_XPATH = "//p[@data-testid='TextComponent']/small[text()='Název a číslo účtu příjemce']";
    String USED_IN_TEMPLATE_TEXT_COMPONENT_XPATH = "//p[@data-testid='TextComponent']/small[text()='Použito v šabloně']";
    String CREATED_TEXT_COMPONENT_XPATH = "//p[@data-testid='TextComponent']/small[text()='Vytvořeno']";
    String FULL_TEXT_FILTER_XPATH = "//input[@data-testid='settings-fullText'][@placeholder='Hledejte v důvěryhodných příjemcích']";
    String DELETE_ICON_XPATH = "(//div[@class='col col-12 col-sm-1 styles_uSmTextRight__3nXBD'])[2]";
    String MODAL_TITLE_XPATH = "//h2[@class='t-title t-title--h3 c-modal__title'][contains(text(),'Chcete smazat důvěryhodného příjemce')]";
    String MODAL_INFO_XPATH = "//div[@class='c-modal__body'][text()='Nového si vždy můžete nastavit.']";
    String MODAL_DECLINE_XPATH = "//button[@data-testid='button-decline']";
    String TRUSTED_ACCOUNT_XPATH = "(//div[@data-testid='trusted-account'])[1]";
    String NAME_IS_NOT_EMPTY_XPATH = "//div[@data-testid='item-info-value-description']/strong[not(@value='')]";
    String ACCOUNT_NUMBER_IS_NOT_EMPTY_XPATH = "//div[@data-testid='item-info-value-accountNumber']/p[@data-testid='TextComponent'][not(@value='')]";
    String CREATED_DATE_IS_NOT_EMPTY_XPATH = "//div[@data-testid='item-info-value-createdDate']/p[@data-testid='TextComponent'][not(@value='')]";
    String USED_IN_TEMPLATE_IS_NOT_EMPTY_XPATH = "//div[@data-testid='item-info-value-inTemplate']/p[@data-testid='TextComponent'][not(@value='')]";
    String EDIT_BUTTON_XPATH = "//button[@data-testid='edit-name-btn']";
    String NAME_OF_TRUSTED_CONTACT_INPUT_XPATH = "//input[@data-testid='Component']";
    String SAVE_BUTTON_XPATH = "//button[@class='c-link c-link--small'][@data-testid='Link']";
    String NAME_OF_LONG_TRUSTED_CONTACT_INPUT_XPATH = "//div[@data-testid='item-info-value-description']/strong[text()='12345678912345678920']";
    String NAME_OF_SHORT_TRUSTED_CONTACT_INPUT_XPATH = "//div[@data-testid='item-info-value-description']/strong[text()='4545']";
    String CANCEL_BUTTON_XPATH = "//button[@class='c-link c-link--small c-link--red'][@data-testid='Link']";
    String TRUSTED_CONTACT_INFO_TEXT_XPATH = "//div[normalize-space(.)='S ohledem na možné zneužití důvěryhodných příjemců podvodníky, jsme pro Vaši bezpečnost tuto možnost vypnuli. Důvěryhodné příjemce už nebude možné využívat.']";

    @CustomAction
    default TrustedContactsPage checkUrl() {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        String actualUrl = newIbEndpoint.getCurrentUrl();
        String urlContains = "/settings/trusted-accounts";
        assertTrue(actualUrl.contains(urlContains));
        return null;
    }

    @CheckElementPresent(BACK_TO_SETTINGS_BTN_XPATH)
    TrustedContactsPage checkBackToSettingsIsPresent();

    @CheckElementPresent(CLOSE_BTN_XPATH)
    TrustedContactsPage checkCloseBtnIsPresent();

    @Click(BACK_TO_SETTINGS_BTN_XPATH)
    SettingsModalPage clickOnBackToSettings();

    @CheckElementPresent(INFO_TEXT_COMPONENT_XPATH)
    TrustedContactsPage checkInfoTextComponetIsPresent();

    @CheckElementPresent(ACCOUNT_COMPONENT_XPATH)
    TrustedContactsPage checkAccountTextComponetIsPresent();

    @CheckElementPresent(USED_IN_TEMPLATE_TEXT_COMPONENT_XPATH)
    TrustedContactsPage checkUsedInTemplateTextComponetIsPresent();

    @CheckElementPresent(CREATED_TEXT_COMPONENT_XPATH)
    TrustedContactsPage checkCreatedTextComponetIsPresent();

    @CheckElementPresent(FULL_TEXT_FILTER_XPATH)
    TrustedContactsPage checkFullTextFilterIsPresent();

    @Click(SHOW_MORE_TRUSTED_CONTACTS_XPATH)
    TrustedContactsPage clickOnShowMoreAccounts();

    @Click(DELETE_ICON_XPATH)
    TrustedContactsPage clickOnDelete();

    @CheckElementPresent(MODAL_TITLE_XPATH)
    TrustedContactsPage checkTitleIsPresent();

    @CheckElementPresent(MODAL_INFO_XPATH)
    TrustedContactsPage checkInfoTextIsPresent();

    @Click(MODAL_DECLINE_XPATH)
    TrustedContactsPage clickOnDecline();

    @Click(TRUSTED_ACCOUNT_XPATH)
    TrustedContactsPage clickOnTrustedAccount();

    @CheckElementPresent(NAME_IS_NOT_EMPTY_XPATH)
    TrustedContactsPage checkNameIsNotEmpty();

    @CheckElementPresent(ACCOUNT_NUMBER_IS_NOT_EMPTY_XPATH)
    TrustedContactsPage checkAccountNumberIsNotEmpty();

    @CheckElementPresent(CREATED_DATE_IS_NOT_EMPTY_XPATH)
    TrustedContactsPage checkCreateDateIsNotEmpty();

    @CheckElementPresent(USED_IN_TEMPLATE_IS_NOT_EMPTY_XPATH)
    TrustedContactsPage checkUsedInTemplateIsNotEmpty();

    @Click(EDIT_BUTTON_XPATH)
    TrustedContactsPage clickOnEdit();

    @TypeInto(clear = true, value = NAME_OF_TRUSTED_CONTACT_INPUT_XPATH)
    TrustedContactsPage setLongName(String setNameOfTrustedContactLong);

    @Click(SAVE_BUTTON_XPATH)
    TrustedContactsPage clickOnSave();

    @CheckElementPresent(NAME_OF_LONG_TRUSTED_CONTACT_INPUT_XPATH)
    TrustedContactsPage checkLongName();

    @TypeInto(clear = true, value = NAME_OF_TRUSTED_CONTACT_INPUT_XPATH)
    TrustedContactsPage setShortName(String setNameOfTrustedContactShort);

    @CheckElementPresent(NAME_OF_SHORT_TRUSTED_CONTACT_INPUT_XPATH)
    TrustedContactsPage checkShortName();

    @Click(CANCEL_BUTTON_XPATH)
    TrustedContactsPage clickOnCancel();

    @Click(CLOSE_BTN_XPATH)
    TrustedContactsPage clickOnCloseBtn();

    @CheckElementPresent(TRUSTED_CONTACT_INFO_TEXT_XPATH)
    TrustedContactsPage checkTrustedContactsInfoTextIsPresent();
}
