import { EnumEvent, EnumUserRole, EnumUserType } from "@/common/enum";
import { useUserStore } from "@/store/userStore";
import IePage from "@/components/ie-page/ie-page.vue";

export const useAuth = () => {
  const userStore = useUserStore();
  const { userInfo, isLogin, isVip, isStudent } = storeToRefs(userStore);
  const hasPermission = (roles: EnumUserRole[] = []) => {
    if (roles.length === 0) {
      return true;
    }
    const hasAuth = roles.some(role => {
      if (role === EnumUserRole.VIP) {
        return isVip.value;
      }
      if (role === EnumUserRole.NORMAL) {
        return isStudent.value && !isVip.value;
      }
      if (role === EnumUserRole.GUEST) {
        return !isLogin.value;
      }
      if (role === EnumUserRole.TEACHER) {
        return userInfo.value.userType === EnumUserType.TEACHER;
      }
      if (role === EnumUserRole.AGENT) {
        return userInfo.value.userType === EnumUserType.AGENT;
      }
      return true;
    });
    if (!hasAuth && roles.includes(EnumUserRole.VIP)) {
      uni.$emit(EnumEvent.OPEN_VIP_POPUP);
      return false;
    }
    return hasAuth;
  }

  const checkVipPermission = () => {
    if (!isVip.value) {

    }
  }

  return {
    hasPermission
  }
}