package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.pageobjects.elements.PageElement;
import org.openqa.selenium.By;

/**
 * Initial page of the user password reset UI.
 */
public class UserPasswordResetPage extends BitbucketPage {

    public static final String URL = "/passwordreset";

    @Override
    public String getUrl() {
        return URL;
    }

    @ElementBy(cssSelector = ".reset-password #identifier")
    private PageElement usernameOrEmailTextbox;

    @ElementBy(cssSelector = ".reset-password #submit")
    private PageElement resetPasswordButton;


    public boolean hasNoMailConfigError() {
        return !driver.findElements(By.cssSelector(".aui-message-error.no-mail-config")).isEmpty();
    }

    public boolean hasNoUserFoundError() {
        return !driver.findElements(By.cssSelector(".aui-message-error.no-user-found")).isEmpty();
    }

    public boolean hasFormError() {
        return !driver.findElements(By.cssSelector(".aui-message-error")).isEmpty();
    }

    public boolean hasConfirmationThatEmailWasSent() {
        return !driver.findElements(By.cssSelector(".aui-message-success.reset-email-sent")).isEmpty();
    }

    public UserPasswordResetPage setUsernameOrEmail(String text) {
        usernameOrEmailTextbox.clear().type(text);
        return this;
    }

    public UserPasswordResetPage clickResetPassword() {
        resetPasswordButton.click();
        return this;
    }

}
