{% extends 'base.html' %}

{% block content %}
    <div class="row">
        <div class="col">
            <h1 class="text-center">{% block title %} {{ resource['name'] }} {% endblock %}</h1>
        </div>
    </div>
    {% if current_user.is_authenticated %}
      {% if resource['type'] == 'tool' %}
      <div class="row text-center py-3">
          <a href="{{ url_for('tool.edit_tool', tool_id=resource['id']) }}">
              <span class="badge bg-dark">Edit</span>
          </a>
      </div>
      {% endif %}
      {% if resource['type'] == 'practice' %}
      <div class="row text-center py-3">
          <a href="{{ url_for('practice.edit_practice', practice_id=resource['id']) }}">
              <span class="badge bg-dark">Edit</span>
          </a>
      </div>
      {% endif %}
    {% endif %}
    <div class="row">
        <div class="col">
            <table class="table table-hover">
                <tbody>
                    <tr>
                        <th>
                            Created:
                        </th>
                        <td>
                            {{ resource['created'].strftime("%Y-%m-%d %H:%M") }} UTC
                        </td>
                    </tr>
                    <tr>
                        <th>
                            Description:
                        </th>
                        <td>
                            {{ resource['description'] }}
                        </td>
                    </tr>
                    {% if resource['projectUrl'] %}
                    <tr>
                        <th>
                            Project page:
                        </th>
                        <td>
                            <a href="{{ resource['projectUrl'] }}">{{ resource['projectUrl'] }}</a>
                        </td>
                    </tr>
                    {% endif %}
                    {% if resource['repositoryUrl'] %}
                    <tr>
                        <th>
                            Code repository:
                        </th>
                        <td>
                            <a href="{{ resource['repositoryUrl'] }}">{{ resource['repositoryUrl'] }}</a>
                        </td>
                    </tr>
                    {% endif %}
                    {% if resource['expertiseToUse'] %}
                    <tr>
                        <th>
                            Expertise required to use:
                        </th>
                        <td>
                            {{ resource['expertiseToUse'] }}
                        </td>
                    </tr>
                    {% endif %}
                    {% if resource['expertiseToHost'] %}
                    <tr>
                        <th>
                            Expertise required to self-host:
                        </th>
                        <td>
                            {{ resource['expertiseToHost'] }}
                        </td>
                    </tr>
                    {% endif %}
                    {% if resource['dependencies'] %}
                    <tr>
                        <th>
                            Technical dependencies:
                        </th>
                        <td>
                            {{ resource['dependencies'] }}
                        </td>
                    </tr>
                    {% endif %}
                    {% if resource['ingestFormats'] %}
                    <tr>
                        <th>
                            Import / ingest formats:
                        </th>
                        <td>
                            {{ resource['ingestFormats'] }}
                        </td>
                    </tr>
                    {% endif %}
                    {% if resource['outputFormats'] %}
                    <tr>
                        <th>
                            Output formats:
                        </th>
                        <td>
                            {{ resource['outputFormats'] }}
                        </td>
                    </tr>
                    {% endif %}
                    {% if resource['status'] %}
                    <tr>
                        <th>
                            Platform status:
                        </th>
                        <td>
                            {{ resource['status'] }}
                        </td>
                    </tr>
                    {% endif %}
                </tbody>
            </table>
        </div>
    </div>
    {% if links %}
    <div class="row">
        <div class="col">
            <h2 class="text-center">Linked resources:</h2>
        </div>
    </div>
    <div class="row">
    {% for link in links %}
        <div class="col-md-4 col-sm-6 py-3">
        {% if link['type'] == 'tool' %}
        <div class="card text-dark bg-tool mb-3">
            <div class="card-body">
                <a href="{{ url_for('tool.show_tool', tool_id=link['id']) }}">
                    <h3 class="card-title text-center text-dark">{{ link['name'] }}</h3>
                </a>
                <p class="card-text">
                    {{ link['description']|truncate(100) }}
                </p>
            </div>
        </div>
        {% endif %}
        {% if link['type'] == 'practice' %}
        <div class="card text-dark bg-practice mb-3">
            <div class="card-body">
                <a href="{{ url_for('practice.show_practice', practice_id=link['id']) }}">
                    <h3 class="card-title text-center text-dark">{{ link['name'] }}</h3>
                </a>
                <p class="card-text">
                    {{ link['description']|truncate(100) }}
                </p>
            </div>
        </div>
        {% endif %}
        </div>
    {% endfor %}
    </div>
    {% endif %}
{% endblock %}