package com.intland.codebeamer.functionaltest.page;

import com.codeborne.selenide.SelenideElement;
import com.intland.codebeamer.functionaltest.page.mystart.MyStartPage;
import org.openqa.selenium.By;

import static com.codeborne.selenide.Selenide.*;
import static com.codeborne.selenide.Condition.*;

public class LoginPage {

    public void setUsername(String username) {
        $(By.id("user")).shouldBe(visible).setValue(username);
    }

    public void setPassword(String password) {
        $(By.id("password")).shouldBe(visible).setValue(password);
    }

    public SelenideElement getInfoMessages() {
        return $(By.className("login_text"));
    }

    public SelenideElement getLoginMenu() {
        return $(By.linkText("Login"));
    }

    public MyStartPage clickOnLogin() {
        $(By.className("login_button")).click();
        return page(MyStartPage.class);
    }

    public LostPasswordPage clickOnForgotIt() {
        $(By.linkText("Forgot it?")).click();
        switchTo().window(1);
        return page(LostPasswordPage.class);
    }

    public CreateUserPage clickOnNotAMemberYetRegisterNow(){
        $(By.xpath(".//a[contains(@href,'/cb/createUser.spr')]")).click();
        return page(CreateUserPage.class);
    }
}
