package com.example.PageObjects;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class AddToCartPage {
   public WebDriver driver;
   public AddToCartPage(WebDriver driver) {
    this.driver=driver;
    }


    public void searchProductFunction(String SearchProduct) {
        driver.findElement(By.cssSelector("#q")).sendKeys(SearchProduct);
        driver.findElement(By.xpath("//button[normalize-space()='SEARCH']")).click();
    }

    public void selectProduct(String selectProduct ) {
        driver.findElement(By.xpath(String.format("//a[contains(text(),'%s')]",selectProduct))).click();
    }

    public void Button(String button) {
        driver.findElement(By.xpath(String.format("//span[contains(text(),'%s')]",button))).click();
    }

    public void emailAddress(String phone , String password) throws InterruptedException {
        Thread.sleep(7000);
        int size = driver.findElements(By.tagName("iframe")).size();
        driver.switchTo().frame(3);
        driver.findElement(By.cssSelector("#container > div > div > div > div:nth-child(2) > form > div > div.mod-login-col1 > div.mod-input.mod-login-input-loginName.mod-input-loginName > input[type=text]")).sendKeys(phone);
        driver.findElement(By.cssSelector("#container > div > div > div > div:nth-child(2) > form > div > div.mod-login-col1 > div.mod-input.mod-input-password.mod-login-input-password.mod-input-password > input[type=password]")).sendKeys(password);
         driver.findElement(By.cssSelector("#container > div > div > div > div:nth-child(2) > form > div > div.mod-login-col2 > div.mod-login-btn > button")).click();
        driver.switchTo().defaultContent();
    }

    public void proceedToPayButtonLocator() {
       driver.findElement(By.cssSelector(".checkout-order-total-button.automation-checkout-order-total-button-button")).click();
    }

    public void paymentTypes(String payment) {
        driver.findElement(By.xpath(String.format("//div[@class='title'][normalize-space()='%s']", payment))).click();
    }

    public void clickButton() {

      driver.findElement(By.cssSelector(".next-btn-large.checkout-order-total-button.automation-checkout-order-total-button-checkout")).click();
    }

    public void accountNumber(String text) {
        driver.findElement(By.cssSelector("input[type='text']")).sendKeys(text);
    }

    public String errorMessage() {
        return  driver.findElement(By.cssSelector("div.payment-input div.error")).getText();
    }



//    public void jsExecutor(String locator) {
//        WebElement element = driver.findElement(By.xpath(String.format("//button[normalize-space()='%s']",locator)));
//        Actions actions = new Actions(driver);
//        actions.moveToElement(element).click().perform();
//    }
}
