package Seznam;

import Support.BasicPage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.testng.Assert;
import org.testng.asserts.SoftAssert;

public class SeznamPage extends BasicPage {
    private WebDriver driver;
    private SoftAssert sa;

    @FindBy(how=How.ID, using = "www-seznam-cz")
    WebElement seznam;
    @FindBy(how=How.CLASS_NAME, using ="show-login-form")
    WebElement showLoginButton;
    @FindBy(how= How.NAME, using = "username")
    WebElement usernameTextBox;
    @FindBy(how= How.NAME, using = "password")
    WebElement passwordTextBox;
    @FindBy(how=How.CLASS_NAME, using = "input-w-button__button")
    WebElement submitButton;

    /**
     * constructor
     * @param driver WebDriver which we are using
     */
    public SeznamPage(WebDriver driver, SoftAssert sa)
    {
        super(driver);
        this.sa = sa;
    }

    /**
     * check if seznam page is displayed
     * @return if login page is displayed
     */
    public void isSeznamPageDisplayed(Boolean shouldBeDisplayed)
    {
        boolean result = true;
        result&=isElementPresent(seznam);

        if (shouldBeDisplayed)
        {
            Assert.assertTrue(result, "Seznam page is not displayed!");
        }
        else
        {
            Assert.assertFalse(result, "Seznam page is displayed but shouldn't be!");
        }
    }

    /**
     * show login
     */
    public void clickShowLoginButton()
    {
        Assert.assertTrue(isElementPresent(showLoginButton),"Show login button in Seznam page is not displayed!");
        showLoginButton.click();
    }

    /**
     * set username
     * @param username which we want to set
     */
    public void fillUsernameTextbox(String username)
    {
        Assert.assertTrue(isElementPresent(usernameTextBox),"Username textBox in Seznam page is not displayed!");
        usernameTextBox.clear();
        usernameTextBox.sendKeys(username);
    }

    /**
     * set password
     * @param password which we want to set
     */
    public void fillPasswordTextbox(String password)
    {
        Assert.assertTrue(isElementPresent(passwordTextBox),"Password textBox in Seznam page is not displayed!");
        passwordTextBox.clear();
        passwordTextBox.sendKeys(password);
    }

    /**
     * click on login button
     */
    public void clickLoginButton()
    {
        Assert.assertTrue(isElementPresent(submitButton),"Submit button in Seznam page is not displayed!");
        submitButton.click();
    }

}
