{#
Map Accordion Content
Shows discovered locations grouped by region
#}
{% if discovered_locations %}
{# Group locations by region #}
{% set regions = {} %}
{% for loc in discovered_locations %}
    {% set region = loc.region %}
    {% if region not in regions %}
        {% set _ = regions.update({region: []}) %}
    {% endif %}
    {% set _ = regions[region].append(loc) %}
{% endfor %}

{% for region_name, locations in regions.items() %}
<div class="map-region">
    <div class="map-region-name">{{ region_name }}</div>
    <div class="map-locations">
        {% for loc in locations %}
        <div class="map-location {% if loc.is_current %}current{% endif %}"
             {% if not loc.is_current %}
             hx-post="{{ url_for('game.do_travel', session_id=session_id) }}"
             hx-vals='{"location_id": "{{ loc.location_id }}"}'
             hx-target="#narrative-content"
             hx-swap="innerHTML"
             hx-confirm="Travel to {{ loc.name }}?"
             {% endif %}>
            <span class="map-location-icon">
                {% if loc.location_type == 'town' %}🏘️
                {% elif loc.location_type == 'tavern' %}🍺
                {% elif loc.location_type == 'wilderness' %}🌲
                {% elif loc.location_type == 'dungeon' %}⚔️
                {% elif loc.location_type == 'ruins' %}🏚️
                {% else %}📍
                {% endif %}
            </span>
            <span class="map-location-name">{{ loc.name }}</span>
            <span class="map-location-type">
                {% if loc.is_current %}(here){% else %}{{ loc.location_type }}{% endif %}
            </span>
        </div>
        {% endfor %}
    </div>
</div>
{% endfor %}
{% else %}
<div class="quest-empty">
    No locations discovered yet.
</div>
{% endif %}
