package com.playwrightdemo.pages;

import com.microsoft.playwright.Page;
import com.playwrightdemo.utils.ConfigReader;

import java.io.IOException;

public class LoginPage extends BasePage {


    private String emailField = "input#email";
    private String pwdField = "input#password";
    private String btnLogin = "button.btn.btn-primary.login_btn";
    private String txtErrorMsg ="span.invalid-feedback strong";

    private String textDashboardMenu="li[title='Dashboard'] span";

    private String textUserName="a#navbarDropdown";



    public LoginPage( ) throws IOException {

        //super();
    }



    public String getPageURL() {

        return page.url();
    }

    public String getPageTitle() {

        return page.title();

    }

    public void fillEmail() {

        fillFields(emailField,ConfigReader.getAppUserName());


    }

    public void fillPassword() {

        fillFields(pwdField,ConfigReader.getAppPassword());

    }


    public void fillEmail(String invalidEmail) {

        fillFields(emailField,invalidEmail);


    }


    public void fillPassword(String invalidPassword) {

        fillFields(pwdField,invalidPassword);

    }


    public void clickLoginButton() {

        doClickSelector(btnLogin);

    }

    public String getErrorMessage() {

      return getTextFromSelector(txtErrorMsg);
    }

    public String getDashboardMenuTextContent(){

        return getTextFromSelector(textDashboardMenu);
    }

    public String getUserNameDisplayed(){

        return getTextFromSelector(textUserName);
    }




    public void doLogin(){

        fillEmail();
        fillPassword();
        clickLoginButton();

    }

public DashboardPage fromLoginPage() throws IOException {

     return new DashboardPage();

}



}
