<template>
  <div class="login-container">
    <div class="login-box">
      <div class="login-header">
        <h1>子系统示例</h1>
        <p>请通过SSO认证中心登录</p>
      </div>
      
      <div class="login-content">
        <el-button 
          type="primary" 
          size="large" 
          :loading="loading"
          @click="handleSSOLogin"
          class="sso-login-btn"
        >
          <el-icon><Key /></el-icon>
          通过SSO登录
        </el-button>
        
        <div class="login-info">
          <p>点击上方按钮将跳转到SSO认证中心进行登录</p>
          <p>登录成功后将自动返回本系统</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'

const router = useRouter()
const authStore = useAuthStore()
const loading = ref(false)

const handleSSOLogin = () => {
  loading.value = true
  // 跳转到后端的SSO登录端点
  window.location.href = '/auth/login'
}

// 如果已经登录，重定向到仪表盘
if (authStore.isAuthenticated) {
  router.push('/dashboard')
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
  width: 400px;
  padding: 40px;
  background: white;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.login-header {
  margin-bottom: 30px;
}

.login-header h1 {
  color: #333;
  margin-bottom: 10px;
  font-size: 24px;
  font-weight: 600;
}

.login-header p {
  color: #666;
  font-size: 14px;
}

.login-content {
  width: 100%;
}

.sso-login-btn {
  width: 100%;
  height: 48px;
  font-size: 16px;
  margin-bottom: 20px;
}

.login-info {
  padding: 20px;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #409EFF;
}

.login-info p {
  margin: 8px 0;
  color: #666;
  font-size: 14px;
  line-height: 1.5;
}
</style>