{% extends "layout.html" %}
{% block title %}- Admin List{% endblock %}
{% block add_button %}
    <a class="navbar-item has-tooltip-bottom has-tooltip-hidden-desktop" data-tooltip="Add entry" href="{{ url_for('admin_edit') }}">
        <i class="fa fa-plus"></i><i>&nbsp;</i>
        <span class="is-hidden-mobile">Add entry</span>
    </a>
    <a class="navbar-item has-tooltip-bottom has-tooltip-hidden-desktop" data-tooltip="Manage folders" href="{{ url_for('folder_list') }}">
        <i class="fa fa-folder-open"></i><i>&nbsp;</i>
        <span class="is-hidden-mobile">Manage folders</span>
    </a>
{% endblock %}
{% block body %}
    <div class="level-right quick-scroll">
        <span class="level-item">Quick Scroll :</span>
        {% for folder in folders %}
            {% if loop.index0 %}
                <a class="level-item" href="#{{ folder.name }}">{{ folder.name }}</a>
            {% endif %}
        {% endfor %}
    </div>

    <table class="table is-bordered is-striped is-narrow is-fullwidth is-hoverable is-size-7">
        <thead>
        <tr>
            <th>Name</th>
            <th>Link</th>
            <th>Season</th>
            <th>Comment</th>
            <th>Tools</th>
        </tr>
        </thead>
        <tbody>

        {% for folder in folders %}
            {% if folder.titles|length > 0 %}
                <th colspan="5" id="{{ folder.name }}">{{ folder.name }}</th>

                {% for title in folder.titles %}
                    {% for link in title.links %}
                        <tr>
                            {% if not loop.index0 %}
                                <td rowspan="{{ title.links|length }}">
                                    {{ title.name }}
                                </td>
                            {% endif %}

                            <td class="{{ link|colorify }}">
                                {{ link.vf|flagify }}
                                {{ link.link|urlize(30, target='_blank') }}
                            </td>

                            <td>
                                {{ link.season }}
                            </td>

                            <td>
                                {{ link.comment|urlize(target='_blank') }}
                            </td>

                            <td>
                                <a href="{{ url_for('search', q=link.title.keyword) }}" target="_blank">
                                    <i class="fa fa-search"></i>
                                </a>
                                <i>&nbsp;</i>
                                <a href="{{ url_for('admin_edit', link_id=link.id) }}">
                                    <i class="fa fa-pencil"></i>
                                </a>
                                <i>&nbsp;</i>
                                <form method="post">
                                    {{ action_form.id(value=link.id) }}
                                    <button class="fa fa-trash fa-button"
                                            onclick="return confirm('Are you sure you want to delete this item ?')">
                                    </button>
                                </form>
                            </td>
                        </tr>
                    {% endfor %}
                {% endfor %}
            {% endif %}
        {% endfor %}

        </tbody>
    </table>
{% endblock %}