{% from 'base/panel.html' import base %}
{% from 'base/panel.html' import count %}
{% macro tag_list() -%}
  {{ base() }}
{%- endmacro %}

{% macro tag(tag) -%}
  {{ base() }}
  <div class="panel panel-default hidden-xs" style="font-size:13px;">
    {{ parents(tag) }}
    {{ relation(tag) }}
    {{ children(tag) }}
  </div>
  {{ count() }}
{%- endmacro %}

{% macro parents(tag) -%}
  <div class="panel-body" style="padding:10;margin:0;">
    <strong>父节点</strong>
  </div>
  {% if tag.parent_id -%}
    {{ link(tag.parent.name) }}
  {% else %}
    {{ link('honmaple') }}
  {%- endif %}
  <div style="border-bottom:1px solid #eee"></div>
{%- endmacro %}

{% macro relation(tag) -%}
  {% set relates = tag.related_tags %}
  {% if relates -%}
    <div class="panel-body" style="padding:10;margin:0;">
      <strong>相关节点</strong>
    </div>
    {% for child in relates -%}
      {{ link(child.name) }}
    {%- endfor %}
  {%- endif %}
{%- endmacro %}

{% macro children(tag) -%}
  {% set children = tag.children.all() %}
  {% if children -%}
    <div class="panel-body" style="padding:10;margin:0;">
      <strong>子节点</strong>
    </div>
    {% for child in children -%}
      {{ link(child.name) }}
    {%- endfor %}
  {%- endif %}
{%- endmacro %}


{% macro link(name) -%}
  <div class="panel-body" style="padding:10px;margin-top:0;padding-top:0">
    <img alt="" src="{{ url_for('avatar',text=name)}}" style="width:24px;"/>
    <a class="text-capitalize" href="{{ url_for('tag.tag',name=name)}}" style="color:#555;">{{ name }}</a>
  </div>
{%- endmacro %}
