{#- foundation.j2 - Core template that ALL others inherit from -#}
{#- This template provides the base structure and extension detection -#}

{#- Get extensions from the global config object that AutoAPI provides -#}
{%- set app_config = config if config is defined else {} -%}
{%- set extensions = app_config.extensions if app_config.extensions is defined else [] -%}

{#- Extension capability detection -#}
{%- set has_mermaid = 'sphinxcontrib.mermaid' in extensions -%}
{%- set has_design = 'sphinx_design' in extensions -%}
{%- set has_toggles = 'sphinx_togglebutton' in extensions -%}
{%- set has_tabs = 'sphinx_tabs.tabs' in extensions or 'sphinx_inline_tabs' in extensions -%}
{%- set has_copybutton = 'sphinx_copybutton' in extensions -%}
{%- set has_panels = 'sphinx_panels' in extensions -%}
{%- set has_tippy = 'sphinx_tippy' in extensions -%}
{%- set has_emoji = 'sphinxemoji.sphinxemoji' in extensions -%}
{%- set has_exec = 'sphinx_exec_code' in extensions -%}
{%- set has_graphviz = 'sphinx.ext.graphviz' in extensions -%}
{%- set has_inheritance = 'sphinx.ext.inheritance_diagram' in extensions -%}
{%- set has_autolinks = 'sphinx_codeautolink' in extensions -%}
{%- set has_opengraph = 'sphinxext.opengraph' in extensions -%}
{%- set has_bibtex = 'sphinxcontrib.bibtex' in extensions -%}
{%- set has_search = True -%}

{%- block document -%}
{%- block header -%}
{%- if obj.name -%}
{{ obj.name }}
{{ "=" * obj.name|length }}
{%- endif -%}
{%- endblock header %}

{%- block metadata -%}
{%- if has_opengraph and obj %}
.. meta::
   :description: {{ obj.short_description|default(obj.summary, true)|default('', true)|truncate(160) }}
   :keywords: {{ obj.type|default('Python', true) }}, {{ obj.module|default('', true) }}, API, documentation
   {%- if obj.file %}
   :og:type: article
   :og:title: {{ obj.name }} - API Documentation
   :og:description: {{ obj.short_description|default(obj.summary, true)|default('', true)|truncate(160) }}
   {%- endif %}
{%- endif %}
{%- endblock metadata %}

{%- block breadcrumb -%}
{%- if obj.module and obj.module != obj.name %}
.. currentmodule:: {{ obj.module }}

{%- endif %}
{%- endblock breadcrumb %}

{%- block signature -%}
{#- Override in child templates for specific signatures -#}
{%- endblock signature %}

{%- block summary -%}
{%- if obj.summary and obj.summary != obj.short_description %}

{{ obj.summary|indent(0) }}
{%- endif %}
{%- endblock summary %}

{%- block deprecation -%}
{%- if obj.deprecated %}

.. deprecated:: {{ obj.deprecated_version|default('', true) }}
   {{ obj.deprecated_description|default('This has been deprecated.', true) }}
{%- endif %}
{%- endblock deprecation %}

{%- block content -%}
{#- Main content block - override in child templates -#}
{%- endblock content %}

{%- block examples -%}
{%- if obj.examples %}

Examples
--------

{%- for example in obj.examples %}
{%- if has_copybutton %}
.. code-block:: python
   :class: copybutton

{%- else %}
.. code-block:: python

{%- endif %}
   {{ example|indent(3) }}
{%- endfor %}
{%- endif %}
{%- endblock examples %}

{%- block see_also -%}
{%- if obj.see_also %}

See Also
--------

{%- for item in obj.see_also %}
* {{ item }}
{%- endfor %}
{%- endif %}
{%- endblock see_also %}

{%- block notes -%}
{%- if obj.notes %}

Notes
-----

{{ obj.notes }}
{%- endif %}
{%- endblock notes %}

{%- block references -%}
{%- if obj.references and has_bibtex %}

References
----------

{%- for ref in obj.references %}
:cite:`{{ ref }}`
{%- endfor %}
{%- endif %}
{%- endblock references %}

{%- block source -%}
{%- if obj.file and 'sphinx.ext.viewcode' in extensions %}

.. container:: source-link

   :Source: :obj:`[source] <{{ obj.file }}#L{{ obj.line|default(1) }}>`
{%- endif %}
{%- endblock source %}

{%- block footer -%}
{#- Additional footer content -#}
{%- endblock footer %}
{%- endblock document -%}