{#
/**
 * Copyright © 2003-2024 The Galette Team
 *
 * This file is part of Galette (https://galette.eu).
 *
 * Galette is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Galette is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
 */
#}
{% if object.getDynamicFields() is not empty and object.getDynamicFields().getFields()|length > 0 %}
<div class="ui basic fitted segment">
    <div class="ui styled fluid accordion row">
        <div class="active title">
            <i class="jsonly displaynone icon dropdown" aria-hidden="true"></i>
            {{ _T("Additionnal fields:") }}
        </div>
        <div class="active content field">
            <table class="ui very basic striped stackable padded table">
                {% for field in object.getDynamicFields().getFields() %}
                    {% if get_class(field) == 'Galette\\DynamicFields\\Separator' %}
                <tr>
                    <td colspan="2"><div class="ui horizontal divider">{{ field.getName()|escape }}</div></td>
                </tr>
                    {% else %}
                <tr>
                    <th class="three wide column">{{ field.getName()|escape }}</th>
                    <td>
                        {% for field_data in object.getDynamicFields().getValues(field.getId()) %}
                            {% set value = field_data.field_val|escape|default("") %}
                            {% if get_class(field) == 'Galette\\DynamicFields\\Choice' %}
                                {% if field_data.text_val is defined %}
                                    {% set value = field_data.text_val %}
                                {% else %}
                                    {% set value = "" %}
                                {% endif %}
                            {% elseif get_class(field) == 'Galette\\DynamicFields\\Text' %}
                                {% set value = field_data.field_val|escape|nl2br|default("") %}
                            {% endif %}
                            {% if not loop.first %}<br />{% endif %}
                            {% if get_class(field) == 'Galette\\DynamicFields\\Boolean' %}
                                {% if value %}
                        {{ _T("Yes") }}
                                {% else %}
                        {{ _T("No") }}
                                {% endif %}
                            {% elseif get_class(field) == 'Galette\\DynamicFields\\File' %}
                                <a href="{{ url_for("getDynamicFile", {"form_name": object.getFormName(), "id": object.id, "fid": field.getId(), "pos": loop.index, "name": value}) }}">{{ value }}</a>
                            {% elseif get_class(field) == 'Galette\\DynamicFields\\Line' and callstatic("Galette\\Core\\GaletteMail", "isValidEmail", value) %}
                                <a href="mailto:{{ value }}">{{ value }}</a>
                            {% elseif get_class(field) == 'Galette\\DynamicFields\\Line' and callstatic("Galette\\Core\\GaletteMail", "isUrl", value) %}
                                <a href="{{ value }}" target="_blank" title="{{ _T("Open '%s' in a new window")|replace({"%s": value}) }}">{{ value }}</a>
                            {% else %}
                                {{ value|raw }}
                            {% endif %}
                        {% endfor %}
                    </td>
                </tr>
                    {% endif %}
                {% endfor %}
            </table>
        </div>
    </div>
</div>
{% endif %}
