{% extends base_template %}
{% load debusine %}
{% block content %}
    <div class="card mt-4" id="user-input">
        {% if not collection %}
            <div class="card-header">
                <h2>Select a task configuration collection to inspect</h2>
            </div>
            {% if collections %}
                <div class="list-group list-group-flush" id="collection-selector">
                    {% for collection in collections %}
                        <a class="list-group-item list-group-item-action"
                           href="?collection={{ collection.id }}">{{ collection.name }} in {{ collection.workspace }}</a>
                    {% endfor %}
                </div>
            {% else %}
                <div class="card-body">
                    <div class="alert alert-light" role="alert">
                        There are no task configuration collections accessible from this workspace.
                    </div>
                </div>
            {% endif %}
        {% else %}
            <div class="card-header d-flex justify-content-between align-items-center">
                <div class="me-auto">
                    <h2>
                        Collection <b>{{ collection.name }}</b> in {{ collection.workspace }}
                    </h2>
                </div>
                {% if collections|length > 1 %}
                    <a class="badge text-bg-primary rounded-pill"
                       href="."
                       title="select another collection"><span class="bi bi-x"></span></a>
                {% endif %}
            </div>
            <div class="card-body">
                {% if form %}
                    <p>{{ item_count }} entries available</p>
                    <form method="get">
                        <input type="hidden" name="collection" value="{{ collection.id }}">
                        {% for error in form.non_field_errors %}<div class="alert alert-danger" role="alert">{{ error }}</div>{% endfor %}
                        {% for field in form %}
                            <div class="mb-3 row">
                                <label for="{{ field.id_for_label }}" class="col-sm-2 col-form-label">{{ field.label }}</label>
                                <div class="col-sm-10">
                                    {{ field }}
                                    {% if field.errors %}
                                        <div class="form-text text-danger">
                                            {% for error in field.errors %}{{ error }}{% endfor %}
                                        </div>
                                    {% endif %}
                                </div>
                            </div>
                        {% endfor %}
                        <p>
                            <input class="btn btn-primary btn-sm" type="submit" value="Lookup">
                        </p>
                    </form>
                {% else %}
                    <div class="alert alert-warning" role="alert">This collection is empty</div>
                {% endif %}
            </div>
        {% endif %}
    </div>
    {% if has_result %}
        <div id="results">
            <h2 class="mt-4">Lookup result</h2>
            <div class="card mt-4" id="default-values">
                <div class="card-header">Default values</div>
                {% include "web/_card-body.html" with data=changes.default_values|as_yaml only %}
            </div>
            <div class="card mt-4" id="override-values">
                <div class="card-header">Override values</div>
                {% include "web/_card-body.html" with data=changes.override_values|as_yaml only %}
            </div>
            <div class="card mt-4" id="provide-tags">
                <div class="card-header">Provide tags</div>
                {% include "web/_card-body.html" with data=provide_tags_formatted only %}
            </div>
            <div class="card mt-4" id="require-tags">
                <div class="card-header">Require tags</div>
                {% include "web/_card-body.html" with data=require_tags_formatted only %}
            </div>
            <h3 class="mt-4">Configuration items used</h3>
            <div id="configuration-items">
                {% for item in config_items %}
                    <div class="card mt-4">
                        <div class="card-header">{{ item.name }}</div>
                        {% include "web/_card-body.html" with data=item.model_dump|as_yaml:"unsorted" only %}
                    </div>
                {% endfor %}
            </div>
        </div>
    {% endif %}
{% endblock %}
