{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2026 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program 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.
 #
 # This program 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 this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import 'components/form/fields_macros.html.twig' as fields %}

{# Compute values for the dropdown #}
{% set actor_values = {} %}
{% set values = input_value is iterable ? input_value : [input_value] %}
{% for actor in values %}
    {% if actor matches '/^(.+)-(.+)$/' %}
        {% set type = actor|split('-')[0] %}
        {% set id = actor|split('-')[1] %}
        {% if actor_values[type] is not defined %}
            {% set actor_values = actor_values|merge({(type): []}) %}
        {% endif %}
        {% set actor_values = actor_values|merge({
            (type): actor_values[type]|merge([id])
        }) %}
    {% endif %}
{% endfor %}

{% set actors_dropdown = call('Glpi\\Form\\Dropdown\\FormActorsDropdown::show', [
    input_name,
    actor_values,
    {
        'multiple'        : multiple,
        'init'            : true,
        'allowed_types'   : allowed_actors,
        'aria_label'      : input_label,
        'specific_tags': {
            'data-glpi-conditions-editor-value': '',
        },
    }
]) %}

{{ fields.htmlField(
    input_name,
    actors_dropdown,
    '',
    {
        'no_label'     : true,
        'wrapper_class': '',
        'mb'           : '',
        'field_class'  : [
            'me-2 value-selector flex-grow-1',
        ]|join(' '),
    }
) }}
