<template>
  <div :class="{ active: isScroll }" class="xb-header-container">
    <div :class="{ active: isScroll }" class="top-header">
      <div class="content left-icon" @click="goBack">
        <img :src="headerLeftIcon" />
      </div>
      <div :class="{ active: isScroll }" class="content title">
        <span>{{ shareTitle1 }}</span>
      </div>
      <div v-show="isShowRightIcon" class="content right-icon" @click="share">
        <img :src="headerRightIcon" />
      </div>
    </div>
  </div>
</template>

<script>
import { getShareUrl } from '@/utils';
import { ENV_CONFIG } from '@/utils/enumerate';

import './index.less';

export default {
  name: 'Header',
  props: {
    isScroll: {
      type: Boolean,
      default: false
    },
    shareTitle1: {
      type: String,
      default: ''
    },
    shareTitle2: {
      type: String,
      default: ''
    },
    isInNotice: {
      type: Boolean,
      default: false
    },
    token: {
      type: String,
      default: ''
    },
    shareIconUrl: {
      type: String
    },
    isShowRightIcon: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    headerLeftIcon() {
      return !!this.isScroll ? 
        'https://file.yunqueyi.com/gpranking/left-icon.png' :
        'https://file.yunqueyi.com/2019/04/template/left-array.png'
    },
    headerRightIcon() {
      return !!this.isScroll ?
        'https://file.yunqueyi.com/gpranking/right-icon.png' :
        'https://file.yunqueyi.com/2019/04/template/share-icon.png'
    }
  },
  methods: {
    goBack() {
      if(this.$rocNative.isWeb) {
        this.$router.go(-1);
      } else {
        this.$rocNative.goBack();
      }
    },
    share() {
      let shareUrl = '';
      const { NUXT_ENV_APP } = process.env;
      const { tempId, token, shareTitle1, shareTitle2, shareIconUrl } = this;
      shareUrl = ENV_CONFIG[NUXT_ENV_APP]['shareUrl'] + '/template_v2/?id=' + tempId + '&token=' + token;
      const h5title = encodeURIComponent(shareTitle1);
      const h5desc = encodeURIComponent(shareTitle2);
      const { id } = this.$route.query;
      this.$sendBuriedData({
        component_tag: `200#400089#${id}#${shareTitle1}`  
      });
      this.$rocNative.shareWechat({
        type: 7,
        shareId: 0,
        shareUrl: shareUrl,
        title1: shareTitle1,
        title2: shareTitle2,
        shareImageUrl: shareIconUrl || 'https://file.yunqueyi.com/logo.png?version=' + new Date().getTime()
      });
    }
  },
}
</script>

