{% load lucide %}

{% comment %}
    The club's home ground -- an events.Location row flagged is_home, so setting or
    editing it here creates/updates the very same Location the club's own Teams >
    Locations page shows, no separate sync step involved. Included with `club`,
    `home_location`, `home_location_form` already in context.
{% endcomment %}
<div class="card flex flex-col">
    <div class="flex items-center justify-between border-b border-line px-4 py-3">
        <span class="font-display text-sm font-extrabold tracking-[.1em] text-ink uppercase">Home location</span>
        <button class="btn btn-outline btn-sm gap-2" type="button" onclick="document.getElementById('club_home_location_modal').showModal()">
            {% if home_location %}
                {% lucide "pencil" size=14 %} Edit
            {% else %}
                {% lucide "plus" size=14 %} Set home location
            {% endif %}
        </button>
    </div>
    <div class="px-4 py-3">
        {% if home_location %}
            <dl>
                <div class="flex items-center justify-between py-2">
                    <dt class="text-sm text-muted">Name</dt>
                    <dd class="font-semibold text-ink">{{ home_location.name }}</dd>
                </div>
                <div class="flex items-center justify-between py-2">
                    <dt class="text-sm text-muted">Address</dt>
                    <dd class="text-right text-sm text-slate">{{ home_location.address }}, {{ home_location.zip_code }} {{ home_location.city }}, {{ home_location.country }}</dd>
                </div>
            </dl>
        {% else %}
            <p class="text-sm text-muted">Not set yet. Once set, events at this location can be recognised as home games.</p>
        {% endif %}
    </div>
</div>

{% url 'controlpanel:club_home_location_set' club.pk as home_location_url %}
{% include "controlpanel/_modal_form.html" with modal_id="club_home_location_modal" title="Home location" form=home_location_form action_url=home_location_url submit_label="Save" submit_icon="save" blurb="This creates or updates a Location for the club -- the same one that shows up on its own Teams > Locations page." %}
