package project_3;
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 PrintCountries {
	
	/*This Class print the Countries Information on GUI*/

	private LinkedList<Country> countryList;
	
	Stage stage = new Stage();
	GridPane pane =new GridPane();
	
	private TableView<Country> table = new TableView<Country>();
	private TableColumn<Country, String> nameColoum =new TableColumn<Country, String>("Name");
	private TableColumn<Country, Double> noColoum = new TableColumn<Country, Double>("No of Tourists");
	private TableColumn<Country, String> citiesColoum = new TableColumn<Country, String>("Cities");

	private TreeNode<Country> root;
	Label rootLable = new Label("Root Higth : ");
	Label countLabel = new Label("# Of Nodes : ");
	
	public PrintCountries(LinkedList<Country> countryList,TreeNode<Country> root,int count) {
		super();
		this.countryList = countryList;
		this.root=root;
		countLabel.setText(countLabel.getText()+count);

	}
	public void show(){

		stage.initModality(Modality.APPLICATION_MODAL);

		pane.setAlignment(Pos.CENTER);
		pane.setHgap(15);
		pane.setVgap(15);
		
		nameColoum.setCellValueFactory(new PropertyValueFactory<>("name"));
		nameColoum.setMinWidth(200);
		
		noColoum.setCellValueFactory(new PropertyValueFactory<>("totalNo"));
		
		citiesColoum.setCellValueFactory(new PropertyValueFactory<>("cities"));
		citiesColoum.setMinWidth(600);
		
		
		table.setItems(get());
		table.getColumns().addAll(nameColoum,noColoum,citiesColoum);
		
		rootLable.setText(rootLable.getText()+root.height);
		
		
		countLabel.setFont(Font.font("verdana",FontWeight.BOLD,20));
		countLabel.setTextFill(Paint.valueOf("gold"));
		rootLable.setFont(Font.font("verdana",FontWeight.BOLD,20));
		rootLable.setTextFill(Paint.valueOf("gold"));
		pane.add(table,0, 0);
		pane.add(rootLable, 0, 1);
		pane.add(countLabel, 0, 2);
		Scene s = new Scene(pane,900,700);
		s.getStylesheets().addAll(this.getClass().getResource("application.css").toExternalForm());
		stage.setScene(s);
		stage.setTitle("Countries Information");
		stage.show();
		
	}
	public  ObservableList<Country> get(){
		ObservableList<Country> array = FXCollections.observableArrayList();

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

		return array;

	}
	
}
