{%- macro automodule(modname, options) -%}
.. automodule:: {{ modname }}
{%- for option in options %}
   :{{ option }}:
{%- endfor %}
{%- endmacro %}

{%- macro toctree(docnames) -%}
.. toctree::
   :maxdepth: {{ maxdepth }}
{% for docname in docnames %}
   {{ docname }}
{%- endfor %}
{%- endmacro %}

{%- if is_namespace %}
{{- [pkgname, "namespace"] | join(" ") | e | heading }}
{% else %}
{{- [pkgname, "package"] | join(" ") | e | heading }}
{% endif %}

{%- if is_namespace %}
.. py:module:: {{ pkgname }}
{% endif %}

{%- if subpackages %}
Subpackages
-----------

{{ toctree(subpackages) }}
{% endif %}

{%- if submodules %}
Overview
----------

.. autosummary::
   :toctree: _autosummary

{% for submodule in submodules if not submodule.startswith('source/apis/components/_autosummary') %}
   {{ submodule }}
{% endfor %}
{%- endif %}

.. toctree::
   :maxdepth: 1
   :hidden:

{% for submodule in submodules if not submodule.startswith('source/apis/components/_autosummary') %}
   {{ submodule }}
{% endfor %}
