package project_1;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class MainScene {
     /*
      * This Class is Main Scene that has a different Choices to the user
      * */
	
	private LinkedList<Course> CoursesList;
	private LinkedList<Student>studentList;
	private LinkedList<Student> sortedNameList;
	private LinkedList<Course> sortedCourseList;
	
	private Stage stage = new Stage();
	private GridPane pane =new GridPane();
	
	private Label nam = new Label("Mohammad Nabil");
	
	private RadioButton StudentInfo = new RadioButton("print Student Information In Each Course ");
	private RadioButton StudentSchedule = new RadioButton("Print Specific Student Schedule ");
	private RadioButton coursesInfo = new RadioButton("Print Courses Information ");
	private RadioButton AllStudentList = new RadioButton("Print All Students In All Courses");
	private ToggleGroup tg = new ToggleGroup();
	Button submit =new Button("Submit"); 
	TextField name = new TextField();
	TextField id = new TextField();
	Button ok = new Button("Ok");

	public MainScene(LinkedList<Course> coursesList, LinkedList<Student> studentList,LinkedList<Student> sortedNameList,
			LinkedList<Course> sortedCourseList) {

		this.sortedCourseList=sortedCourseList;
		this.sortedNameList = sortedNameList;
		this.CoursesList = coursesList;
		this.studentList = studentList;

	}
	public void show(){
		Text title = new Text("Choose One Of These  :");
		title.setFill(Paint.valueOf("#FF0000"));
		title.setFont(Font.font("verdana",FontWeight.BOLD,24));

		StudentInfo.setToggleGroup(tg);
		StudentSchedule.setToggleGroup(tg);
		coursesInfo.setToggleGroup(tg);
		AllStudentList.setToggleGroup(tg);

		StudentInfo.setStyle("-fx-font-size:24px;");
		StudentSchedule.setStyle("-fx-font-size:24px;");
		coursesInfo.setStyle("-fx-font-size:24px;");
		AllStudentList.setStyle("-fx-font-size:24px;");

		StudentInfo.setTextFill(Paint.valueOf("gold"));
		StudentSchedule.setTextFill(Paint.valueOf("gold"));
		coursesInfo.setTextFill(Paint.valueOf("gold"));
		AllStudentList.setTextFill(Paint.valueOf("gold"));

		submit.setStyle("-fx-font-size:24px;");
		ok.setStyle("-fx-font-size:24px;");
		name.setFont(Font.font("verdana",FontWeight.BOLD,15));
		id.setFont(Font.font("verdana",FontWeight.BOLD,15));
		pane.setAlignment(Pos.CENTER);
		pane.setHgap(15);
		pane.setVgap(15);

		name.setPromptText("Enter The Name");
		id.setPromptText("Enter ID");
		
		pane.add(title, 0, 0);
		pane.add(StudentInfo, 0, 1);
		pane.add(StudentSchedule, 0, 2);
		pane.add(coursesInfo, 0, 3);
		pane.add(AllStudentList, 0, 4);
		pane.add(submit, 2, 6);

		StudentInfo.setOnAction(e->{
			name.setVisible(false);
			id.setVisible(false);
			ok.setVisible(false);
		});
		
		coursesInfo.setOnAction(e->{
			name.setVisible(false);
			id.setVisible(false);
			ok.setVisible(false);
		});

		AllStudentList.setOnAction(e->{
			name.setVisible(false);
			id.setVisible(false);
			ok.setVisible(false);
		});
		submit.setOnAction(e->{
			if(StudentInfo.isSelected()){
				
				new ShowData(CoursesList).show();
			}
			if(coursesInfo.isSelected()){
			
				new CoursesInformation(sortedCourseList).show();;
			}
			if(AllStudentList.isSelected()){
				
				new PrintAllStudents(sortedNameList).show();;
			}
			if(StudentSchedule.isSelected()){


				name.setVisible(true);
				id.setVisible(true);
				ok.setVisible(true);

			}
		});

		ok.setOnAction(e->{
			try{
				Student s = new Student(name.getText(), Integer.parseInt(id.getText()));
				new SpecificStudentData(studentList, s).show();
			}
			catch (Exception ex) {
				Alert a = new Alert(AlertType.ERROR);
				a.setContentText(" Error Fields!!");
				a.show();
			}
		});
		
		
		nam.setTextFill(Paint.valueOf("#c0e51b"));
		nam.setFont(Font.font("algerian",FontWeight.BOLD,15));
		pane.add(name, 0, 7);
		pane.add(id, 0, 8);
		pane.add(ok, 0, 9);
		pane.add(nam, 4, 0);
		name.setVisible(false);
		id.setVisible(false);
		ok.setVisible(false);
		Scene s = new Scene(pane,800,500);
		s.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
		stage.setScene(s);
		stage.setTitle("Welcome :)");
		stage.show();


	}

}
