<template>
  <div :class="[wrapperclass, 'footer-collapsible']">
    <span class="text-xl uppercase text-white footer-collapsible__toggle" :class="[labelclass, show ? 'footer-collapsible__toggle--open' : '']" @click="handleClick">{{ label }}</span>
    <div v-show="show || isLgScreenSize" :class="[slotwrapperclass]">
      <slot>
      </slot>
    </div>
  </div>
</template>

<script>
import screens from "../../../../screens";

const lgScreenSize = parseInt(screens.lg.replace("px", ""), 10);

export default {
  data() {
    return {
      isLgScreenSize: this.getWindowWidth() >= lgScreenSize,
      show: false,
      resizeHandler: () => {
        this.$data.isLgScreenSize = this.getWindowWidth() >= lgScreenSize;
      },
    };
  },
  props: {
    href: {
      type: String,
    },
    label: {
      type: String,
    },
    labelclass: {
      type: String,
    },
    wrapperclass: {
      type: String,
      default: "",
    },
    slotwrapperclass: {
      type: String,
      default: "",
    }
  },
  methods: {
    getWindowWidth() {
      return Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0);
    },
    handleClick() {
      if (this.$props.href) {
        window.location = this.$props.href;
      }

      this.$data.show = !this.$data.show;
    }
  },
  mounted() {
    this.$nextTick(() => {
      window.addEventListener("resize", this.$data.resizeHandler);
    });
  },
  beforeDestroy() {
    window.removeEventListener("resize", this.$data.resizeHandler);
  }
}
</script>
