{% extends "wagtailadmin/base.html" %}
{% load wagtailimages_tags compress %}
{% load i18n %}
{% block titletag %}{% blocktrans with title=image.title %}Editing image {{ title }}{% endblocktrans %}{% endblock %}
{% block bodyclass %}menu-images{% endblock %}
{% block extra_css %}
    {% include "wagtailadmin/shared/tag_field_css.html" %}

    <!-- Focal point chooser -->
    <link rel="stylesheet" href="{{ STATIC_URL }}wagtailimages/scss/vendor/jquery.Jcrop.min.css" type="text/css">
    {% compress css %}
        <link rel="stylesheet" href="{{ STATIC_URL }}wagtailimages/scss/focal-point-chooser.scss" type="text/x-scss">
    {% endcompress %}
{% endblock %}

{% block extra_js %}
    {% include "wagtailadmin/shared/tag_field_js.html" %}

    <!-- Focal point chooser -->
    <script src="{{ STATIC_URL }}wagtailadmin/js/vendor/jquery.ba-throttle-debounce.min.js"></script>
    <script src="{{ STATIC_URL }}wagtailimages/js/vendor/jquery.Jcrop.min.js"></script>
    <script src="{{ STATIC_URL }}wagtailimages/js/focal-point-chooser.js"></script>
{% endblock %}

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

    <div class="row row-flush nice-padding">

        <div class="col7">
            <form action="{% url 'wagtailimages_edit_image' image.id %}" method="POST" enctype="multipart/form-data">
                {% csrf_token %}
                <ul class="fields">
                    {% for field in form %}

                        {% if field.name == 'file' %}
                            {% include "wagtailimages/images/_file_field.html" %}
                        {% elif field.is_hidden %}
                            {{ field }}
                        {% else %}
                            {% include "wagtailadmin/shared/field_as_li.html" %}
                        {% endif %}

                    {% endfor %}
                    <li><input type="submit" value="{% trans 'Save' %}" /><a href="{% url 'wagtailimages_delete_image' image.id %}" class="button button-secondary no">{% trans "Delete image" %}</a></li>
                </ul>
            </form>
        </div>
        <div class="col5">
            <h2 class="label">{% trans "Focal point (optional)" %}</h2>
            <p>{% trans "To define this image's most important region, drag a box over the image below." %} {% if image.focal_point %}({% trans "Current focal point shown" %}){% endif %}</p>
            <div class="focal-point-chooser"
                data-focal-point-x="{{ image.focal_point_x }}"
                data-focal-point-y="{{ image.focal_point_y }}"
                data-focal-point-width="{{ image.focal_point_width }}"
                data-focal-point-height="{{ image.focal_point_height }}">

                {% image image max-800x600 data-original-width=image.width data-original-height=image.height %}
                <div class="current-focal-point-indicator{% if not image.focal_point %} hidden{% endif %}"></div>
            </div>

            {% if url_generator_enabled %}
                <a href="{% url 'wagtailimages_url_generator' image.id %}" class="button bicolor icon icon-link">{% trans "URL Generator" %}</a>
            {% endif %}
        </div>
    </div>
{% endblock %}
