<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login - GNSS Guard Cloud</title>
    <link rel="stylesheet" href="/static/style.css?v={{ cache_buster }}">
</head>
<body class="login-page">

<div class="login-container">
    <div class="login-box">
        <div class="login-header">
            <div class="login-title">TM GNSS Guard</div>
            <div class="login-subtitle">Cloud Dashboard</div>
        </div>
        
        <form id="loginForm" class="login-form">
            <div class="form-group">
                <label for="username">Username</label>
                <input type="text" id="username" name="username" required autocomplete="username">
            </div>
            
            <div class="form-group">
                <label for="password">Password</label>
                <input type="password" id="password" name="password" required autocomplete="current-password">
            </div>
            
            <div class="form-error hidden" id="loginError">Invalid credentials</div>
            
            <button type="submit" class="login-btn">Sign In</button>
        </form>
        
        <div class="login-footer">
            Tototheo Global © 2025
        </div>
    </div>
</div>

<script>
document.getElementById('loginForm').addEventListener('submit', async (e) => {
    e.preventDefault();
    
    const username = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    const errorEl = document.getElementById('loginError');
    
    errorEl.classList.add('hidden');
    
    try {
        const response = await fetch('/login', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ username, password })
        });
        
        if (response.ok) {
            window.location.href = '/';
        } else {
            errorEl.classList.remove('hidden');
            errorEl.textContent = 'Invalid username or password';
        }
    } catch (error) {
        errorEl.classList.remove('hidden');
        errorEl.textContent = 'Connection error. Please try again.';
    }
});
</script>
</body>
</html>

