/* ----------------------------------------
 * Origin  : Akkodis 
 * Project : CDPP Propagation Tool 
 * ----------------------------------------
 * History 
 * Version : 01/05/2015 : KKH
 * DM-ID : Redmine#11685 : 19/07/2024 : creation 
 * ----------------------------------------
 */

package fr.tlse.irap.pt.client.controller.eclipticPlane;



import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

/**
 * FXML Controller class
 *
 * @author Kea-Hour.KHUM
 */
public class MinMaxComponentController implements Initializable {
    @FXML
    private TextField minField;

    @FXML
    private TextField maxField;
    
    @FXML
    private Label lblMsg;

    private boolean validated = false;
    
    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // TODO
    }

    public double getMinValue() {
        return Double.parseDouble(minField.getText());
    }

    public double getMaxValue() {
        return Double.parseDouble(maxField.getText());
    }    

    public void setMinField(double pMin) {
        minField.setText(String.valueOf(pMin));
    }

    public void setMaxField(double pMax ) {
        maxField.setText(String.valueOf(pMax));

    }
      
   
    public void okMinMaxColor() {
                
        if(getMinValue() > getMaxValue()){
            
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Data Error");
            alert.setHeaderText("Error min/max value");
            alert.setContentText("The min value must be lower than the max value.");
            alert.showAndWait().ifPresent(rs -> {
                if (rs == ButtonType.OK) {
                    //System.out.println("OK.");
                }
            });
 
        }else{
            validated = true;
            closeWindowMinMaxColor();
        }
        

    }

    
    public void cancelMinMaxColor() {
        // non validé et fermer la fenêtre
        validated = false;
        closeWindowMinMaxColor();
    }

    private void closeWindowMinMaxColor() {
        Stage stage = (Stage) minField.getScene().getWindow();
        stage.close();
    }

    public boolean isValidated() {
        return validated;
    }

    public String getLblMsg() {
        return lblMsg.getText();
    }

    public void setLblMsg(String message) {
        this.lblMsg.setText(message);
    }
   
    
    
}
