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

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.newib.payments.NewPaymentMenuPage.*;

@Wait({NEW_PAYMENT_TITLE, PAYMENT_SECTION_XPATH, DOMESTIC_BUTTON_XPATH})
public interface NewPaymentMenuPage extends Builder, StoreAccessor {
    String NEW_PAYMENT_TITLE = "//h1[@class='t-title t-title--h3'][text()='Nová platba']";
    String PAYMENT_SECTION_XPATH = "//section[@data-testid='Tabs']";
    String MENU_LIST = "//ul[@role='tablist']";
    String DOMESTIC_BUTTON_XPATH = MENU_LIST + "//span[@data-testid='domestic-order-tab']/ancestor::button";
    String MOBILE_OPERATORS_BTN_XPATH = "//span[@data-testid='top-up-tab'][//span[contains(text(), 'Mobilní operátoři')]]";
    String FOREIGN_BTN_XPATH = "//span[@data-testid='foreign-tab']";
    String STANDING_ORDER_BTN_XPATH = "//span[@data-testid='standing-order-tab']";
    String DIRECT_DEBIT_BTN_XPATH = "//span[@data-testid='direct-debit-tab']";
    String SIPO_BTN_XPATH = "//span[@data-testid='sipo-tab']";
    String BULK_PAYMENT_BTN_XPATH = "//span[@data-testid='bulk-order-form']";
    String MORE_XPATH = "//div[@class='c-tabs__text'][text()='Další']";
    String MORE_DROPDOWN_XPATH = "//div[@class='c-tabs__text' and text()='Další']/../../../following-sibling::div";
    String MORE_DROPDOWN_NOT_EMPTY_XPATH = MORE_DROPDOWN_XPATH + "//span[not(text='')]";


    @Click(MOBILE_OPERATORS_BTN_XPATH)
    MobileOperatorsPaymentPage clickOnMobileOperatorsTab();

    @Click(FOREIGN_BTN_XPATH)
    NewForeignPaymentPage clickOnForeignTab();

    @Click(STANDING_ORDER_BTN_XPATH)
    StandingOrderPage clickOnStandingOrderTab();

    @Click(SIPO_BTN_XPATH)
    SipoOrderPage clickOnSipoTab();

    @Click(BULK_PAYMENT_BTN_XPATH)
    BulkPaymentPage clickOnBulkPaymentTab();

    @Click(value = DIRECT_DEBIT_BTN_XPATH)
    DirectDebitPage clickOnDirectDebitTab();

    @Click(value = MORE_XPATH , andWait = @Wait(MORE_DROPDOWN_NOT_EMPTY_XPATH))
    NewPaymentMenuPage clickMore();

    @CustomAction
    default NewPaymentMenuPage checkNoSipo() {
        NewIbEndpoint endpoint = getEndpoint(NewIbEndpoint.class);
        String dropDownText = endpoint.getText(MORE_DROPDOWN_XPATH);
        Assertions.assertFalse(dropDownText.contains("SIPO"));
        return null;
    }
}
