{#-
Base Template for All Autodoc Documentation

This template provides the common structure and layout that all documentation
types (Python, CLI, OpenAPI) inherit from. It ensures consistency across
all generated documentation.
-#}

{#- Import shared macros -#}
{% from 'macros/safe_macros.md.jinja2' import safe_section, debug_info, autodoc_title, autodoc_description %}
{% from 'macros/navigation.md.jinja2' import breadcrumbs, source_link with context %}

---
title: "{% block title %}{{ autodoc_title(element) }}{% endblock %}"
type: "{% block doc_type %}doc{% endblock %}"
{% block source_metadata %}
{% if element and element.source_file %}
source_file: "{{ element.source_file | project_relative }}"
{% endif %}
{% if element and element.line_number %}
line_number: {{ element.line_number }}
{% endif %}
{% endblock %}
description: "{% block description %}{{ autodoc_description(element) }}{% endblock %}"
{% block extra_frontmatter %}{% endblock %}
---

{% block header %}
# {% block page_title %}{% if element and element.name %}{{ element.name }}{% elif element and element.element_type == 'module' and element.qualified_name and '.' not in element.qualified_name %}API{% else %}Documentation{% endif %}{% endblock %}

{% block element_info %}
{% if element %}
{% if element.element_type %}
**Type:** {{ element.element_type | title }}
{% endif %}
{% if element.source_file %}
**Source:** {{ source_link(element.source_file, element.line_number) }}
{% endif %}
{% endif %}
{% endblock %}
{% endblock %}

{% block badges %}
{#- Override in child templates for type-specific badges -#}
{% endblock %}

{% block navigation %}
{#- Breadcrumb navigation and action bar -#}
{% if element %}
{# Note: In a real template context, we would include the action-bar partial #}
{# But for autodoc (which renders markdown first), we rely on the theme to #}
{# render the action bar if we provide the right metadata/structure. #}
{# However, if this template is used directly by the engine, we might want #}
{# to simulate the action bar structure or just use breadcrumbs. #}

{# For now, let's keep breadcrumbs but ensure they look correct #}
{{ breadcrumbs(element) }}
{% endif %}
{% endblock %}

{% block content %}
{#- Child templates implement this block -#}
{% if element and element.description %}
{{ element.description }}
{% else %}
*No description provided.*
{% endif %}
{% endblock %}

{% block see_also %}
{#- Cross-references and related links -#}
{% endblock %}

{% block footer %}
{% block footer_content %}
---
*Generated by Bengal autodoc{% if element and element.source_file %} from `{{ element.source_file | project_relative }}`{% endif %}*
{% endblock %}
{% endblock %}

{% block debug %}
{#- Debug information (only shows in debug mode) -#}
{% if config.get('autodoc', {}).get('template_safety', {}).get('debug_mode', false) %}
{{ debug_info('Template', 'base.md.jinja2') }}
{% if element %}
{{ debug_info('Element Type', element.element_type) }}
{{ debug_info('Element Name', element.name) }}
{% endif %}
{% endif %}
{% endblock %}
