{% asset 'ckanext-multiuploader/my-css' %}
{% asset 'ckanext-multiuploader/my-js' %}


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

{% set data = data or {} %}
{% set errors = errors or {} %}
{% set action = h.url_for('multiuploader.upload_resources', _external=True) %}
<input type="hidden" value="{{action}}" id="dest_url" >

<form id="resource-edit" class="dataset-form dataset-resource-form" method="post" action="" data-module="basic-form resource-form" enctype="multipart/form-data">

  {% block stages %}
    {# An empty stages variable will not show the stages #}
    {% if stage %}
      {{ h.snippet('package/snippets/stages.html', stages=stage, pkg_name=pkg_name) }}
    {% endif %}
  {% endblock %}

  {% block errors %}{{ form.errors(error_summary) }}{% endblock %}

  <input id="id" value="{{ data.id }}" type="hidden"/>
  <input id="pck_id" value="{{ pkg_name }}" type="hidden"/>
  {% snippet 'snippets/progress_bar_modal.html' %}

  {% block basic_fields %}
    {% block basic_fields_url %}
        <input type="hidden" id="upload_limit" value={{h.get_max_upload_size()}}>
        <div class="alert alert-danger" id="file-danger">
            {{_('You need to upload file(s) or add a Link ' )}}
        </div>
        <div class="alert alert-danger" id="file-danger-size">
            {{_('Please check your file(s) size. Each file has to be less than ' ) + h.get_max_upload_size() + ' GB'}}
        </div>
        <div id="dataTitle">{{_('Data')}}:</div><br>
        <button  type="button" class="btn btn-primary fakebtn upload-related-parts" id="UpBtn">{{_('Upload')}}</button>
        <button  type="button" class="btn btn-primary fakebtn" id="RemoveBtn">{{_('Remove All')}}</button>
        <button  type="button" class="btn btn-primary fakebtn upload-related-parts" id="LinkBtn">{{_('Link')}}</button>
        <div id='urlBox'>
            {{ form.input('url', id='urlText', label=_('URL'), placeholder=_('http://example.com/my-image.jpg'), value=data.name, error=errors.name, classes=['control-full']) }}
            <button  type="button" class="btn btn-primary" id="urlRemove">Remove</button>
            <br><br>
            {{ form.input('urlName', id='urlName', label=_('Name'), placeholder=_('eg. January 2011 Gold Prices'), value=data.name, error=errors.name, classes=['control-full']) }}
        </div>
        <input type="file" name="urls[]" multiple="multiple" id="fileUpload">
    {% endblock %}
    <br><br><br>
    <div class="alert alert-warning upload-related-parts" id="file-size-info-box">
        <p>
          {{_('Please note: Maximum size for a single file is limited to ') +  h.get_max_upload_size()  + ' GB.'}}
        </p>
      </div>
    {% block basic_fields_name %}
      
      <div id="fileNameBox" class="upload-related-parts">
        <label for="fileNames">{{_('Files')}}</label>
        <div class="row" id="fileNames">
            <div id="fileNameMessage">
                <i class="fa fa-arrows-alt"></i>
                {{_('Drop file(s) here or use the Upload button')}}
            </div>
        </div>
        <br><br>
      </div>
    
              
    {% endblock %}

    {% block basic_fields_description %}
      {{ form.markdown('description', id='field-description', label=_('Description'), placeholder=_('Some useful notes about the data'), value=data.description, error=errors.description) }}
    {% endblock %}

   
  {% endblock basic_fields %}

  {% block metadata_fields %}
    {% if include_metadata %}
      {# TODO: Where do these come from, they don't exist in /package/new_package_form.html #}
      {# {{ form.select('resource_type', id='field-type', label=_('Resource Type'), options=[{'value': 'empty', 'text': _('Select a type…')}], selected="empty", error=errors.type) }} #}

      {{ form.input('last_modified', id='field-last-modified', label=_('Last Modified'), placeholder=_('eg. 2012-06-05'), value=data.last_modified, error=errors.last_modified, classes=[]) }}

      {{ form.input('size', id='field-size', label=_('File Size'), placeholder=_('eg. 1024'), value=data.size, error=errors.size, classes=[]) }}

      {{ form.input('mimetype', id='field-mimetype', label=_('MIME Type'), placeholder=_('eg. application/json'), value=data.mimetype, error=errors.mimetype, classes=[]) }}

      {{ form.input('mimetype_inner', id='field-mimetype-inner', label=_('MIME Type'), placeholder=_('eg. application/json'), value=data.mimetype_inner, error=errors.mimetype_inner, classes=[]) }}
    {% endif %}
  {% endblock %}

  <div class="form-actions">
  {% block cancel_dataset %}
      {% if stage and h.cancel_dataset_is_enabled() %} 
        {% set dest_url = h.url_for('cancel_dataset_creation.cancel_dataset', package_id=pkg_dict.id, is_draft=0, _external=True) %}
       <a class="btn btn-danger pull-left" href="{{dest_url}}" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this dataset?') }}">{{ _('Cancel & Delete Dataset') }}</a>
      {% endif %}
    {% endblock %}
    {% block delete_button %}
      {% if data.id %}
        {% if h.check_access('resource_delete', {'id': data.id})  %}
          <a class="btn btn-danger pull-left" href="{% url_for dataset_type ~ '_resource.delete', resource_id=data.id, id=pkg_name %}" data-module="confirm-action" data-module-content="{{ _('Are you sure you want to delete this resource?') }}">{% block delete_button_text %}{{ _('Delete') }}{% endblock %}</a>
        {% endif %}
      {% endif %}
    {% endblock %}
    {% if stage %}
      {% block previous_button %}
        <button class="btn btn-default" name="Csave" value="go-dataset" type="submit">{{ _('Previous') }}</button>
      {% endblock %}
    {% endif %}
   
    {% if stage %}
      {% block save_button %}
        <button id="ckanext_multiuploader_finish" class="btn btn-primary" name="Csave" value="go-metadata" type="submit">{% block save_button_text %}{{ _('Finish') }}{% endblock %}</button>
      {% endblock %}
    {% else %}
      {% block add_button %}
        <button class="btn btn-primary" name="Csave" value="go-dataset-complete" type="submit">{{ _('Add') }}</button>
      {% endblock %}
    {% endif %}
  </div>
</form>
