{% import 'macros/form.html' as form %}
{% set action = g.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" method="post" action="{{ action }}" data-module="basic-form" novalidate>
  {{ h.csrf_input() }}
  {% block stages %}
    {% snippet 'package/snippets/stages.html', stages=stage, dataset_type=dataset_type %}
  {% 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 %}
  {% endblock %}

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

  {% block form_actions %}
    {{ form.required_message() }}

    <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' %}
          <a class="btn btn-danger pull-left" href="{% url_for dataset_type ~ '.delete', id=data.id %}" data-module="confirm-action" data-module-content="{{ h.humanize_entity_type('package', dataset_type, 'delete confirmation') or _('Are you sure you want to delete this dataset?') }}">{% 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 %}
    </div>
  {% endblock %}
</form>
