{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 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/>.
 #
 # ---------------------------------------------------------------------
 #}

{% extends "generic_show_form.html.twig" %}
{% import 'components/form/fields_macros.html.twig' as fields %}
{% set params  = params ?? [] %}
{% set field_options = field_options ?? {} %}

{% block more_fields %}
    {{ fields.dropdownYesNo(
       'locked',
       item.fields['locked'],
       __('Locked'),
       field_options
    ) }}

    {{ fields.textField(
        'deviceid',
        item.fields['deviceid'],
        __('Device id'),
        field_options
    ) }}

    {{ fields.numberField(
        'port',
        item.fields['port'],
        _n('Port', 'Ports', 1),
        field_options
    ) }}

    {{ fields.htmlField(
        "Agent",
        item.fields['remote_addr'],
        __('Public contact address'),
        field_options
    ) }}

    {{ fields.dropdownArrayField(
        'itemtype',
        item.fields['itemtype'],
        itemtypes,
        __('Item type'),
        field_options
    ) }}

    {% if not item.isNewItem() %}
        {% set asset_item = get_item(item.fields['itemtype'], item.fields['items_id']) %}
        {{ fields.htmlField(
            'items_id',
            asset_item.getLink(),
            __('Item link'),
            field_options
        ) }}
        <input type="hidden" name="items_id" value="{{ item.fields['items_id'] }}">

        {% set versions %}
            {% set versions_array = call("importArrayFromDB", [versions_field]) %}
            {% if versions_array|length %}
                <ul>
                {% for module, version in versions_array %}
                    <li><strong>{{ module }}</strong>: {{ version }}</li>
                {% endfor %}
                </ul>
            {% elseif versions_field|length %}
                {{ versions_field }}
            {% endif %}
        {% endset %}
        {{ fields.htmlField(
            'versions',
            versions,
            _n('Version', 'Versions', 1),
            field_options
        ) }}

        {{ fields.readOnlyField(
            'tag',
            item.fields['tag'],
            __('Tag'),
            field_options
        ) }}

        {{ fields.readOnlyField(
            'useragent',
            item.fields['useragent'],
            __('Useragent'),
            field_options
        ) }}

        {{ fields.htmlField(
            'last_contact',
            call("Html::convDateTime", [item.fields['last_contact']]),
            __('Last contact'),
            field_options
        ) }}

        <h2 class="header">{{ __('Agent configuration') }}</h2>

        {% for netfield, netlabel in {
            'threads_networkdiscovery': __('Network discovery threads'),
            'timeout_networkdiscovery': __('Network discovery timeout'),
            'threads_networkinventory': __('Network inventory threads'),
            'timeout_networkinventory': __('Network inventory timeout'),
        } %}
            {% set general = __('General setup') %}
            {% if config(netfield) != null %}
                {% set general = "%1$s (%2$s)"|format(general, config(netfield)) %}
            {% endif %}

            {{ fields.dropdownNumberField(
                netfield,
                item.fields[netfield],
                netlabel,
                field_options|merge({
                    'min': 1,
                    'toadd': [
                        general
                    ]
                })
            ) }}
        {% endfor %}

        <h2 class="header">{{ __('Supported tasks') }}*</h2>

        {% for modulefield, modulelabel in {
            'use_module_wake_on_lan': __('Wake on LAN'),
            'use_module_computer_inventory': __('Computer inventory'),
            'use_module_esx_remote_inventory': __('ESX remote inventory'),
            'use_module_network_inventory': __('Network inventory (SNMP)'),
            'use_module_network_discovery': __('Network discovery (SNMP)'),
            'use_module_package_deployment': __('Package Deployment'),
            'use_module_collect_data': __('Collect data'),
            'use_module_remote_inventory': __('Remote inventory'),
        } %}

        {% if item.fields[modulefield] %}
            {% set html = '<i class="ti ti-check"></i>' %}
        {% else %}
            {% set html = '' %}
        {% endif %}

        {{ fields.htmlField('', html, modulelabel) }}
        {% endfor %}
        <i>* {{ __('when reported by GLPI agent via native inventory') }}</i>
    {% endif %}
{% endblock %}
