package schedule;/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
//package jonscheduler;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ScrollPane;
import javafx.stage.Stage;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.layout.AnchorPane;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

/**
 * FXML Controller class
 *
 * @author jmiran03
 */
public class ViewSchedule_Controller implements Initializable {

    Stage stage;
    @FXML
    ScrollPane viewContainer;
    @FXML
    ComboBox viewDropDown;
    @FXML
    AnchorPane monthlyView;
    @FXML
    AnchorPane weeklyView;
    @FXML
    TableView tableView;
    @FXML
    TableColumn columnTime;
    @FXML
    TableView weeklyTableView;
    @FXML
    TableColumn columnCourse;
    @FXML
    TableColumn columnSect;
    @FXML
    TableColumn columnClass;
    @FXML
    TableColumn columnType;
    @FXML
    TableColumn columnGE;
    @FXML
    TableColumn columnDays;
    @FXML
    TableColumn columnStart;
    @FXML
    TableColumn columnEnd;
    @FXML
    TableColumn columnInstructor;
    @FXML
    TableColumn columnLocation;
    @FXML
    TableColumn columnLCap;
    @FXML
    TableColumn columnECap;
    @FXML
    TableColumn columnEnrl;
    @FXML
    TableColumn columnWait;
    @FXML
    TableColumn columnDrop;
    @FXML
    TableColumn columnMonday;
    @FXML
    TableColumn columnTuesday;
    @FXML
    TableColumn columnWednesday;
    @FXML
    TableColumn columnThursday;
    @FXML
    TableColumn columnFriday;

    public class TimeRow {

        private SimpleStringProperty time;
        private SimpleStringProperty mondayCourse;
        private SimpleStringProperty tuesdayCourse;
        private SimpleStringProperty wednesdayCourse;
        private SimpleStringProperty thursdayCourse;
        private SimpleStringProperty fridayCourse;

        public TimeRow(String time, String mondayCourse, String tuesdayCourse, String wednesdayCourse, String thursdayCourse, String fridayCourse) {
            this.time = new SimpleStringProperty(time);
            this.mondayCourse = new SimpleStringProperty(mondayCourse);
            this.tuesdayCourse = new SimpleStringProperty(tuesdayCourse);
            this.wednesdayCourse = new SimpleStringProperty(wednesdayCourse);
            this.thursdayCourse = new SimpleStringProperty(thursdayCourse);
            this.fridayCourse = new SimpleStringProperty(fridayCourse);
        }

        public String getTime() {
            return time.get();
        }

        public String getMondayCourse() {
            return mondayCourse.get();
        }

        public String getTuesdayCourse() {
            return tuesdayCourse.get();
        }

        public String getWednesdayCourse() {
            return wednesdayCourse.get();
        }

        public String getThursdayCourse() {
            return thursdayCourse.get();
        }

        public String getFridayCourse() {
            return fridayCourse.get();
        }
    }

    public class ScheduleCourseRow {

        private SimpleStringProperty course;
        private SimpleStringProperty section;
        private SimpleStringProperty classNumber;
        private SimpleStringProperty type;
        private SimpleStringProperty ge;
        private SimpleStringProperty days;
        private SimpleStringProperty start;
        private SimpleStringProperty end;
        private SimpleStringProperty instructor;
        private SimpleStringProperty location;
        private SimpleStringProperty lCap;
        private SimpleStringProperty eCap;
        private SimpleStringProperty enrl;
        private SimpleStringProperty wait;
        private SimpleStringProperty drop;

        public ScheduleCourseRow(String course, String section, String classNumber,
                String type, String ge, String days, String start, String end, String instructor,
                String location, String lCap, String eCap, String enrl, String wait,
                String drop) {

            this.course = new SimpleStringProperty(course);

            this.section = new SimpleStringProperty(section);

            this.classNumber = new SimpleStringProperty(classNumber);

            this.type = new SimpleStringProperty(type);

            this.ge = new SimpleStringProperty(ge);

            this.days = new SimpleStringProperty(days);

            this.start = new SimpleStringProperty(start);

            this.end = new SimpleStringProperty(end);

            this.instructor = new SimpleStringProperty(instructor);

            this.location = new SimpleStringProperty(location);

            this.lCap = new SimpleStringProperty(lCap);

            this.eCap = new SimpleStringProperty(eCap);

            this.enrl = new SimpleStringProperty(enrl);

            this.wait = new SimpleStringProperty(wait);

            this.drop = new SimpleStringProperty(drop);
        }

        public String getCourse() {
            return course.get();
        }

        public String getSection() {
            return section.get();
        }

        public String getClassNumber() {
            return classNumber.get();
        }

        public String getType() {
            return type.get();
        }

        public String getGe() {
            return ge.get();
        }

        public String getDays() {
            return days.get();
        }

        public String getStart() {
            return start.get();
        }

        public String getEnd() {
            return end.get();
        }

        public String getInstructor() {
            return instructor.get();
        }

        public String getLocation() {
            return location.get();
        }

        public String getLCap() {
            return lCap.get();
        }

        public String getECap() {
            return eCap.get();
        }

        public String getEnrl() {
            return enrl.get();
        }

        public String getWait() {
            return wait.get();
        }

        public String getDrop() {
            return drop.get();
        }
    }
    private ObservableList<ScheduleCourseRow> dataList = FXCollections.observableArrayList(
            new ScheduleCourseRow("CPE101", "01", "3304", "Lec", "", "MWF", "09:10AM", "10:00AM", "Workman, J", "022-0211", "36", "30", "36", "14", "7"),
            new ScheduleCourseRow("CPE101", "02", "4208", "Lab", "", "MWF", "10:10AM", "11:00AM", "Workman, J", "014-0301", "35", "30", "36", "14", "7"),
            new ScheduleCourseRow("CPE101", "03", "4605", "Lec", "", "MWF", "10:10AM", "11:00AM", "Armstrong, B", "014-0247", "35", "30", "33", "13", "10"),
            new ScheduleCourseRow("CPE101", "04", "4606", "Lab", "", "MWF", "11:10AM", "12:00PM", "Armstrong, B", "014-0303", "24", "30", "33", "13", "10"),
            new ScheduleCourseRow("CPE101", "05", "4607", "Lec", "", "MWF", "11:10AM", "12:00PM", "Mammen, K", "014-0251", "35", "30", "35", "7", "13"),
            new ScheduleCourseRow("CPE101", "06", "4608", "Lab", "", "MWF", "12:10PM", "01:00PM", "Mammen, K", "014-0301", "35", "30", "35", "7", "13"),
            new ScheduleCourseRow("CPE101", "07", "4609", "Lec", "", "MWF", "12:10PM", "01:00PM", "Workman, J", "026-0104", "72", "30", "39", "12", "4"),
            new ScheduleCourseRow("CPE101", "08", "4961", "Lab", "", "MWF", "01:10PM", "02:00PM", "Workman, J", "014-0301", "35", "30", "39", "12", "4"),
            new ScheduleCourseRow("CPE101", "09", "4962", "Lec", "", "MWF", "12:10PM", "01:00PM", "Campbell, J", "014-0251", "35", "30", "31", "14", "3"),
            new ScheduleCourseRow("CPE101", "10", "4963", "Lab", "", "MWF", "01:10PM", "02:00PM", "Campbell, J", "014-0303", "24", "30", "31", "14", "3"),
            new ScheduleCourseRow("CPE101", "11", "4964", "Lec", "", "MWF", "02:10PM", "03:00PM", "Workman, J", "014-0252", "35", "30", "32", "11", "13"),
            new ScheduleCourseRow("CPE101", "12", "5121", "Lab", "", "MWF", "03:10PM", "04:00PM", "Workman, J", "014-0301", "35", "30", "32", "11", "13"));

    private ObservableList<TimeRow> weeklyDataList = FXCollections.observableArrayList(
            new TimeRow("7:00AM\n\n\n",
                    "CPE 101 Lab\n", "", "CPE 101 Lab\n", "", "CPE 101 Lab\n"),
            new TimeRow("8:00AM\n\n\n",
                    "CPE 101 Lec\n", "", "CPE 101 Lec\n", "", "CPE 101 Lec\n"),
            new TimeRow("9:00AM\n\n\n",
                    "CPE 101 Lab\n", "CPE 315", "CPE 101 Lab\n", "CPE 315", "CPE 101 Lab\n"),
            new TimeRow("10:00AM\n\n\n",
                    "CPE 101 Lec\n", "CPE 315", "CPE 101 Lec\n", "CPE 315", "CPE 101 Lec\n"),
            new TimeRow("11:00AM\n\n\n",
                    "CPE 101 Lab\n", "CPE 456\n", "CPE 101 Lab\n", "CPE 456\n", "CPE 101 Lab\n"),
            new TimeRow("12:00PM\n\n\n",
                    "CPE 101 Lec\n", "CPE 456\n", "CPE 101 Lec\n", "CPE 456\n", "CPE 101 Lec\n"),
            new TimeRow("1:00PM\n\n\n",
                    "", "CPE 315\nCPE 300", "CPE 315\nCPE 300", "CPE 315\nCPE 300", "CPE 315\nCPE 300"),
            new TimeRow("2:00PM\n\n\n",
                    "CPE 357\n", "CPE 315\nCPE 300", "CPE 357\n", "CPE 315\nCPE 300", "CPE 357\n"),
            new TimeRow("3:00PM\n\n\n",
                    "CPE 357\n", "CPE 315\nCPE 300", "CPE 357\n", "CPE 315\nCPE 300", "CPE 357\n"),
            new TimeRow("4:00PM\n\n\n",
                    "", "CPE 315\nCPE 300", "CPE 315\nCPE 300", "CPE 315\nCPE 300", "CPE 315\nCPE 300"),
            new TimeRow("5:00PM\n\n\n",
                    "", "CPE 315\nCPE 300", "CPE 315\nCPE 300", "CPE 315\nCPE 300", "CPE 315\nCPE 300"),
            new TimeRow("6:00PM\n\n\n",
                    "CPE 101 Lab\n", "CPE 300\n", "CPE 101 Lab\n", "CPE 300\n", "CPE 101 Lab\n"),
            new TimeRow("7:00PM\n\n\n",
                    "CPE 101 Lec\n", "CPE 300\n", "CPE 101 Lec\n", "CPE 300\n", "CPE 101 Lec\n"),
            new TimeRow("8:00PM\n\n\n",
                    "", "", "", "", ""),
            new TimeRow("9:00PM\n\n\n",
                    "", "", "", "", ""),
            new TimeRow("10:00PM\n\n\n",
                    "", "", "", "", ""));

    @Override
    public void initialize(URL url, ResourceBundle rb) {
        columnTime.setCellValueFactory(
                new PropertyValueFactory<TimeRow, String>("time"));

        columnMonday.setCellValueFactory(
                new PropertyValueFactory<TimeRow, String>("mondayCourse"));

        columnTuesday.setCellValueFactory(
                new PropertyValueFactory<TimeRow, String>("tuesdayCourse"));

        columnWednesday.setCellValueFactory(
                new PropertyValueFactory<TimeRow, String>("wednesdayCourse"));

        columnThursday.setCellValueFactory(
                new PropertyValueFactory<TimeRow, String>("thursdayCourse"));

        columnFriday.setCellValueFactory(
                new PropertyValueFactory<TimeRow, String>("fridayCourse"));

        weeklyTableView.setItems(weeklyDataList);

        columnCourse.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("course"));
        columnSect.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("section"));
        columnClass.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("classNumber"));
        columnType.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("type"));
        columnGE.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("GE"));
        columnDays.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("days"));
        columnStart.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("start"));
        columnEnd.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("end"));
        columnInstructor.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("instructor"));
        columnLocation.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("location"));
        columnLCap.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("lCap"));
        columnECap.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("eCap"));
        columnEnrl.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("enrl"));
        columnWait.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("wait"));
        columnDrop.setCellValueFactory(
                new PropertyValueFactory<ScheduleCourseRow, String>("drop"));

        tableView.setItems(dataList);
    }
    private final String TABLE_VIEW = "Table View";
    private final String MONTHLY_VIEW = "Monthly View";
    private final String WEEKLY_VIEW = "Weekly View";
    String dropDownValue;

    @FXML
    private void handleComboBoxAction() {
        String dropDownValue = viewDropDown.getSelectionModel().getSelectedItem().toString();
        tableView.setVisible(dropDownValue.equals(TABLE_VIEW));
        monthlyView.setVisible(dropDownValue.equals(MONTHLY_VIEW));
        weeklyView.setVisible(dropDownValue.equals(WEEKLY_VIEW));
    }

    public void setStage(Stage main) {
        this.stage = main;
    }

}