<template>
  <div class="login-container">
    <!-- 背景视频 -->
    <video src="../../public/登陆界面背景.mp4" autoplay muted loop class="bg-video"></video>
    <div class="video-overlay"></div>

    <!-- 登录卡片 -->
    <el-card class="login-card" shadow="always">
      <template #header>
        <div class="card-header">
          <img src="../../public/logo.png" alt="logo" class="login-logo">
          <h2>蜜雪冰城管理系统</h2>
          <p class="subtitle">请输入您的账号信息</p>
        </div>
      </template>

      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="rules"
        label-position="top"
        @keyup.enter="handleLogin"
      >
        <el-form-item label="用户名" prop="username">
          <el-input
            v-model="loginForm.username"
            :prefix-icon="User"
            clearable
            placeholder="请输入用户名"
          />
        </el-form-item>

        <el-form-item label="密码" prop="password">
          <el-input
            v-model="loginForm.password"
            :prefix-icon="Lock"
            clearable
            placeholder="请输入密码"
            show-password
            type="password"
          />
        </el-form-item>

        <el-form-item>
          <el-checkbox v-model="loginForm.remember">记住我</el-checkbox>
        </el-form-item>

        <el-form-item class="login-form-button">
          <el-button
            :loading="loading"
            class="login-btn"
            type="primary"
            @click="handleLogin"
          >
            登 录
          </el-button>
        </el-form-item>

      </el-form>

    </el-card>
  </div>
</template>

<script setup>
import {reactive, ref} from 'vue'
import {ElMessage} from 'element-plus'
import {Lock, User} from '@element-plus/icons-vue'
import {useRouter} from 'vue-router'

const router = useRouter()

const loginFormRef = ref(null)
const loading = ref(false)

const loginForm = reactive({
  username: '',
  password: '',
  remember: false,
})

const rules = {
  username: [
    { required: true, message: '请输入用户名', trigger: 'blur' },
  ],
  password: [
    { required: true, message: '请输入密码', trigger: 'blur' },
  ],
}

const handleLogin = async () => {
  if (!loginFormRef.value) return
  try {
    await loginFormRef.value.validate()
    loading.value = true
    await new Promise((r) => setTimeout(r, 800))
    ElMessage.success('登录成功（模拟）')
    router.push('/panel')
  } catch {
    // 校验失败，element-plus 会自动显示红色提示
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.login-container {
  position: relative;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 100vh;
  padding: 20px 60px 20px 20px;
  overflow: hidden;
}

/* 背景视频 */
.bg-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.video-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1;
}

/* 登录卡片 */
.login-card {
  position: relative;
  z-index: 2;
  width: 420px;
  border-radius: 16px;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.login-card :deep(.el-card__header) {
  border-bottom: 2px solid #E60012;
  padding: 20px;
}

.login-logo {
  display: block;
  width: 60px;
  height: 60px;
  margin: 0 auto 12px;
  object-fit: contain;
}

.card-header {
  text-align: center;
}

.card-header h2 {
  margin: 0 0 8px;
  color: #E60012;
  font-size: 22px;
  font-weight: 600;
}

.subtitle {
  margin: 0;
  font-size: 14px;
  color: #909399;
}

/* 输入框聚焦时红色边框 */
.login-card :deep(.el-input__wrapper:focus-within) {
  box-shadow: 0 0 0 1px #E60012 inset;
}

/* 登录按钮 */
.login-btn {
  display: block;
  margin: 0 auto;
  text-align: center;
  width: 75%;
  background: #E60012;
  border-color: #E60012;
}

.login-btn:hover {
  background: #d50010;
  border-color: #d50010;
}

/* 记住我复选框 */
.login-card :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
  background-color: #E60012;
  border-color: #E60012;
}

.login-card :deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
  color: #E60012;
}
</style>
