<template>
  <Touchable 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';
import { navTo } from '@/components/utils/PageAction';

const showAct = isDev || isTestEnv;

function showBuildInfo() {
  alert({
    title: '关于程序',
    content: '版本: ' + AppCofig.version + (showAct ?
     ('\n构建时间：' + DateUtils.formatDate(new Date(parseInt(AppCofig.buildTime)), 'yyyy-MM-dd HH:mm:ss') + 
        ' (' + AppCofig.buildTime + ')' + 
     '\n构建GUID：' + AppCofig.buildInfo) : ''),
    icon: 'prompt-filling',
    iconColor: 'primary',
    customButtons: showAct ? [
      {
        text: '测试话题页',
        name: 'testTopic',
      },
      {
        text: '测试提交BUG（1）',
        name: 'testBug',
      },
      {
        text: '测试异常BUG（2）',
        name: 'testBug2',
      },
    ] : [],
    bottomVertical: true,
    width: 560,
  }).then((res) => {
    if (res == 'testTopic') {
      navTo('/pages/test/topic');
    } else 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>
