package cz.moneta.test.dsl.monetaportal.loans;

import cz.moneta.test.dsl.monetaportal.components.Naviblocks;
import cz.moneta.test.dsl.monetaportal.components.QuestionQuickCall;
import cz.moneta.test.dsl.monetaportal.components.Web2Branch;
import cz.moneta.test.dsl.monetaportal.components.Web2Call;
import cz.moneta.test.dsl.monetaportal.components.calculators.ExpressLoanBannerCalculator;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.monetaportal.loans.ExpressLoanPage.CALCULATOR_DIV;

// TODO: Will be removed

@Wait(CALCULATOR_DIV)
public interface ExpressLoanPage extends WebFlow<ExpressLoanPage>, ExpressLoanBannerCalculator, Naviblocks, QuestionQuickCall, StoreAccessor {
    //Express loan calculator
    String CALCULATOR_DIV = "//div[contains(@id, 'PersonalCalculator')]";
    String CALCULATOR_AMOUNT_INPUT = CALCULATOR_DIV + "//input[@class='calcInput__input___KmRsG calcInput__inputStrong___2ApyV']";
    String CALCULATOR_REDUCE_OBLIGATIONS_BUTTON = CALCULATOR_DIV + "//span[@data-message-id='ObligationForm.reducePayments']";
    String CALCULATOR_BOX = CALCULATOR_DIV + "//div[@class='CalcCalculatorBoxFullDesign__box___3AiZy']";

    //NAVIBLOCK
    String NAVIBLOCK_W2B_BUTTON = "//div[contains(@class, 'naviblocks')]//div[not(contains(@class, 'phone-visible'))]/a[contains(@class, 'w2b-modal')]";

    //W2C
    String W2C_DIV = "//div[@id='W2cModal']";
    String W2C_INPUT = W2C_DIV + "//input[@data-message-id='w2c.ContactForm.placeholder']";
    String W2C_SUBMIT_BUTTON = W2C_DIV + "//span[@data-message-id='w2c.ContactForm.submit']/..";
    String W2C_SUCCESS_MESSAGE = W2C_DIV + "//span[@data-message-id='w2c.W2cResponse.responseMessage']";

    //W2B
    String W2B_DIV = "//div[@id='W2bModal']";
    String W2B_SEARCH_BRANCH_INPUT = W2B_DIV + "//input[@id = 'searchBranchInput']";
    String W2B_SEARCH_RESULT_BRANCH = "//div[@class = 'pac-item']//span[contains(text(),'%s')]";
    String W2B_ARRANGE_APPOINTMENT_BUTTON = "(" + W2B_DIV + "//span[@data-message-id = 'BranchItem.arrangeAppointment'])[1]";
    String W2B_CONTINUE_BUTTON = W2B_DIV + "//span[@data-message-id = 'AppointmentForm.continueButton']/..";
    String W2B_FORM_CLIENT_FULL_NAME_INPUT = W2B_DIV + "//input[@id = 'clientFullName']";
    String W2B_FORM_CLIENT_PHONE_NUMBER_INPUT = W2B_DIV + "//input[@id = 'clientPhoneNumber']";
    String W2B_FORM_CLIENT_EMAIL_INPUT = W2B_DIV + "//input[@id = 'clientEmail']";
    String W2B_SUBMIT_BUTTON = W2B_DIV + "//span[@data-message-id = 'ContactInfoForm.submitButton']/..";
    String W2B_SUCCESS_MESSAGE = W2B_DIV + "//span[@data-message-id='ResultFormSuccess.appointmentSuccessfulHeader']";
    String W2B_BUTTON = "//a[@href='#w2b-modal']";
    String W2C_BUTTON = "//a[@href='/pujcky-a-uvery/pujcka-na-cokoliv#w2c-modal']";

    @Waits({@Wait(value = W2B_BUTTON, until = Until.VISIBLE), @Wait(value = W2B_BUTTON, until = Until.CLICKABLE), @Wait(explicitWaitSeconds = 2)})
    @Click(value = W2B_BUTTON, jsClick = true)
    Web2Branch clickArrangeAppointmentAtBranch();

    @Wait(value = W2C_BUTTON, until = Until.VISIBLE)
    @Click(value = W2C_BUTTON, jsClick = true)
    Web2Call clickToCall();

    //Express loan calculator
    /*@Wait(value = {CALCULATOR_AMOUNT_INPUT})
    @Click(CALCULATOR_AMOUNT_INPUT)
    ExpressLoanPage clickCalculatorAmountInput();

    @CustomAction
    default ExpressLoanPage fillCalculatorAmount(String amount) {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        String initialMonthlyPrice = this.getMonthlyPrice();
        endpoint.type(() -> CALCULATOR_AMOUNT_INPUT, amount, true);
        endpoint.click(() -> CALCULATOR_BOX);
        String changedMonthlyPrice = this.getMonthlyPrice();
        System.out.println(initialMonthlyPrice);
        System.out.println(changedMonthlyPrice);
        Assertions.assertNotEquals(initialMonthlyPrice, changedMonthlyPrice, "Monthly price calculation did not change.");
        return null;
    }

    @CustomAction
    default ExpressLoanPage moveCalculatorLoanLengthBy(int xOffset) {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        String initialMonthlyPrice = this.getMonthlyPrice();
        endpoint.dragAndDropBy(CALCULATOR_LENGTH_BY_SLIDER, xOffset, 0);
        String changedMonthlyPrice = this.getMonthlyPrice();
        Assertions.assertNotEquals(initialMonthlyPrice, changedMonthlyPrice, "Monthly price calculation did not change.");
        return null;
    }

    //@Wait(value = CALCULATOR_SPINNER, until = Until.GONE)
    //@Click(CALCULATOR_NEXT_BUTTON)
    //GetExpressLoanPage clickCalculatorGetLoan();

    @Click(CALCULATOR_REDUCE_OBLIGATIONS_BUTTON)
    UDCLoanPage clickCalculatorReduceObligations();*/

    //NAVIBLOCK
    // @Click(value = NAVIBLOCK_W2C_BUTTON, andWait = @Wait(explicitWaitSeconds = 1))
    //Web2Call clickNaviblocksW2C();

    /*
    @Click(value = NAVIBLOCK_W2B_BUTTON, andWait = @Wait(value = W2B_SEARCH_BRANCH_INPUT, until = Until.VISIBLE))
    ExpressLoanPage clickNaviblocksW2B();

    //W2C
    @Click(W2C_INPUT)
    ExpressLoanPage clickW2CPhone();

    @Click(W2C_SUBMIT_BUTTON)
    ExpressLoanPage clickW2CSubmit();

    @TypeInto(value = W2C_INPUT, clear = true)
    ExpressLoanPage fillW2CPhone(String phoneNumber);

    @CheckElementPresent(W2C_SUCCESS_MESSAGE)
    ExpressLoanPage checkW2CSuccessMessage();

    //W2B
    @Click(W2B_SEARCH_BRANCH_INPUT)
    ExpressLoanPage clickW2BSearchBranch();

    @Click(W2B_ARRANGE_APPOINTMENT_BUTTON)
    ExpressLoanPage clickW2BArrangeAppointment();

    @Click(W2B_CONTINUE_BUTTON)
    ExpressLoanPage clickW2BContinue();

    @Click(W2B_SUBMIT_BUTTON)
    ExpressLoanPage clickW2BSubmit();

    @TypeInto(value = W2B_SEARCH_BRANCH_INPUT, clear = true)
    ExpressLoanPage fillW2BSearchBranch(String searchBranchName);

    @TypeInto(value = W2B_FORM_CLIENT_FULL_NAME_INPUT, clear = true)
    ExpressLoanPage fillW2BClientFullName(String clientFullName);

    @TypeInto(value = W2B_FORM_CLIENT_PHONE_NUMBER_INPUT, clear = true)
    ExpressLoanPage fillW2BClientPhoneNumber(String clientPhoneNumber);

    @TypeInto(value = W2B_FORM_CLIENT_EMAIL_INPUT, clear = true)
    ExpressLoanPage fillW2BClientEmail(String clientEmail);

    @CheckElementPresent(W2B_SUCCESS_MESSAGE)
    ExpressLoanPage checkW2BSuccessMessage();

    @Click(W2B_SEARCH_RESULT_BRANCH)
    ExpressLoanPage clickW2BSearchResultBranches(SearchBranchName searchBranchName);
*/
}