import { Modal } from 'ant-design-vue'
import { defineStore } from 'pinia'
import { reactive } from 'vue'

export const useUserStore = defineStore('userStore', () => {
  const userInfo = reactive({})

  const clearUserInfo = () => {
    return new Promise((resolve) => {
      // 做些什么
      // useSchedulerOnce(() => resolve(true), 500)
    })
  }

  const login = () => {
    // 设置用户信息, 校验后的登录
  }

  const logout = () => {
    Modal.confirm({
      title: '您确定要退出吗？',
      cancelText: '取消',
      okText: '确定',
      onCancel: () => {},
      onOk: async () => {
        await clearUserInfo()
      // 退出
      }
    })
  }

  return {
    userInfo,
    login,
    logout,
    clearUserInfo
  }
})
