    <template>
  <v-app id="pages-dasboard">
    <v-tabs grow slider-color="gray">
      <v-tab
        ripple
        @click="activeTab('existing')"
        v-bind:class="{ active: isActive }"
        id="tab"
        class="subheading"
      >Existing Exam Schedule</v-tab>
      <v-tab
        ripple
        @click="activeTab('new')"
        v-bind:class="{ active: newActive }"
        id="tab1"
        User
        class="subheading"
      >Add Exam Schedule</v-tab>

      <!-- ****** Edit Exam Schedule****** -->

      <v-tab-item>
        <v-snackbar
          :timeout="timeout"
          :top="y === 'top'"
          :right="x === 'right'"
          :vertical="mode === 'vertical'"
          v-model="snackbar"
          color="success"
        >{{ text }}</v-snackbar>
        <v-dialog v-model="dialog" max-width="800px" scrollable>
          <v-card flat>
            <v-toolbar class="grey lighten-2" flat>
              <v-spacer></v-spacer>
              <v-toolbar-title>
                <h3>Edit Exam Schedule</h3>
              </v-toolbar-title>
              <v-spacer></v-spacer>
            </v-toolbar>
            <v-card-text style="height:670px;">
              <v-form ref="form">
                <v-container fluid>
                  <v-layout>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Exam Name:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-select
                            :rules="examNameRules"
                            :items="examList"
                            v-model="editedItem.examName"
                            label="Select your Exam Name"
                            item-text="examName"
                            item-value="examName"
                          ></v-select>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Class:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-select
                            v-model="editedItem.classId"
                            label="Select your Class"
                            type="text"
                            :items="classList"
                            item-text="classNum"
                            item-value="_id"
                            :rules="classRules"
                            @change="getSections(editedItem.classId)"
                            required
                          ></v-select>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Section:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-select
                            :items="addSection"
                            label="Select your section"
                            v-model="editedItem.sectionId"
                            item-text="name"
                            item-value="_id"
                            name="Select Section"
                            :rules="sectionRules"
                            required
                          ></v-select>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Subject Name:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-select
                            :items="subjects"
                            label="Select your Subject Name"
                            v-model="editedItem.subjectName"
                            item-text="subjectName"
                            item-value="subjectName"
                            name="Select Section"
                            :rules="sectionRules"
                            required
                          ></v-select>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Date:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-menu
                            ref="editDate"
                            :close-on-content-click="false"
                            v-model="editDate"
                            :nudge-right="40"
                            :return-value.sync="editDate"
                            lazy
                            transition="scale-transition"
                            offset-y
                            full-width
                            min-width="290px"
                          >
                            <v-text-field
                              slot="activator"
                              v-model="editedItem.date"
                              label="Select Date"
                              append-icon="event"
                              readonly
                            ></v-text-field>
                            <v-date-picker v-model="editedItem.date" @input="editDate = false"></v-date-picker>
                          </v-menu>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Time From:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-menu
                            ref="menuEdit"
                            :close-on-content-click="false"
                            v-model="menuEdit"
                            :nudge-right="40"
                            :return-value.sync="editedItem.timeFrom"
                            lazy
                            transition="scale-transition"
                            offset-y
                            full-width
                            max-width="290px"
                            min-width="290px"
                          >
                            <v-text-field
                              slot="activator"
                              v-model="editedItem.timeFrom"
                              label="Select your time From"
                              append-icon="access_time"
                              :rules="timeInRules"
                            ></v-text-field>
                            <v-time-picker
                              v-model="editedItem.timeIn"
                              @change="$refs.menuEdit.save(editedItem.timeIn)"
                            ></v-time-picker>
                          </v-menu>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Time To:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-menu
                            ref="timeToEdit"
                            :close-on-content-click="false"
                            v-model="timeToEdit"
                            :nudge-right="40"
                            :return-value.sync="editedItem.timeTo"
                            lazy
                            transition="scale-transition"
                            offset-y
                            full-width
                            max-width="290px"
                            min-width="290px"
                          >
                            <v-text-field
                              slot="activator"
                              v-model="editedItem.timeTo"
                              label="Select your Time To"
                              append-icon="access_time"
                              :rules="timeOutRules"
                            ></v-text-field>
                            <v-time-picker
                              v-model="editedItem.timeTo"
                              @change="$refs.timeToEdit.save(editedItem.timeTo)"
                            ></v-time-picker>
                          </v-menu>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Room:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-text-field
                            placeholder="fill your room"
                            v-model="editedItem.room"
                            @keyup.enter="save"
                          ></v-text-field>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12 sm8 offset-sm2>
                      <v-card-actions>
                        <v-btn round dark @click.native="close">Close</v-btn>
                        <v-spacer></v-spacer>
                        <v-btn round dark @click="save">Save</v-btn>
                      </v-card-actions>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-form>
            </v-card-text>
          </v-card>
        </v-dialog>

        <!-- ****** PROFILE VIEW Exam Schedule  DATA ******  -->

        <v-dialog v-model="dialog1" max-width="600px">
          <v-card>
            <v-toolbar color="grey lighten-2" flat>
              <v-spacer></v-spacer>
              <v-toolbar-title>
                <h3>Exam Schedule</h3>
              </v-toolbar-title>
              <v-spacer></v-spacer>
              <v-icon @click="close1">close</v-icon>
            </v-toolbar>
            <v-card-text>
              <v-container grid-list-md>
                <v-layout wrap>
                  <v-flex>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Exam Name:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.examName }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Class:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.classId }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Section:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.sectionId }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Subject Name:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.subjectName }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Date:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ dates(editedItem.date) }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Time From:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.timeFrom }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Time To:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.timeTo }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Room:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.room }}</h5>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                </v-layout>
              </v-container>
            </v-card-text>
          </v-card>
        </v-dialog>

        <v-snackbar
          :timeout="timeout"
          :top="y === 'top'"
          :right="x === 'right'"
          :vertical="mode === 'vertical'"
          v-model="snackbar"
          color="success"
        >{{ text }}</v-snackbar>

        <!-- ****** EXISTING  Exam Schedule TABLE****** -->
        <v-card flat>
          <v-layout>
            <v-flex xs12>
              <v-layout>
                <v-flex xs2 sm1 md1 class="pt-4 subheading">
                  <label class="right">Class:</label>
                </v-flex>
                <v-flex xs8 sm3 md2 class="ml-3">
                  <v-select
                    v-model="getScheduleData.classId"
                    label="Select your class"
                    type="text"
                    :items="classList"
                    item-text="classNum"
                    item-value="_id"
                    :rules="classRules"
                    @change="getSchedulesList()"
                    required
                  ></v-select>
                </v-flex>
              </v-layout>
            </v-flex>
          </v-layout>
        </v-card>
        <v-data-table
          :headers="headers"
          :items="ScheduleData"
          :pagination.sync="pagination"
          :search="search"
        >
          <template slot="items" slot-scope="props">
            <td class="text-xs-center">{{ props.index + 1}}</td>
            <!-- <td id="td" class="text-xs-center">{{ props.item.bookId.name}}</td> -->
            <td id="td" class="text-xs-center">{{ props.item.examName}}</td>
            <td id="td" class="text-xs-center">{{ props.item.classId.classNum}}</td>
            <td id="td" class="text-xs-center">{{ props.item.sectionId.name }}</td>
            <td id="td" class="text-xs-center">{{ props.item.subjectName }}</td>
            <td id="td" class="text-xs-center">{{ dates(props.item.date) }}</td>
            <td id="td" class="text-xs-center">{{ props.item.timeFrom }} - {{ props.item.timeTo }}</td>
            <td id="td" class="text-xs-center">{{ props.item.room }}</td>
            <td class="text-xs-center">
              <span>
                <img
                  style="cursor:pointer; width:25px; height:18px; "
                  class="mr-5"
                  @click="profile(props.item)"
                  src="/static/icon/eye1.png"
                />
                <img
                  style="cursor:pointer; width:20px; height:18px; "
                  class="mr-5"
                  @click="editItem(props.item)"
                  src="/static/icon/edit1.png"
                />
                <img
                  style="cursor:pointer;width:20px; height:20px; "
                  class="mr-5"
                  @click="deleteSchedule(props.item)"
                  src="/static/icon/delete1.png"
                />
              </span>
            </td>
          </template>
          <v-alert
            slot="no-results"
            :value="true"
            color="error"
            icon="warning"
          >Your search for "{{ search }}" found no results.</v-alert>
        </v-data-table>
      </v-tab-item>

      <!-- ****** ADD  Exam Schedule ****** -->

      <v-tab-item>
        <v-container>
          <v-snackbar
            :timeout="timeout"
            :top="y === 'top'"
            :right="x === 'right'"
            :vertical="mode === 'vertical'"
            v-model="snackbar"
            :color="color"
          >{{ text }}</v-snackbar>
          <v-flex xs12 sm12 class="my-4">
            <v-card flat>
              <v-form ref="form" v-model="valid" lazy-validation>
                <v-container fluid>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Exam Name:</label>
                      </v-flex>
                      <v-flex xs7 sm4 class="ml-3">
                        <v-select
                          label="Select your Exam Name"
                          :rules="examNameRules"
                          :items="examList"
                          v-model="addSchedule.examName"
                          item-text="examName"
                          item-value="examName"
                        ></v-select>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Class:</label>
                      </v-flex>
                      <v-flex xs7 sm4 class="ml-3">
                        <v-select
                          v-model="addSchedule.classId"
                          label="Select your class"
                          type="text"
                          :items="classList"
                          item-text="classNum"
                          item-value="_id"
                          :rules="classRules"
                          @change="getSections(addSchedule.classId)"
                          required
                        ></v-select>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Section:</label>
                      </v-flex>
                      <v-flex xs7 sm4 class="ml-3">
                        <v-select
                          :items="addSection"
                          label="Select Section"
                          v-model="addSchedule.sectionId"
                          item-text="name"
                          item-value="_id"
                          name="Select Section"
                          :rules="sectionRules"
                          required
                        ></v-select>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Subject Name:</label>
                      </v-flex>
                      <v-flex xs7 sm4 class="ml-3">
                        <v-select
                          :items="subjects"
                          label="Select Section"
                          v-model="addSchedule.subjectName"
                          item-text="subjectName"
                          item-value="subjectName"
                          name="Select Section"
                          :rules="sectionRules"
                          required
                        ></v-select>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Date:</label>
                      </v-flex>
                      <v-flex xs7 sm4  class="ml-3">
                        <v-menu
                          ref="menu2"
                          :close-on-content-click="false"
                          v-model="menu2"
                          :nudge-right="40"
                          :return-value.sync="addSchedule.date"
                          lazy
                          transition="scale-transition"
                          offset-y
                          full-width
                          min-width="290px"
                        >
                          <v-text-field
                            slot="activator"
                            v-model="addSchedule.date"
                            label="Select Date"
                            append-icon="event"
                            readonly
                          ></v-text-field>
                          <v-date-picker
                            v-model="addSchedule.date"
                            @input="$refs.menu2.save(addSchedule.date)"
                          ></v-date-picker>
                        </v-menu>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Time From:</label>
                      </v-flex>
                      <v-flex xs7 sm4 class="ml-3">
                        <v-menu
                          ref="menuA"
                          :close-on-content-click="false"
                          v-model="menuB"
                          :nudge-right="40"
                          :return-value.sync="addSchedule.timeFrom"
                          lazy
                          transition="scale-transition"
                          offset-y
                          full-width
                          max-width="290px"
                          min-width="290px"
                        >
                          <v-text-field
                            slot="activator"
                            v-model="addSchedule.timeIn"
                            label="Select your time From"
                            append-icon="access_time"
                            :rules="timeInRules"
                          ></v-text-field>
                          <v-time-picker
                            v-model="addSchedule.timeIn"
                            @change="$refs.menuA.save(addSchedule.timeIn)"
                          ></v-time-picker>
                        </v-menu>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Time To:</label>
                      </v-flex>
                      <v-flex xs7 sm4 class="ml-3">
                        <v-menu
                          ref="menu"
                          :close-on-content-click="false"
                          v-model="menu1"
                          :nudge-right="40"
                          :return-value.sync="addSchedule.timeTo"
                          lazy
                          transition="scale-transition"
                          offset-y
                          full-width
                          max-width="290px"
                          min-width="290px"
                        >
                          <v-text-field
                            slot="activator"
                            v-model="addSchedule.timeTo"
                            label="Select your Time To"
                            append-icon="access_time"
                            :rules="timeOutRules"
                          ></v-text-field>
                          <v-time-picker
                            v-model="addSchedule.timeTo"
                            @change="$refs.menu.save(addSchedule.timeTo)"
                          ></v-time-picker>
                        </v-menu>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs5 class="pt-4 subheading">
                        <label class="right">Room:</label>
                      </v-flex>
                      <v-flex xs7 sm4 class="ml-3">
                        <v-text-field
                          placeholder="fill your room"
                          :rules="roomRules"
                          v-model="addSchedule.room"
                          @keyup.enter="submit"
                        ></v-text-field>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-layout>
                    <v-flex xs12 sm7 offset-sm3>
                      <v-card-actions>
                        <v-btn @click="clear" round dark>clear</v-btn>
                        <v-spacer class="hidden-xs-only"></v-spacer>
                        <v-btn @click="submit" round dark :loading="loading">Add</v-btn>
                      </v-card-actions>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-form>
            </v-card>
          </v-flex>
        </v-container>
      </v-tab-item>
    </v-tabs>
    <div class="loader" v-if="showLoader">
      <v-progress-circular indeterminate color="white"></v-progress-circular>
    </div>
  </v-app>
</template>

<script>
import http from "@/Services/http.js";
import moment from "moment";

export default {
  data: () => ({
    snackbar: false,
    date: null,
    editDate: false,
    menu1: false,
    menuB: false,
    menu2: false,
    menuEdit: false,
    timeToEdit: false,
    color: "",
    y: "top",
    x: "right",
    mode: "",
    timeout: 10000,
    text: "",
    loading: false,
    date: null,
    search: "",
    showLoader: false,
    dialog: false,
    dialog1: false,
    valid: true,
    isActive: true,
    newActive: false,
    addSection: [],
    pagination: {
      rowsPerPage: 15
    },
    examNameRules: [v => !!v || "Exam Name is required"],
    classRules: [v => !!v || "Class Name is required"],
    sectionRules: [v => !!v || "section is required"],
    timeInRules: [v => !!v || "Time In is required"],
    timeOutRules: [v => !!v || "time Out s is required"],
    roomRules: [v => !!v || "Room is required"],
    headers: [
      {
        align: "justify-center",
        text: "No",
        sortable: false,
        value: "No"
      },
      {
        text: "Exam Name",
        vaue: "examName",
        sortable: false,
        align: "center"
      },
      {
        text: "Class",
        value: "classId.classNum",
        sortable: false,
        align: "center"
      },
      {
        text: "Section",
        value: "sectionId.name",
        sortable: false,
        align: "center"
      },
      {
        text: "Subject Name",
        value: "subjectName",
        sortable: false,
        align: "center"
      },
      {
        text: "Date",
        value: "date",
        sortable: false,
        align: "center"
      },
      {
        text: "Time",
        value: "timeFrom",
        sortable: false,
        align: "center"
      },
      {
        text: "Room",
        value: "room",
        sortable: false,
        align: "center"
      },
      { text: "Action", value: "", sortable: false, align: "center" }
    ],
    classList: [],
    examList: [],
    subjects: [],
    addSchedule: {},
    editedItem: {},
    getScheduleData: {},
    ScheduleData: [],
    token: ""
  }),
  methods: {
    dates: function(date) {
      return moment(date).format("MMMM DD, YYYY");
    },
    pickFile() {
      this.$refs.image.click();
    },
    getSchedulesList() {
      this.showLoader = true;
      http()
        .get("/getSchedulesList", {
          params: { classId: this.getScheduleData.classId },
          headers: { Authorization: "Bearer " + this.token }
        })
        .then(response => {
          this.ScheduleData = response.data.data;
          this.showLoader = false;
        })
        .catch(error => {
          // console.log("err====>", err);
          this.showLoader = false;
          this.loadingSearch = false;
          this.snackbar = true;
          this.text = error.response.data.message;
          if (error.response.status === 401) {
            this.$router.replace({ path: "/" });
            this.$store.dispatch("setToken", null);
            this.$store.dispatch("Id", null);
          }
        });
    },
    editItem(item) {
      console.log("item", item);
      this.editedIndex = this.ScheduleData.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.editedItem.classId = this.editedItem.classId._id;
      this.editedItem.sectionId = this.editedItem.sectionId._id;
      this.editedItem.date =
        this.editedItem.date != undefined
          ? (this.editedItem.date = this.editedItem.date.substring(0, 10))
          : (this.editedItem.date = "");
      this.dialog = true;
    },
    profile(item) {
      this.editedIndex = this.ScheduleData.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.editedItem.classId = this.editedItem.classId.classNum;
      this.editedItem.sectionId = this.editedItem.sectionId.name;
      this.dialog1 = true;
    },
    deleteSchedule(item) {
      let deleteSchedule = {
        scheduleId: item._id
      };
      http()
        .delete(
          "/deleteSchedule",
          confirm("Are you sure you want to Delete this?") && {
            params: deleteSchedule
          }
        )
        .then(response => {
          this.snackbar = true;
          this.text = "Successfully Delete Schedule ";
          this.getSchedulesList();
        })
        .catch(error => {
          // console.log(error);
        });
    },
    activeTab(type) {
      switch (type) {
        case "existing":
          this.newActive = false;
          this.isActive = true;
          break;

        default:
          this.newActive = true;
          this.isActive = false;
          break;
      }
    },
    close() {
      this.dialog = false;
    },
    close1() {
      this.dialog1 = false;
    },
    submit() {
      this.loading = true;
      if (this.$refs.form.validate()) {
        http()
          .post("/createSchedule", this.addSchedule)
          .then(response => {
            this.snackbar = true;
            this.text = "New  Exam Schedule added successfully";
            this.getSchedulesList();
            this.color = "succses";
            this.loading = false;
            this.clear();
          })
          .catch(error => {
            if ((this.snackbar = true)) {
              this.text = error.response.data.message;
              this.color = "red";
            }
          });
      }
    },
    clear() {
      this.$refs.form.reset();
      this.disable = false;
      this.loading = false;
    },
    save() {
      this.editedItem.scheduleId = this.editedItem._id;
      http()
        .put("/updateSchedule", this.editedItem)
        .then(response => {
          this.snackbar = true;
          this.text = "Successfully Edit Exam Schedule";
          this.color = "green";
          this.getSchedulesList();
          this.close();
        })
        .catch(error => {
          this.snackbar = true;
          this.text = error.response.data.message;
          this.color = "red";
        });
    },
    getClass() {
      http()
        .get("/getClassesList", {
          headers: { Authorization: "Bearer " + this.token }
        })
        .then(response => {
          this.classList = response.data.data;
          // console.log("getClassesList=====>",this.addclass)
        })
        .catch(err => {
          // console.log("err====>", err);
        });
    },
    getSections(_id) {
      console.log(_id);
      for (let i = 0; i < this.classList.length; i++) {
        if (_id == this.classList[i]._id) {
          //   console.log(this.classList[i].subjects);
          this.subjects = this.classList[i].subjects;
        }
      }
      http()
        .get(
          "/getSectionsList",
          { params: { classId: _id } },
          {
            headers: { Authorization: "Bearer " + this.token }
          }
        )
        .then(response => {
          this.addSection = response.data.data;
        })
        .catch(err => {
          // console.log("err====>", err);
        });
    },
    getExamList() {
      this.showLoader = true;
      this.loadingSearch = true;
      http()
        .get("/getExamsList", {
          headers: { Authorization: "Bearer " + this.token }
        })
        .then(response => {
          this.examList = response.data.data;
          this.showLoader = false;
          this.loadingSearch = false;
        })
        .catch(error => {
          // console.log("err====>", err);
          this.showLoader = false;
          this.loadingSearch = false;
          this.snackbar = true;
          this.text = error.response.data.message;
          if (error.response.status === 401) {
            this.$router.replace({ path: "/" });
            this.$store.dispatch("setToken", null);
            this.$store.dispatch("Id", null);
          }
        });
    }
  },
  mounted() {
    this.token = this.$store.state.token;
    // this.getSchedulesList();
    this.getClass();
    this.getExamList();
  },
  created() {
    this.$root.$on("app:search", search => {
      this.search = search;
    });
  },
  beforeDestroy() {
    // dont forget to remove the listener
    this.$root.$off("app:search");
  }
};
</script>
<style scoped>
.active {
  background-color: gray;
  color: white !important;
}
.activebtn {
  color: black !important;
}
</style>