<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reitti - Login</title>
    <link rel="icon" th:href="@{/img/logo.svg}">
    <link rel="apple-touch-icon" th:href="@{/img/logo.svg}">
    <link rel="shortcut icon" type="image/x-icon" th:href="@{/img/logo.svg}">
    <link rel="stylesheet" href="/css/leaflet.css">
    <script src="/js/leaflet.js"></script>
    <script src="/js/TileLayer.Grayscale.js"></script>
    <style>
        :root {
            --color-highlight: #F5DEB3FF;
            --color-background-dark: #3b3b3b;
            --color-background-dark-light: #5c5c5c;
            --color-text-white: #e3e3e3;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            margin: 0;
            padding: 0;
            height: 100vh;
            overflow: hidden;
            position: relative;
        }
        
        #login-map {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1;
        }
        
        .login-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            background: rgba(17, 17, 17, 0.7);
            backdrop-filter: blur(5px);
        }
        
        .login-container {
            background-color: var(--color-background-dark);
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.3);
            width: 350px;
            border: 1px solid var(--color-highlight);
            backdrop-filter: blur(10px);
        }
        
        h1 {
            text-align: center;
            color: var(--color-highlight);
            margin-bottom: 30px;
            font-family: "Fraunces", serif;
            font-size: 3rem;
            font-weight: lighter;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: 400;
            color: var(--color-text-white);
        }
        
        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 12px;
            background-color: var(--color-background-dark-light);
            border: 1px solid #666;
            border-radius: 4px;
            box-sizing: border-box;
            color: var(--color-text-white);
            transition: border-color 0.3s;
        }
        
        input[type="text"]:focus,
        input[type="password"]:focus {
            border-color: var(--color-highlight);
            outline: none;
        }
        
        .remember-me {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .remember-me input {
            margin-right: 8px;
        }
        
        button {
            background-color: transparent;
            color: var(--color-highlight);
            border: 1px solid var(--color-highlight);
            padding: 12px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
            transition: background-color 0.3s, color 0.3s;
        }
        
        button:hover {
            background-color: var(--color-highlight);
            color: var(--color-background-dark);
        }
        
        .error-message {
            color: #ff6b6b;
            margin-bottom: 20px;
            text-align: center;
            padding: 10px;
            background-color: rgba(255, 107, 107, 0.1);
            border-radius: 4px;
        }
    </style>
</head>
<body>
    <!-- Background Map -->
    <div id="login-map"></div>
    
    <!-- Login Form Overlay -->
    <div class="login-overlay">
        <div class="login-container">
        <h1>Reitti</h1>
        
        <div th:if="${param.error}" class="error-message" th:text="#{login.invalid.credentials}">
            Invalid username or password
        </div>
        
        <form th:action="@{/login}" method="post" th:if="${localLoginEnabled}">
            <div class="form-group">
                <label for="username" th:text="#{login.username}">Username</label>
                <input type="text" id="username" name="username" required autofocus>
            </div>
            
            <div class="form-group">
                <label for="password" th:text="#{login.password}">Password</label>
                <input type="password" id="password" name="password" required>
            </div>
            
            <div class="remember-me">
                <input type="checkbox" id="remember-me" name="remember-me">
                <label for="remember-me" th:text="#{login.remember.me}">Remember me</label>
            </div>
            
            <button type="submit" th:text="#{login.button}">Login</button>
        </form>
        <div th:if="${oidcEnabled}">
            <hr th:if="${localLoginEnabled}" style="margin: 30px 0; border: none; border-top: 1px solid var(--color-highlight);">
            <a href="/oauth2/authorization/oauth" style="text-decoration: none;">
              <button type="button" th:text="#{login.oauth.button}">Log in with OAuth</button>
            </a>
        </div>
    </div>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        // Random cities for the demo map
        const cities = [
            { name: 'Paris', lat: 48.8566, lng: 2.3522, zoom: 12 },
            { name: 'Tokyo', lat: 35.6762, lng: 139.6503, zoom: 11 },
            { name: 'New York', lat: 40.7128, lng: -74.0060, zoom: 11 },
            { name: 'London', lat: 51.5074, lng: -0.1278, zoom: 11 },
            { name: 'Sydney', lat: -33.8688, lng: 151.2093, zoom: 11 },
            { name: 'Barcelona', lat: 41.3851, lng: 2.1734, zoom: 12 },
            { name: 'Amsterdam', lat: 52.3676, lng: 4.9041, zoom: 12 },
            { name: 'San Francisco', lat: 37.7749, lng: -122.4194, zoom: 12 }
        ];
        
        // Pick a random city
        const randomCity = cities[Math.floor(Math.random() * cities.length)];
        
        // Initialize the map
        const map = L.map('login-map', {
            zoomControl: false,
            attributionControl: false
        }).setView([randomCity.lat, randomCity.lng], randomCity.zoom);
        
        // Add grayscale tile layer
        L.tileLayer.grayscale('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
            maxZoom: 19
        }).addTo(map);
        
        // Add a subtle marker for the city
        L.circleMarker([randomCity.lat, randomCity.lng], {
            radius: 6,
            fillColor: '#F5DEB3',
            color: '#fff',
            weight: 1,
            opacity: 0.7,
            fillOpacity: 0.6
        }).addTo(map);
        
        // Disable map interaction to keep it as decoration
        map.dragging.disable();
        map.touchZoom.disable();
        map.doubleClickZoom.disable();
        map.scrollWheelZoom.disable();
        map.boxZoom.disable();
        map.keyboard.disable();
        if (map.tap) map.tap.disable();
    });
</script>
</body>
</html>
