{#
================================================================================
Element Card Macro (Kida-Native)
================================================================================

Renders a single autodoc element as a card (command, class, function, endpoint, etc.).

USAGE:
{% from 'autodoc/partials/_macros/element-card.html' import element_card %}
{{ element_card(child) }}
{{ element_card(child, card_type='command') }}

ARGS:
child: DocElement to render (required)
card_type: Override element type for styling (optional)

NOTE:
DocElement.href is pre-computed during page building with baseurl included.
Templates should use {{ child.href }} directly for links.

KIDA FEATURES USED:
- Optional chaining (?.) for safe attribute access
- Null coalescing (??) for defaults

================================================================================
#}

{% def element_card(child, card_type=none) %}
{# Extract values with null-safety using {% let %} #}
{% let child_type = card_type ?? child?.element_type ?? 'unknown' %}
{% let child_url = child?.href ?? '#' %}
{% let child_name = child?.name ?? 'Unknown' %}
{% let child_desc = child?.description ?? '' %}
{% let child_meta = child?.metadata ?? {} %}
{% let http_method = child_meta?.method ?? '' %}

<a href="{{ child_url }}" class="autodoc-card" data-card="{{ child_type }}">
    {% match child_type, http_method %}
    {% case 'endpoint', method if method %}
    <span class="autodoc-method" data-method="{{ method | lower }}">{{ method | upper }}</span>
    {% end %}

    <code class="autodoc-card-name">{{ child_name }}</code>
    {% if child_desc %}
    <span class="autodoc-card-desc">{{ child_desc | excerpt_for_card(child_name) | excerpt(100) }}</span>
    {% end %}
</a>
{% end %}
