<script setup>
    import CloseIcon from '../assets/icons/close.svg'
</script>

<template>
    <div id="linkPannel" class="windowStyle" ref="linkPannel" @mousedown="$emit('focus')" @touchstart="$emit('focus')">
      <Moveable
          className="moveable"
          :target="target"
          :draggable="true"
          @drag="onDrag"
      />
      <div class="windowTitle">
        <p>
          {{selectedLink.caption}}
        </p>
        <!-- touchstart.capture pour passer en prio sur déplacement fenêtre/ .stop si pas de method-->
        <button type="button" class="closeBtn" @mousedown.capture="$emit('close')" @touchstart.stop="$emit('close')" data-tooltip="fermer">
          <CloseIcon name="close" class="icon"/>
        </button>
      </div>
      <div class="windowContent" id="linkContent">
        <p id="linkTextStyle">{{selectedLink.description}}</p>
        <a class="textBtnStyle" v-for="item in selectedLink.linksData" :href="item.url" target="_blank" @mousedown.stop @touchstart.stop>{{item.caption}}</a>
      </div>
    </div>
</template>

<style scoped>
  /*================= Mise en page:
    => Mobile First : par défaut, moins de 500px
    => Tablette et PC format haut : de 500 à 1000px
    => PC large : à partir de 1000px
  */

  /*+++++++++++++++++ COPYBOX
      ================ PC HAUT/IPAD
      @media(min-width:650px){}
      ================ PC LARGE
      @media(min-width:1300px){}
  */

  #linkPannel{
    position: fixed;
    width: 333px;
    height: auto;
    top: 500px;
    left: 16.1px;
    overflow-y: scroll;
  }

  #linkContent{
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
  }

  #linkContent .textBtnStyle{
    width: 267px;
    height: 77px;
    margin-bottom: 16.1px;
    animation: none;
  }

  #linkContent .textBtnStyle:hover{
    animation : blinkBack 3.33s infinite;
  }

  #linkTextStyle{
    font-size: 16.1px;
    font-family: 'velvelyne';
    color: var(--main-color);
    font-weight: bold;
    padding-right: 33px;
    padding-left: 33px;
    padding-top: 16.1px;
  }
  /*================ PC LARGE*/
  @media(min-width:1300px){
    #linkPannel{
      top: 333px;
      left: 161px;
    }
  }
</style>

<script>
  import Moveable from 'vue3-moveable';
  import { dataStorage } from '../dataExchange.js'

  export default {
    name : 'LinkPannel',
    components:{
      Moveable
    },
    data(){
      return{
        target: null,
      }
    },
    emits: ['close','focus'],
    computed: {
      selectedLink(){
        //console.log(this.selectedLink);
        return dataStorage.selectedLink
      }
    },
    methods:{
      onDrag({ target, transform }) {
        target.style.transform = transform;
      }
    },
    mounted(){
      this.target = this.$refs.linkPannel;
      console.log("Link pannel is loaded!");
    }
  };
</script>
