<template>
  <div class="redirect-container">
    <a-spin tip="正在验证身份..." size="large" />
    <div class="message">正在跳转登录...</div>
  </div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useUserStore } from '../stores/user';
import { Message } from '@arco-design/web-vue';

const route = useRoute();
const router = useRouter();
const userStore = useUserStore();

onMounted(async () => {
  const ticket = route.query.ticket as string;
  
  if (!ticket) {
    Message.error('登录失败：未收到票据');
    router.push('/login');
    return;
  }

  try {
    await userStore.ssoLogin(ticket);
    Message.success('登录成功');
    router.push('/');
  } catch (error) {
    console.error('SSO Login Error:', error);
    Message.error('登录验证失败，请重试');
    router.push('/login');
  }
});
</script>

<style scoped>
.redirect-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: var(--color-bg-1);
}

.message {
  margin-top: 16px;
  color: var(--color-text-2);
  font-size: 16px;
}
</style>
