<template>
  <van-popup v-model:show="show" ref="drawerRef" position="left">
    <div class="drawer-home">
      <div class="drawer-home-nav">
        <van-icon name="cross" size="22" color="#333333" class="close-icon" @click="close" />
        <span class="title">我的</span>
      </div>

      <MineSetting ref="mineSettingRef" @close="close" />
    </div>
  </van-popup>
</template>

<script setup>
import { ref, defineExpose } from "vue";
import { checkToken } from "@/hooks/useGoLogin";
import MineSetting from "./components/MineSetting/index.vue";

const drawerRef = ref(null);

// 监听抽屉显示事件
const mineSettingRef = ref(null);
const show = ref(false);

const open = async () => {
  await checkToken();

  show.value = true;

  try {
    await mineSettingRef.value?.getLoginUserPhoneInfo?.();
  } catch (error) {
    console.warn("获取登录用户手机号失败:", error);
  }
};

// 监听抽屉隐藏事件
const close = () => show.value = false;

defineExpose({
  open,
  close,
});
</script>

<style lang="scss" scoped>
@import "./styles/index.scss";
</style>
