import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class LoginPage {
  WebDriver driver;
  WebDriverWait waiter;

  public LoginPage(WebDriver driver) {
    this.driver = driver;
    this.waiter = new WebDriverWait(this.driver, 5);
  }

  public WebElement getNameInput() {
    return driver.findElement(By.xpath("//input[@name='userId']"));
  }

  public WebElement getPassInput() {
    return driver.findElement(By.name("inputPassword"));
  }

  public WebElement getSubmitBtn() {
    return driver.findElement(By.id("btnSignIn"));
  }

//  public WebDriverWait getWaiter() {
//    return new WebDriverWait(this.driver, 5 );
//  }

  public void login(String username, String password) {

//    this.waiter.until(ExpectedConditions.visibilityOfElementLocated(By.id("btnSignIn")));

    getNameInput().sendKeys(username);
    getPassInput().sendKeys(password);
    getSubmitBtn().click();

    this.waiter.until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Account")));

  }
}
