package com.example.stepdefinations.usa;

import com.example.pageobjects.usa.WebPage;
import com.example.utils.TextContextSetupUSA;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.testng.Assert;


public class WebPageSteps {
    TextContextSetupUSA textContextSetup;

    public WebPageSteps(TextContextSetupUSA textContextSetup) {
        this.textContextSetup = textContextSetup;
    }


    @When("I select donation {string} cause in 'Donation now modal' on Home page")
    public void iSelectDonationCause(String type) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.selectDonationCause(type);
    }

    @When("I select donation {string} type in 'Donation now modal' on Home page")
    public void iSelectDonationType(String type) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.selectDonationType(type);
    }


    @When("I select {string} payment type")
    public void iSelectPayment(String paymentType) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.paymentTypes(paymentType).click();
    }

    @When("^I press paypal button$")
    public void iPressButton() throws InterruptedException {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        Thread.sleep(1000);
        webPage.payPalButton().click();
        Thread.sleep(7000);
    }

    @When("I Enter Donation {string} amount")
    public void iEnterDonationAmount(String amount) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.driver.findElement(webPage.donationAmountLocator).sendKeys(amount);
    }

    @When("I press {string} title button on home page")
    public void iPressTitleButton(String button) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.titleButton(button).click();
    }

    @Then("I should see tile button is redirected to {string}")
    public void iShouldSee(String title) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.title(title).isDisplayed();
    }

    @Then("I should see tile button is redirected to contacts {string}")
    public void iShouldSeeContactsInformation(String title) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.contactTitle(title).isDisplayed();
    }

    @When("I hover on program and select the {string} program")
    public void iSelectPrograms(String title) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.selectPrograms(title);
    }

    @When("I click on {string} button")
    public void iClickOnButton(String button) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.clickButton(button);
    }

    @When("User redirected to correct website {string}")
    public void iRedirectedToWebsite(String websiteUrl) {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        String currentUrl = webPage.getCurrentUrl();
        Assert.assertEquals(websiteUrl, currentUrl);
    }

    @When("User landed on paypal {string} page")
    public void iRedirectedToPaypal(String paypalTitle) throws InterruptedException {
        WebPage webPage = textContextSetup.pagesObject.getWebPage();
        webPage.switchScreen();
        String pageTitle = webPage.payPalTitle();
        System.out.println(pageTitle);
        Assert.assertEquals(paypalTitle, pageTitle);
    }

}
