{% import 'macros/form.html' as form %}
{% set action = c.form_action or '' %}

{# This provides a full page that renders a form for adding a dataset. It can
then itself be extended to add/remove blocks of functionality. #}
<form id="dataset-edit" class="dataset-form form-horizontal" method="post" action="{{ action }}" data-module="basic-form">
  {% block stages %}
    {{ h.snippet('package/snippets/stages.html', stages=stage) }}
  {% endblock %}

  <input type="hidden" name="_ckan_phase" value="dataset_new_1" />
  {# pkg_name used in 3 stage edit #}
  <input type="hidden" name="pkg_name" value="{{ data.id }}" />
  {% block errors %}{{ form.errors(error_summary) }}{% endblock %}

  {% block basic_fields %}
    {% snippet 'package/snippets/package_basic_fields.html', data=data, errors=errors, licenses=c.licenses, groups_available=c.groups_available %}
  {% endblock %}

  {% block metadata_fields %}
    {% snippet 'package/snippets/package_metadata_fields.html', data=data, errors=errors %}
  {% endblock %}

  {% block form_actions %}
    <div class="form-actions">
      {% block disclaimer %}
        <p class="action-info small">
          {%- trans -%}
          The <i>data license</i> you select above only applies to the contents
          of any resource files that you add to this dataset. By submitting
          this form, you agree to release the <i>metadata</i> values that you
          enter into the form under the
          <a href="http://opendatacommons.org/licenses/odbl/1-0/">Open Database License</a>.
          {%- endtrans -%}
        </p>
      {% endblock %}
      {% block delete_button %}
        {% if h.check_access('package_delete', {'id': data.id}) and not data.state == 'deleted' %}
          {% set locale = h.dump_json({'content': _('Are you sure you want to delete this dataset?')}) %}
          <a class="btn btn-danger pull-left" href="{% url_for controller='package', action='delete', id=data.id %}" data-module="confirm-action" data-module-i18n="{{ locale }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
        {% endif %}
      {% endblock %}
      {% block save_button %}
        <button class="btn btn-primary" type="submit" name="save">{% block save_button_text %}{{ _('Next: Add Data') }}{% endblock %}</button>
      {% endblock %}
      {{ form.required_message() }}
    </div>
  {% endblock %}
</form>
