<template lang="pug">
  .card(:class="{'card--active': isReferenced}")
    //- a.card--link(:href="url" :target='title' rel='noreferrer')
    p.card--title {{title}}
    p.card--description {{desc}}
    div
      a.card--reference(@click='createCopyUrl') Copy reference
      br
      a(:href="url" :target='title' rel='noreferrer') Visit website
</template>

<script>
export default {
  props: ['title', 'desc', 'url'],
  data(){
    return {
      isReferenced: false,
    }
  },
  methods: {
     async createCopyUrl() {
      try {
        let currentPath = this.$router.history.current.path
        let reference =  this.$props.title.replace(/ /g, '').toLowerCase()

        await this.$copyText(`https://webgems.io${currentPath}/#${reference}`)

        window.location.reload(`https://webgems.io${currentPath}#${reference}`)
        // this.$router.push(`${currentPath}#${reference}`)
        // this.checkReference()
      } catch (e) {
        console.error(e);
      }
    },
    screateCopyUrl() {
      this.$router.push(`${this.$router.history.current.path}#${this.$props.title.replace(/ /g, '').toLowerCase()}`)
    },
    checkReference(){
      if(typeof this.$route.hash !== undefined) {
        const query = this.$route.hash.substring(1);
        const title = this.$props.title.replace(/ /g, '');

        title.toLowerCase() === query
          ? this.isReferenced = true
          : this.isReferenced = false
      }
    },
  },
  mounted() {
    this.checkReference()
  },
}
</script>


<style lang="scss" scoped>
.card {
  background: #2D3748;
  border-radius: .3rem;
  padding: 1rem;
  transition: .2s ease-in-out;
  display: flex;
  flex-direction: column;
  position: relative;

  &--active{
    box-shadow:inset 0px 0px 0px 3px #08e5ff;
  }

  &--reference {
    cursor: pointer;

    &::before {
    	// content: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHZpZXdCb3g9IjAgMCAxNiAxNiIgdmVyc2lvbj0iMS4xIiBmaWxsPSIjMjkyOTI5Ij48ZyBpZD0ic3VyZmFjZTEiIGZpbGw9IiMyOTI5Mjk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top: 0;
    bottom: 0;
  }

  // &:hover {
  //   transform: scale(1.002);
  //   background: #008190;
  //   cursor: pointer;
  //   box-shadow: 0 4px 6px -1px rgba(45, 55, 72, 0.1), 0 2px 4px -1px rgba(45, 55, 72, 0.06);
  // }

  &--title {
    font-weight: 900;
    margin: 0;
  }

  &--description {
    display: flex;
    align-content: stretch;
    flex: 1 1 auto;
    flex-direction: column;
    font-size: 13px;
    color: white;
    margin: 0 0 .7rem 0;
    line-height: 1.3;
    letter-spacing: .5px;
    max-width: 15rem;
  }
  a {
    font-size: 12px;
    line-height: 1;
    align-self: flex-end;
  }
}
</style>
