{% 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() }}

  <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 %}

  <div class="package-metadata-field rounded container">
    <div class="row ">
      
        {% 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 %}
      
    </div>
  </div>

  {% 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 form_style == 'edit' and 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 publish_button %}
        {% if form_style == 'edit' %}
          <button class="btn btn-warning" name="save" value="go-metadata-unpublish" type="submit">{% block publish_button_text %}{{ _('Unpublish') }}{% endblock %}</button>
        {% endif %}
      {% endblock %}
      {% block save_button %}
        <button class="btn btn-primary" type="submit" name="save">
          {%- block save_button_text -%}
            {%- if form_style == 'edit' -%}
              {{ h.humanize_entity_type('package', pkg_dict.type, 'update label') or _('Update Dataset') }}
            {%- else -%}
              {{ _('Next: Add Data') }}
            {%- endif -%}
          {%- endblock -%}
        </button>
      {% endblock %}
    </div>
  {% endblock %}
</form>
