{% extends "cranefly/layout.html" %}
{% import "cranefly/macros.html" as macros with context %}

{% block title %}{{ macros.page_title(title=_("Forum Map")) }}{% endblock %}

{% block container %}
<div class="page-header header-primary">
  <div class="container">
    {{ messages_list(messages) }}
    <h1>{% trans %}Forum Map{% endtrans %}</h1>
  </div>
</div>

<div class="container container-primary">
  {% if forums %}
  <div class="row">
    <div class="span6">
      {% for category in forums %}{% if loop.index0 is odd and category.subforums %}
      {{ draw_category(category) }}
      {% endif %}{% endfor %}
    </div>
    <div class="span6">
      {% for category in forums %}{% if loop.index0 is even and category.subforums %}
      {{ draw_category(category) }}
      {% endif %}{% endfor %}
    </div>
  </div>
  {% else %}
  <p class="lead">{% trans %}Looks like no forums exist that you have permission to see.{% endtrans %}</p>
  {% endif %}
</div>
{% endblock %}


{% macro draw_category(category) %}
<div class="forum-map-category{% if category.style %} forum-map-category-{{ category.style }}{% endif %}">
  <div class="header">
    <h2>{{ category.name }}</h2>
  </div>
  {% for forum in category.subforums%}
  {{ draw_forum(forum) }}
  {% endfor %}
</div>
{% endmacro %}

{% macro draw_forum(forum, depth=0, branch='', last=false) %}
  <div class="{% if depth -%}
    forum-map-subforum
    {%- else -%}
    forum-map-forum
    {%- endif %}">
    <h3>{% if depth %}{% if last -%}
    {{ draw_tree(branch ~ 'l') }}
    {%- else -%}
    {{ draw_tree(branch ~ 't') }}
    {%- endif %}{% endif %} <a href="{{ forum.type|url(slug=forum.slug, forum=forum.id) }}">{{ forum.name }}</a></h3>
  </div>
  {% for subforum in forum.subforums %}
    {% if depth %}
      {% if last %}
      {{ draw_forum(subforum, (depth + 1), (branch ~ 's'), loop.last) }}
      {% else %}
      {{ draw_forum(subforum, (depth + 1), (branch ~ 'i'), loop.last) }}
      {% endif %}
    {% else %}
    {{ draw_forum(subforum, (depth + 1), '', loop.last) }}
    {% endif %}
  {% endfor %}
{% endmacro %}

{% macro draw_tree(branch) %}
{% for item in branch %}
<span class="tree-{{ item }}"><span></span></span>
{% endfor %}
{% endmacro %}