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

<template>
    <div id="newsletterPannel" class="windowStyle" ref="newsletterPannel" @mousedown="$emit('focus')" @touchstart="$emit('focus')">
      <Moveable
          className="moveable"
          :target="target"
          :draggable="true"
          @drag="onDrag"
      />
      <div class="windowTitle">
        <p>
          Newsletter
        </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.capture="$emit('close')" data-tooltip="fermer">
          <CloseIcon name="close" class="icon"/>
        </button>
      </div>
      <div class="windowContent" id="newsletterContent">
        <div id="newsletterText">
          <p>Pour t'inscrire à la newsletter Drags & Nerds,<br>renseigne ton E-MAIL ici :</p>
        </div>
        <form id="newsletterForm">
          <input type="text" name="emailIn" placeholder="example@drags-nerds.net" @touchstart.stop @mousedown.stop>
          <button type="submit" name="subscribeNews" class="textBtnStyle" @touchstart.stop @mousedown.stop>S'INSCRIRE !</button>
        </form>
      </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){}
  */

  #newsletterPannel{
    position: fixed;
    width: 333px;
    height: 200px;
    top: 77px;
    left: 33px;
  }

  #newsletterContent{
    width:100%;
    height:100%;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
  }

  #newsletterText{
    font-family: 'velvelyne';
    font-size: 16.1px;
    color: var(--main-color);
    font-weight: bold;
    width:95%;
    height:16.1%;
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding-top: 20px;
    margin-left: 0;
  }

  #newsletterForm{
    width:100%;
    height:75%;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-around;
    padding-top: 16.1px;
  }
  #newsletterForm input{
    width:60%;
    height:50px;
    padding-left: 16.1px;
    background-color: transparent;
    color: var(--main-color);
    font-family: 'velvelyne';
    font-size: 16.1px;
    color: var(--main-color);
    font-weight: bold;
    border-radius: 50px;
    border-style: solid;
    border-width: thin;
    border-color: var(--main-color);
  }
  #newsletterForm input:focus{
    color: var(--accent-color);
    color: var(--accent-color);
    border-color: var(--accent-color);
    border-width: thin;
    outline: none;
  }
  #newsletterForm .textBtnStyle{
    height: 50px;
    width: 77px;
    border-radius: 50px;
  }
  /*================ PC LARGE*/
  @media(min-width:1300px){
    #newsletterPannel{
      height: 190px;
      width: 444px;
      left:333px;
    }

    #newsletterText{
        width: 100%;
        margin-left: -93px;
    }

    #newsletterForm .textBtnStyle{
      width:100px;
    }
  }
</style>

<script>
  import Moveable from 'vue3-moveable';

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