package project_1;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
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 CoursesInformation {
	
	/*
	 * This Class Print all courses on a TableView sorting by year
	 * */
	
	private LinkedList<Course> sortedYearList ;
	Stage stage = new Stage();

	private TableView<Course> table = new TableView<Course>();
	Label name =  new Label("Courses Information");
	
	GridPane pane =new GridPane();
	public CoursesInformation(LinkedList<Course> sortedYearList) {

		this.sortedYearList = sortedYearList;
	}



	private TableColumn<Course, String> nameColum =new TableColumn<Course, String>("Name");
	private TableColumn<Course, String> idColum =new TableColumn<Course, String>("ID");
	private TableColumn<Course, Integer> yearColum = new TableColumn<Course, Integer>("Year");
	private TableColumn<Course, Integer> noOfStudentsColum = new TableColumn<Course, Integer>("No. of Students");

	public void show(){
		stage.initModality(Modality.APPLICATION_MODAL);
		pane.setAlignment(Pos.CENTER);
		pane.setHgap(15);
		pane.setVgap(15);
		name.setTextFill(Paint.valueOf("#ff00ff"));
		name.setFont(Font.font("verdana",FontWeight.BOLD,30));
		
		nameColum.setCellValueFactory(new PropertyValueFactory<>("name"));
		nameColum.setMinWidth(200);
		idColum.setCellValueFactory(new PropertyValueFactory<>("id"));
		idColum.setMinWidth(200);
		
		noOfStudentsColum.setCellValueFactory(new PropertyValueFactory<>("noOfStudents"));
		noOfStudentsColum.setMinWidth(200);
		
		yearColum.setCellValueFactory(new PropertyValueFactory<>("year"));
		yearColum.setMinWidth(200);

		table.setItems(get());

		table.getColumns().addAll(nameColum,idColum,yearColum,noOfStudentsColum);

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

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

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

		return array;

	}

}
