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 PrintAllStudents {
    /*
     * This Class Print all Student in all courses on a TabelView sorted by name
     * */
	
	private LinkedList<Student> sortedNameList;

	public PrintAllStudents(LinkedList<Student> sortedNameList) {

		this.sortedNameList = sortedNameList;
	}

	Stage stage = new Stage();
	GridPane pane =new GridPane();
	Label title = new Label("All Students Information");
	
	private TableView<Student> table = new TableView<Student>();
	private TableColumn<Student, String> nameColum =new TableColumn<Student, String>("Name");
	private TableColumn<Student, Integer> idColoum = new TableColumn<Student, Integer>("ID");
	private TableColumn<Student, String> coursesColoum = new TableColumn<Student, String>("Courses He/she take");
	
	public void show(){
		
		stage.initModality(Modality.APPLICATION_MODAL);
		
		pane.setAlignment(Pos.CENTER);
		pane.setHgap(15);
		pane.setVgap(15);
	

		title.setTextFill(Paint.valueOf("#ff00ff"));
		title.setFont(Font.font("verdana",FontWeight.BOLD,30));
		
		nameColum.setCellValueFactory(new PropertyValueFactory<>("name"));
		nameColum.setMinWidth(200);
		idColoum.setCellValueFactory(new PropertyValueFactory<>("id"));
		idColoum.setMinWidth(200);
		coursesColoum.setCellValueFactory(new PropertyValueFactory<>("coursesNames"));
		coursesColoum.setMinWidth(300);
		table.setItems(get());
		table.getColumns().addAll(nameColum,idColoum,coursesColoum);
		
		pane.add(title, 0, 0);
		pane.add(table, 0, 1);

		Scene s = new Scene(pane,900,600);
		 s.getStylesheets().addAll(this.getClass().getResource("application.css").toExternalForm());
		stage.setScene(s);
		stage.show();

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

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

		return array;

	}
}
