package project_1;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Label;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class SpecificStudentData {

	/*
	 * This class print Specific Student Scedule
	 * */
	private LinkedList<Student> studentList;
	private Student s;
	private int index;
	private Label name = new Label();
	private Label id = new Label();
	Stage stage = new Stage();
	GridPane pane =new GridPane();

	public SpecificStudentData(LinkedList<Student> studentList,Student s) {
		this.studentList = studentList;
		this.s=s;
	}
	private TableView<Course> table = new TableView<Course>();
	private TableColumn<Course, String> nameColum =new TableColumn<Course, String>("Name");
	private TableColumn<Course, String> idColoum = new TableColumn<Course, String>("ID");
	private TableColumn<Course, String> startTimeColum = new TableColumn<Course, String>("Start Time");
	private TableColumn<Course, String> FinsihTimeColum = new TableColumn<Course, String>("Finish Time");

	public void show(){
		
		
		if(findStudent()==-1){
			Alert a = new Alert(AlertType.ERROR);
			a.setContentText("The Student is Not found !!!!");
			a.show();

		}
		else{
			stage.initModality(Modality.APPLICATION_MODAL);
			pane.setAlignment(Pos.CENTER);
			pane.setHgap(5);
			pane.setVgap(5);
			
			name.setTextFill(Paint.valueOf("red"));
			id.setTextFill(Paint.valueOf("brown"));
			id.setFont(Font.font("verdana",FontWeight.BOLD,15));
			name.setFont(Font.font("verdana",FontWeight.BOLD,15));
			
			nameColum.setCellValueFactory(new PropertyValueFactory<>("name"));
			nameColum.setMinWidth(200);
			idColoum.setCellValueFactory(new PropertyValueFactory<>("id"));
			idColoum.setMinWidth(200);
			startTimeColum.setCellValueFactory(new PropertyValueFactory<>("startTime"));
			startTimeColum.setMinWidth(200);
			FinsihTimeColum.setCellValueFactory(new PropertyValueFactory<>("finishTime"));
			FinsihTimeColum.setMinWidth(200);
			table.setItems(get());
		
			table.getColumns().addAll(nameColum,idColoum,startTimeColum,FinsihTimeColum);

			pane.add(table, 1, 2);
			pane.add(name, 0, 0);
			pane.add(id, 0, 1);
			Scene s = new Scene(pane,1000,600);
			s.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
			stage.setScene(s);
			stage.show();
		}

	}

	public int findStudent(){
		for (int i = 0; i < studentList.getSize(); i++) {
			if(studentList.getIndexData(i).getId() == s.getId() && studentList.getIndexData(i).getName().equalsIgnoreCase(s.getName())){
				index=i;
				return i;
			}
		}
		return -1;
	}

	public  ObservableList<Course> get(){
		ObservableList<Course> array = FXCollections.observableArrayList();

		name.setText(studentList.getIndexData(index).getName());
		id.setText(String.valueOf(studentList.getIndexData(index).getId()));

		for (int i = 0; i <studentList.getIndexData(index).getList().getSize() ; i++) {
			array.add(studentList.getIndexData(index).getList().getIndexData(i));
		}

		return array;

	}
}
