<template>
  <article class="card minicard">
    <header>
      <h1>{{ item.title }}</h1>
      <span class="ref">{{ item.field_reference }}</span>
    </header>
    <nav class="tools">
      <section class="tool flags">
        <span
          class="mdi unflag"
          :class="[
            itemIsLoading() ? 'mdi-loading mdi-spin' : 'mdi-folder-remove'
          ]"
          @click.prevent="onUnFlagCard"
        />
      </section>
    </nav>
    <section class="images" v-switcher>
      <figure
        v-for="(img, index) in item.images"
        :key="img.url"
      >
        <img
          class="lazy"
          v-lazy="index"
          :data-src="img.style_minicard.url"
          :title="img.title"
        />
        <img class="blank" :src="blanksrc">
      </figure>
    </section>
  </article>
</template>

<script>
import { mapState, mapActions } from 'vuex'
import cardMixins from 'vuejs/components/cardMixins'

export default {
  name: "MiniCard",
  props: ['item', 'collid'],
  mixins: [cardMixins],
  data() {
    return {
      blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
      loadingItem: false
    }
  },
  computed: {
  },
  methods: {
    ...mapActions({
      flagUnflag: 'User/flagUnflag'
    }),
    itemIsLoading(id) {
      return this.loadingItem
    },
    onUnFlagCard (e) {
      console.log("Card onFlagActionCard", e, this.item);
      if (!this.loadingItem) {
        this.loadingItem = true;
        this.flagUnflag({
          action: 'unflag',
          id: this.item.id,
          collid: this.collid
        })
        .then(data => {
          console.log("onUnFlagCard then", data);
          this.loadingItem = false;
        })
      }
    }
  }
}

</script>

<style lang="scss" scoped>

</style>
