<template>
  <nuxt />
</template>

<script>
import Cookies from 'js-cookie'
import Stats from '@/kaifain_v2/mixins/stats'

const MOB_HOST = process.env.NODE_ENV === 'development' ? 'kaifain-m.test.proginn.com' : 'kaifain.m.proginn.com'
const REM_RESET_STYLE = `font-size:16px !important;`

const resetRem = () => {
  const _rem_mark = document.querySelector('#rootsize')

  if (_rem_mark) {
    _rem_mark.innerHTML = `html{${REM_RESET_STYLE}}`
    document.documentElement.style = REM_RESET_STYLE
    document.body.style = REM_RESET_STYLE
  }
}

export default {
  head() {
    return {
      bodyAttrs: {
        class: ['kaifain-view', 'non-rem']
      },
      ...Stats.head
    }
  },

  created() {
    if (process.client) {
      if (Cookies.get('x_app')) {
        const path = window.location.pathname
        let target

        if (/\/dashboard/.test(path)) {
          return
        } else if (/\/(s|d)\/[0-9a-f]+/.test(path)) {
          target = path.replace(location.host, MOB_HOST)
        } else {
          target = `https://${MOB_HOST}/`
        }

        window.location.replace(target)
      }
    }
  },

  beforeMount() {
    resetRem()
  }
}
</script>

<style lang="scss">
:root {
  font-size: 16px;
}
</style>
