package project_1;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
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 ShowData {
  
     /*
      * This Class Print the Information of students in each course
      * */	
	private LinkedList<Course> CoursesList;
	
	Stage stage = new Stage();
	GridPane root =new GridPane();
	Scene s;
	Button next = new Button("Next");
	Button prev = new Button("Prev");

	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");
	private Label courseLabel = new Label();
	private int counter;


	public ShowData(LinkedList<Course> coursesList) {

		this.CoursesList = coursesList;
		


	}

	public void show(){

		stage.initModality(Modality.APPLICATION_MODAL);
		root.setAlignment(Pos.CENTER);
		root.setHgap(15);
		root.setVgap(15);
		courseLabel.setTextFill(Paint.valueOf("#ff00ff"));
		courseLabel.setFont(Font.font("verdana",FontWeight.BOLD,30));


		next.setStyle("-fx-font-size:24px;");
		prev.setStyle("-fx-font-size:24px;");

	
		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(counter));
		table.getColumns().addAll(nameColum,idColoum,coursesColoum);
		root.add(courseLabel, 1, 0);
		root.add(table, 1, 1);

		next.setStyle("-fx-font-size:24px;");
		prev.setStyle("-fx-font-size:24px;");

		next.setOnAction(e-> {
			++counter;
			if(counter==CoursesList.getSize()){
				counter=0;
			}
			nextTable();
		});
		prev.setOnAction(e->{
			--counter;
			if(counter < 0 )
				counter=CoursesList.getSize()-1;
			prevTable();
		});
		root.add(next, 2, 3);
		root.add(prev, 1, 3);
		s = new Scene(root,900,600);
		s.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
		stage.setScene(s);
		stage.show();
	}

	public  ObservableList<Student> get(int counter){


		ObservableList<Student> array = FXCollections.observableArrayList();
		courseLabel.setText(CoursesList.getIndexData(counter).getName());
		for (int i = 0; i <CoursesList.getIndexData(counter).getList().getSize() ; i++) {
			array.add(CoursesList.getIndexData(counter).getList().getIndexData(i));
		}

		return array;

	}

	public void nextTable(){

		table.getItems().clear();
		table.setItems(get(counter));
	}
	public void prevTable(){

		table.getItems().clear();
		table.setItems(get(counter));
	}


}
