<template>
  <ie-page bg-color="#f8fcff">
    <ie-navbar title="关于" />
    <view class="flex items-center justify-center py-80">
      <ie-image src="/static/logo.png" custom-class="w-160 h-160" mode="widthFix" />
    </view>
    <uv-cell-group class="bg-white !flex-none">
      <uv-cell v-for="item in settings" :icon="item.icon" :is-link="item.isLink" :title="item.title" :value="item.value"
        icon-style="font-size: 20px;" @click="item.handler()" />
    </uv-cell-group>
  </ie-page>
</template>

<script lang="ts" setup>
import { useTransferPage } from '@/hooks/useTransferPage';
import { useAppStore } from '@/store/appStore';
import { useUserStore } from '@/store/userStore';

const appStore = useAppStore();
const userStore = useUserStore();
const { transferTo, routes } = useTransferPage();
const contactPhone = computed(() => userStore.orgInfo.contactPhone);

const settings = computed(() => [
  {
    title: '服务协议',
    icon: 'empty-order',
    isLink: true,
    handler: () => {
      transferTo(routes.pageUserProtocol);
    }
  },
  {
    title: '隐私政策',
    icon: 'lock',
    isLink: true,
    handler: () => {
      transferTo(routes.pagePrivacyPolicy);
    }
  },
  {
    title: '清除数据',
    icon: 'empty-page',
    isLink: true,
    value: '',
    handler: () => {
      // 清除所有本地数据，重启 app
      uni.$ie.showModal({
        title: '提示',
        content: '清除数据后需要重新登录\n是否继续？',
      }).then(confirm => {
        if (confirm) {
          uni.clearStorageSync();
          setTimeout(() => {
            // 再次尝试清除，防止有补偿机制
            uni.clearStorageSync();
            // #ifdef H5
            window.location.href = '/h5/';
            // #endif
            // #ifdef MP-WEIXIN
            wx.restartMiniProgram({
              path: '/pagesMain/pages/splash/splash'
            });
            // #endif
          }, 100);
        }
      })
    }
  },
  {
    title: '当前版本',
    icon: 'tags',
    value: appStore.systemInfo?.appVersion,
    handler: () => {
    }
  },
  {
    title: '注销账号',
    icon: 'trash',
    isLink: true,
    handler: async () => {
      uni.$ie.showModal({
        title: '注销账号',
        content: '是否注销账号，注销后卡号将不能再注册使用系统且永久失效。请谨慎操作！'
      }).then(confirm => {
        if (confirm) {
          userStore.deleteAccount();
        }
      });
    }
  },
  {
    title: 'APP备案号',
    icon: 'empty-permission',
    value: '湘ICP备18012964号-8A',
    handler: () => {
    }
  },
  {
    title: '客服电话',
    icon: 'server-man',
    value: contactPhone.value,
    handler: () => {
      userStore.callContactPhone();
    }
  }
]);
</script>

<style lang="scss"></style>