<template>
  <div v-show="show" class="rt-button--large">
    <rt-button :class="classes" type="sub" size="large" :click="click">
      <template v-if="hasIcon">
        <slot name="icon" />
      </template>
      <span class="rt-button--bottom__text">{{text}}</span>
    </rt-button>
  </div>
</template>


<script>
export default {
  name: 'rtButtonLarge',
  props: {
    click: Function,
    text: {
      type: String,
      required: true
    },
    fixedBottom: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      clientHeight: document.documentElement.clientHeight,
      show: true
    };
  },
  mounted() {
    if (!rt.isiOS()) {
      window.addEventListener('resize', this.handleDisplay);
    }
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.handleDisplay);
  },
  computed: {
    hasIcon() {
      return this.$slots.icon;
    },
    classes() {
      if (this.fixedBottom) {
        return 'rt-button--bottom fixed-bottom';
      }
      return 'rt-button--bottom';
    }
  },
  methods: {
    handleDisplay() {
      this.show = this.clientHeight <= document.documentElement.clientHeight;
    }
  }
};
</script>
