package hozza.network.views.backend;

import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.login.LoginForm;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;

@Route("login")
@PageTitle("Login")
public class Login extends VerticalLayout implements BeforeEnterObserver
{
    private final LoginForm form = new LoginForm();
    
    public Login()
    {
        this.createForm();
    }
    
    private void createForm()
    {
        this.addClassName("login");
        this.setSizeFull();
        this.setAlignItems(Alignment.CENTER);
        this.setJustifyContentMode(JustifyContentMode.CENTER);
        this.form.setAction("login");
        this.add(new H1("Please log-in"), this.form);
    }

    @Override
    public void beforeEnter(BeforeEnterEvent event) 
    {
        if(event.getLocation().getQueryParameters().getParameters().containsKey("error"))
        {
            this.form.setError(true);
        }
    }
    
}