/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Controllers.Dialog;

import Controllers.Traitement.MyWindow;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.stage.Stage;

/**
 *
 * @author Maher
 */
public class ShowDialog{
    
    public static String  titre ;
    public static String detail ;
    
    public static String getTitre() {
        return titre;
    }

    public static String getDetail() {
        return detail;
    }

    public static void setTitre(String titre) {
        ShowDialog.titre = titre;
    }

    public static void setDetail(String detail) {
        ShowDialog.detail = detail;
    }
    
    
    public Node DialogAlert(String MsgTitre, String MsgDetail){
        
        final StackPane stackpane = new StackPane();
        Group group = new Group();
        
        AnchorPane Ap = new AnchorPane();
        Ap.setStyle("-fx-background-color: rgba(0,0,0,0.6);");
        Ap.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                    System.out.println("mouse click detected! ");
                }
            });
    
    
        Pane pa1 = new Pane();
        pa1.setStyle("-fx-background-color:#ffffff; -fx-border-color: #212121; -fx-border-radius: 10 10 0 0; -fx-background-radius: 10 10 0 0;");
        pa1.setPrefHeight(231);
        pa1.setPrefWidth(497);
        
        Pane pa2 = new Pane();
        pa2.setStyle("-fx-background-color:linear-gradient(to bottom, #585858, #333333); -fx-background-radius: 10 10 0 0;");
        pa2.setPrefHeight(36);
        pa2.setPrefWidth(497);
        
        Text titre = new Text();
        titre.setText("Exception Dialog");
        titre.setFont(Font.font("System", FontWeight.BOLD, 13));
        titre.setFill(Color.web("#ffffff"));
        titre.setLayoutX(17);
        titre.setLayoutY(22);
        
        Pane pa3 = new Pane();
        pa3.setStyle("-fx-background-color:linear-gradient(to bottom, #E2E2E2, #EDEDED); -fx-border-color: #B4B4B4;");
        pa3.setLayoutY(36);
        pa3.setPrefHeight(48);
        pa3.setPrefWidth(497);
        
        //Image imgicon = new Image(getClass().getResourceAsStream("/Public/icon/dialoginform.png"));
        //ImageView icon = new ImageView(imgicon);
        Image image = new Image(getClass().getResourceAsStream("/Public/icon/dialog_error.png"));
        ImageView icon = new ImageView(image);
        icon.setLayoutX(440);
        icon.setLayoutY(40);
        icon.setFitWidth(38);
        icon.setFitHeight(38);
        
        Text titreMSG = new Text();
        titreMSG.setText(MsgTitre);
        titreMSG.setFont(Font.font("System", FontWeight.NORMAL, 13));
        titreMSG.setFill(Color.web("#000000"));
        titreMSG.setLayoutX(27);
        titreMSG.setLayoutY(65);
        
        Text detail = new Text();
        detail.setText(MsgDetail);
        detail.setFont(Font.font("System", FontWeight.NORMAL, 12));
        detail.setFill(Color.web("#000000"));
        TextFlow DetailMSG = new TextFlow(detail);
        DetailMSG.setPrefHeight(92);
        DetailMSG.setPrefWidth(344);
        DetailMSG.setLayoutX(28);
        DetailMSG.setLayoutY(95);
        
        
        Button boutton = new Button();
        boutton.setText("Valider");
        boutton.setFont(Font.font ("System", FontWeight.BOLD, 12));
        boutton.setStyle("{-fx-background-color:#EFEFEF; -fx-border-color: #959595; -fx-border-radius: 5 5 5 5;} hover:{-fx-background-color:#E6E6E6;}");
        boutton.setPrefWidth(84);
        boutton.setPrefHeight(31);
        boutton.setLayoutX(388);
        boutton.setLayoutY(186);
        boutton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                stackpane.setVisible(false);
            }
        });
        
        
        group.getChildren().addAll(pa1, pa2, titre, pa3, titreMSG, icon, DetailMSG, boutton);
        
        
       
        
        stackpane.getChildren().add(Ap);
        stackpane.getChildren().add(group);
        
        
        
            
        return stackpane ;
    }
    
    
    public Node DialogNotification(String MsgTitre, String MsgDetail){
        
        final StackPane stackpane = new StackPane();
        Group group = new Group();
        
        AnchorPane Ap = new AnchorPane();
        Ap.setStyle("-fx-background-color: rgba(0,0,0,0.6);");
        Ap.addEventFilter(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                    System.out.println("mouse click detected! ");
                }
            });
    
    
        Pane pa1 = new Pane();
        pa1.setStyle("-fx-background-color:#ffffff; -fx-border-color: #212121; -fx-border-radius: 10 10 0 0; -fx-background-radius: 10 10 0 0;");
        pa1.setPrefHeight(231);
        pa1.setPrefWidth(497);
        
        Pane pa2 = new Pane();
        pa2.setStyle("-fx-background-color:linear-gradient(to bottom, #585858, #333333); -fx-background-radius: 10 10 0 0;");
        pa2.setPrefHeight(36);
        pa2.setPrefWidth(497);
        
        Text titre = new Text();
        titre.setText("Dialog de notification");
        titre.setFont(Font.font("System", FontWeight.BOLD, 13));
        titre.setFill(Color.web("#ffffff"));
        titre.setLayoutX(17);
        titre.setLayoutY(22);
        
        Pane pa3 = new Pane();
        pa3.setStyle("-fx-background-color:linear-gradient(to bottom, #E2E2E2, #EDEDED); -fx-border-color: #B4B4B4;");
        pa3.setLayoutY(36);
        pa3.setPrefHeight(48);
        pa3.setPrefWidth(497);
        
        Image image = new Image(getClass().getResourceAsStream("/Public/icon/dialog_notification.png"));
        ImageView icon = new ImageView(image);
        icon.setLayoutX(440);
        icon.setLayoutY(40);
        icon.setFitWidth(40);
        icon.setFitHeight(40);
        
        Text titreMSG = new Text();
        titreMSG.setText(MsgTitre);
        titreMSG.setFont(Font.font("System", FontWeight.NORMAL, 16));
        titreMSG.setFill(Color.web("#000000"));
        titreMSG.setLayoutX(27);
        titreMSG.setLayoutY(65);
        
        Text detail = new Text();
        detail.setText(MsgDetail);
        detail.setFont(Font.font("System", FontWeight.NORMAL, 15));
        detail.setFill(Color.web("#000000"));
        TextFlow DetailMSG = new TextFlow(detail);
        DetailMSG.setPrefHeight(92);
        DetailMSG.setPrefWidth(344);
        DetailMSG.setLayoutX(28);
        DetailMSG.setLayoutY(95);
        
        
        
        Button bouttonOK = new Button();
        bouttonOK.setText("Valider");
        bouttonOK.setFont(Font.font ("System", FontWeight.BOLD, 12));
        bouttonOK.setStyle("{-fx-background-color:#EFEFEF; -fx-border-color: #959595; -fx-border-radius: 5 5 5 5;} hover:{-fx-background-color:#E6E6E6;}");
        bouttonOK.setPrefWidth(73);
        bouttonOK.setPrefHeight(28);
        bouttonOK.setLayoutX(300);
        bouttonOK.setLayoutY(186);
        bouttonOK.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                stackpane.setVisible(false);
            }
        });
        
        
        Button bouttonNo = new Button();
        bouttonNo.setText("Annuler");
        bouttonNo.setFont(Font.font ("System", FontWeight.BOLD, 12));
        bouttonNo.setStyle("{-fx-background-color:#EFEFEF; -fx-border-color: #959595; -fx-border-radius: 5 5 5 5;} hover:{-fx-background-color:#E6E6E6;}");
        bouttonNo.setPrefWidth(73);
        bouttonNo.setPrefHeight(28);
        bouttonNo.setLayoutX(400);
        bouttonNo.setLayoutY(186);
        bouttonNo.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                stackpane.setVisible(false);
            }
        });
        
        group.getChildren().addAll(pa1, pa2, titre, pa3, titreMSG, icon, DetailMSG, bouttonOK, bouttonNo);
        
        
       
        
        stackpane.getChildren().add(Ap);
        stackpane.getChildren().add(group);
        
        
        
            
        return stackpane ;
    }
    
    public void ShowAletDialog()
    {
        Node node = DialogAlert(titre, detail);
            
        StackPane Sp = new StackPane();
        Sp.setPrefSize((double)MyWindow.PrincipalContentWidth, (double)MyWindow.PrincipalContentHeight);
        
        Sp.getChildren().add(MyWindow.myParent);
        Sp.getChildren().add(node);
        
        Scene scene = new Scene(Sp);
        Stage stage = MyWindow.myStage;
        stage.setScene(scene);
        stage.show();
    }
    
    public void ShowNotificationDialog(String Titre, String Detail)
    {
        Node node = DialogNotification(Titre, Detail);
            
        StackPane Sp = new StackPane();
        
        Sp.setPrefSize((double)MyWindow.PrincipalContentWidth, (double)MyWindow.PrincipalContentHeight);
        
        Sp.getChildren().add(MyWindow.myParent);
        Sp.getChildren().add(node);
        
        Scene scene = new Scene(Sp);
        Stage stage = MyWindow.myStage;
        stage.setScene(scene);
        stage.show();
    }
    
     public void Show(Node node)
     {
        StackPane Sp = new StackPane();
        
        Sp.setPrefSize((double)MyWindow.PrincipalContentWidth, (double)MyWindow.PrincipalContentHeight);
        Sp.getChildren().add(MyWindow.myParent);
        Sp.getChildren().add(node);
        
        Scene scene = new Scene(Sp);
        
        Stage stage = MyWindow.myStage;  
        stage.setScene(scene);
        stage.show();
    }
}
