{% from "macros.tex" import show_item %}


{% if repo["needs_discussion"]|length > 0 %}
{% for item in repo["needs_discussion"] %}
\begin{frame}[allowframebreaks,t]{Needs discussion}

  \begin{itemize}
    {%- call show_item(item, repo.spec, mode) -%}
    {%- endcall %}
  \end{itemize}

  \vspace{1em}
  {% if item.body is not none %}
    {{ item.body | sanitize }}
  {% endif %}

\end{frame}
{%- endfor %}

{% endif %}

{% if repo["merged_prs"]|length > 0 %}

\section{ {{repo_name}} \\ Merged PRs}
\begin{frame}[allowframebreaks]{ {{ repo_name }}: PRs merged {{ date_range() }}}

  \begin{itemize}
    {% for pr in repo["merged_prs"]|sort(attribute="closed_at") %}
    {%- call show_item(pr, repo.spec, mode="MERGED") -%}
    , merged on {{ pr.closed_at.strftime('%Y-%m-%d') }}
    {%- endcall %}
    {%- endfor %}
  \end{itemize}

\end{frame}

{% else %}
\begin{frame}[c]{}
  \begin{center}
    \Large
    \color{shivablue}
    \sffamily
    No merged PRs since \textbf{ {{ since.strftime('%Y-%m-%d') }} } in\\
    \textbf{ {{ repo_name }} }
  \end{center}
\end{frame}
{% endif %}

\section{ {{repo_name}} \\ Open PRs}
{% if repo["open_prs"]| length > 0 %}
\begin{frame}[allowframebreaks]{ {{ repo_name }}: Open PRs
}

  \begin{itemize}
    {% for wip in ["false", "true"] %}
    {% for pr in repo["open_prs"]|selectattr("is_wip", wip)|sort(reverse=True, attribute="updated_at") %}
    {%- call show_item(pr, repo.spec, mode="OPEN") -%}
    , updated on {{ pr.updated_at.strftime('%Y-%m-%d') }}
    {%- endcall %}
    {%- endfor %}
    {%- endfor %}
  \end{itemize}

\end{frame}
{% endif %}

{% if repo["spec"].do_recent_issues %}
{% if repo["recent_issues"] | length > 0 %}
  \section{ {{repo_name}} \\ Issues opened since {{ since.strftime('%Y-%m-%d') }} }
  \begin{frame}[allowframebreaks]{ {{ repo_name }}: Issues opened since {{ since.strftime('%Y-%m-%d') }} }
    \begin{itemize}
      {% for item in repo["recent_issues"]|sort(reverse=True, attribute="updated_at") %}
      {%- call show_item(item, repo.spec) -%}
          , updated on {{ item.updated_at.strftime('%Y-%m-%d') }}
      {%- endcall %}
      {%- endfor %}
      \end{itemize}
  \end{frame}
{% else %}
  \section{ {{repo_name}} \\ No issues opened since {{ since.strftime('%Y-%m-%d') }} }
{% endif %}
{% endif %}

{% if repo.spec.do_stale %}
{% set newly_stale = repo["stale"] | selectattr("updated_at", ">", since) | list %}
{% if newly_stale | length > 0 %}
\section{ {{repo_name}} \\ Stale Issues and PRs}
\begin{frame}[allowframebreaks]{ {{ repo_name }}: New stale Issues / PRs since {{ since.strftime('%Y-%m-%d') }} }
  \begin{itemize}
    {% for item in newly_stale %}
    {%- call show_item(item, repo.spec, mode="OPEN") -%}
        , updated on {{ item.updated_at.strftime('%Y-%m-%d') }}
    {%- endcall %}
    {%- endfor %}
  \end{itemize}
\end{frame}
{% else %}
\section{ {{repo_name}} \\ No new stale issues or PRs since {{ since.strftime('%Y-%m-%d') }} }
{% endif %}

{% if repo["stale"]|length > 0 %}
\section{ {{repo_name}} \\ All stale Issues and PRs}
\begin{frame}[allowframebreaks]{ {{ repo_name }}: All stale Issues / PRs}
  \begin{itemize}
    {% for item in repo["stale"]|sort(reverse=True, attribute="updated_at") %}
    {%- call show_item(item, repo.spec, mode="OPEN") -%}
        , updated on {{ item.updated_at.strftime('%Y-%m-%d') }}
    {%- endcall %}
    {%- endfor %}
  \end{itemize}
\end{frame}
{% endif %}
{% endif %}
