{% extends 'base.html' %}
{% load i18n l10n static fontawesome_5 %}

{% block head %}
    {% comment %}
        dal documentation (django-autocomplete-light) states using form.media for adding needed scripts.
        This does not work properly with modal forms, as the scripts are not loaded properly inside the modal.
        Therefore the script linkages from form.media have been extracted and put inside dal/scripts.html to ensure
        these scripts are loaded when needed.
    {% endcomment %}
    {% include 'dal/scripts.html' %}
{% endblock %}

{% block body %}

    <div id="detail-header" class="row">
        <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
            <h3>{% trans 'Intervention' %}<br> {{obj.identifier}}</h3>
        </div>
        <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
            {% include 'intervention/detail/includes/controls.html' %}
        </div>
    </div>
    <hr>
    <div id="data" class="row">
        <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
            <div class="table-container">
                <table class="table table-hover">
                    <tr {% if not obj.title %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th class="w-25" scope="row">{% trans 'Title' %}</th>
                        <td class="align-middle">{{obj.title|default_if_none:""}}</td>
                    </tr>
                    <tr {% if not obj.legal.process_type %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Process type' %}</th>
                        <td class="align-middle">{{obj.legal.process_type|default_if_none:""}}</td>
                    </tr>
                    <tr {% if obj.legal.laws.count == 0 %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Law' %}</th>
                        <td class="align-middle">
                            {% for law in obj.legal.laws.all %}
                                <div class="badge pill-badge rlp-r-outline">{{law.short_name}} - {{law.long_name}}</div>
                                <br>
                            {% endfor %}
                        </td>
                    </tr>
                    <tr {% if not obj.responsible.registration_office %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Registration office' %}</th>
                        <td class="align-middle">{{obj.responsible.registration_office.str_as_office|default_if_none:""}}</td>
                    </tr>
                    <tr {% if not obj.responsible.registration_file_number %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Registration office file number' %}</th>
                        <td class="align-middle">{{obj.responsible.registration_file_number|default_if_none:""}}</td>
                    </tr>
                    <tr {% if not obj.responsible.conservation_office %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Conservation office' %}</th>
                        <td class="align-middle">{{obj.responsible.conservation_office.str_as_office|default_if_none:""}}</td>
                    </tr>
                    <tr {% if not obj.responsible.conservation_file_number %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Conservation office file number' %}</th>
                        <td class="align-middle">{{obj.responsible.conservation_file_number|default_if_none:""}}</td>
                    </tr>
                    <tr {% if not obj.responsible.handler %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Intervention handler' %}</th>
                        <td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
                    </tr>
                    <tr>
                        <th scope="row">{% trans 'Checked' %}</th>
                        <td class="align-middle">
                            {% if obj.checked is None %}
                                <span>
                                    {% fa5_icon 'star' 'far' %}
                                </span>
                                {% if last_checked %}
                                    <span class="rlp-gd-inv" title="{{last_checked_tooltip}}">
                                        {% fa5_icon 'star' 'fas' %}
                                    </span>
                                {% endif %}
                            {% else %}
                                <span class="check-star" title="{% trans 'Checked on '%} {{obj.checked.timestamp}} {% trans 'by' %} {{obj.checked.user}}">
                                    {% fa5_icon 'star' %}
                                </span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">{% trans 'Recorded' %}</th>
                        <td class="align-middle">
                            {% if obj.recorded is None %}
                                <span title="{% trans 'Not recorded yet' %}">
                                    {% fa5_icon 'bookmark' 'far' %}
                                </span>
                            {% else %}
                                <span class="registered-bookmark" title="{% trans 'Recorded on '%} {{obj.recorded.timestamp}} {% trans 'by' %} {{obj.recorded.user}}">
                                    {% fa5_icon 'bookmark' %}
                                </span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr {% if not obj.legal.registration_date %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Registration date' %}</th>
                        <td class="align-middle">{{obj.legal.registration_date|default_if_none:""}}</td>
                    </tr>
                    <tr {% if not obj.legal.binding_date %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Binding on' %}</th>
                        <td class="align-middle">{{obj.legal.binding_date|default_if_none:""}}</td>
                    </tr>
                    <tr {% if obj.legal.revocations.all %}class="alert alert-danger" title="{% trans 'Exists' %}" {% endif %}>
                        <th scope="row">{% trans 'Revocations' %}</th>
                        <td class="align-middle">{{obj.legal.revocations.count}}</td>
                    </tr>
                    <tr>
                        <th scope="row">{% trans 'Last modified' %}</th>
                        <td class="align-middle">
                            {% if obj.modified %}
                                {{obj.modified.timestamp|default_if_none:""}}
                                <br>
                                {{obj.modified.user.username}}
                            {% else %}
                                {{obj.created.timestamp|default_if_none:""}}
                                <br>
                                {{obj.created.user.username}}
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">{% trans 'Shared with' %}</th>
                        <td class="align-middle">
                            {% for team in obj.shared_teams %}
                                {% include 'user/includes/team_data_modal_button.html' %}
                            {% endfor %}
                            <hr>
                            {% if is_entry_shared %}
                                {% for user in obj.users.all %}
                                    {% include 'user/includes/contact_modal_button.html' %}
                                {% endfor %}
                            {% else %}
                            <span title="{% trans 'The data must be shared with you, if you want to see which other users have shared access as well.' %}">
                                {% fa5_icon 'eye-slash' %}
                                {{obj.users.count}} {% trans 'other users' %}
                            </span>
                            {% endif %}
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
            <div class="row">
                <div class="col-sm-12">
                    {% include 'map/geom_form.html' %}
                </div>
            </div>
            <div class="row">
                {% include 'konova/includes/parcels/parcels.html' %}
            </div>
            <div class="row">
                {% include 'konova/includes/comment_card.html' %}
            </div>
        </div>
    </div>
    <hr>

    <div id="related_data">
        <div class="row">
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'intervention/detail/includes/compensations.html' %}
            </div>
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'intervention/detail/includes/payments.html' %}
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'intervention/detail/includes/deductions.html' %}
            </div>
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'intervention/detail/includes/revocation.html' %}
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'intervention/detail/includes/documents.html' %}
            </div>
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
            </div>
        </div>
    </div>


{% with 'btn-modal' as btn_class %}
    {% include 'modal/modal_form_script.html' %}
{% endwith %}

{% endblock %}