package be.iminds.ilabt.jfed.ui.javafx.userlogin;

import be.iminds.ilabt.jfed.lowlevel.GeniUser;
import be.iminds.ilabt.jfed.lowlevel.user.UserLoginInfo;
import be.iminds.ilabt.jfed.ui.javafx.GuiceFXMLUtil;
import be.iminds.ilabt.jfed.ui.javafx.util.StageUtils;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Window;

import javax.inject.Inject;

/**
 * User: twalcari
 * Date: 11/28/2014
 * Time: 17:12
 */
public class AdvancedUserLoginDialog {
    private final AdvancedUserLoginController controller;
    private final Stage stage;

    private UserLoginInfo userLoginInfo;

    @Inject
    AdvancedUserLoginDialog(GuiceFXMLUtil guiceFXMLUtil) {
        GuiceFXMLUtil.Result<?, AdvancedUserLoginController> result =
                guiceFXMLUtil.createFromFXML(AdvancedUserLoginController.class);

        Scene scene = new Scene(result.getRoot());
        stage = new Stage();
        StageUtils.setJFedStageIcons(stage);
        stage.setTitle("JFed Advanced User Login");
        stage.initModality(Modality.WINDOW_MODAL);
        stage.setScene(scene);
        stage.sizeToScene();

        controller = result.getController();
    }

    /**
     * doesn't wait, but you can use the listener for feedback
     */
    public GeniUser showUserLogin(Window parentWindow) {
        stage.initOwner(parentWindow);
        stage.showAndWait();

        this.userLoginInfo = controller.getUserLoginInfo();
        return controller.getResult();
    }

    public UserLoginInfo getUserLoginInfo(){
        return controller.getUserLoginInfo();
    }
}

