{% extends 'base.html' %}

{% block head %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='assets/leaflet/leaflet.css') }}" />
<script src="{{ url_for('static', filename='assets/leaflet/leaflet.js') }}"></script>
<script src="{{ url_for('static', filename='assets/leaflet/utils.js') }}"></script>
{% endblock %}

{% block app_content %}
<h1>{{ game.name }}: {{ current_user.name }}</h1>
{% include '_game_player_info.html' %}
<h2>Objective Locations:</h2>
{% if game.objectives %}
<div class="table-responsive">
    <table class="table">
        <thead>
            <tr>
                <th scope="col">Objective Name</th>
                <th scope="col">Latitude</th>
                <th scope="col">Longitude</th>
                <th scope="col">Found</th>
            </tr>
        </thead>
        <tbody>
            {% for objective in game.objectives %}
            <tr>
                <td>{{ objective.name }}</td>
                <td>{{ objective.latitude }}</td>
                <td>{{ objective.longitude }}</td>
                <td>{{ 'Yes' if objective in current_user.player_in(game).found_objectives else 'No' }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
<div id="map" style=" height: 500px; border-radius: 10px; " class="col-md-6 col-xs-12"></div>
{% endif %}


{% endblock %}

{% block scripts %}
{{ super() }}
{{ moment.include_moment() }}
<script type="text/javascript", crossorigin="anonymous">
    // Leaflet Map
    var map = L.map( 'map', {
        center: [52.2, 5.3],
        minZoom: 6,
        maxZoom: 19,
        bounds: [[50.5, 3.25], [54, 7.6]],
        zoom: 8
    });
    L.control.scale().addTo(map);

    L.tileLayer( 'https://geodata.nationaalgeoregister.nl/tiles/service/wmts/brtachtergrondkaartpastel/EPSG:3857/{z}/{x}/{y}.png', {
        attribution: 'Kaartgegevens &copy; <a href="https://kadaster.nl">Kadaster</a>'
    }).addTo( map );

    var string = '{{ current_user.player_in(game).encode_objectives() |safe }}'
    var objectives = JSON.parse(string)
    for (var i = 0; i < objectives.length; i++){
        addObjectiveMarker(map, objectives[i])
    }

    var self = JSON.parse('{{ json.dumps(current_user.last_location(game), cls=location_encoder)|safe }}')
    if (self){
        addPlayerMarker(map, self)
    }

</script>
{% endblock %}