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

{% 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 'Eco-account' %}<br> {{obj.identifier}}</h3>
        </div>
        <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
            {% include 'compensation/detail/eco_account/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>
                        <th class="w-25" scope="row">{% trans 'Title' %}</th>
                        <td class="align-middle">{{obj.title}}</td>
                    </tr>
                    <tr {% if not obj.deductable_surface %}class="alert alert-danger" title="{% trans 'No surface deductable' %}" {% endif %}>
                        <th scope="row">{% trans 'Available' %}</th>
                        <td class="align-middle">
                            {{available_total|floatformat:2}} / {{obj.deductable_surface|default_if_none:0.00|floatformat:2}} m²
                            {% with available as value %}
                                {% include 'konova/widgets/progressbar.html' %}
                            {% endwith %}
                        </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.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.legal.registration_date %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Agreement date' %}</th>
                        <td class="align-middle">{{obj.legal.registration_date|default_if_none:""}}</td>
                    </tr>
                    <tr {% if not obj.responsible.handler %}class="alert alert-danger" title="{% trans 'Missing' %}" {% endif %}>
                        <th scope="row">{% trans 'Action handler' %}</th>
                        <td class="align-middle">{{obj.responsible.handler|default_if_none:""}}</td>
                    </tr>
                    <tr>
                        <th scope="row">{% trans 'Is PIK' %}</th>
                        <td class="align-middle">
                            {% if obj.is_pik %}
                                {% trans 'Yes' %}
                            {% else %}
                                {% trans 'No' %}
                            {% endif %}
                        </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 has_access %}
                                {% 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 'compensation/detail/eco_account/includes/states-before.html' %}
            </div>
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'compensation/detail/eco_account/includes/states-after.html' %}
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'compensation/detail/eco_account/includes/actions.html' %}
            </div>
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'compensation/detail/eco_account/includes/deadlines.html' %}
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'compensation/detail/eco_account/includes/documents.html' %}
            </div>
            <div class="col-sm-12 col-md-12 col-lg-12 col-xl-6">
                {% include 'compensation/detail/eco_account/includes/deductions.html' %}
            </div>
        </div>
    </div>


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

{% endblock %}