{#
Bengal OpenAPI Endpoint Page (Hero Template)
=============================================

Full endpoint documentation with three-column explorer layout.
The primary template for individual REST API endpoints.

Context:
- element: DocElement with OpenAPIEndpointMetadata
- page: Page object
- section: Section for navigation
- site: Site instance
- config: Config instance

Kida Features:
- {% match %} for HTTP method and status code styling
- {% with %} for nil-resilient optional sections
- {% cache %} for expensive response rendering
- {% spaceless %} for compact badge output
- Optional chaining (?.) and null coalescing (??)
#}
{% extends 'autodoc/openapi/layouts/explorer.html' %}

{% let meta = element?.typed_metadata ?? element?.metadata ?? {} %}
{% let http_method = meta?.method ?? 'GET' %}
{% let endpoint_path = meta?.path ?? '/' %}
{% let operation_id = meta?.operation_id %}
{% let summary = meta?.summary ?? element?.description ?? '' %}
{% let is_deprecated = meta?.deprecated ?? false %}
{% let parameters = meta?.parameters ?? () %}
{% let request_body = meta?.request_body %}
{% let responses = meta?.responses ?? () %}
{% let security = meta?.security ?? () %}
{% let tags = meta?.tags ?? () %}

{# Group parameters by location #}
{% let path_params = parameters |> where('location', 'path') %}
{% let query_params = parameters |> where('location', 'query') %}
{% let header_params = parameters |> where('location', 'header') %}
{% let cookie_params = parameters |> where('location', 'cookie') %}

{% block header %}
{# Playground Bar: Method + Path + Copy #}
{% let method = http_method %}
{% let path = endpoint_path %}
{% let deprecated = is_deprecated %}
{% include 'autodoc/openapi/partials/playground-bar.html' %}

{# Endpoint Header #}
{% include 'autodoc/openapi/partials/endpoint-header.html' %}
{% end %}

{% block content_main %}
<div class="api-endpoint" data-autodoc="openapi" data-element="endpoint">

    {# Parameters Section #}
    {% if parameters | length > 0 %}
    <section class="api-endpoint__section autodoc-section" data-section="parameters">
        <h2 class="api-endpoint__section-title">Parameters</h2>

        {# Path Parameters #}
        {% if path_params | length > 0 %}
        <div class="api-endpoint__param-group">
            <h3 class="api-endpoint__param-group-title">
                {{ icon('link', size=14) }}
                Path Parameters
            </h3>
            <div class="api-endpoint__param-list">
                {% for p in path_params %}
                {% let param = p %}
                {% include 'autodoc/openapi/partials/param-row.html' %}
                {% end %}
            </div>
        </div>
        {% end %}

        {# Query Parameters #}
        {% if query_params | length > 0 %}
        <div class="api-endpoint__param-group">
            <h3 class="api-endpoint__param-group-title">
                {{ icon('filter', size=14) }}
                Query Parameters
            </h3>
            <div class="api-endpoint__param-list">
                {% for p in query_params %}
                {% let param = p %}
                {% include 'autodoc/openapi/partials/param-row.html' %}
                {% end %}
            </div>
        </div>
        {% end %}

        {# Header Parameters #}
        {% if header_params | length > 0 %}
        <div class="api-endpoint__param-group">
            <h3 class="api-endpoint__param-group-title">
                {{ icon('file-text', size=14) }}
                Header Parameters
            </h3>
            <div class="api-endpoint__param-list">
                {% for p in header_params %}
                {% let param = p %}
                {% include 'autodoc/openapi/partials/param-row.html' %}
                {% end %}
            </div>
        </div>
        {% end %}

        {# Cookie Parameters #}
        {% if cookie_params | length > 0 %}
        <div class="api-endpoint__param-group">
            <h3 class="api-endpoint__param-group-title">
                {{ icon('disc', size=14) }}
                Cookie Parameters
            </h3>
            <div class="api-endpoint__param-list">
                {% for p in cookie_params %}
                {% let param = p %}
                {% include 'autodoc/openapi/partials/param-row.html' %}
                {% end %}
            </div>
        </div>
        {% end %}
    </section>
    {% end %}

    {# Request Body #}
    {% with request_body as req_body %}
    {% include 'autodoc/openapi/partials/request-body.html' %}
    {% end %}

    {# Responses #}
    {% if responses | length > 0 %}
    {% cache 'openapi-responses-' ~ endpoint_path ~ '-' ~ http_method %}
    {% include 'autodoc/openapi/partials/responses.html' %}
    {% end %}
    {% end %}

    {# Security Requirements #}
    {% if security | length > 0 %}
    <section class="api-endpoint__section autodoc-section" data-section="security">
        <h2 class="api-endpoint__section-title">{{ icon('lock', size=18) }} Authorization</h2>
        <div class="api-endpoint__security">
            {% for scheme in security %}
            <span class="badge badge--outline">
                {{ icon('key', size=12) }}
                {{ scheme }}
            </span>
            {% end %}
        </div>
    </section>
    {% end %}
</div>
{% end %}

{% block code_examples %}
{# Code Samples Panel #}
{% let method = http_method %}
{% let path = endpoint_path %}
{% let response_example = get_response_example(responses, '200') %}
{% include 'autodoc/openapi/partials/code-samples.html' %}
{% end %}
