{% import 'macros/form.html' as form %}

<form class="dataset-form form-horizontal" method="post" data-module="basic-form">
  {% block error_summary %}
    {% if error_summary | count %}
      <div class="alert alert-error error-explanation">
        <p>{{ _('The form contains invalid entries:') }}</p>
        <ul>
          {% for key, error in error_summary.items() %}
            <li>{{ key }}: {{ error }}</li>
          {% endfor %}
        </ul>
      </div>
    {% endif %}
  {% endblock %}

  {% block fields %}
    {{ form.input('title', label=_('Title'), id='field-title', placeholder=_('My Related Item'), value=data.title, error=errors.title, classes=['control-full']) }}
    {{ form.input('url', label=_('URL'), id='field-url', placeholder=_('http://example.com/'), value=data.url, error=errors.url, classes=['control-full']) }}
    {{ form.input('image_url', label=_('Image URL'), id='field-image-url', placeholder=_('http://example.com/image.png'), value=data.image_url, error=errors.image_url, classes=['control-full']) }}
    {{ form.markdown('description', label=_('Description'), id='field-description', placeholder=_('A little information about the item...'), value=data.description, error=errors.description) }}
    {{ form.select('type', label=_('Type'), id='field-types', selected=data.type, options=c.types, error=errors.type) }}
  {% endblock %}

  <div class="form-actions">
    {% block delete_button %}
      {% if h.check_access('related_delete', {'id': data.id})  %}
        {% set locale = h.dump_json({'content': _('Are you sure you want to delete this related item?')}) %}
        <a class="btn btn-danger pull-left" href="{% url_for controller='related', action='delete', related_id=data.id, id=c.pkg_id %}" data-module="confirm-action" data-module-i18n="{{ locale }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
      {% endif %}
    {% endblock %}
    {{ h.nav_link(_('Cancel'), controller='related', action='list', id=c.id, class_='btn') }}
    <button class="btn btn-primary" type="submit" name="save">{% block button_text %}{{ _('Save') }}{% endblock %}</button>
  </div>
</form>
