{% extends 'base/layout.html' %}
{% load helpers %}
{% load form_helpers %}

{% block title %}Search{% endblock %}

{% block content %}
    {% if request.GET.q %}
        {% if results %}
            <div class="row">
                <div class="col col-md-9">
                    {% for obj_type in results %}
                        <h3 id="{{ obj_type.name|lower }}">{{ obj_type.name|bettertitle }}</h3>
                        {% include 'inc/panel_table.html' with table=obj_type.table %}
                        <a href="{{ obj_type.url }}" class="btn btn-primary float-end my-3">
                            <i class="mdi mdi-arrow-right-bold" aria-hidden="true"></i>
                            {% if obj_type.table.page.has_next %}
                                See All {{ obj_type.table.page.paginator.count }} Results
                            {% else %}
                                Refine Search
                            {% endif %}
                        </a>
                    {% endfor %}
                </div>
                <div class="col col-md-3">
                    <h3 class="invisible">&nbsp;</h3>
                    <div class="card">
                        <h5 class="card-header">
                            Search Results
                        </h5>
                        <div class="card-body">
                            <div class="list-group list-group-flush">
                                {% for obj_type in results %}
                                    <a href="#{{ obj_type.name|lower }}" class="list-group-item">
                                        {{ obj_type.name|bettertitle }}
                                        <span class="badge bg-primary">{{ obj_type.table.page.paginator.count }}</span>
                                    </a>
                                {% endfor %}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        {% else %}
            <h3 class="text-muted text-center">No results found</h3>
        {% endif %}
    {% else %}
        <div class="row">
            <div class="col-4 offset-4">
                <form action="{% url 'search' %}" method="get" class="form form-horizontal">
                    <div class="card">
                        <h5 class="card-header">
                            Search
                        </h5>
                        <div class="card-body">
                            {% render_form form %}
                        </div>
                        <div class="card-footer text-end">
                            <button type="submit" class="btn btn-primary">
                                <span class="mdi mdi-magnify" aria-hidden="true"></span> Search
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    {% endif %}
{% endblock content %}
