{#
SPDX-License-Identifier: Apache-2.0
SPDX-FileCopyrightText: 2025 The Linux Foundation
#}

{#- Base Markdown template for repository analysis reports -#}
{#- Phase 8: Renderer Modernization - Modular Component-Based Design -#}
{#-
    This template orchestrates the complete report by including modular sections.
    Each section is self-contained and can be enabled/disabled via configuration.

    Context required:
        - project: Project metadata (name, generated_at, schema_version)
        - summary: Summary statistics
        - repositories: Repository data
        - contributors: Contributor data
        - organizations: Organization data
        - features: Feature detection data
        - workflows: CI/CD job data
        - orphaned_jobs: Orphaned job data
        - time_windows: Time window data
        - config: Configuration options
-#}

{#- Report Header -#}
# 📊 {% if project.project_type == 'github' %}GitHub{% else %}Gerrit{% endif %} Project Analysis Report: {{ project.name | default('Repository Analysis') }}

**Generated:** {{ project.generated_at_formatted | default('Unknown') }}
**Schema Version:** {{ project.schema_version | default('1.0') }}

---

{#- Table of Contents -#}
{% include 'markdown/components/table_of_contents.md.j2' %}

{#- Summary Section -#}
{% include 'markdown/sections/summary.md.j2' %}

{#- Organizations Section -#}
{% include 'markdown/sections/organizations.md.j2' %}

{#- Contributors Section -#}
{% include 'markdown/sections/contributors.md.j2' %}

{#- Repositories Section -#}
{% include 'markdown/sections/repositories.md.j2' %}

{#- Features Section -#}
{% include 'markdown/sections/features.md.j2' %}

{#- Workflows Section -#}
{% include 'markdown/sections/workflows.md.j2' %}

{#- Orphaned Jobs Section -#}
{% include 'markdown/sections/orphaned_jobs.md.j2' %}

{#- Unattributed Jobs Section -#}
{% include 'markdown/sections/unattributed_jobs.md.j2' %}

{#- INFO.yaml Sections -#}
{% if info_yaml.has_projects %}
## 📋 Committer INFO.yaml Report

{% if info_yaml.has_error %}
**Error collecting INFO.yaml data:** {{ info_yaml.error }}

{% endif %}
{% if info_yaml.projects %}
{% set projects = info_yaml.projects %}
{% set group_by_server = (info_yaml.servers | length) > 1 %}
{% if group_by_server %}
{% set projects_by_server = {} %}
{% for project in projects %}
{% set server = project.gerrit_server | default('Unknown') %}
{% if server not in projects_by_server %}
{% set _ = projects_by_server.update({server: []}) %}
{% endif %}
{% set _ = projects_by_server[server].append(project) %}
{% endfor %}
{% endif %}
{% include 'markdown/sections/info_yaml_committers.md.j2' %}
{% endif %}

---
{% endif %}

{% if info_yaml.has_lifecycle_summary %}
## 📊 INFO.yaml Lifecycle State Summary

{% set lifecycle_summaries = info_yaml.lifecycle_summary %}
{% set total_projects = info_yaml.total_projects %}
{% include 'markdown/sections/info_yaml_lifecycle.md.j2' %}

---
{% endif %}

{#- Time Windows Section -#}
{#- TODO: Create time_windows.md.j2 section template -#}
{% if time_windows is defined and time_windows is iterable and time_windows|length > 0 %}
## Time Windows

{% for window in time_windows %}
### {{ window.name | default('Unknown') }} ({{ window.days | default(0) }} days)

**Date Range:** {{ window.start_date | default('N/A') }} to {{ window.end_date | default('N/A') }}

| Metric | Value |
|--------|-------|
| Commits | {{ window.commits | default(0) | format_number }} |
| Contributors | {{ window.contributors | default(0) }} |
| Lines Added | {{ window.lines_added | default(0) | format_number }} |
| Lines Removed | {{ window.lines_removed | default(0) | format_number }} |
| Net Lines | {{ window.net_lines | default(0) | format_number }} |

{% endfor %}

---
{% endif %}

---

{#- Report Footer -#}
*Generated with ❤️ by Release Engineering*
