<template>
  <div class="container">
    <NuxtLayout>
        <NuxtPage/>
    </NuxtLayout>
  </div>
</template>


<script setup>
import { ID_INJECTION_KEY } from 'element-plus'

useHead({
  link: [
    { rel: 'icon', type: 'image/x-icon', href: '/favicon.png' },
 ],
 script: [
      {
        src: 'https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit',
        type:'text/javascript',
        async: true,
        body: true,
      },
    ]
})


const setHead = () => {
  get('v3/system/front/setting/getSettings?names=gz_code').then(res=>{
    if(!res.data[0] || res.data[0] == ''){
      return
    }
    useHead({
        script: [
              {
                src: "https://www.googletagmanager.com/gtm.js?id="+ res.data[0],
                type:'text/javascript',
                async: true,
              },
            ]
        })
  })
}
setHead()

provide(ID_INJECTION_KEY, {
  prefix: 100,
  current: 0,
})

const googleTranslateInit = () => {
  let checkIfGoogleLoaded = setInterval(() => {
    if (google?.translate?.TranslateElement != null) {
        clearInterval(checkIfGoogleLoaded);
      googleTranslateElement('google_translate_element');
    }
    }, 1000);
}

const googleTranslateElement = (id) => {
  new google.translate.TranslateElement({pageLanguage: 'en',layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, id);

}

onMounted(() => {
  nextTick(()=>{
    googleTranslateInit()
  })

  window.addEventListener('storage', function (e) {
    if (e.key === 'isLoggedIn') {
      location.reload();  // 其他页面刷新
    }
  });
})


</script>
