<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>What Did You Do?</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    <script>
    window.onload = function() {
        var dateInput = document.getElementById('date');
        if (!dateInput.value) {
            var today = new Date();
            var yyyy = today.getFullYear();
            var mm = String(today.getMonth() + 1).padStart(2, '0');
            var dd = String(today.getDate()).padStart(2, '0');
            dateInput.value = yyyy + '-' + mm + '-' + dd;
        }
    };
    </script>
</head>
<body>
    <div class="container">
        <h2><a href="/">What Did You Do?</a></h2>
        <form method="get" action="" onsubmit="event.preventDefault(); window.location.href='/' + encodeURIComponent(document.getElementById('user').value) + '/' + encodeURIComponent(document.getElementById('date').value);">
            <label for="user">User:</label>
            <input type="text" id="user" name="user" value="{{ user or '' }}" placeholder="insert OSM username" required>

            <label for="date">Date:</label>
            <input type="date" id="date" name="date" value="{{ date or '' }}" required>

            <button type="submit">Show</button>
        </form>
    {% if user and date %}
        {% if error %}
            <p class=error>{{ error }}</p>
        {% elif changes %}
            <p><a href="https://www.openstreetmap.org/user/{{ user }}">{{ user }}</a> did {{ changes.values() | sum }} changes in {{ changesets }} changeset{{ "s" if changesets > 1 else ""  }} on {{ date }}:</p>
            <ul>
            {% for app, count in changes.items() %}
                <li>{{ count }} changes in {{ app }}</li>
            {% endfor %}
            </ul>
        {% else %}
            <p><a href="https://www.openstreetmap.org/user/{{ user }}">{{ user }}</a> did not do anything on {{ date }}.</p>
        {% endif %}
    {% else %}
        <p>
            How much did you contribute to <a href="https://www.openstreetmap.org/">OpenStreetMap</a> today? Or any other day?
        </p>
        <p>
            To answer this question, enter your OSM username and the date you want to check above and click "Show".
        </p>
        <div class="disclaimer">
            <h4>Disclaimers</h4>
            <ul>
                <li>This is a very simple service. It does exactly one job and tries to do it good.</li>
                <li>Quality beats quantity. While it's nice to see big numbers here, please remember
                    that just one high-effort change will help more that any amount of mediocre changes.</li>
                <li>This service is rate-limited to 10 OSM API requests per minute and caches results
                     for 1 hour to reduce load on the API.</li>
            </ul>
        </div>
    {% endif %}
    <p class="footer">Powered by <a href="https://github.com/rompe/whatdidyoudo">whatdidyoudo {{ version }}</a></p>
    </div>
</body>
</html>
