package cz.moneta.test.dsl.newib.settings.envelopes;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.harness.support.web.CheckElementPresent;
import cz.moneta.test.harness.support.web.CheckElementsPresent;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.newib.settings.envelopes.EnvelopesPage.*;

@Wait(value = {ENVELOPES_TITLE_XPATH, NEW_ENVELOPE_BTN_XPATH}, waitSecondsForElement = 30)
public interface EnvelopesPage extends NewIbPageFlow<EnvelopesPage> {
    String ENVELOPES_TITLE_XPATH = "//h1[@class='t-title t-title--h3'][text()='Obálky']";
    String NEW_ENVELOPE_BTN_XPATH = "//button[@data-testid='create-envelope-button']";
    String DELETE_ENVELOPE_BTN_XPATH = "//button[@aria-label='Smazat']";
    String CONFIRM_DELETE_BTN_XPATH = "//button[@data-testid='button-confirm'][text()='Smazat']";
    String ENVELOPE_DELETED_CONFIRM_SCREEN_VICTORY_TEXT = "//h2[@class='t-title t-title--h3 c-modal__title'][text()='Obálka byla smazána']";
    String CLOSE_DELETED_CONFIRM_MODAL_BTN_XPATH = "//button[@data-testid='confirm-close-and-reload'][text()='Zavřít']";
    String NO_ENVELOPES_XPATH = "//small[normalize-space(.)='Momentálně nemáte žádnou obálku']";
    String ENVELOPE_NAME_XPATH = "//div[@data-testid='TextComponent' and normalize-space(.)='%s']";
    String ENVELOPE_AMOUNT_XPATH = "//div[@data-testid='TextComponent' and contains(normalize-space(.),'Chci si naspořit %s CZK')]";
    String EDIT_ENVELOPE_BTN_XPATH = "//div[@class='c-flex c-flex--align-items--center c-flex--wrap--nowrap']" + "[.//div[@data-testid='TextComponent' and normalize-space(text())='%s']]" + "/button[@aria-label='Upravit']";
    String DELETE_INFO_MODAL_XPATH = "//div[contains(@class, 'c-modal__body')][contains(normalize-space(.), concat('obálku ', '%s'))]";

    @Click(NEW_ENVELOPE_BTN_XPATH)
    CreateNewEnvelopePage createNewEnvelope();

    @Click(DELETE_ENVELOPE_BTN_XPATH)
    EnvelopesPage deleteEnvelope();

    @CheckElementPresent(value = DELETE_INFO_MODAL_XPATH, isStringDynamicXpath = true)
    EnvelopesPage checkDeleteEnvelopeModalIsPresent(String envelopeName);

    @Click(CONFIRM_DELETE_BTN_XPATH)
    EnvelopesPage confirmDeleteEnvelope();

    @CheckElementPresent(ENVELOPE_DELETED_CONFIRM_SCREEN_VICTORY_TEXT)
    EnvelopesPage checkEnvelopeDeletedVictoryTextIsPresent();

    @Click(CLOSE_DELETED_CONFIRM_MODAL_BTN_XPATH)
    EnvelopesPage closeDeletedEnvelopeConfirmationModal();

    @CheckElementPresent(NO_ENVELOPES_XPATH)
    EnvelopesPage checkNoEnvelopesMessageIsPresent();

    @CheckElementsPresent({
            @CheckElementPresent(value = ENVELOPE_NAME_XPATH, isStringDynamicXpath = true),
            @CheckElementPresent(value = ENVELOPE_AMOUNT_XPATH, isStringDynamicXpath = true)})
    EnvelopesPage checkCreatedEnvelopeIsPresent(String envelopeName, String envelopeAmount);

    @Click(value = EDIT_ENVELOPE_BTN_XPATH, isStringDynamicXpath = true)
    EditEnvelopePage editEnvelope(String envelopeName);
}