<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 Parents</v-tab>
      <v-tab
        ripple
        @click="activeTab('new')"
        v-bind:class="{ active: newActive }"
        id="tab1"
        User
        class="subheading"
      >Add New Parents</v-tab>

      <!-- ****** EDITS  Parents DETAILS ****** -->

      <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="600px" scrollable>
          <v-card flat>
            <v-toolbar color="grey lighten-2" flat>
              <v-spacer></v-spacer>
              <v-toolbar-title>
                <h3 class="hidden-xs-only">Edit Parent Profile</h3>
                <h5
                  class="hidden-sm-only hidden-md-only hidden-lg-only hidden-xl-only"
                >Edit Parent Profile</h5>
              </v-toolbar-title>
              <v-spacer></v-spacer>
              <v-icon @click="close" class="hidden-xs-only pr-2">close</v-icon>
              <v-icon
                @click="close"
                size="26"
                class="hidden-sm-only hidden-md-only hidden-lg-only hidden-xl-only"
              >close</v-icon>
            </v-toolbar>
            <v-card-text style="height: 600px;" class="hidden-xs-only hidden-sm-only">
              <v-form ref="editParentForm" v-model="validEditParent" lazy-validation>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs3 sm4 class="pt-4 subheading">
                      <label class="right">Email ID:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        placeholder="fill your email"
                        v-model="editedItem.email"
                        type="text"
                        name="email"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs3 sm4 class="pt-4 subheading">
                      <label class="right">Father Name:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        v-model="editedItem.fatherName"
                        placeholder="fill your father Name"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs3 sm4 class="pt-4 subheading">
                      <label class="right">Father Cell No:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        v-model="editedItem.fatherCellNo"
                        placeholder="fill your father Cell Number"
                        :rules="editFatherNoRule"
                        type="number"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs3 sm4 class="pt-4 subheading">
                      <label class="right">Father Profession:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        v-model="editedItem.fatherProfession"
                        placeholder="fill your father Profession"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs3 sm4 class="pt-4 subheading">
                      <label class="right">Mother Name:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        v-model="editedItem.motherName"
                        placeholder="fill your Mother Name"
                        type="text"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs3 sm4 class="pt-4 subheading">
                      <label class="right">Mother Cell No:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        v-model="editedItem.motherCellNo"
                        placeholder="fill your  Mother Cell Number"
                        type="number"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs3 sm4 class="pt-4 subheading">
                      <label class="right">Mother Profession:</label>
                    </v-flex>
                    <v-flex xs8 sm6 class="ml-3">
                      <v-text-field
                        v-model="editedItem.motherProfession"
                        placeholder="fill your Mother Profession"
                        type="text"
                        required
                      ></v-text-field>
                    </v-flex>
                  </v-layout>
                </v-flex>
                <v-layout>
                  <v-flex xs12 sm12>
                    <v-card-actions>
                      <v-spacer></v-spacer>
                      <v-btn round dark @click="save">Save</v-btn>
                      <v-spacer></v-spacer>
                    </v-card-actions>
                  </v-flex>
                </v-layout>
              </v-form>
            </v-card-text>
            <v-card-text
              style="height: 600px;"
              class="hidden-lg-only hidden-xl-only hidden-md-only"
            >
              <v-flex xs12>
                <v-layout wrap>
                  <v-flex xs12 class="pt-4 subheading">
                    <label>Email ID:</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      placeholder="fill your email"
                      v-model="editedItem.email"
                      type="text"
                      name="email"
                      required
                    ></v-text-field>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout wrap>
                  <v-flex xs12 class="pt-4 subheading">
                    <label>Father Name:</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      v-model="editedItem.fatherName"
                      placeholder="fill your father Name"
                      required
                    ></v-text-field>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout wrap>
                  <v-flex xs12 class="pt-4 subheading">
                    <label>Father Cell No:</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      v-model="editedItem.fatherCellNo"
                      placeholder="fill your father Cell Number"
                      type="number"
                      required
                    ></v-text-field>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout wrap>
                  <v-flex xs12 class="pt-4 subheading">
                    <label>Father Profession:</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      v-model="editedItem.fatherProfession"
                      placeholder="fill your father Profession"
                      required
                    ></v-text-field>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout wrap>
                  <v-flex xs12 class="pt-4 subheading">
                    <label>Mother Name:</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      v-model="editedItem.motherName"
                      placeholder="fill your Mother Name"
                      type="text"
                      required
                    ></v-text-field>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout wrap>
                  <v-flex xs12 class="pt-4 subheading">
                    <label>Mother Cell No:</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      v-model="editedItem.motherCellNo"
                      placeholder="fill your  Mother Cell Number"
                      type="number"
                      required
                    ></v-text-field>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-flex xs12>
                <v-layout wrap>
                  <v-flex xs12 class="pt-4 subheading">
                    <label>Mother Profession:</label>
                  </v-flex>
                  <v-flex xs12>
                    <v-text-field
                      v-model="editedItem.motherProfession"
                      placeholder="fill your Mother Profession"
                      type="text"
                      required
                    ></v-text-field>
                  </v-flex>
                </v-layout>
              </v-flex>
              <v-layout>
                <v-flex xs12 sm12>
                  <v-card-actions>
                    <v-spacer></v-spacer>
                    <v-btn round dark @click="save">Save</v-btn>
                    <v-spacer></v-spacer>
                  </v-card-actions>
                </v-flex>
              </v-layout>
            </v-card-text>
          </v-card>
        </v-dialog>

        <!-- ****** PROFILE VIEW Parents DEATILS ******  -->

        <v-dialog v-model="dialog1" max-width="600px" scrollable>
          <v-card>
            <v-toolbar color="grey lighten-2" flat>
              <v-spacer></v-spacer>
              <v-toolbar-title>Parent Profile</v-toolbar-title>
              <v-spacer></v-spacer>
              <v-icon @click="close1">close</v-icon>
            </v-toolbar>
            <v-container grid-list-md>
              <v-layout wrap>
                <v-flex xs12>
                  <v-layout>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs6>
                          <h5 class="right my-1">
                            <b>Email:</b>
                          </h5>
                        </v-flex>
                        <v-flex xs6>
                          <h5 class="my-1">{{ editedItem.email }}</h5>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs6>
                          <b>
                            <h5 class="right my-1">
                              <b>Fahter Name:</b>
                            </h5>
                          </b>
                        </v-flex>
                        <v-flex xs6>
                          <h5 class="my-1">{{ editedItem.fatherName }}</h5>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs6>
                          <b>
                            <h5 class="right my-1">
                              <b>Mother Name:</b>
                            </h5>
                          </b>
                        </v-flex>
                        <v-flex xs6>
                          <h5 class="my-1">{{ editedItem.motherName }}</h5>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex sm6>
                          <b>
                            <h5 class="right my-1">
                              <b>Father Cell No:</b>
                            </h5>
                          </b>
                        </v-flex>
                        <v-flex sm6>
                          <h5 class="my-1">{{ editedItem.fatherCellNo }}</h5>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs6>
                          <b>
                            <h5 class="right my-1">
                              <b>Mother Cell No:</b>
                            </h5>
                          </b>
                        </v-flex>
                        <v-flex xs6>
                          <h5 class="my-1">{{ editedItem.motherCellNo }}</h5>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs6>
                          <b>
                            <h5 class="right my-1">
                              <b>Father Profession:</b>
                            </h5>
                          </b>
                        </v-flex>
                        <v-flex xs6>
                          <h5 class="my-1">{{ editedItem.fatherProfession }}</h5>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs6>
                          <b>
                            <h5 class="right my-1">
                              <b>Mother Profession:</b>
                            </h5>
                          </b>
                        </v-flex>
                        <v-flex xs6>
                          <h5 class="my-1">{{ editedItem.motherProfession }}</h5>
                        </v-flex>
                      </v-layout>
                    </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-USERS Parents TABLE ****** -->
        <v-data-table
          :headers="headers"
          :items="parentsList"
          :pagination.sync="pagination"
          :search="search"
        >
          <template slot="items" slot-scope="props">
            <td id="td" class="text-xs-center">{{ props.index + 1}}</td>
            <td id="td" class="text-xs-center">{{ props.item.email }}</td>
            <td id="td" class="text-xs-center">{{ props.item.fatherName }}</td>
            <td id="td" class="text-xs-center">{{ props.item.fatherCellNo }}</td>
            <td id="td" class="text-xs-center">{{ props.item.motherName }}</td>
            <td id="td" class="text-xs-center">{{ props.item.motherCellNo }}</td>
            <td class="text-xs-center">
              <span>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:25px; height:18px; "
                    class="mr5"
                    @click="profile(props.item)"
                    src="/static/icon/eye1.png"
                  />
                  <span>View</span>
                </v-tooltip>
                <v-tooltip top>
                  <img
                    slot="activator"
                    style="cursor:pointer; width:20px; height:18px; "
                    class="mr5"
                    @click="editItem(props.item)"
                    src="/static/icon/edit1.png"
                  />
                  <span>Edit</span>
                </v-tooltip>
              </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 PARENTS DETAILS****** -->
      <v-tab-item>
        <v-container fluid class="mt-5">
          <v-layout align-center justify-center fill-height>
            <v-flex xs12 sm12 md10 lg11>
              <v-card>
                <v-container fluid class>
                  <v-layout>
                    <v-flex xs12>
                      <v-snackbar
                        :timeout="timeout"
                        :top="y === 'top'"
                        :right="x === 'right'"
                        :vertical="mode === 'vertical'"
                        v-model="snackbar"
                        color="success"
                      >{{ text }}</v-snackbar>
                      <v-flex xs12 sm12>
                        <v-form ref="parentForm" v-model="valid" lazy-validation>
                          <v-container fluid class="hidden-xs-only hidden-sm-only">
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout>
                                  <v-flex xs4 class="pt-4 subheading">
                                    <label class="right">Father Cell No:</label>
                                  </v-flex>
                                  <v-flex xs8 class="ml-3">
                                    <v-text-field
                                      v-model="parentData.fatherCellNo"
                                      placeholder="fill your father Cell Number"
                                      type="number"
                                      :rules="fatheCellNoRules"
                                      counter="10"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                              <v-flex xs12 sm6>
                                <v-layout>
                                  <v-flex xs4 class="pt-4 subheading">
                                    <label class="right">Parent Email Id:</label>
                                  </v-flex>
                                  <v-flex xs8 class="ml-3">
                                    <v-text-field
                                      placeholder="fill Parent email"
                                      v-model="parentData.email"
                                      type="text"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout>
                                  <v-flex xs4 class="pt-4 subheading">
                                    <label class="right">Father Name:</label>
                                  </v-flex>
                                  <v-flex xs8 class="ml-3">
                                    <v-text-field
                                      v-model="parentData.fatherName"
                                      placeholder="Fill your father Name"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                              <v-flex xs12 sm6>
                                <v-layout>
                                  <v-flex xs4 class="pt-4 subheading">
                                    <label class="right">Father Profession:</label>
                                  </v-flex>
                                  <v-flex xs8 class="ml-3">
                                    <v-text-field
                                      v-model="parentData.fatherProfession"
                                      placeholder="fill your father Profession"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout>
                                  <v-flex xs4 class="pt-4 subheading">
                                    <label class="right">Mother Name:</label>
                                  </v-flex>
                                  <v-flex xs8 class="ml-3">
                                    <v-text-field
                                      v-model="parentData.motherName"
                                      placeholder="fill your Mother Name"
                                      type="text"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                              <v-flex xs12 sm6>
                                <v-layout>
                                  <v-flex xs4 class="pt-4 subheading">
                                    <label class="right">Mother Cell No:</label>
                                  </v-flex>
                                  <v-flex xs8 class="ml-3">
                                    <v-text-field
                                      v-model="parentData.motherCellNo"
                                      placeholder="fill your  Mother Cell Number"
                                      counter="10"
                                      type="number"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout>
                                  <v-flex xs4 class="pt-4 subheading">
                                    <label class="right">Mother Profession:</label>
                                  </v-flex>
                                  <v-flex xs8 class="ml-3">
                                    <v-text-field
                                      v-model="parentData.motherProfession"
                                      placeholder="fill your Mother Profession"
                                      type="text"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-flex xs12 sm12>
                              <v-layout>
                                <v-flex xs6 sm6 offset-sm1>
                                  <v-btn @click="clear" round dark class="ml-4">clear</v-btn>
                                </v-flex>
                                <v-flex xs6 sm6>
                                  <v-btn
                                    class="right"
                                    @click="submitParentDetails"
                                    round
                                    dark
                                    :loading="loading"
                                    v-show="showParent"
                                  >Add</v-btn>
                                </v-flex>
                              </v-layout>
                            </v-flex>
                          </v-container>
                          <v-container fluid class="hidden-lg-only hidden-xl-only hidden-md-only">
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout wrap>
                                  <v-flex xs12 class="pt-4 subheading">
                                    <label>Father Cell No:</label>
                                  </v-flex>
                                  <v-flex xs12>
                                    <v-text-field
                                      v-model="parentData.fatherCellNo"
                                      :rules="fatheCellNoRules"
                                      counter="10"
                                      placeholder="fill your father Cell Number"
                                      type="number"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                              <v-flex xs12 sm6>
                                <v-layout wrap>
                                  <v-flex xs12 class="pt-4 subheading">
                                    <label>Parent Email Id:</label>
                                  </v-flex>
                                  <v-flex xs12>
                                    <v-text-field
                                      placeholder="fill Parent email"
                                      v-model="parentData.email"
                                      type="text"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout wrap>
                                  <v-flex xs12 class="pt-4 subheading">
                                    <label>Father Name:</label>
                                  </v-flex>
                                  <v-flex xs12>
                                    <v-text-field
                                      v-model="parentData.fatherName"
                                      placeholder="Fill your father Name"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                              <v-flex xs12 sm6>
                                <v-layout wrap>
                                  <v-flex xs12 class="pt-4 subheading">
                                    <label>Father Profession:</label>
                                  </v-flex>
                                  <v-flex xs12>
                                    <v-text-field
                                      v-model="parentData.fatherProfession"
                                      placeholder="fill your father Profession"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout wrap>
                                  <v-flex xs12 class="pt-4 subheading">
                                    <label>Mother Name:</label>
                                  </v-flex>
                                  <v-flex xs12>
                                    <v-text-field
                                      v-model="parentData.motherName"
                                      placeholder="fill your Mother Name"
                                      type="text"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                              <v-flex xs12 sm6>
                                <v-layout wrap>
                                  <v-flex xs42 class="pt-4 subheading">
                                    <label>Mother Cell No:</label>
                                  </v-flex>
                                  <v-flex xs12>
                                    <v-text-field
                                      v-model="parentData.motherCellNo"
                                      placeholder="fill your  Mother Cell Number"
                                      type="number"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-layout>
                              <v-flex xs12 sm6>
                                <v-layout wrap>
                                  <v-flex xs12 class="pt-4 subheading">
                                    <label>Mother Profession:</label>
                                  </v-flex>
                                  <v-flex xs12>
                                    <v-text-field
                                      v-model="parentData.motherProfession"
                                      placeholder="fill your Mother Profession"
                                      type="text"
                                      required
                                    ></v-text-field>
                                  </v-flex>
                                </v-layout>
                              </v-flex>
                            </v-layout>
                            <v-flex xs12 sm12>
                              <v-layout>
                                <v-flex xs6 sm6 offset-sm1>
                                  <v-btn @click="clear" round dark class="ml-4">clear</v-btn>
                                </v-flex>
                                <v-flex xs6 sm6>
                                  <v-btn
                                    class="right"
                                    @click="submitParentDetails"
                                    round
                                    dark
                                    :loading="loading"
                                    v-show="showParent"
                                  >Add</v-btn>
                                </v-flex>
                              </v-layout>
                            </v-flex>
                          </v-container>
                        </v-form>
                      </v-flex>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card>
            </v-flex>
          </v-layout>
        </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 Util from "@/util";
import moment from "moment";

export default {
  data: () => ({
    showParent: true,
    snackbar: false,
    y: "top",
    x: "right",
    mode: "",
    timeout: 3000,
    text: "",
    showLoader: false,
    loading: false,
    date: null,
    search: "",
    menu: false,
    menu1: false,
    dialog: false,
    dialog1: false,
    valid: true,
    validEditParent: true,
    isActive: true,
    newActive: false,
    AddUsercredentials: {},
    pagination: {
      rowsPerPage: 15
    },
    fatherNameRules: [v => !!v || " Father Name is required"],
    fatheCellNoRules: [
      v => !!v || " father Cell Number  is required",
      v => v <= 10000000000 || "Max 10 characters is required"
    ],
    editFatherNoRule: [
      v => !!v || " father Cell Number  is required",
      v => v <= 10000000000 || "Max 10 characters is required"
    ],

    editfatherCellNo: [v => !!v || " Father Name is required"],
    errorMessages: "",
    emailRules: [
      v => !!v || "E-mail is required",
      v =>
        /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) ||
        "E-mail must be valid"
    ],
    headers: [
      {
        text: "No",
        align: "center",
        sortable: false,
        value: "No"
      },
      { text: "Email", value: "email", sortable: false, align: "center" },
      {
        text: "Father Name",
        value: "fatherName",
        sortable: false,
        align: "center"
      },
      {
        text: "Father Cell No",
        value: "fatherName",
        sortable: false,
        align: "center"
      },
      {
        text: "Mother Name",
        value: "motherName",
        sortable: false,
        align: "center"
      },
      {
        text: "Mother Cell No",
        value: "motherCellNo",
        sortable: false,
        align: "center"
      },
      { text: "Action", value: "", sortable: false, align: "center" }
    ],
    parentsList: [],
    editedIndex: -1,
    parentData: {},
    max: 10,
    editedItem: {
      fatherName: "",
      fatherCellNo: "",
      motherName: "",
      motherCellNo: "",
      email: ""
    }
  }),
  watch: {
    menu(val) {
      val && this.$nextTick(() => (this.$refs.picker.activePicker = "YEAR"));
    },
    menu1(val) {
      val && this.$nextTick(() => (this.$refs.picker.activePicker = "YEAR"));
    }
  },
  methods: {
    editItem(item) {
      this.editedIndex = this.parentsList.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.dialog = true;
    },
    profile(item) {
      // console.log("item", item);
      this.editedIndex = this.parentsList.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.dialog1 = true;
    },
    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;
      setTimeout(() => {
        this.editedItem = Object.assign({}, this.defaultItem);
        this.editedIndex = -1;
      }, 300);
    },
    close1() {
      this.dialog1 = false;
    },
    clear() {
      this.$refs.parentForm.reset();
    },
    save() {
      if (this.$refs.editParentForm.validate()) {
        this.editedItem.parentId = this.editedItem._id;
        http()
          .put("/updateParent", this.editedItem)
          .then(response => {
            this.snackbar = true;
            this.color = "green";
            this.text = "Successfully Student Existing User";
            this.getParentDetails();
            this.close();
          })
          .catch(error => {
            this.snackbar = true;
            this.color = "error";
            this.text = error.response.data.message;
            if (error.response.data.statusText) {
              this.text = error.response.data.statusText;
            }
          });
      }
    },
    async submitParentDetails() {
      if (this.$refs.parentForm.validate()) {
        this.parentData.role = "PARENT";
        this.loading = true;
        await http()
          .post("/createParent", this.parentData)
          .then(response => {
            this.parentId = response.data.data.id;
            this.snackbar = true;
            this.text = response.data.data.message;
            this.getParentDetails();
            this.clear();
            this.loading = false;
          })
          .catch(error => {
            // console.log(error.response.data);
            this.snackbar = true;
            this.text = error.response.data.message;
            if (error.response.data.statusText) {
              this.text = error.response.data.statusText;
            }
            this.loading = false;
          });
      }
    },
    getParentDetails() {
      http()
        .get("getParentsList", {
          headers: {
            Authorization: "Bearer " + this.$store.state.token
          }
        })
        .then(response => {
          this.parentsList = response.data.data;
        })
        .catch(error => {
          // console.log("err====>", error.response.data.message);
          this.showLoader = false;
          if (error.response.status === 401) {
            this.$router.replace({ path: "/" });
            this.$store.dispatch("setToken", null);
            this.$store.dispatch("Id", null);
            this.$store.dispatch("Role", null);
          }
        });
    }
  },
  mounted() {
    this.getParentDetails();
  },
  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>