package pages;

import core.BasePage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

/**
 * @author kote
 */
public class ResetPasswordPage extends BasePage {

  private static final By HEADER = By.xpath("//p[contains(.,'Вспомнили пароль?')]");
  private static final By RESET_BUTTON = By.xpath("//div[@class='reset-password-btn-box']//button");
  private static final By CHANGE_BUTTON = By.xpath("//button[contains(.,'Изменить пароль')]");

  @FindBy(xpath = "//a[contains(text(), 'Войти')]")
  private WebElement loginLink;
  @FindBy(xpath = "//div//input[@name='email']")
  private WebElement emailInput;
  @FindBy(xpath = "//div//input[@name='password']")
  private WebElement passwordInput;
  @FindBy(xpath = "//div//input[@name='confirmPassword']")
  private WebElement confirmPasswordInput;

  public ResetPasswordPage(WebDriver browser) {
    super(browser, "/#/reset-password");
  }

  public boolean isHeaderVisible() {
    return isPresent(HEADER);
  }

  public void loginLinkClick() {
    loginLink.click();
  }

  public void resetButtonClick() {
    waitForElementToBeClickable(RESET_BUTTON).click();
  }

  public void changeButtonClick() {
    waitForElementToBeClickable(CHANGE_BUTTON).click();
  }

  public void editEmail(String value) {
    editField(emailInput, value);
  }

  public void editPassword(String value) {
    editField(passwordInput, value);
  }

  public void editConfirmPassword(String value) {
    editField(confirmPasswordInput, value);
  }
}
