<template>
  <div class="content-box">
    <template v-if="contactInfo.show_contact_content == 'yes'">

      <div class="flex between-xs middle-xs" @click.prevent=" isMobile ? showContent = !showContent : ''">
        <h4 class="footer-title text-small text-bold vertical-margin-x-small">{{ contactInfo.contact_title }}</h4>
        <i class="fas hidden-md-up" :class="showContent && isMobile ? 'fa-angle-up' : 'fa-angle-down'"></i>
      </div>

      <transition name="contact-transition">
        <div v-if="showContent"> 
          
          <template v-if="contactInfo.column_type == 'easy'">

            <template v-if="contactInfo.telephones">
              <div v-for="(data, key) in contactInfo.telephones" :key="key">
                <div class="flex middle-xs vertical-padding-x-small">

                  <i :class="data.icon" class="contact-icon" :style="styleIcon"></i>

                  <div class="contact-description left-padding-x-small">
                    <template v-if="data.only_number.length == type_cellphone">
                      <a 
                        target="_blank" 
                        title="Abrir com Whatsapp" 
                        class="text-small visible-block"
                        :href="'https://api.whatsapp.com/send?phone=55' + data.only_number" 
                      >
                        {{ data.number }}
                      </a>
                    </template>

                    <template v-else>
                      <span class="text-small visible-block">{{ data.number }}</span>
                    </template>
                  </div>

                </div>
              </div>
            </template>

            <template v-if="contactInfo.moreInfo">
              <div v-for="(info, index) in contactInfo.moreInfo" :key="index">
                <div class="flex vertical-padding-x-small" :class="index !== 'address' ? 'middle-xs' : ''">

                  <i :class="info.icon" class="contact-icon" :style="styleIcon"></i>

                  <div class="contact-description left-padding-x-small">
										<span v-if="index !== 'address'" class="text-small visible-block">{{ info.text }}</span>
                    <a 
                      v-else 
                      :href="'https://www.google.com/maps?q=' + info.text" 
                      class="text-small visible-block" 
                      title="Abrir com Google Maps" 
                      target="_blank"
                    >
                      {{ info.text }}
                    </a>
									</div>

                </div>
              </div>
            </template>

          </template>

        </div>
      </transition>

    </template>
  </div>
</template>

<script>
import store from "@components/TheFooter/storeFooter.js";

export default {
  name: 'DynamicContact',
  data() {
    return {
      contactInfo: store.state.dynamicContact,
      language: store.state.languages,
      showContent: true, 
      isMobile: false,
      type_cellphone: 11,
    };
  },
  computed: {
    styleIcon() {
      return {
        'color': this.contactInfo.color,
      }
    },
  },
  methods: {
    resize() {
      this.isMobile =  window.innerWidth < 992 ?? false;
      this.showContent = !this.isMobile ?? true;

      window.addEventListener('resize', () => {
        this.isMobile =  window.innerWidth < 992 ?? false;
        this.showContent = !this.isMobile ?? true;
      });
    },
  },
  created() {
    this.resize();
  },
}
</script>

<style scoped>
.contact-transition-enter-active {
transition: all .3s ease;
}
.contact-transition-leave-active {
  transition: all .3s cubic-bezier(1.0, 0.5, 0.8, 1.0);
}
.contact-transition-enter, .contact-transition-leave-to {
  transform: translateY(-20px);
  opacity: 0;
}
.contact-icon {
  width: 1.5rem;
  height: 1.5rem;
  line-height: 1.5rem;
  text-align: center;
}
.contact-description {
  width: calc(100% - 2.75rem);
}
</style>