{% ckan_extends %}

{% block resource_actions_inner %}
  {% block action_manage %}
    {% if h.check_access('package_update', {'id':pkg.id }) %}
      <li>{% link_for _('Manage'), named_route=pkg.type ~ '_resource.edit', id=pkg.name, resource_id=res.id, class_='btn btn-default', icon='wrench' %}</li>
    {% endif %}
  {% endblock action_manage %}
  <li>
    {% if res.datastore_active %}
      <div class="btn-group">
    {% endif %}
      {% if res.url and h.is_url(res.url) %}
        <a class="btn btn-primary resource-url-analytics" href="{{ h.url_for('download.download', id=pkg.id, resource_id=res.id) }}?user-download=true" download>
          {% if res.resource_type in ('listing', 'service') %}
            <i class="fa fa-eye"></i> {{ _('View') }}
          {% elif  res.resource_type == 'api' %}
            <i class="fa fa-key"></i> {{ _('API Endpoint') }}
          {% elif not res.has_views and not res.url_type == 'upload' %}
            <i class="fa fa-external-link"></i> {{ _('Go to resource') }}
          {% else %}
            <i class="fa fa-arrow-circle-down"></i> {{ _('Download') }}
          {% endif %}
        </a>
      {% endif %}
      {% block download_resource_button %}
        {% if res.datastore_active %}
          {% if h.is_base_public_folder_bs3() %}
            <button class="btn btn-primary dropdown-toggle" role="button" id="dropdownDownloadFormat" data-toggle="dropdown" aria-expanded="false" aria-label="{{ _('List of downloadable formats') }}">
              {% if not res.url or not h.is_url(res.url) %}
                {{ _('Download') }}&nbsp;
              {% endif %}
              <span class="caret"></span>
            </button>
          {% else %}
            <button class="btn btn-primary dropdown-toggle" role="button" id="dropdownDownloadFormat" data-bs-toggle="dropdown" aria-expanded="false" aria-label="{{ _('List of downloadable formats') }}">
              {% if not res.url or not h.is_url(res.url) %}
                {{ _('Download') }}&nbsp;
              {% endif %}
              <span class="caret"></span>
            </button>
          {% endif %}
          <ul class="dropdown-menu" aria-labelledby="dropdownDownloadFormat">
            <li>
              <a class="dropdown-item" href="{{ h.url_for('datastore.dump', resource_id=res.id, bom=True) }}"
                target="_blank" rel="noreferrer"><span>CSV</span></a>
            </li>
            <li>
              <a class="dropdown-item" href="{{ h.url_for('datastore.dump', resource_id=res.id, format='tsv', bom=True) }}"
                target="_blank" rel="noreferrer"><span>TSV</span></a>
            </li>
            <li>
                <a class="dropdown-item" href="{{ h.url_for('datastore.dump', resource_id=res.id, format='json') }}"
                target="_blank" rel="noreferrer"><span>JSON</span></a>
            </li>
            <li>
                <a class="dropdown-item" href="{{ h.url_for('datastore.dump', resource_id=res.id, format='xml') }}"
                target="_blank" rel="noreferrer"><span>XML</span></a>
            </li>
          </ul>
        {% endif %}
      {% endblock %}
    {% if res.datastore_active %}
      </div>
    {% endif %}
  </li>
  {% if h.is_enabled_utilizations_org(pkg.owner_org) %}
    <li>
      <a class="btn btn-primary resource-url-analytics resource-type-{{ res.resource_type }}" href="{{ h.url_for('utilization.new', package_name=pkg.name, resource_id=res.id, return_to_resource=true) }}">
        <i class="fa-solid fa-seedling"></i> {{ _('Create utilization application') }}
      </a>
    </li>
  {% endif %}
  {% if h.is_enabled_resources_org(pkg.owner_org) %}
    <li>
      <a class="btn btn-primary resource-url-analytics resource-type-{{ res.resource_type }}" href="{{ h.url_for('resource_comment.comment', resource_id=res.id) }}">
        <i class="fa-solid fa-comment-dots"></i> {{ _('Comment') }}
      </a>
    </li>
  {% endif %}
{% endblock %}

{% block resource_read_url %}
  {% if res.url and h.is_url(res.url) %}
    <p class="text-muted ellipsis">{{ _('URL:') }} <a class="resource-url-analytics" href="{{ h.url_for('download.download', id=pkg.id, resource_id=res.id) }}?user-download=true" title="{{ res.url }}" download>{{ res.url }}</a></p>
  {% elif res.url %}
    <p class="text-muted break-word">{{ _('URL:') }} {{ res.url }}</p>
  {% endif %}
{% endblock %}
