{% load i18n lucide %}

{% comment %}
    The two-level sidebar (design_handoff_rosterchief_platform/README.md, D1/D2): seven
    top-level sections -- Overview/Members/Teams/Calendar/News/Finance/Settings -- each
    except News expanding into sub-items while it (or a sub-item) is active. `nav`/
    `nav_section` come from management.context_processors.active_nav_section.

    Admin-only sub-items are hidden here for plain staff -- the views are gated
    regardless (ClubAdminRequiredMixin), this is just so the nav never shows a link
    they can't follow. Same reasoning as the old flat nav this replaces.
{% endcomment %}
<a class="nav-item {% if nav_section == 'overview' %}active{% endif %}" href="{% url 'management:home' %}">{% lucide "layout-dashboard" size=17 %} {% trans "Overview" %}</a>

<div>
    <a class="nav-item {% if nav_section == 'members' %}active{% endif %}" href="{% url 'management:member_list' %}">{% lucide "users" size=17 %} {% trans "Members" %}</a>
    {% if nav_section == 'members' %}
        <div class="flex flex-col">
            <a class="nav-subitem {% if nav == 'member_list' %}active{% endif %}" href="{% url 'management:member_list' %}">{% trans "All members" %}</a>
            {% if is_club_admin %}
                {# Sign-up is admin only (finance-adjacent -- fee status feeds it) even though parent claims/households/groups below open up to MEMBER_ADMIN too. #}
                <a class="nav-subitem {% if nav == 'signup_list' %}active{% endif %}" href="{% url 'management:signup_list' %}">{% trans "Sign-up" %}</a>
            {% endif %}
            {% if can_manage_members %}
                {# Membership dues/fee tracking (management:membership_list) lives under Finance, not here -- see that section below. #}
                <!--
                <a class="nav-subitem flex items-center gap-2 {% if nav == 'parent_claim_list' %}active{% endif %}" href="{% url 'management:parent_claim_list' %}">{% trans "Parent claims" %}
                    {% if pending_parent_claims_count %}<span class="badge badge-error badge-xs">{{ pending_parent_claims_count }}</span>{% endif %}
                </a>
                -->
            {% endif %}
            <a class="nav-subitem {% if nav == 'family_list' %}active{% endif %}" href="{% url 'management:family_list' %}">{% trans "Households" %}</a>
            {% if can_manage_members %}
                <a class="nav-subitem {% if nav == 'group_list' %}active{% endif %}" href="{% url 'management:group_list' %}">{% trans "Groups" %}</a>
                {% comment %}
                    Placeholder -- nothing else is built yet (see ARCHITECTURE.md §5.8 and
                    management.views.EvaluationsComingSoonView). Gated on forms_enabled,
                    same as Forms below: the design (ARCHITECTURE.md §5.8) reuses formbuilder
                    underneath, so a club without that flag shouldn't see it either.
                {% endcomment %}
                {% if forms_enabled %}
                    <a class="nav-subitem flex items-center gap-1.5 {% if nav == 'evaluations' %}active{% endif %}" href="{% url 'management:evaluations' %}">{% trans "Evaluations" %} <span class="badge badge-neutral badge-xs">{% trans "Soon" %}</span></a>
                {% endif %}
            {% endif %}
        </div>
    {% endif %}
</div>

<div>
    <a class="nav-item {% if nav_section == 'teams' %}active{% endif %}" href="{% url 'management:team_list' %}">{% lucide "shirt" size=17 %} {% trans "Teams" %}</a>
    {% if nav_section == 'teams' %}
        <div class="flex flex-col">
            <a class="nav-subitem {% if nav == 'team_list' %}active{% endif %}" href="{% url 'management:team_list' %}">{% trans "All teams" %}</a>
            <a class="nav-subitem {% if nav == 'referee_list' %}active{% endif %}" href="{% url 'management:referee_list' %}">{% trans "Referees" %}</a>
        </div>
    {% endif %}
</div>

<div>
    <a class="nav-item {% if nav_section == 'calendar' %}active{% endif %}" href="{% url 'management:event_list' %}">{% lucide "calendar" size=17 %} {% trans "Calendar" %}</a>
    {% if nav_section == 'calendar' %}
        <div class="flex flex-col">
            <a class="nav-subitem {% if nav == 'event_list' %}active{% endif %}" href="{% url 'management:event_list' %}">{% trans "Events" %}</a>
            {% if has_management_position %}
                <a class="nav-subitem {% if nav == 'location_list' %}active{% endif %}" href="{% url 'management:location_list' %}">{% trans "Locations" %}</a>
                <a class="nav-subitem {% if nav == 'opponent_list' %}active{% endif %}" href="{% url 'management:opponent_list' %}">{% trans "Opponents" %}</a>
            {% endif %}
            {% if is_club_admin or can_manage_members %}
                <a class="nav-subitem flex items-center gap-2 {% if nav == 'referee_management' %}active{% endif %}" href="{% url 'management:referee_management' %}">{% trans "Referee management" %}
                    {% if games_missing_referees_count %}<span class="badge badge-error badge-xs">{{ games_missing_referees_count }}</span>{% endif %}
                </a>
            {% endif %}
        </div>
    {% endif %}
</div>

<a class="nav-item {% if nav_section == 'news' %}active{% endif %}" href="{% url 'management:news_list' %}">{% lucide "newspaper" size=17 %} {% trans "News" %}</a>

{% if is_club_admin %}
    <div>
        <a class="nav-item {% if nav_section == 'finance' %}active{% endif %}" href="{% url 'management:membership_list' %}">{% lucide "wallet" size=17 %} {% trans "Finance" %}</a>
        {% if nav_section == 'finance' %}
            <div class="flex flex-col">
                <a class="nav-subitem {% if nav == 'membership_list' %}active{% endif %}" href="{% url 'management:membership_list' %}">{% trans "Dues & billing" %}</a>
                <a class="nav-subitem {% if nav == 'sponsor_list' %}active{% endif %}" href="{% url 'management:sponsor_list' %}">{% trans "Sponsors" %}</a>
                {% if shop_enabled %}
                    <a class="nav-subitem {% if nav == 'product_list' %}active{% endif %}" href="{% url 'management:product_list' %}">{% trans "Products" %}</a>
                    <a class="nav-subitem {% if nav == 'order_list' %}active{% endif %}" href="{% url 'management:order_list' %}">{% trans "Orders" %}</a>
                    <a class="nav-subitem {% if nav == 'discount_list' %}active{% endif %}" href="{% url 'management:discount_list' %}">{% trans "Discounts" %}</a>
                    <a class="nav-subitem {% if nav == 'invoice_list' %}active{% endif %}" href="{% url 'management:invoice_list' %}">{% trans "Invoices" %}</a>
                {% endif %}
            </div>
        {% endif %}
    </div>
{% endif %}

{% if is_club_admin or can_manage_members %}
    <div>
        {# MEMBER_ADMIN has no Club identity access, so their landing click on "Settings" itself goes to the first sub-item they can actually reach. #}
        <a class="nav-item {% if nav_section == 'settings' %}active{% endif %}" href="{% if is_club_admin %}{% url 'management:club_settings' %}{% else %}{% url 'management:onboarding_requirement_list' %}{% endif %}">{% lucide "settings" size=17 %} {% trans "Settings" %}</a>
        {% if nav_section == 'settings' %}
            <div class="flex flex-col">
                {% if is_club_admin %}
                    <a class="nav-subitem {% if nav == 'club_settings' %}active{% endif %}" href="{% url 'management:club_settings' %}">{% trans "Club identity" %}</a>
                {% endif %}
                <a class="nav-subitem {% if nav == 'onboarding_requirement_list' %}active{% endif %}" href="{% url 'management:onboarding_requirement_list' %}">{% trans "Onboarding requirements" %}</a>
                {% if is_club_admin %}
                    <a class="nav-subitem {% if nav == 'role_list' %}active{% endif %}" href="{% url 'management:role_list' %}">{% trans "Roles" %}</a>
                    <a class="nav-subitem {% if nav == 'position_list' %}active{% endif %}" href="{% url 'management:position_list' %}">{% trans "Positions" %}</a>
                {% endif %}
                <a class="nav-subitem {% if nav == 'referee_level_list' %}active{% endif %}" href="{% url 'management:referee_level_list' %}">{% trans "Referee levels" %}</a>
                {% if is_club_admin %}
                    {% if forms_enabled %}
                        <a class="nav-subitem {% if nav == 'form_list' %}active{% endif %}" href="{% url 'management:form_list' %}">{% trans "Forms" %}</a>
                    {% endif %}
                {% endif %}
            </div>
        {% endif %}
    </div>
{% endif %}
