package PageComponents;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginModalPF {
    WebDriver driver;
    WebDriverWait wdw;

    @FindBy(how = How.ID, using = "label-email")
    WebElement userNameInputBox;

    @FindBy(how = How.ID, using = "label-password")
    WebElement userPasswordInputBox;

    @FindBy(how = How.ID, using = "btnSignIn")
    WebElement signInButton;

    public LoginModalPF(WebDriver driver) {
        this.driver = driver;
        this.wdw = new WebDriverWait(this.driver, 1);
        PageFactory.initElements(driver, this);
    }

    public void fillUserInfo(String userName, String password) {
        wdw.until(ExpectedConditions.elementToBeClickable(userNameInputBox));
        wdw.until(ExpectedConditions.elementToBeClickable(userPasswordInputBox));
        this.userNameInputBox.sendKeys(userName);
        this.userPasswordInputBox.sendKeys(password);
    }

    public void sendCredentials() {
        signInButton.click();
    }

}
