{% extends "layout.html" %}
{% from "_forms.html" import quickform, parsefield %}

{% block content %}
<h1 class="ui header">Bookie Overview</h1><br/>
{% if listChain %}
<div class="ui grid">
{{ popListChainMenuStyle( listChain ) }}
</div>
{% endif %}  
{% endblock %}

{%- macro popListChainMenuStyle( listChain, parentChain=None ) -%}
<div class="three wide column"> 
<div class="ui fluid secondary vertical pointing wide menu">
 {% if listChain['title'] %} <h4 class="ui header">{{ listChain['title'] }}</h4> {% endif %}
 {% for entry in listChain['list'] %}
 <div class="{% if selected[entry['typeName']] and selected[entry['typeName']] == entry['id'] %}active {% endif %}item"> 
  <a style="color: black;"
     href="{{ url_for('overview', typeName=entry['typeName'], identifier=entry['id'] ) }}">
 	  	{{ entry['toString'] }}
  </a>
   <div class="ui right inline dropdown">
    <i class="dropdown icon"></i>
    <div class="menu">
      <a class="item" href="{{ url_for(entry['typeName'] + '_details', selectId=entry['id'], next=request.path ) }}">
      	<i title="Details" class="large unhide icon"></i>
      	Details
      </a>
      <a class="item" href="{{ url_for(entry['typeName'] + '_update', selectId=entry['id'], next=request.path ) }}">
      	<i title="Update" class="large edit icon"></i>
      	Update
      </a>
      {% if entry['extraLink'] %}
      	<div class="divider"></div>
      {% endif %}
      {% for sublink in entry['extraLink'] %}
      	{% if sublink['title'] == "divider" %}
      		<div class="divider"></div>
      	{% else %}
	  	  	<a class="item" href="{{ url_for(sublink['link'], selectId=entry['id'], next=request.path) }}">
	      		<i title="{{ sublink['title'] }}" class="large {{ sublink['icon'] }} icon"></i>
	      		{{ sublink['title'] }}
	      	</a>
      	{% endif %}
      {% endfor %}
    </div>
  </div>
  </div>
  {% endfor %}
  {% if not listChain['list'] %}
  <a class="item">No {{ listChain['title'] }} found</a>
  {% endif %}
  {% if parentChain %}
  	<a class="item" href="{{ url_for(listChain['typeName'] + '_new', parentId=selected[parentChain['typeName']], next=request.path) }}">
  {% else %}
  	<a class="item" href="{{ url_for(listChain['typeName'] + '_new', next=request.path) }}">
  {% endif %}
  <span><i class="small plus icon"></i> Create {{ listChain['title'] }}</span></a>
  {% if listChain['extraLink'] %}
  {% for extra in listChain['extraLink'] %}
  	{% if extra['argument'] %}
  		<a class="item" href="{{ url_for(extra['link'], **{extra['argument'][0]: extra['argument'][1]} ) }}"><!-- this a hack, look up proper JinJa2 -->
  	{% else %}
  		<a class="item" href="{{ url_for(extra['link'] ) }}">
	{% endif %}
  	<span><i class="small {{ extra['icon'] }} icon"></i> {{ extra['title'] }}</span></a>
  {% endfor %}
  {% endif %}
  
</div>
</div>
{% if listChain['nextChainElement'] %}
{{ popListChainMenuStyle( listChain['nextChainElement'], listChain ) }}
{% else %}
<!--  <div class="ui secondary vertical pointing menu">
<h4 class="ui header"></h4><a class="item">No {{ listChain['title'] }} selected</a></div>
</div>  -->
{% endif %}
{%- endmacro -%}

