{#-
Endpoints Overview Component

Renders a comprehensive overview of all API endpoints grouped by tags.
Provides navigation and summary information for each endpoint.
-#}

{% from 'macros/safe_macros.md.jinja2' import safe_section, safe_render, safe_for %}
{% from 'macros/navigation.md.jinja2' import doc_link %}

{% set endpoints = element.children | selectattr('element_type', 'equalto', 'endpoint') | list %}

{% if endpoints %}
{% call safe_section("endpoints_overview") %}
## API Endpoints

{#- Group endpoints by tags -#}
{% set endpoints_by_tag = endpoints | groupby('metadata.tags.0') %}

{% call(item) safe_for(endpoints_by_tag, "*No endpoints found.*") %}
{% set tag_name = item[0] | default('Untagged') %}
{% set tag_endpoints = item[1] %}

### {{ tag_name | title }}

{% call(endpoint_item) safe_for(tag_endpoints, "*No endpoints in this tag.*") %}
{% call safe_render("endpoint", endpoint_item) %}
#### `{{ endpoint_item.metadata.method | upper | default('GET') }}` {{ endpoint_item.metadata.path | default('/') }}

{% if endpoint_item.description %}
{{ endpoint_item.description | truncate_text(150) }}
{% else %}
*No description provided.*
{% endif %}

{% if endpoint_item.metadata.summary %}
**Summary:** {{ endpoint_item.metadata.summary }}
{% endif %}

{% if endpoint_item.metadata.deprecated %}
:::{warning}
This endpoint is deprecated.
:::
{% endif %}

{% endcall %}
{% endcall %}

{% endcall %}
{% endcall %}
{% endif %}
