{% load wagtailadmin_tags %}
{% load i18n %}
{% trans "Choose an embed video" as choose_str %}
{% include "wagtailadmin/shared/header.html" with title=choose_str merged=1 tabbed=1 icon="media" %}

{{ uploadform.media.js }}
{{ uploadform.media.css }}

{% if uploadform %}
    <ul class="tab-nav merged">
        <li class="{% if not uploadform.errors %}active{% endif %}"><a href="#search" >{% trans "Search" %}</a></li>
        <li class="{% if uploadform.errors %}active{% endif %}"><a href="#upload">{% trans "Upload" %}</a></li>
    </ul>
{% endif %}

<div class="tab-content">
    <section id="search" class="{% if not uploadform.errors %}active{% endif %} nice-padding">
        <form class="embed_video-search search-bar" action="{% url 'wagtail_embed_videos:chooser' %}" method="GET" autocomplete="off" novalidate>
            <ul class="fields">
                {% for field in searchform %}
                    {% include "wagtailadmin/shared/field_as_li.html" with field=field %}
                {% endfor %}
                {% if collections %}
                    {% include "wagtailadmin/shared/collection_chooser.html" %}
                {% endif %}
                {% if popular_tags %}
                    <li class="taglist">
                        <h3>{% trans 'Popular tags' %}</h3>
                        {% for tag in popular_tags %}
                            <a class="suggested-tag tag" href="{% url 'wagtail_embed_videos:index' %}?tag={{ tag.name|urlencode }}">{{ tag.name }}</a>
                        {% endfor %}
                    </li>
                {% endif %}
            </ul>
        </form>
        <div id="embed_video-results">
            {% include "wagtail_embed_videos/chooser/results.html" %}
        </div>
    </section>
    {% if uploadform %}
        <section id="upload" class="{% if uploadform.errors %}active{% endif %} nice-padding">
            {% include "wagtailadmin/shared/non_field_errors.html" with form=uploadform %}
            <form class="embed_video-upload" action="{% url 'wagtail_embed_videos:chooser_upload' %}" method="POST" enctype="multipart/form-data" novalidate>
                {% csrf_token %}
                <ul class="fields">
                    {% for field in uploadform %}
                        {% if field.is_hidden %}
                            {{ field }}
                        {% else %}
                            {% include "wagtailadmin/shared/field_as_li.html" with field=field %}
                        {% endif %}
                    {% endfor %}
                    <li>
                        <button type="submit" class="button button-longrunning" data-clicked-text="{% trans 'Uploading…' %}">{% icon name="spinner" %}<em>{% trans 'Upload' %}</em></button>
                    </li>
                </ul>
            </form>
        </section>
    {% endif %}
</div>
