{% extends "base.html.j2" %}
{% import "materialize/wtf.html.j2" as wtf %}

{% block main_attribs %} class="service-scheme" data-service="corpus-analysis"{% endblock main_attribs %}

{% block page_content %}
<div class="container">
  <div class="row">
    <div class="col s12">
      <h1>{{ corpus.title }} </h1>
      <div class="row">
        <div class="col s8 m9 l10">
          {% if current_user.is_following_corpus(corpus) %}
          <a class="action-button btn waves-effect waves-light" data-action="unfollow-request"><i class="material-icons left outlined">close</i>Unfollow Corpus</a>
          {% endif %}
          {% if corpus.status.name in ['BUILT', 'STARTING_ANALYSIS_SESSION', 'RUNNING_ANALYSIS_SESSION', 'CANCELING_ANALYSIS_SESSION'] and current_user.is_following_corpus(corpus) %}
          <a class="btn waves-effect waves-light" href="{{ url_for('corpora.analyse_corpus', corpus_id=corpus.id) }}">Analyze</a>
          {% endif %}
        </div>
      </div>
      <div class="card service-color-border border-darken" data-service="corpus-analysis" style="border-top: 10px solid">
        <div class="card-content">
          <div class="row">
            <div class="col s12">
              <p><b>Status:</b> <span class="chip corpus-status-text corpus-status-color white-text" data-status="{{ corpus.status.name }}"></span></p>
              <p></p>
              <br>
            </div>
            <div class="col s12">
              <p><b>Description:</b> {{ corpus.description }}</p>
              <br>
              <p></p>
            </div>
            <div class="col s6">
              <p><b>Creation date:</b> {{ corpus.creation_date }}</p>
            </div>
            <div class="col s6">
              <p><b>Number of tokens used:</b> {{ corpus.num_tokens }}</p>
            </div>
          </div>
        </div>
      </div>
      <div class="card">
        <div class="card-content">
          <span class="card-title" id="files">Corpus Owner</span>
          <div class="row">
            <div class="col s12">
              <table>
                <tr>
                  <td style="width:10%; margin-top:25px;">
                    {% if corpus.user.avatar %}
                    <img src="{{ url_for('users.profile_avatar', user_id=corpus.user.id) }}" alt="user-image" class="circle responsive-img">
                    {% else %}
                    <img src="{{ url_for('static', filename='images/user_avatar.png') }}" alt="user-image" class="circle responsive-img">
                    {% endif %}
                  </td>
                  <td></td>
                  <td>
                    <ul>
                      <li><b>{{ owner.username }}</b></li>
                      {% if owner.full_name %}
                      <li>{{ owner.full_name }}</li>
                      {% endif %}
                      {% if owner.show_email %}
                      <li></li><a href="mailto:{{ owner.email }}">{{ owner.email }}</a></li>
                      {% endif %}
                    </ul>
                  </td>
                </tr>
              </table>
              <br>
              <p></p>
              {% if not current_user.is_following_corpus(corpus) %}
              <a class="waves-effect waves-light btn-small">Request Corpus</a>
              {% endif %}
              <a class="waves-effect waves-light btn-small" href="{{ url_for('users.user', user_id=corpus.user.id) }}">View profile</a>
            </div>
          </div>
        </div>
      </div>

      {% if cfa.role.has_permission('VIEW') %}
      <div class="card">
        <div class="card-content">
          <span class="card-title" id="files">Corpus files</span>
          <div class="corpus-file-list no-autoinit" data-user-id="{{ owner.hashid }}" data-corpus-id="{{ corpus.hashid }}"></div>
        </div>
      </div>
      {% endif %}

      {% if cfa.role.has_permission('UPDATE_FOLLOWER') %}
      <div class="card">
        <div class="card-content">
          <span class="card-title" id="files">Corpus followers</span>
          <div class="corpus-follower-list" data-user-id="{{ corpus.user.hashid }}" data-corpus-id="{{ corpus.hashid }}"></div>
        </div>
      </div>
      {% endif %}

    </div>
  </div>
</div>
{% endblock page_content %}
