{% extends "wagtailadmin/base.html" %}
{% load wagtailimages_tags wagtailadmin_tags static i18n l10n %}
{% block titletag %}{% blocktrans with title=video.title %}Editing {{ title }}{% endblocktrans %}{% endblock %}

{% block content %}
    {% trans "Editing" as editing_str %}
    {% include "wagtailadmin/shared/header.html" with title=editing_str subtitle=video.title icon="media" usage_object=video %}

    <form action="{% url 'wagtail_video:edit' video.id %}" method="POST" enctype="multipart/form-data" novalidate>
        {% csrf_token %}
        <div class="row row-flush nice-padding">
            <div class="col6">
                <ul class="fields">
                    {% for field in form %}
                        {% if field.name == 'mp4' %}
                            {% include "wagtail_video/video/_file_field_as_li.html" %}
                        {% elif field.name == 'ogg' %}
                            {% include "wagtail_video/video/_file_field_as_li.html" %}
                        {% elif field.name == 'webm' %}
                            {% include "wagtail_video/video/_file_field_as_li.html" %}
                        {% elif field.name == 'thumbnail' %}
                            {% include "wagtail_video/video/_thumbnail_field_as_li.html" %}
                        {% else %}
                            {% include "wagtailadmin/shared/field_as_li.html" %}
                        {% endif %}
                    {% endfor %}
                </ul>
                <div class="u-hidden@xs">
                    <input class="button" type="submit" value="{% trans 'Save' %}" />
                    {% if user_can_delete %}
                        <a href="{% url 'wagtail_video:delete' video.id %}" class="button button-secondary no">{% trans "Delete Video" %}</a>
                    {% endif %}
                </div>
            </div>

            <div class="col6">
                <video controls style="max-width: 100%; margin-bottom: 20px;">
                    <source src="{{ video.mp4_url }}" type="video/mp4">
                    {% if video.ogg %}
                        <source src="{{ video.ogg_url }}" type="video/ogg">
                    {% endif %}
                    {% if video.webm %}
                        <source src="{{ video.webm_url }}" type="video/webm">
                    {% endif %}
                </video>

                <div class="row">
                    <div class="col8 divider-after">
                        <div style="display: inline-block"></div>
                    </div>
                    <div class="col4">
                        {% image image original as original_image %}

                        <dl>
                            {% if video.file %}
                                <dt>{% trans "Filesize" %}</dt>
                                <dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd>
                            {% endif %}

                            {% usage_count_enabled as uc_enabled %}
                            {% if uc_enabled %}
                                <dt>{% trans "Usage" %}</dt>
                                <dd>
                                    <a href="{{ video.usage_url }}">{% blocktrans count usage_count=video.get_usage.count %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
                                </dd>
                            {% endif %}
                        </dl>
                    </div>
                </div>
            </div>
        </div>

        <div class="row row-flush nice-padding u-hidden@sm">
            <div class="col5">
                <input class="button" type="submit" value="{% trans 'Save' %}" />
                {% if user_can_delete %}
                    <a href="{% url 'wagtail_video:delete' video.id %}" class="button button-secondary no">{% trans "Delete Video" %}</a>
                {% endif %}
            </div>
        </div>
    </form>
{% endblock %}
