'use client'; import { useState } from 'react'; import { motion } from 'framer-motion'; import toast, { Toaster } from 'react-hot-toast'; import Link from 'next/link'; import Image from 'next/image'; import { useRouter } from 'next/navigation'; import { Mail, Lock, Eye, EyeOff, ArrowLeft, LogIn, CheckCircle, Loader2, Home, Shield } from 'lucide-react'; export default function LoginPage() { const router = useRouter(); const [showPassword, setShowPassword] = useState(false); const [isLoading, setIsLoading] = useState(false); const [isSuccess, setIsSuccess] = useState(false); const [formData, setFormData] = useState({ email: '', password: '', rememberMe: false }); const [errors, setErrors] = useState({}); const ADMIN_EMAIL = 'admin@gmail.com'; const ADMIN_PASSWORD = '123'; const validateEmail = (email) => { const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return re.test(email); }; const validateForm = () => { const newErrors = {}; if (!formData.email) { newErrors.email = 'البريد الإلكتروني مطلوب'; } else if (!validateEmail(formData.email)) { newErrors.email = 'البريد الإلكتروني غير صالح'; } if (!formData.password) { newErrors.password = 'كلمة المرور مطلوبة'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleSubmit = async (e) => { e.preventDefault(); if (!validateForm()) { toast.error('يرجى تصحيح الأخطاء في النموذج', { style: { background: '#fee2e2', color: '#991b1b' } }); return; } setIsLoading(true); setTimeout(() => { if (formData.email.toLowerCase() === ADMIN_EMAIL && formData.password === ADMIN_PASSWORD) { setIsLoading(false); setIsSuccess(true); toast.success('تم تسجيل الدخول كأدمن!', { style: { background: '#dcfce7', color: '#166534' }, duration: 3000 }); localStorage.setItem('user', JSON.stringify({ name: 'مدير النظام', email: ADMIN_EMAIL, role: 'admin', avatar: 'أ' })); setTimeout(() => { router.push('/admin'); }, 1500); } else { setIsLoading(false); toast.error('بيانات الدخول غير صحيحة. حاول مع admin@gmail.com / 123', { style: { background: '#fee2e2', color: '#991b1b' }, duration: 4000 }); } }, 1500); }; const particles = Array.from({ length: 30 }, (_, i) => ({ id: i, x: Math.random() * 100, y: Math.random() * 100, size: Math.random() * 3 + 1, duration: Math.random() * 15 + 10, delay: Math.random() * 5 })); const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { staggerChildren: 0.1, delayChildren: 0.2 } } }; const itemVariants = { hidden: { y: 20, opacity: 0 }, visible: { y: 0, opacity: 1, transition: { type: 'spring', stiffness: 100 } } }; return (
مرحباً بعودتك!