<template>
  <Touchable v-if="showAct" direction="column" center :padding="40" :gap="10" @click="showBuildInfo">
    <Text 
      color="text.second"
      :fontSize="22"
      :text="`软件版本 ${AppCofig.version}`"
    />
  </Touchable>
</template>

<script setup lang="ts">
import { DateUtils } from '@imengyu/imengyu-utils';
import { alert } from '@/components/dialog/CommonRoot';
import Text from '@/components/basic/Text.vue';
import Touchable from '@/components/feedback/Touchable.vue';
import BugReporter from '@/common/BugReporter';
import AppCofig, { isDev, isTestEnv } from '@/common/config/AppCofig';

const showAct = isDev || isTestEnv;

function showBuildInfo() {
  alert({
    title: '关于程序',
    content: '版本: ' + AppCofig.version + (showAct ?
     ('\n构建时间：' + DateUtils.formatDate(new Date(AppCofig.buildTime), 'yyyy-MM-dd HH:mm:ss') + 
        ' (' + AppCofig.buildTime + ')' + 
     '\n构建GUID：' + AppCofig.buildInfo) : ''),
    icon: 'prompt-filling',
    iconColor: 'primary',
    customButtons: [
      {
        text: '测试非遗路线页面',
        name: 'testRoutePage',
      },
      {
        text: '测试提交BUG（1）',
        name: 'testBug',
      },
      {
        text: '测试异常BUG（2）',
        name: 'testBug2',
      },
    ],
    bottomVertical: true,
    width: 560,
  }).then((res) => {
    if (res == 'testRoutePage') {
      uni.navigateTo({
        url: '/pages/travel/route/list',
      });
    }
    if (res == 'testBug') {
      uni.showToast({
        title: '测试提交BUG（1）',
        icon: 'none',
      });
      BugReporter.reportError(new Error('测试提交BUG（1）'));
    } else if (res == 'testBug2') {
      uni.showToast({
        title: '测试异常BUG（2）',
        icon: 'none',
      });
      throw new Error('测试异常BUG（2）');
    }
  });
}
</script>
