{% extends "@ChillPerson/Person/layout.html.twig"  %}

{% set activeRouteKey = 'chill_person_resource_list' %}

{% block title %}{{ 'Person resources'|trans|capitalize ~ ' ' ~ person|chill_entity_render_string }}{% endblock %}

{% block js %}
    {{ encore_entry_script_tags('page_person_resource_showhide_input') }}
    {{ encore_entry_script_tags('mod_pickentity_type') }}
{% endblock %}

{% block css %}
    {{ encore_entry_link_tags('page_person_resource_showhide_input') }}
    {{ encore_entry_link_tags('mod_pickentity_type') }}
{% endblock %}

{% block content %}

<h1>{{ 'List of resources'|trans }}</h1>

{% if personResources|length > 0 %}
    <div class="flex-table">
        {% for resource in personResources %}
            <div class="item-bloc">
                {% if resource.kind is not null %}
                    <div class="item-row">
                        <section>
                            <p>{{ resource.kind.title.fr|capitalize }}</p>
                        </section>
                    </div>
                {% endif %}
                <div class="{% if resource.kind is not null %} separator {% endif %}">
                    {% if resource.person is not null %}
                        {{ resource.person|chill_entity_render_box({
                            'render': 'bloc',
                            'addLink': true,
                            'addInfo': true,
                            'addAge': true
                        }) }}
                    {% elseif resource.thirdparty is not null %}
                        {{ resource.thirdparty|chill_entity_render_box({
                            'render': 'bloc',
                            'showContacts': false,
                            'addLink': true,
                            'isConfidential': (resource.thirdparty.contactDataAnonymous ? true : false)
                        }) }}
                    {% else %}
                        <div class="denomination h3">
                            <span>{{ resource.freetext }}</span>
                        </div>
                    {% endif %}
                </div>
                {% if resource.comment.comment is not empty %}
                    <div class="item-row separator">
                        <section class="chill-entity entity-comment-embeddable">
                            <div>{{ resource.comment|chill_entity_render_box }}<div>
                        </section>
                    </div>
                {% endif %}
                {% if is_granted('CHILL_PERSON_UPDATE', resource.personOwner) %}
                    <div class="item-row separator">
                        <div class="item-col">
                            <ul class="record_actions">
                                <li>
                                    <a href="{{ chill_path_add_return_path('chill_person_resource_edit', {'resource_id': resource.id,
                                                    'person_id': person.id,}) }}"
                                                    class="btn btn-sm btn-edit"
                                                    title="{{ 'Edit'|trans }}"></a>
                                </li>
                                <li>
                                    <a href="{{ chill_path_add_return_path('chill_person_resource_delete', {'person_id': person.id,
                                                    'resource_id': resource.id}) }}"
                                        class="btn btn-sm btn-delete"
                                        title="{{ 'Delete'|trans }}"></a>
                                </li>
                            </ul>
                        </div>
                    </div>
                {% endif %}
            </div>
        {% endfor %}
    </div>

{% else %}
    <p class="chill-no-data-statement">{{ 'There are no available resources'|trans }}</p>
{% endif %}

{% if is_granted('CHILL_PERSON_UPDATE', person) %}
<ul class="record_actions sticky-form-buttons">
    <li>
        <a href="{{ chill_path_add_return_path('chill_person_resource_new', {'person_id': person.id,}) }}"
                class="btn btn-new"
                title="{{ 'Create'|trans }}">{{ 'Create'|trans }}</a>
    </li>
</ul>
{% endif %}

{% endblock %}
