import React, { useState, useEffect } from 'react'; import { Lock, X, KeyRound } from 'lucide-react'; import { Button } from './Button'; interface AdminLoginModalProps { isOpen: boolean; onClose: () => void; onSuccess: () => void; } export const AdminLoginModal: React.FC = ({ isOpen, onClose, onSuccess }) => { const [password, setPassword] = useState(''); const [error, setError] = useState(false); const [isAnimating, setIsAnimating] = useState(false); useEffect(() => { if (isOpen) { setIsAnimating(true); setPassword(''); setError(false); } else { setTimeout(() => setIsAnimating(false), 200); } }, [isOpen]); if (!isOpen && !isAnimating) return null; const handleLogin = async () => { try { console.log('[AdminLogin] Starting login process...'); if (!password) { console.log('[AdminLogin] No password entered'); setError(true); return; } if (!window.crypto || !window.crypto.subtle) { console.error('[AdminLogin] Crypto API not available', { crypto: !!window.crypto, subtle: !!window.crypto?.subtle }); alert('Error crítico: Tu navegador no soporta la encriptación necesaria (crypto.subtle). Por favor usa un navegador moderno o contexto seguro (HTTPS/localhost).'); return; } const encoder = new TextEncoder(); const data = encoder.encode(password); console.log('[AdminLogin] Hashing password...'); const hashBuffer = await crypto.subtle.digest('SHA-256', data); const hashArray = Array.from(new Uint8Array(hashBuffer)); const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); console.log('[AdminLogin] Hash generated:', hashHex); // Hash for 'codebydante069012*' const expectedHash = '19362a1b321cd1b4fe5a625b8a6647a371beebebd3daddccdb2ed271a9a7ee5d'; if (hashHex === expectedHash) { console.log('[AdminLogin] Password correct!'); onSuccess(); onClose(); } else { console.warn('[AdminLogin] Password incorrect. Expected:', expectedHash, 'Got:', hashHex); setError(true); } } catch (e: any) { console.error('[AdminLogin] Unexpected error:', e); alert(`Error inesperado: ${e.message || e}`); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleLogin(); } }; return (
{/* Header */}

Acceso Administrativo

Introduce la credencial de seguridad

{/* Content */}

Esta zona está protegida. Solo personal autorizado.

{ setPassword(e.target.value); setError(false); }} onKeyDown={handleKeyDown} className={`w-full bg-black/40 border rounded-lg px-4 py-3 text-white placeholder-gray-600 outline-none focus:ring-1 transition-all ${error ? 'border-red-500 focus:border-red-500 focus:ring-red-500/20' : 'border-white/10 focus:border-primary focus:ring-primary/20' }`} placeholder="••••••••••••••" autoFocus /> {error && (

Acceso denegado. Credencial inválida.

)}
{/* Footer */}
); };