package com.moviesdb;

import javafx.fxml.FXML;
import javafx.scene.control.*;

import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;

import javafx.stage.Modality;

//For reading properties from .properties file

public class LogInController extends Controller {

    @FXML
    Button logInButton21;
    @FXML
    TextField userTextBox1;
    @FXML
    TextField passTextBox1;
    @FXML
    TextFlow errorTextBox;

    Object caller;

    public void open(Object caller) {
        prepare();
        stage.initModality(Modality.WINDOW_MODAL);
        stage.initOwner(((BrowserController)caller).stage.getScene().getWindow());
        this.caller = caller;
        stage.setTitle("Log in");
        stage.show();
    }

    public void closeLoginForm(){
        if(((BrowserController)caller).newArgLogin(userTextBox1.getText(), passTextBox1.getText())) {
            ((BrowserController)caller).loadPosters();
            ((BrowserController)caller).closeDetails();
            stage.close();
        }
        else
        {
            Text errorMessage = new Text("Incorrect login or password!");
            errorMessage.setStyle("-fx-font-size: 14; -fx-fill: #FF0000;");
            errorTextBox.getChildren().clear();
            errorTextBox.getChildren().add(errorMessage);
        }
        //System.out.println("LoginForm closed");
    }
}
