<script setup>
import { ACCESS_TOKEN_KEY } from '@/constants/storage'
import { useUserStore } from '@/store/user'

// 修改密码 建议反馈 关于 退出账号
const list = ref([
  { title: '修改密码', path: '/pages/views/update-password/index' },
  // { title: '建议反馈', path: '/pages/views/user-feedback/index' },
  { title: '关于', path: '/pages/views/about-app/index' },
  { title: '退出账号', path: '', action: 'logout' }
])
const showLogoutModal = ref(false)
const handleItem = ({ action }) => {
  if (action === 'logout') {
    showLogoutModal.value = true
  }
}
const { setUserInfo, setUserRoles } = useUserStore()
const confirm = () => {
  uni.setStorageSync(ACCESS_TOKEN_KEY, '')
  setUserRoles([])
  setUserInfo({})
  uni.$u.toast('退出成功')
  showLogoutModal.value = false
  setTimeout(() => {
    uni.reLaunch({
      url: '/pages/views/login/index'
    })
  }, 1500)
}
const cancel = () => {
  showLogoutModal.value = false
}
const close = () => {
  showLogoutModal.value = false
}
</script>

<template>
  <view min-h-100vh bg="#F6F5F5" class="user-setting">
    <up-cell-group
      :border="false"
      :custom-style="{
        backgroundColor: '#FFFFFF'
      }"
    >
      <view v-for="(item, index) in list" :key="index">
        <up-cell
          :title="item.title"
          :is-link="true"
          :url="item.path"
          @tap="handleItem(item)"
        />
        <view w-full h-20 bg="#F6F5F5" />
      </view>
    </up-cell-group>

    <!-- 退出提示 -->
    <up-modal
      title="提示"
      content="您确定退出当前账号？"
      :show="showLogoutModal"
      show-cancel-button
      close-on-click-overlay
      @confirm="confirm"
      @cancel="cancel"
      @close="close"
    />
  </view>
</template>

<style>
.user-setting .u-modal__content__text {
  text-align: center !important;
}
</style>
