<template>
  <v-container fluid class="body-color">
    <v-dialog v-model="editParentDilaog" max-width="600px" scrollable persistent>
      <v-card flat class="Card-style pa-2">
        <v-layout>
          <v-flex xs12>
            <label class="title text-xs-center">Edit Parents Details</label>
            <v-icon size="24" class="right" @click="editParentDilaog = false">cancel</v-icon>
          </v-flex>
        </v-layout>
        <v-card-text 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>
            <!-- EDIT FATHER CELL NUMBER - HIDDEN AT xs and sm screen -->
            <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-layout row wrap>
                    <v-flex md3 class="mt-3">
                      <vue-country-code @onSelect="editFatherCellCode" class="black--text"></vue-country-code>
                    </v-flex>
                    <v-flex md9>
                      <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-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-layout row wrap>
                    <v-flex md3 class="mt-3">
                      <vue-country-code @onSelect="onSelect" class="black--text"></vue-country-code>
                    </v-flex>
                    <v-flex md9>
                      <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-layout>
            </v-flex>
            <v-flex xs12>
              <!-- EDIT MOTHER CELL NUMBER - HIDDEN AT xs and sm screen -->
              <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-layout>
                <v-flex xs4 class="pt-4 subheading">
                  <label class="right">Password:</label>
                </v-flex>
                <v-flex xs8 class="ml-3">
                  <v-text-field
                    v-model="editedItem.password"
                    placeholder="Enter Password"
                    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" class="add-button">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>
            <!-- EDIT FATHER CELL NUMBER - visible AT xs and sm screen -->
            <v-layout wrap>
              <v-flex xs12 class="pt-4 subheading">
                <label>Father Cell No:</label>
              </v-flex>
              <v-flex xs12>
                <v-layout row wrap>
                  <v-flex sm3 class="mt-3">
                    <vue-country-code @onSelect="editFatherCellCode" class="black--text"></vue-country-code>
                  </v-flex>
                  <v-flex sm9>
                    <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-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>
            <!-- EDIT MOTHER CELL NUMBER -  VISIBLE ONLY AT xs and sm screen -->
            <v-layout wrap>
              <v-flex xs12 class="pt-4 subheading">
                <label>Mother Cell No:</label>
              </v-flex>
              <v-flex xs12>
                <v-layout row wrap>
                  <v-flex sm3 class="mt-3">
                    <vue-country-code @onSelect="onSelect" class="black--text"></vue-country-code>
                  </v-flex>
                  <v-flex sm9>
                    <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-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-flex xs12 class="pt-4 subheading">
                <label>Password:</label>
              </v-flex>
              <v-flex xs12>
                <v-text-field
                  v-model="editedItem.password"
                  placeholder="Enter Password"
                  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" class="add-button">Save</v-btn>
                <v-spacer></v-spacer>
              </v-card-actions>
            </v-flex>
          </v-layout>
        </v-card-text>
      </v-card>
    </v-dialog>

    <!-- ****** RESET Parents MPIN ******  -->
    <v-dialog v-model="resetParentMpin" max-width="500px" scrollable persistent>
      <v-card class="Card-style pa-2">
        <v-layout>
          <v-flex xs12>
            <label class="title text-xs-center">Reset Mpin</label>
            <v-icon size="24" class="right" @click="resetParentMpin = false">cancel</v-icon>
          </v-flex>
        </v-layout>
        <v-card-text class="hidden-xs-only hidden-sm-only">
          <v-form ref="resetParentMpinForm" v-model="validParentMpin" lazy-validation>
            <v-flex xs12>
              <v-layout>
                <v-flex xs3 sm4 class="pt-4 subheading">
                  <label class="right">Change Mpin:</label>
                </v-flex>
                <v-flex xs8 sm6 class="ml-3">
                  <v-text-field
                    placeholder="change mpin"
                    :rules="mPinRules"
                    v-model="editMpin.mPin"
                    type="number"
                    counter="4"
                    required
                  ></v-text-field>
                </v-flex>
              </v-layout>
            </v-flex>
          </v-form>
          <v-layout>
            <v-flex xs12 sm12>
              <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn round dark @click="resetMpin" class="add-button">Reset</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="profileParentDialog" max-width="700px" persistent>
      <v-card class="Card-style pa-2">
        <v-layout>
          <v-flex xs12>
            <label class="title text-xs-center">View Parent Details</label>
            <v-icon size="24" class="right" @click="profileParentDialog = false">cancel</v-icon>
          </v-flex>
        </v-layout>
        <v-flex align-center justify-center layout text-xs-center class="mt-3">
          <v-avatar size="100px">
            <img src="/static/icon/user.png" v-if="!editedItem.profilePicUrl" />
            <img :src="editedItem.profilePicUrl" v-else-if="editedItem.profilePicUrl" />
          </v-avatar>
        </v-flex>
        <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 xs6>
                      <b>
                        <h5 class="right my-1">
                          <b>Father Cell No:</b>
                        </h5>
                      </b>
                    </v-flex>
                    <v-flex sm6 xs6>
                      <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 hidden-lg-only hidden-xl-only hidden-md-only">
                          <b>FatherProfession:</b>
                        </h5>
                        <h5 class="right my-1 hidden-sm-only hidden-xs-only">
                          <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 hidden-lg-only hidden-xl-only hidden-md-only">
                          <b>MotherProfession:</b>
                        </h5>
                        <h5 class="right my-1 hidden-sm-only hidden-xs-only">
                          <b>Mother Profession:</b>
                        </h5>
                      </b>
                    </v-flex>
                    <v-flex xs6>
                      <h5 class="my-1">{{ editedItem.motherProfession }}</h5>
                    </v-flex>
                  </v-layout>
                  <!-- <v-layout>
                    <v-flex xs6>
                      <b>
                        <h5 class="right my-1 hidden-lg-only hidden-xl-only hidden-md-only">
                          <b>Password:</b>
                        </h5>
                        <h5 class="right my-1 hidden-sm-only hidden-xs-only">
                          <b>Password:</b>
                        </h5>
                      </b>
                    </v-flex>
                    <v-flex xs6>
                      <h5 class="my-1">{{ editedItem.password }}</h5>
                    </v-flex>
                  </v-layout>-->
                </v-flex>
              </v-layout>
            </v-flex>
          </v-layout>
        </v-container>
      </v-card>
    </v-dialog>
    <!-- ****** EXISTING-USERS Parents TABLE ****** -->
    <v-toolbar color="transparent" flat>
      <v-btn
        fab
        dark
        class="open-dialog-button hidden-xl-only hidden-md-only hidden-lg-only"
        small
        @click="addParentDialog = true"
      >
        <v-icon dark>add</v-icon>
      </v-btn>
      <v-btn
        v-if="role != 'TEACHER' "
        round
        class="open-dialog-button hidden-sm-only hidden-xs-only"
        dark
        @click="addParentDialog = true"
      >
        <v-icon class="white--text pr-1" size="20">add</v-icon>Add Parent
      </v-btn>
      <v-spacer></v-spacer>
      <v-card-title class="body-1" v-show="show">
        <v-btn icon large flat @click="displaySearch">
          <v-avatar size="27">
            <img src="/static/icon/search.png" alt="icon" />
          </v-avatar>
        </v-btn>
      </v-card-title>
      <v-flex xs8 sm8 md2 lg2 v-if="showSearch">
        <v-layout>
          <v-text-field
            v-model="search"
            label="Search"
            prepend-inner-icon="search"
            color="primary"
            ref="searchField"
            autofocus
            style="transition: 0.8s cubic-bezier(0.25, 0.8, 0.25, 1); !important"
          ></v-text-field>
          <v-icon @click="closeSearch" color="error">close</v-icon>
        </v-layout>
      </v-flex>
    </v-toolbar>
    <v-data-table
      :headers="headers"
      :items="parentsList"
      :pagination.sync="pagination"
      :search="search"
    >
      <template slot="items" slot-scope="props">
        <tr class="tr">
          <td class="text-xs-center td td-row">{{ props.index + 1}}</td>
          <td class="text-xs-center td td-row">{{ props.item.email }}</td>
          <td class="text-xs-center td td-row">{{ props.item.fatherName }}</td>
          <td class="text-xs-center td td-row">{{ props.item.fatherCellNo }}</td>
          <td class="text-xs-center td td-row">{{ props.item.motherName }}</td>
          <td class="text-xs-center td td-row">{{ props.item.motherCellNo }}</td>
          <td class="text-xs-center td td-row">
            <span>
              <v-tooltip top>
                <img
                  slot="activator"
                  style="cursor:pointer; width:25px; height:25px; "
                  class="mr-3"
                  @click="profile(props.item)"
                  src="/static/icon/view.png"
                />
                <span>View</span>
              </v-tooltip>
              <v-tooltip top v-if="role != 'TEACHER' ">
                <img
                  slot="activator"
                  style="cursor:pointer; width:20px; height:18px; "
                  @click="editItem(props.item)"
                  src="/static/icon/edit.png"
                  class="mr-3"
                />
                <span>Edit</span>
              </v-tooltip>
              <span v-if="role === 'ADMIN' ">
                <i
                  class="material-icons md-18"
                  style="cursor:pointer; width:20px; height:18px;"
                  @click="resetParentMPIN(props.item)"
                >vpn_key</i>
              </span>
            </span>
          </td>
        </tr>
      </template>
      <v-alert
        slot="no-results"
        :value="true"
        color="error"
        icon="warning"
      >Your search for "{{ search }}" found no results.</v-alert>
    </v-data-table>

    <!-- ******DIALOG BOX -  ADD PARENTS DETAILS****** -->
    <v-dialog v-model="addParentDialog" max-width="1100px" v-if="addParentDialog" persistent>
      <v-card flat class="Card-style pa-2">
        <v-layout>
          <v-flex xs12>
            <label class="title text-xs-center">Add Parent</label>
            <v-icon
              size="24"
              class="right"
              @click="$refs.parentForm.reset();addParentDialog = false"
            >cancel</v-icon>
          </v-flex>
        </v-layout>
        <v-container fluid fill-height>
          <v-layout align-center>
            <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>
                    <!-- ADD FATHER CELL NUMBER HIDDEN ON xs and sm screen-->
                    <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-layout row wrap>
                            <v-flex md3 class="mt-3">
                              <vue-country-code @onSelect="addFatherCellCode" class="black--text"></vue-country-code>
                            </v-flex>
                            <v-flex md9>
                              <v-text-field
                                v-model="parentData.fatherCellNo"
                                placeholder="Father Cell Number"
                                type="number"
                                :rules="fatheCellNoRules"
                                counter="10"
                                required
                              ></v-text-field>
                            </v-flex>
                          </v-layout>
                        </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>
                    <!-- MOTHER CELL NUMBER HIDDEN ON xs and sm screen -->
                    <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-layout row wrap>
                            <v-flex md3 class="mt-3">
                              <vue-country-code @onSelect="onSelect" class="black--text"></vue-country-code>
                            </v-flex>
                            <v-flex md9>
                              <v-text-field
                                v-model="parentData.motherCellNo"
                                placeholder="Mother Cell Number"
                                counter="10"
                                type="number"
                                required
                              ></v-text-field>
                            </v-flex>
                          </v-layout>
                        </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-flex xs12 sm6>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Password:</label>
                        </v-flex>
                        <v-flex xs8 class="ml-3">
                          <v-text-field
                            v-model="parentData.password"
                            :append-icon="e1 ? 'visibility_off' : 'visibility'"
                            :append-icon-cb="() => (e1 = !e1)"
                            :type="e1 ? 'password' : 'text'"
                            :rules="password"
                            placeholder="Enter Your Password"
                            :disabled="isFatherCellExists"
                            required
                          ></v-text-field>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-flex xs12 sm12>
                    <v-layout>
                      <v-flex xs12 sm12>
                        <v-btn
                          class="right add-button"
                          @click="submitParentDetails"
                          round
                          dark
                          :loading="loading"
                          v-show="showParent"
                        >Add</v-btn>
                        <v-btn @click="clear" round dark class="clear-button right">Clear</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 wrap>
                    <!-- ADD FATHER CELL NUMBER -- VISIBLE ON xs and sm screens -->
                    <v-flex xs12 sm6>
                      <v-layout wrap>
                        <v-flex xs12 class="pt-4 subheading">
                          <label>Father Cell No:</label>
                        </v-flex>
                        <v-layout row wrap xs12>
                          <v-flex sm3 class="mt-3">
                            <vue-country-code @onSelect="addFatherCellCode" class="black--text"></vue-country-code>
                          </v-flex>

                          <v-flex sm9>
                            <v-text-field
                              v-model="parentData.fatherCellNo"
                              :rules="fatheCellNoRules"
                              counter="10"
                              placeholder="Father Cell Number"
                              type="number"
                              required
                            ></v-text-field>
                          </v-flex>
                        </v-layout>
                      </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 wrap>
                    <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 wrap>
                    <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>
                    <!-- MOTHER CELL NUMBER - VISIBLE ONLY ON xs and sm screen-->
                    <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-layout row wrap>
                            <v-flex sm3 class="mt-3">
                              <vue-country-code @onSelect="onSelect" class="black--text"></vue-country-code>
                            </v-flex>
                            <v-flex sm9>
                              <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-flex>
                  </v-layout>
                  <v-layout wrap>
                    <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" class="clear-button" round dark>clear</v-btn>
                      </v-flex>
                      <v-flex xs6 sm6>
                        <v-btn
                          class="add-button"
                          @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-layout>
        </v-container>
      </v-card>
    </v-dialog>
    <div class="loader" v-if="showLoader">
      <v-progress-circular indeterminate color="white"></v-progress-circular>
    </div>
    <v-snackbar
      :timeout="timeout"
      :top="y === 'top'"
      :right="x === 'right'"
      :vertical="mode === 'vertical'"
      v-model="snackbar"
      color="success"
    >{{ text }}</v-snackbar>
  </v-container>
</template>

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

export default {
  data: () => ({
    /* EDIT FATHER CELL */
    editedFatherCellCode: "",
    /* ADD FATHER CELL */
    addedFatherCellCode: "",
    e1: true,
    showParent: true,
    snackbar: false,
    role: "",
    // TEACHER: "",
    y: "top",
    x: "right",
    color: "",
    mode: "",
    timeout: 3000,
    text: "",
    show: true,
    showSearch: false,
    showLoader: false,
    loading: false,
    date: null,
    search: "",
    password: "",
    addParentDialog: false,
    menu: false,
    menu1: false,
    editParentDilaog: false,
    profileParentDialog: false,
    resetParentMpin: false,
    viewProfileParentDialog: false,
    valid: true,
    validEditParent: true,
    validParentMpin: true,
    pagination: {
      rowsPerPage: 10,
    },
    fatherNameRules: [(v) => !!v || " Father Name is required"],
    fatheCellNoRules: [
      (v) => !!v || " father Cell Number  is required",
      (v) => v <= 10000000000 || "Max 10 characters is required",
    ],
    password: [
      (v) => !!v || "Password field is Required.",
      // v => (/^(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*])(?=.{8,})/).test(v) && v.length >= 8 || 'Min 8 characters lower case symbol 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",
    ],
    mPinRules: [
      (v) => !!v || "MPIN is required",
      (v) => v <= 10000 || "Max 4 numbers are required",
    ],
    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: "",
      password: "",
    },
    editMpin: {
      mPin: "",
    },
    isFatherCellExists: false,
  }),
  watch: {
    menu(val) {
      val && this.$nextTick(() => (this.$refs.picker.activePicker = "YEAR"));
    },
    menu1(val) {
      val && this.$nextTick(() => (this.$refs.picker.activePicker = "YEAR"));
    },
    addParentDialog: function (val) {
      if (!val) {
        this.parentData = [];
      }
    },
  },
  methods: {
    onSelect({ name, iso2, dialCode }) {
      // console.log("country codes", name, iso2, dialCode);
      // this.countryCode = iso2
    },
    editFatherCellCode({ name, iso2, dialCode }) {
      // console.log("Edit father cell", name,iso2);
      this.editedFatherCellCode = dialCode;
    },
    addFatherCellCode({ name, iso2, dialCode }) {
      this.addedFatherCellCode = dialCode;
    },
    editItem(item) {
      this.editedIndex = this.parentsList.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.editParentDilaog = true;
    },
    profile(item) {
      this.editedIndex = this.parentsList.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.profileParentDialog = true;
    },
    resetParentMPIN(item) {
      this.editMpin = Object.assign({}, item);
      this.resetParentMpin = true;
    },
    close() {
      this.editParentDilaog = false;
    },
    closeProfile() {
      this.profileParentDialog = false;
    },
    closeReset() {
      this.resetParentMpin = false;
    },
    clear() {
      this.$refs.parentForm.reset();
    },
    save() {
      if (this.$refs.editParentForm.validate()) {
        this.editedItem.parentId = this.editedItem._id;
        this.editedItem.countryCode = this.editedFatherCellCode;
        http()
          .put("/updateParent", this.editedItem)
          .then((response) => {
            this.snackbar = true;
            this.color = "green";
            this.text = response.data.message;
            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;
            }
          });
      }
    },
    resetMpin() {
      if (this.$refs.resetParentMpinForm.validate()) {
        var changeMpin = {
          parentId: this.editMpin._id,
          mPin: this.editMpin.mPin,
        };
        http()
          .put("/resetMPin", changeMpin)
          .then((response) => {
            this.snackbar = true;
            this.color = "green";
            this.text = response.data.message;
            this.getParentDetails();
            this.resetParentMpin = false;
            this.closeReset();
          })
          .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;
        (this.parentData.countryCode = this.addedFatherCellCode),
          await http()
            .post("/createParent", this.parentData)
            .then((response) => {
              this.parentId = response.data.data.id;
              this.snackbar = true;
              this.color = "green";
              this.text = response.data.message;
              this.getParentDetails();
              this.clear();
              this.loading = false;
              this.isFatherCellExists = true;
              this.addParentDialog = false;
            })
            .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;
              }
              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);
          }
        });
    },
    displaySearch() {
      this.show = false;
      this.showSearch = true;
      // this.$refs.searchField.focus()
    },
    closeSearch() {
      this.showSearch = false;
      this.show = true;
      this.search = "";
    },
  },
  mounted() {
    this.getParentDetails();
    // console.log("role", this.$store.state.role);
    this.role = this.$store.state.role;
  },
};
</script>