{% extends 'base.html.twig' %}

{% block title %}{{ ("documentType_" ~ document.getClassShort)|trans }}: {{ document.getTitle }}{% endblock %}
{% block subtitle %}#{{ document.id }}: {{ document.getTitle }} {% endblock %}

{% block body %}

{% set groupLogo = 'img/nologo.png' %}
{% if document.mainGroup %}
  {% if document.mainGroup.imageSize != 0 %}
    {% set groupLogo = 'uploads/groups/' ~ document.mainGroup.imageName %}
  {% endif %}
{% endif %}
<div class="row">
  <div class="col-12 col-md-8 mb-5{% if shared is defined %} mx-5 my-2{% endif %}">

    {% if document.archive %}
    <div class="card prod-p-card bg-primary background-pattern-white">
        <div class="card-body">
            <div class="row align-items-center m-b-0">
                <div class="col">
                    <h6 class="m-b-5 text-white">{% trans %}title_document_archived{% endtrans %}</h6>
                </div>
                <div class="col-auto">
                  <i class="fas fa-archive text-white"></i>
                </div>
            </div>
        </div>
    </div>
    {% endif %}

    {% if shared is not defined %}
      {% if document.AllowShare %}
      <div class="card prod-p-card bg-danger background-pattern-white">
          <div class="card-body">
              <div class="row align-items-center m-b-0">
                  <div class="col">
                      <h6 class="m-b-5 text-white">{% trans %}title_document_shared{% endtrans %}</h6>
                  </div>
                  <div class="col-auto">
                    <i class="fas fa-exclamation-triangle text-white"></i>
                  </div>
              </div>
          </div>
      </div>
      {% endif %}
    {% endif %}


    <div class="document-container p-2 mt-2">

      <div class="row align-items-center">
        <div class="col-12 col-xl-3">
          <img src="{{ asset(groupLogo) }}" alt="{{document.mainGroup.shortname}}" class="img-fluid document-group-logo">
        </div>
        <div class="col">
          <h1 style="color:beige;">{{document.mainGroup.name}}</h1>
          <h2 style="color:beige;">{{ ("documentType_" ~ document.getClassShort)|trans }} #{{ document.getId }} : {{ document.getTitle }}</h2>
        </div>      
      </div>
      <hr>
      <div class="row p-2">
        <div class="col-12">
          {% include 'document/types/' ~ document.getClassShort ~ '.html.twig' with {'document': document} %}
        </div>
      </div>
      <hr>
      <div class="row mb-2">
        <div class="col-12 col-md-6">
          {% if shared is not defined and history |length > 1 %}
          <p>{% trans %}title_document_edited{% endtrans %} {{ history |length -1 }} {% trans %}since_its_creation{% endtrans %}. <a href="{{path('document_history', {'id': document.id})}}">{% trans %}button_view_history{% endtrans %}</a></p>
          {% endif %}
        </div>
        <div class="col-12 col-md-6">
          {{ document.creator.fullname }}, {% trans %}for{% endtrans %} {{ document.mainGroup.name }} <br>{% trans %}title_created_at{% endtrans %} {{ document.createdAt|date('_datetime.format'|trans) }}
          {% if shared is not defined %}<span class="float-end">{% include '_cells/documentActions.html.twig' with {'document': document} %}</span> {% endif %}
        </div>
      </div>

    </div>

    <div class="row mt-5">
      <div class="col">
        <h3>{% trans %}title_comments{% endtrans %} {% if shared is not defined %}<a href="#" data-bs-toggle="modal" data-bs-target="#addCommentModal"><span class="badge rounded-pill bg-success"><i class="fa fa-plus"></i> {% trans %}button_add_comment{% endtrans %}</span></a>{% endif %}</h3><hr>
        
  
        <ul class="timeline">
          {% for c in document.comments %}
          <li>
            {{ c.creator.fullname }} {{c.creator.mainGroup ? c.creator.mainGroup.shortname : 'No Group'}}, {% trans %}title_created_at{% endtrans %} {{ c.createdAt|date('_datetime.format'|trans) }}
            <hr>            
            {{ c.content | raw }}
            <span class="float-end">{% if shared is not defined %}{% include '_cells/commentActions.html.twig' with {'comment': c} %}{% endif %}</span>
          </li>
          {% endfor %}
        </ul>     
    </div>
    </div>
  </div>
  <div class="col-12 col-md-4">
    {% if document.directory is defined and document.directory is not null %}
      <h3>{% trans %}title_directory_linked{% endtrans %}</h3><hr>
          {% include '_cells/directoryCard.html.twig' with {'directory': document.directory} %}          
      {% endif %}
      
      {% if document.user is defined and document.user is not null %}
        <h3>{% trans %}title_user_linked{% endtrans %}</h3><hr>
          {% include '_cells/userInformations.html.twig' with {'user': document.user} %}         
        {% endif %}    
      
  </div>
</div>

{% if shared is not defined %}
<!-- Modal -->
<div class="modal fade" id="addCommentModal" tabindex="-1" role="dialog" aria-labelledby="addCommentModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-xl" role="document">
    <div class="modal-content">
    <div class="modal-header">
        <h5 class="modal-title" id="addCommentModalTitle">{% trans %}title_add_comment{% endtrans %}</h5>              
    </div>
    <div class="modal-body">
        {{ form(formComment) }}
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">{% trans %}button_cancel{% endtrans %}</button>              
    </div>
    </div>
</div>
</div>
{% endif %} 

{% endblock %}


