{% extends 'ndr_core/admin_views/base.html' %}

{% block content %}
    <h2><i class="fa-regular fa-magnifying-glass"></i> Configure Searches</h2>
    <div class="card-deck">
        <div class="card bg-light mb-3">
            <div class="card-body">
                <h5 class="card-title">Options</h5>
                <div class="list-group">
                    <a href="{% url 'ndr_core:create_search_config' %}" class="list-group-item list-group-item-action py-2">
                        <i class="fa-regular fa-magnifying-glass"></i>
                        Create New Search Configuration
                    </a>
                    <a href="{% url 'ndr_core:create_search_field' %}" class="list-group-item list-group-item-action py-2">
                        <i class="fa-regular fa-table-list"></i>
                        Create New Search Field
                    </a>
                    <a href="{% url 'ndr_core:create_result_field' %}" class="list-group-item list-group-item-action py-2">
                        <i class="fa-regular fa-table-list"></i>
                        Create New Result Field
                    </a>
                    <a href="{% url 'ndr_core:help_chapter' 'search' %}" class="list-group-item list-group-item-action py-2">
                        <i class="fa-regular fa-circle-info"></i>
                        Help
                    </a>
                </div>
            </div>
        </div>

        <div class="card bg-light mb-3">
            <div class="card-body">
                <h5 class="card-title">Configured Searches</h5>
                <ul class="list-group">
                    {% for search in searches %}
                        <li class="list-group-item list-group-item-action d-flex py-2">
                            <p class="p-0 m-0 flex-grow-1">
                                <i class="fa-regular fa-search"></i> {{ search.conf_label }} ({{ search.conf_name }})
                                <br/>
                                <small>
                                    <a href="{% url 'ndr_core:edit_search_form' search.conf_name %}">Configure Search Form</a> &nbsp;|&nbsp;
                                    <a href="{% url 'ndr_core:edit_result_card' search.conf_name %}">Configure Result Card</a>
                                </small>
                            </p>

                            <p class="p-0 m-0">
                                <a href="{% url 'ndr_core:copy_search_config' search.pk %}" class="btn btn-sm btn-secondary">
                                    <i class="fa-regular fa-copy"></i>
                                </a>
                                <a href="{% url 'ndr_core:edit_search_config' search.pk %}" class="btn btn-sm btn-secondary">
                                    <i class="fa-regular fa-pen-to-square"></i>
                                </a>
                                <a href="{% url 'ndr_core:delete_search_config' search.pk %}" class="btn btn-sm btn-danger">
                                    <i class="fa-regular fa-delete-left"></i>
                                </a>
                            </p>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>

    <div class="card-deck">
        <div class="card bg-light mb-3">
            <div class="card-body">
                <h5 class="card-title">Search Fields</h5>
                <ul class="list-group">
                    {% for field in search_fields %}
                        <li class="list-group-item list-group-item-action d-flex py-2">
                            <p class="p-0 m-0 flex-grow-1">
                                <i class="fa-regular fa-square"></i> {{ field.field_label }} ({{ field.get_field_type_display }}: {{ field.field_name }})
                            </p>

                            <p class="p-0 m-0">
                                <a href="{% url 'ndr_core:edit_search_field' field.pk %}" class="btn btn-sm btn-secondary">
                                    <i class="fa-regular fa-pen-to-square"></i>
                                </a>
                                <a href="{% url 'ndr_core:delete_search_field' field.pk %}" class="btn btn-sm btn-danger">
                                    <i class="fa-regular fa-delete-left"></i>
                                </a>
                            </p>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>

        <div class="card bg-light mb-3">
            <div class="card-body">
                <h5 class="card-title">Result Fields</h5>
                <ul class="list-group">
                    {% for field in result_fields %}
                        <li class="list-group-item list-group-item-action d-flex py-2">
                            <p class="p-0 m-0 flex-grow-1">
                                <i class="fa-regular fa-square"></i> {{ field }})
                            </p>

                            <p class="p-0 m-0">
                                <a href="{% url 'ndr_core:edit_result_field' field.pk %}" class="btn btn-sm btn-secondary">
                                    <i class="fa-regular fa-pen-to-square"></i>
                                </a>
                                <a href="{% url 'ndr_core:delete_result_field' field.pk %}" class="btn btn-sm btn-danger">
                                    <i class="fa-regular fa-delete-left"></i>
                                </a>
                            </p>
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    </div>

    <div class="alert alert-info small" role="alert">
        <i class="fa-regular fa-circle-info"></i>
        <strong>Search Configurations</strong> define the access to your data. Search configurations contain a search form,
        consisting of search fields and a result card, consisting of result fields.
        <strong>Search Fields</strong> are the fields that are used to search for records.
        <strong>Result Fields</strong> are the fields that are displayed in the search results.
    </div>

{% endblock %}