{#
/**
 * 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/>.
 */
#}
{% set can_edit = group.canEdit(login) %}

{% set managers = group.getManagers() %}
{% set members = group.getMembers() %}

<div class="ui stackable pointing inverted menu tabbed">
    <div class="item header">
        <div class="ui breadcrumb">
            {% for parent in group.parents %}
                <span class="section">{{ parent }}</span>
                <i class="right angle icon divider"></i>
            {% endfor %}
            <span class="section active">{{ group.getName() }}</span>
        </div>
    </div>
    <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_information" class="item{{ tab == 'group_information' ? ' active' }}" data-tab="group_information">{{ _T("Information") }}</a>
    <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_managers" class="item{{ tab == 'group_managers' ? ' active' }}" data-tab="group_managers"><i class="user shield icon" aria-hidden="true"></i>{{ _T("Managers") }} ({{ managers|length }})</a>
    <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_members" class="item{{ tab == 'group_members' ? ' active' }}" data-tab="group_members"><i class="user icon" aria-hidden="true"></i>{{ _T("Members") }} ({{ members|length }})</a>
</div>
<form class="ui form" action="{{ url_for("doEditGroup", {"id": group.getId()}) }}" method="post" enctype="multipart/form-data" id="group_form">
    <div class="ui{{ tab == 'group_information' ? ' active' }} tab segment" data-tab="group_information">
        <div class="ui basic segment">
            {% if group.getId() %}
                <div class="inline field">
                    <label>{{ _T("Creation date:") }}</label>
                    <span>{{ group.getCreationDate() }}</span>
                </div>
            {% endif %}
            <div class="inline field{% if can_edit %} required{% endif %}">
                <label for="group_name">{{ _T("Name:") }}</label>
            {% if can_edit %}
                <input type="text" name="group_name" id="group_name" value="{{ group.getName() }}" maxlength="250" required/>
            {% else %}
                <span>{{ group.getName() }}</span>
            {% endif %}
            </div>

            {% if group.getParentGroup() %}
                {% set pgroup = group.getParentGroup() %}
            {% endif %}
            <div class="inline field">
                    <label for="parent_group">{{ _T("Parent group:") }}</label>
                {% if can_edit and parent_groups|length > 0 %}
                    {% if pgroup is defined and not login.isGroupManager(pgroup.getId()) %}
                        {{ pgroup.getName() }}
                        <input type="hidden" name="parent_group" value="{{ pgroup.getId() }}"/>
                    {% else %}
                        <div class="ui search compact selection dropdown">
                            <input type="hidden" name="parent_group" id="parent_group" value="{% if pgroup is defined %}{{ pgroup.getId() }}{% endif %}">
                            <i class="dropdown icon" aria-hidden="true"></i>
                            <div class="text">{% if pgroup is defined %}{{ pgroup.getName() }}{% endif %}</div>
                            <div class="menu">
                                <div class="item" data-value="">{{ _T("None") }}</div>
                            {% for g in parent_groups %}
                                <div class="item" data-value="{{ g.getId() }}">{{ g.getIndentName()|raw }}</div>
                            {% endfor %}
                            </div>
                        </div>
                    {% endif %}
                {% else %}
                    <span>
                    {% if pgroup is defined %}
                        {{ pgroup.getName() }}
                        <input type="hidden" name="parent_group" value="{{ pgroup.getId() }}"/>
                    {% else %}
                        {{ _T("None") }}
                        <input type="hidden" name="parent_group" value=""/>
                    {% endif %}
                    </span>
                {% endif %}
            </div>
        </div>
    </div>

    <div id="group_managers" class="ui{{ tab == 'group_managers' ? ' active' }} tab segment" data-tab="group_managers">
        <div class="ui basic segment">
            {% if group %}
                {% if login.isAdmin() or login.isStaff() %}
                <a href="#" class="jsonly disabled ui labeled icon button" id="btnmanagers_small">
                    <i class="user shield icon" aria-hidden="true"></i>
                    {{ _T("Manage managers") }}
                </a>
                {% endif %}
                {% include "elements/group_persons.html.twig" with {'person_mode': "managers", 'persons': managers} %}
            {% endif %}
        </div>
    </div>

    <div id="group_members" class="ui{{ tab == 'group_members' ? ' active' }} tab segment" data-tab="group_members">
        <div class="ui basic segment">
            {% if group %}
                {% if login.isAdmin() or login.isStaff() %}
                <a href="#" class="jsonly disabled ui labeled icon button" id="btnusers_small">
                    <i class="user icon" aria-hidden="true"></i>
                    {{ _T("Manage members") }}
                </a>
                {% endif %}
                {% include "elements/group_persons.html.twig" with {'person_mode': "members", 'persons': members} %}
            {% endif %}
        </div>
    </div>

    <div class="ui basic center aligned segment">
        <div class="ui wrapping spaced buttons">
            {% if can_edit %}
            <button type="submit" name="valid" class="ui labeled icon primary button action">
                <i class="save icon" aria-hidden="true"></i> {{ _T("Save") }}
            </button>
            <input type="hidden" name="id_group" id="id_group" value="{{ group.getId() }}"/>
            <input type="hidden" name="tab" id="tab" value="{{ tab }}"/>
            {% include "components/forms/csrf.html.twig" %}
            {% endif %}
            {% if can_export %}
                <a href="{{ url_for("pdf_groups", {"id": group.getId()}) }}" class="ui labeled icon button tooltip" title="{{ _T("Current group (and attached people) as PDF") }}">
                    <i class="file pdf red icon" aria-hidden="true"></i>
                    {{ _T("Group PDF") }}
                </a>
            {% endif %}
            {% if login.isAdmin() or login.isStaff() %}
                <a class="ui labeled icon button delete" id="delete" href="{{ url_for("removeGroup", {"id": group.getId()}) }}">
                    <i class="trash alt red icon" aria-hidden="true"></i>
                    {{ _T("Delete") }}
                </a>
            {% endif %}
        </div>
    </div>
</form>
