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

      <!-- ****** EDITS ALL Gallery 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="1000px" scrollable>
          <v-card flat>
            <v-toolbar class="grey lighten-2" flat>
              <v-spacer></v-spacer>
              <v-toolbar-title>
                <h3>Edit Gallery</h3>
              </v-toolbar-title>
              <v-spacer></v-spacer>
            </v-toolbar>
            <v-card-text style="height:700px;">
              <v-form ref="form">
                <v-container fluid>
                  <v-layout row>
                    <v-flex
                      xs12
                      class="text-xs-center text-sm-center text-md-center text-lg-center my-4 mr-4"
                    >
                      <input
                        type="file"
                        style="display: none"
                        ref="editImage"
                        accept="image/*"
                        multiple
                        @change="editFilePicked"
                      />
                      <v-layout justify-center>
                        <v-flex
                          xs3
                          v-for="Image in editedItem.imageUrl"
                          :key="Image._id"
                          v-if="editedItem.imageUrl"
                          class="profile-image-wrapper"
                        >
                          <img
                            :src="Image.imageLink"
                            height="160"
                            width="160"
                            alt="Gallery"
                            class="pa-2"
                          />
                          <v-icon
                            class="red edit-profile-icon"
                            dark
                            @click="deleteImage(Image._id,editedItem._id)"
                          >close</v-icon>
                        </v-flex>
                        <v-flex v-for="(file, index) in editFiles" :key="index">
                          <img :src="file" height="160" width="160" class="pa-2" />
                        </v-flex>
                      </v-layout>
                      <img
                        src="/static/icon/user.png"
                        v-if="editedItem.imageUrl == '' && editFiles == ''"
                        height="160"
                        width="160"
                        alt="Gallery"
                      />
                    </v-flex>
                  </v-layout>
                  <!-- </v-layout> -->
                  <v-layout>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Title:</label>
                        </v-flex>
                        <v-flex xs8 sm5 class="ml-3">
                          <v-text-field
                            v-model="editedItem.title"
                            placeholder="fill your Title"
                            name="name"
                            type="text"
                            required
                          ></v-text-field>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-flex xs12 sm12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">Description:</label>
                        </v-flex>
                        <v-flex xs8 sm5 class="ml-3">
                          <v-text-field
                            placeholder="fill your Description"
                            v-model="editedItem.description"
                            type="text"
                            name="email"
                            required
                          ></v-text-field>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                    <v-layout>
                      <v-flex xs4 class="pt-4 subheading">
                        <label class="right hidden-xs-only hidden-sm-only">Select Class:</label>
                        <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Class:</label>
                      </v-flex>
                      <v-flex xs8 sm5 class="ml-3">
                        <v-select
                          :items="addclass"
                          label="Select Class"
                          v-model="editedItem.classNum"
                          item-text="classNum"
                          item-value="_id"
                          name="Select Class"
                          required
                        ></v-select>
                      </v-flex>
                    </v-layout>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right hidden-xs-only hidden-sm-only">Add New Images:</label>
                        <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Upload:</label>
                        </v-flex>
                        <v-flex xs8 sm5 class="ml-3">
                          <v-text-field
                            label="Select Image"
                            @click="editPickFile"
                            v-model="editImageName"
                            append-icon="attach_file"
                            multiple
                          ></v-text-field>
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                  <v-flex xs12>
                    <div
                      v-for="(editImage,index) in editedItem.youTubeLinkUrl"
                      :key="index"
                      v-if="editImage.youTubeLink !=[]"
                    >
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">You Tube Link Url:</label>
                        </v-flex>
                        <v-flex xs8 sm5 class="ml-3">
                          <v-text-field
                            v-model="editImage.youTubeLink"
                            type="text"
                            name="link"
                            required
                          ></v-text-field>
                        </v-flex>
                        <v-flex xs2 class="pt-4">
                          <v-icon @click="deleteUrl(index,editImage._id,editedItem._id)">cancel</v-icon>
                        </v-flex>
                      </v-layout>
                    </div>
                  </v-flex>
                  <v-flex xs12>
                    <div v-for="(updateImage,index) in updates" :key="index">
                      <v-layout>
                        <v-flex xs4 class="pt-4 subheading">
                          <label class="right">You Tube Link Url:</label>
                        </v-flex>
                        <v-flex xs5 class="ml-3">
                          <v-text-field
                            v-model="updateImage.youTubeLink"
                            label="Upload new you tube link url"
                            type="text"
                            name="link"
                            required
                          ></v-text-field>
                        </v-flex>
                        <v-flex xs2 class="pt-4">
                          <v-icon @click="deleteUpdate(index)" v-if="index !=0">cancel</v-icon>
                          <v-icon @click="update">add_circle</v-icon>
                        </v-flex>
                      </v-layout>
                    </div>
                  </v-flex>
                  <v-layout>
                    <v-flex xs12 sm8 offset-sm2>
                      <v-card-actions>
                        <v-btn round dark @click.native="close">Cancel</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 Gallery ******  -->

        <v-dialog v-model="dialog1" max-width="940px">
          <v-card>
            <v-toolbar color="grey lighten-2" flat>
              <v-spacer></v-spacer>
              <v-toolbar-title>
                <h3>Gallery</h3>
              </v-toolbar-title>
              <v-spacer></v-spacer>
              <v-icon @click="close1">close</v-icon>
            </v-toolbar>
            <v-flex align-center justify-center layout text-xs-center>
              <v-avatar size="100" v-if="editedItem.imageUrl == ''" class="mt-4 pa-2">
                <img src="/static/icon/user.png" width="240" height="180" />
              </v-avatar>
              <span
                v-for="(image,i) in editedItem.imageUrl"
                :key="i"
                class="mt-4 pa-2"
                v-if="editedItem.imageUrl"
              >
                <img :src="image.imageLink" alt="Gallery" width="240" height="180" />
              </span>
            </v-flex>
            <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>Title:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.title }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>Description:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1">{{ editedItem.description }}</h5>
                      </v-flex>
                    </v-layout>
                    <v-layout>
                      <v-flex xs5 sm6>
                        <h5 class="right my-1">
                          <b>You Tube Link Url:</b>
                        </h5>
                      </v-flex>
                      <v-flex sm6 xs8>
                        <h5 class="my-1 ml-3">
                          <ul v-for="youTubeLinkUrl in editedItem.youTubeLinkUrl">
                            <li>{{ youTubeLinkUrl.youTubeLink }}</li>
                          </ul>
                        </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-USERS Gallery TABLE ****** -->
        <v-data-table
          :headers="headers"
          :items="desserts"
          :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">
              <span v-for="(image,_id) in props.item.imageUrl" class="pa-2">
                <img :src="image.imageLink" alt="newsImage" width="100" height="70" />
              </span>
            </td>
            <td id="td" class="text-xs-center">{{ props.item.title}}</td>
            <td id="td" class="text-xs-center">{{ props.item.description}}</td>

            <td id="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="deleteItem(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 MULTIPLE Gallery Data ****** -->

      <v-tab-item>
        <v-container>
          <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 class="my-4">
            <v-card flat>
              <v-form ref="form" v-model="valid" lazy-validation>
                <v-container fluid>
                  <v-layout>
                    <v-flex
                      xs12
                      class="text-xs-center text-sm-center text-md-center text-lg-center my-4 mr-4"
                    >
                      <input
                        type="file"
                        style="display: none"
                        ref="image"
                        accept="image/*"
                        multiple
                        @change="onFilePicked"
                      />
                      <v-layout justify-center>
                        <v-flex v-for="(file,index) in files" :key="index" v-if="files">
                          <img :src="file" height="160" width="160px;" />
                        </v-flex>
                      </v-layout>
                      <img
                        src="/static/icon/user.png"
                        v-if="files ==''"
                        height="140"
                        width="180px;"
                      />
                    </v-flex>
                  </v-layout>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs4 class="pt-4 subheading">
                        <label class="right">Title:</label>
                      </v-flex>
                      <v-flex xs8 sm4 class="ml-3">
                        <v-text-field
                          v-model="addGallery.title"
                          placeholder="fill your Title"
                          name="name"
                          type="text"
                          :rules="titleRules"
                          required
                        ></v-text-field>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs4 class="pt-4 subheading">
                        <label class="right">Description:</label>
                      </v-flex>
                      <v-flex xs8 sm4 class="ml-3">
                        <v-text-field
                          placeholder="fill your Description"
                          :rules="descriptionRules"
                          v-model="addGallery.description"
                          type="text"
                          name="email"
                          required
                        ></v-text-field>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs4 class="pt-4 subheading">
                        <label class="right hidden-xs-only hidden-sm-only">Select Class:</label>
                        <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Class:</label>
                      </v-flex>
                      <v-flex xs8 sm4 class="ml-3">
                        <v-select
                          :items="addclass"
                          label="Select Class"
                          v-model="addGallery.classNum"
                          item-text="classNum"
                          item-value="_id"
                          name="Select Class"
                          required
                        ></v-select>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-flex xs12>
                    <v-layout>
                      <v-flex xs4 class="pt-4 subheading">
                        <label class="right hidden-xs-only hidden-sm-only">Uplaod Image:</label>
                        <label class="right hidden-lg-only hidden-md-only hidden-xl-only">Uplaod:</label>
                      </v-flex>
                      <v-flex xs8 sm4 class="ml-3">
                        <v-text-field
                          label="Select Image"
                          @click="pickFile"
                          v-model="imageName"
                          append-icon="attach_file"
                          multiple
                        ></v-text-field>
                      </v-flex>
                    </v-layout>
                  </v-flex>
                  <v-layout>
                    <v-flex xs12>
                      <div v-for="(youTubeLink,index) in finds" :key="index">
                        <v-layout>
                          <v-flex xs4 class="pt-4 subheading">
                            <label class="right">You Tube Link Url:</label>
                          </v-flex>
                          <v-flex xs8 sm4 class="ml-3">
                            <v-text-field
                              placeholder="fill your youtube link"
                              v-model="youTubeLink.value"
                              type="text"
                              name="link"
                              required
                            ></v-text-field>
                          </v-flex>
                          <v-flex xs2 class="pt-4">
                            <v-icon @click="deleteFind(index)" v-if="index !=0 ">cancel</v-icon>
                            <v-icon @click="addFind">add_circle</v-icon>
                          </v-flex>
                        </v-layout>
                      </div>
                    </v-flex>
                    <v-flex xs12 sm6 offset-sm3>
                      <v-card-actions>
                        <v-btn @click="clear" round dark>clear</v-btn>
                        <v-spacer></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 Util from "@/util";

export default {
  data: () => ({
    snackbar: false,
    y: "top",
    x: "right",
    mode: "",
    timeout: 3000,
    text: "",
    loading: false,
    date: null,
    search: "",
    showLoader: false,
    dialog: false,
    dialog1: false,
    valid: true,
    isActive: true,
    newActive: false,
    addclass: [],
    addSection: [],
    finds: [{ value: "" }],
    updates: [{ youTubeLink: "" }],
    youTubeLink: {},
    addGallery: {
      youTubeLinkUrl: []
    },
    pagination: {
      rowsPerPage: 15
    },
    imageName: "",
    imageUrl: "",
    imageFile: "",
    image: [],
    upload: "",
    editImageName: "",
    editFiles: [],
    files: [],
    token: "",
    titleRules: [v => !!v || " Tilte is required"],
    descriptionRules: [v => !!v || " Description is required"],
    headers: [
      {
        align: "justify-center",
        text: "No",
        sortable: false,
        value: "index"
      },
      { text: "Image", vaue: "image", sortable: false, align: "center" },
      { text: "Title", value: "title", sortable: false, align: "center" },
      {
        text: "Description",
        value: "description",
        sortable: false,
        align: "center"
      },
      { text: "Action", value: "", sortable: false, align: "center" }
    ],
    desserts: [],
    editedIndex: -1,
    editedItem: {},
    index: ""
  }),
  methods: {
    pickFile() {
      this.$refs.image.click();
    },
    editPickFile() {
      this.$refs.editImage.click();
    },
    onFilePicked(e) {
      const files = e.target.files;
      /** fetch Image Name **/
      if (files[0] !== undefined) {
        this.imageName = files[0].name;
        if (this.imageName.lastIndexOf(".") <= 0) {
          return;
        }
        this.files = [];
        // console.log("files", this.files);
        /** Select many image and showing many image add to Gallery card **/
        const test = Array.from(files).forEach((file, idx) => {
          const fr = new FileReader();
          const getResult = new Promise(resolve => {
            fr.onload = e => {
              this.files.push(
                // id: idx,
                e.target.result
              );
            };
            console.log("uploadImage=======>", this.files);
          });
          fr.readAsDataURL(file);
          return getResult.then(file => {
            return file;
          });
        });
        const fr = new FileReader();
        fr.readAsDataURL(files[0]);
        fr.addEventListener("load", () => {
          this.imageFile = files; // this is an image file that can be sent to server...
        });
      } else {
        this.imageName = "";
        this.imageFile = "";
        this.imageUrl = "";
      }
    },
    editFilePicked(e) {
      const files = e.target.files;
      /** fetch Image Name **/
      if (files[0] !== undefined) {
        this.editImageName = files[0].name;
        if (this.editImageName.lastIndexOf(".") <= 0) {
          return;
        }
        /** Select many image and showing many image add to Gallery card **/
        const test = Array.from(files).forEach((file, idx) => {
          const fr = new FileReader();
          const getResult = new Promise(resolve => {
            fr.onload = e => {
              this.editFiles.push(
                // id: idx,
                e.target.result
              );
            };
            console.log("uploadImage=======>", this.files);
          });
          fr.readAsDataURL(file);
          return getResult.then(file => {
            return file;
          });
        });
        const fr = new FileReader();
        fr.readAsDataURL(files[0]);
        // fr.addEventListener("load", () => {
        //   this.imageFile = files; // this is an image file that can be sent to server...
        // });
      } else {
        this.editImageName = "";
        this.editFiles = "";
      }
    },
    getGalleryList() {
      this.showLoader = true;
      http()
        .get("/getGalleryList", {
          headers: { Authorization: "Bearer " + this.token }
        })
        .then(response => {
          this.desserts = response.data.data;
          this.showLoader = false;
        })
        .catch(error => {
          // console.log("err====>", err);
          this.showLoader = false;
          if (error.response.status === 401) {
            this.$router.replace({ path: "/" });
            this.$store.dispatch("setToken", null);
            this.$store.dispatch("Id", null);
          }
        });
    },
    editItem(item) {
      this.files = [];
      this.editedIndex = this.desserts.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.dialog = true;
    },
    profile(item) {
      this.editedIndex = this.desserts.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.dialog1 = true;
    },
    deleteItem(item) {
      let deleteGallery = {
        galleryId: item._id
      };
      http()
        .delete(
          "/deleteGallery",
          confirm("Are you sure you want to delete this?") && {
            params: deleteGallery,
            headers: {
              Authorization: "Bearer " + this.token
            }
          }
        )
        .then(response => {
          if ((this.snackbar = true)) {
            this.text = "Successfully delete Existing Gallery";
          }
          this.getGalleryList();
        })
        .catch(error => {
          // console.log(error);
        });
    },
    deleteImage(imageId, id) {
      console.log("imageId", imageId, "id", id);
      let deleteImages = {
        galleryId: id,
        imageId: imageId
      };
      http()
        .put("/deleteImage", deleteImages)
        .then(response => {
          this.snackbar = true;
          this.text = response.data.message;
          this.getGalleryList();
          this.close();
        })
        .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;
      setTimeout(() => {
        this.editedItem = Object.assign({}, this.defaultItem);
        this.editedIndex = -1;
      }, 300);
    },
    close1() {
      this.dialog1 = false;
    },
    submit() {
      this.loading = true;
      for (let i = 0; i < this.finds.length; i++) {
        this.addGallery.youTubeLinkUrl.push(this.finds[i].value);
      }
      if (this.$refs.form.validate()) {
        if (this.files) {
          var ary = [];
          var imageData = [];
          ary = this.files;
          for (let i = 0; i < ary.length; i++) {
            const [baseUrl, imageUrl] = ary[i].split(/,/);
            imageData.push(imageUrl);
            this.addGallery.upload = imageData;
          }
        }
        if (this.addGallery.youTubeLinkUrl == "") {
          var galleryData = {
            classId: this.addGallery.classNum,
            title: this.addGallery.title,
            description: this.addGallery.description,
            upload: this.addGallery.upload
          };
          http()
            .post("/createGallery", galleryData)
            .then(response => {
              this.getGalleryList();
              this.loading = false;
              this.snackbar = true;
              this.text = response.data.message;
              this.clear();
              this.files = "";
            })
            .catch(error => {
              if ((this.snackbar = true)) {
                this.text = error.response.data.message;
              }
            });
        } else if (this.addGallery.youTubeLinkUrl) {
          http()
            .post("/createGallery", this.addGallery)
            .then(response => {
              this.getGalleryList();
              this.loading = false;
              this.snackbar = true;
              this.text = response.data.message;
              this.clear();
              this.files = "";
            })
            .catch(error => {
              if ((this.snackbar = true)) {
                this.text = error.response.data.message;
              }
            });
        }
      }
    },
    clear() {
      this.$refs.form.reset();
    },
    save() {
      this.editedItem.gelleryId = this.editedItem._id;
      var linkUrl = [];
      for (let i = 0; i < this.updates.length; i++) {
        linkUrl.push(this.updates[i].youTubeLink);
      }
      if (this.editFiles) {
        var ary = [];
        var imageData = [];
        ary = this.editFiles;
        for (let i = 0; i < ary.length; i++) {
          const [baseUrl, imageUrl] = ary[i].split(/,/);
          imageData.push(imageUrl);
          this.editedItem.editFiles = imageData;
        }
      }
      if (linkUrl != "") {
        var updateData = {
          galleryId: this.editedItem._id,
          description: this.editedItem.description,
          classId: this.editedItem.classNum,
          uploadImage: this.editedItem.editFiles,
          title: this.editedItem.title,
          updateYouTubeLinkUrl: linkUrl
        };
      } else if (linkUrl == "") {
        var updateData = {
          galleryId: this.editedItem._id,
          description: this.editedItem.description,
          classId: this.editedItem.classNum,
          uploadImage: this.editedItem.editFiles,
          title: this.editedItem.title
        };
      }
      http()
        .put("/updateGallery", updateData)
        .then(response => {
          this.getGalleryList();
          this.close();
          this.snackbar = true;
          this.text = response.data.message;
        })
        .catch(error => {
          console.log(error);
        });
    },
    getAllClasses() {
      http()
        .get("/getClassesList", {
          headers: { Authorization: "Bearer " + this.token }
        })
        .then(response => {
          this.addclass = response.data.data;
        })
        .catch(err => {
          // console.log("err====>", err);
        });
    },
    addFind: function() {
      this.finds.push({ value: "" });
    },
    update: function() {
      this.updates.push({ youTubeLink: "" });
    },
    deleteFind: function(index) {
      this.finds.splice(index, 1);
      if (index === 0) this.addFind();
    },
    deleteUpdate: function(index) {
      this.updates.splice(index, 1);
      if (index === 0) this.update();
    },
    deleteUrl: function(index, youTubelinkId, id) {
      this.editedItem.youTubeLinkUrl.splice(index, 1);
      if (index === 0) this.update();
      let deleteYouTubeUrl = {
        galleryId: id,
        youTubeId: youTubelinkId
      };
      http()
        .put("/deleteYoutubeLink", deleteYouTubeUrl)
        .then(response => {
          this.snackbar = true;
          this.text = response.data.message;
          this.getGalleryList();
          this.close();
        })
        .catch(error => {
          console.log(error);
        });
    }
  },
  mounted() {
    this.token = this.$store.state.token;
    this.getAllClasses();
    this.getGalleryList();
    // console.log("index",index);
  },
  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>
#td {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 2px 0px;
  max-width: 200px;
}
.active {
  background-color: gray;
  color: white !important;
}
.activebtn {
  color: black !important;
}
</style>