<commit_before><script>
  import BaseModal from 'app/components/common/BaseModal'

  export default {
    components: {
      BaseModal
    },

    props: {
      show: {
        type: Boolean,
        default: false
      },

      classType: {
        type: String,
        default: undefined
      }
    },

    computed: {
      // Note this is not used because changing the page url causes a reload, which makes
      // the pre load of this iframe useless
      timetapIframeUrl () {
        if (this.classType === undefined) {
          return 'https://codecombat.timetap.com?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal'
        } else if (this.classType === 'group') {
          return 'https://www.timetap.com/appts/jPlOQTv7JXIJ?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal'
        } else if (this.classType === 'private') {
          return 'https://www.timetap.com/appts/wPvlbTkKwauE?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal'
        }
      }
    },

    methods: {
      onWindowMessage (event) {
        if (event.source === this.$refs.timetapIframe.contentWindow && event.data === 'class.booked') {
          this.$emit('booked')
        }
      }
    },

    mounted () {
      window.addEventListener('message', this.onWindowMessage, false)
    },

    beforeDestroy () {
      window.removeEventListener('message', this.onWindowMessage)
    }
  }
</script>

<template>
  <base-modal :class="[ !show ? 'hide' : undefined, 'timetap-modal']">
    <template slot="header">
      {{ $t('parents_landing_2.book_your_class') }}
      <span class="glyphicon glyphicon-remove close" @click="$emit('close')"></span>
    </template>

    <template slot="body">
      <iframe ref="timetapIframe" src="https://codecombat.timetap.com?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal" sandbox="allow-same-origin allow-scripts" />
    </template>
  </base-modal>
</template>

<style scoped>
  .hide {
    display: none;
  }

  .timetap-modal ::v-deep .modal-container {
    width: 700px;
    max-width: 100%;

    height: 900px;
    max-height: 100%;
  }

  .timetap-modal ::v-deep .modal-body {
    padding-left: 4px;
    padding-right: 4px;

    flex-direction: column;
  }

  .timetap-modal ::v-deep .modal-footer {
    margin: 0;
    padding: 0;
    height: 4px;
  }

  .timetap-modal iframe {
    flex-grow: 1;
    width: 100%;
    height: 100%;
  }

  .close {
    position: absolute;
    right: 0;

    height: 100%;
    display: flex;
    align-items: center;

    margin-right: 10px;

    cursor: pointer;
  }
</style>
<commit_msg>Help Timetap debug their confirmation iframe<commit_after><script>
  import BaseModal from 'app/components/common/BaseModal'

  export default {
    components: {
      BaseModal
    },

    props: {
      show: {
        type: Boolean,
        default: false
      },

      classType: {
        type: String,
        default: undefined
      }
    },

    computed: {
      // Note this is not used because changing the page url causes a reload, which makes
      // the pre load of this iframe useless
      timetapIframeUrl () {
        if (this.classType === undefined) {
          return 'https://codecombat.timetap.com?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal'
        } else if (this.classType === 'group') {
          return 'https://www.timetap.com/appts/jPlOQTv7JXIJ?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal'
        } else if (this.classType === 'private') {
          return 'https://www.timetap.com/appts/wPvlbTkKwauE?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal'
        }
      }
    },

    methods: {
      onWindowMessage (event) {
        if (event.source === this.$refs.timetapIframe.contentWindow && event.data === 'class.booked') {
          this.$emit('booked')
        }
      }
    },

    mounted () {
      window.addEventListener('message', this.onWindowMessage, false)
    },

    beforeDestroy () {
      window.removeEventListener('message', this.onWindowMessage)
    }
  }
</script>

<template>
  <base-modal :class="[ !show ? 'hide' : undefined, 'timetap-modal']">
    <template slot="header">
      {{ $t('parents_landing_2.book_your_class') }}
      <span class="glyphicon glyphicon-remove close" @click="$emit('close')"></span>
    </template>

    <template slot="body">
      <!-- Temporarily removed 'sandbox="allow-same-origin allow-scripts"' for TimeTap to debug sessionStorage error -->
      <iframe ref="timetapIframe" src="https://codecombat.timetap.com?utm_campaign=timetapliveclasses&utm_source=codecombat&utm_medium=modal" />
    </template>
  </base-modal>
</template>

<style scoped>
  .hide {
    display: none;
  }

  .timetap-modal ::v-deep .modal-container {
    width: 700px;
    max-width: 100%;

    height: 900px;
    max-height: 100%;
  }

  .timetap-modal ::v-deep .modal-body {
    padding-left: 4px;
    padding-right: 4px;

    flex-direction: column;
  }

  .timetap-modal ::v-deep .modal-footer {
    margin: 0;
    padding: 0;
    height: 4px;
  }

  .timetap-modal iframe {
    flex-grow: 1;
    width: 100%;
    height: 100%;
  }

  .close {
    position: absolute;
    right: 0;

    height: 100%;
    display: flex;
    align-items: center;

    margin-right: 10px;

    cursor: pointer;
  }
</style>

{'fraction_non_alphanumeric': 0.1396596374398816, 'fraction_numerical': 0.011838697743248243, 'mean_word_length': 2.678231292517007, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 34, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '527793', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1800, 'n_words': 337}