<template>
  <div class="login-page">
    <!-- 登录加载遮罩 -->
    <div class="login-loading" :class="{ active: isLoading }">
      <div class="loading-spinner"></div>
      <div class="loading-text">正在登录，请稍候...</div>
    </div>

    <div class="login-header">
      <div class="logo">
        <div class="logo-icon"><img src="/logo.png" alt="有维商学" /></div>
        有维商学
      </div>
    </div>

    <div class="login-content">
      <div class="login-info">
        <h1>OPC创业者<br />赋能平台</h1>
        <p>
          基于"有维教育+AI工具+有维校友"三位一体的商业模式，为OPC创业者提供全方位的成长支持
        </p>

        <div class="feature-cards">
          <div class="feature-card">
            <div class="feature-card-icon">📚</div>
            <h3>有维教育</h3>
            <p>系统化商业课程，知行合一</p>
          </div>
          <div class="feature-card">
            <div class="feature-card-icon">🤖</div>
            <h3>AI工具</h3>
            <p>智能体赋能，数字员工</p>
          </div>
          <div class="feature-card">
            <div class="feature-card-icon">👥</div>
            <h3>有维校友</h3>
            <p>创业者社群，互助共赢</p>
          </div>
        </div>
      </div>

      <div class="login-form-container">
        <h2>欢迎回来</h2>
        <p class="subtitle">登录您的有维商学账户</p>

        <form @submit.prevent="handleLogin">
          <div class="form-group">
            <label>手机号/邮箱</label>
            <input
              v-model="username"
              type="text"
              placeholder="请输入手机号或邮箱"
              required
            />
          </div>
          <div class="form-group">
            <label>密码</label>
            <input
              v-model="password"
              type="password"
              placeholder="请输入密码"
              required
            />
          </div>
          <div class="form-options">
            <label class="remember-me">
              <input v-model="rememberMe" type="checkbox" />
              <span>记住我</span>
            </label>
            <a href="#" class="forgot-password">忘记密码？</a>
          </div>
          <button type="submit" class="login-btn">登 录</button>
        </form>

        <div class="divider"><span>或使用以下方式登录</span></div>

        <div class="social-login">
          <button class="social-btn">💬 微信</button>
          <button class="social-btn">📱 手机验证码</button>
        </div>

        <p class="register-link">
          还没有账户？<a href="#">立即注册</a>
        </p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

const username = ref('')
const password = ref('')
const rememberMe = ref(false)
const isLoading = ref(false)

// 页面加载时检查是否已登录
onMounted(() => {
  if (userStore.checkLoginStatus()) {
    router.push('/')
  }
})

const handleLogin = () => {
  if (!username.value.trim() || !password.value.trim()) {
    alert('请输入账号和密码')
    return
  }

  isLoading.value = true

  // 模拟登录延迟
  setTimeout(() => {
    userStore.login(username.value.trim(), rememberMe.value)
    isLoading.value = false
    router.push('/')
  }, 1500)
}
</script>

<style scoped>
.login-page {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.login-loading {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  z-index: 9999;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 24px;
}

.login-loading.active {
  display: flex;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  color: white;
  font-size: 18px;
  font-weight: 500;
}

.login-header {
  padding: 20px 60px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  width: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: white;
  font-size: 24px;
  font-weight: 700;
}

.logo-icon {
  width: 44px;
  height: 44px;
  background: white;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 4px;
}

.logo-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.login-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 60px;
  gap: 120px;
  width: 100%;
  overflow-y: auto;
}

.login-info {
  flex: 1;
  max-width: 550px;
  color: white;
}

.login-info h1 {
  font-size: 48px;
  font-weight: 800;
  margin-bottom: 20px;
  line-height: 1.2;
}

.login-info p {
  font-size: 18px;
  opacity: 0.9;
  margin-bottom: 40px;
}

.feature-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.feature-card {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 24px;
  transition:
    transform 0.3s,
    background 0.3s;
}

.feature-card:hover {
  transform: translateY(-5px);
  background: rgba(255, 255, 255, 0.25);
}

.feature-card-icon {
  width: 48px;
  height: 48px;
  background: white;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 24px;
}

.feature-card h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.feature-card p {
  font-size: 13px;
  opacity: 0.8;
  margin: 0;
}

.login-form-container {
  background: white;
  border-radius: 24px;
  padding: 48px;
  width: 440px;
  flex-shrink: 0;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.login-form-container h2 {
  font-size: 28px;
  margin-bottom: 8px;
  color: #1e293b;
}

.login-form-container .subtitle {
  color: #64748b;
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  color: #1e293b;
}

.form-group input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  font-size: 15px;
  transition:
    border-color 0.3s,
    box-shadow 0.3s;
}

.form-group input:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.remember-me {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.remember-me input {
  width: 18px;
  height: 18px;
  accent-color: #4f46e5;
}

.forgot-password {
  color: #4f46e5;
  text-decoration: none;
  font-weight: 500;
}

.login-btn {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.divider {
  display: flex;
  align-items: center;
  margin: 24px 0;
  color: #64748b;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

.divider span {
  padding: 0 16px;
  font-size: 14px;
}

.social-login {
  display: flex;
  gap: 12px;
}

.social-btn {
  flex: 1;
  padding: 12px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  transition:
    border-color 0.3s,
    background 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 500;
}

.social-btn:hover {
  border-color: #4f46e5;
  background: #f8fafc;
}

.register-link {
  text-align: center;
  margin-top: 24px;
  color: #64748b;
}

.register-link a {
  color: #4f46e5;
  text-decoration: none;
  font-weight: 600;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .login-content {
    flex-direction: column;
    gap: 40px;
    padding: 20px;
    justify-content: center;
  }

  .login-info {
    text-align: center;
    max-width: 100%;
  }

  .login-info h1 {
    font-size: 36px;
  }

  .feature-cards {
    display: none;
  }

  .login-form-container {
    width: 100%;
    max-width: 440px;
  }
}
</style>
