<template>
  <div class="login">
    <div class="login-bg">
      <div class="bg-circle circle-1"></div>
      <div class="bg-circle circle-2"></div>
      <div class="bg-circle circle-3"></div>
    </div>
    
    <div class="login-content">
      <div class="logo">
        <div class="logo-icon">
          <van-icon name="manager-o" />
        </div>
        <h1>泉友米管理后台</h1>
        <p>欢迎回来</p>
      </div>
      
      <van-form @submit="onSubmit" class="login-form">
        <van-cell-group inset>
          <van-field 
            v-model="form.username" 
            label="用户名" 
            placeholder="请输入用户名" 
            required 
            left-icon="user-o"
            clearable
          />
          <van-field 
            v-model="form.password" 
            type="password" 
            label="密码" 
            placeholder="请输入密码" 
            required 
            left-icon="lock"
            clearable
          />
        </van-cell-group>
        
        <div class="form-actions">
          <van-button round block type="primary" native-type="submit" size="large">
            登录
          </van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { showToast } from 'vant';
import api from '../../api';

const router = useRouter();
const form = ref({
  username: '',
  password: ''
});

const onSubmit = async () => {
  try {
    const { data } = await api.adminLogin(form.value);
    localStorage.setItem('token', data.token);
    showToast('登录成功');
    router.push('/admin');
  } catch (error) {
    showToast('登录失败');
  }
};
</script>

<style scoped>
.login {
  min-height: 100vh;
  background: linear-gradient(135deg, #FF6700 0%, #FF8533 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.bg-circle {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  animation: float 20s ease-in-out infinite;
}

.circle-1 {
  width: 300px;
  height: 300px;
  top: -100px;
  right: -100px;
  animation-delay: 0s;
}

.circle-2 {
  width: 200px;
  height: 200px;
  bottom: -50px;
  left: -50px;
  animation-delay: 5s;
}

.circle-3 {
  width: 150px;
  height: 150px;
  top: 50%;
  left: 10%;
  animation-delay: 10s;
}

@keyframes float {
  0%, 100% { 
    transform: translate(0, 0) scale(1);
    opacity: 0.3;
  }
  50% { 
    transform: translate(30px, -30px) scale(1.1);
    opacity: 0.5;
  }
}

.login-content {
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 1;
}

.logo {
  text-align: center;
  margin-bottom: 48px;
}

.logo-icon {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: rgba(255,255,255,0.25);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.logo-icon .van-icon {
  font-size: 42px;
  color: #fff;
}

.logo h1 {
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  margin: 0 0 8px;
  text-shadow: 0 2px 12px rgba(0,0,0,0.2);
  letter-spacing: 1px;
}

.logo p {
  color: rgba(255,255,255,0.9);
  font-size: 15px;
  margin: 0;
  font-weight: 500;
}

.login-form {
  position: relative;
}

.login-form .van-cell-group {
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  backdrop-filter: blur(10px);
  background: rgba(255,255,255,0.95);
}

.login-form .van-field {
  padding: 16px;
}

.login-form .van-field__label {
  font-weight: 600;
  color: #333;
  font-size: 14px;
}

.login-form .van-field__control {
  font-size: 15px;
}

.form-actions {
  margin-top: 32px;
}

.form-actions .van-button {
  height: 52px;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  background: linear-gradient(135deg, #FF6700 0%, #FF8533 100%);
  border: none;
  transition: all 0.3s ease;
}

.form-actions .van-button:active {
  transform: translateY(2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
</style>
