{#
 # ---------------------------------------------------------------------
 #
 # 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 ?? [] %}

{% block more_fields %}
   {{ fields.dropdownArrayField(
      'snmpversion',
      item.fields['snmpversion'],
      {0: '-----', 1: '1', 2: '2c', 3: '3'},
      __('SNMP version'),
      {
         required: true
      }
   ) }}

   {{ fields.textField(
      'community',
      item.fields['community'],
      __('Community'),
      {
         add_field_attribs: {
            'data-snmp-version': '1'
         }
      },
   ) }}

   {{ fields.textField(
      'username',
      item.fields['username'],
      _n('User', 'Users', get_plural_number()),
      {
         add_field_attribs: {
            'data-snmp-version': '3'
         }
      },
   ) }}

   {{ fields.nullField() }}

   {{ fields.dropdownArrayField(
      'authentication',
      item.fields['authentication'],
      {0: '-----', 1: 'MD5', 2: 'SHA', 3: 'SHA224', 4: 'SHA256', 5: 'SHA384', 6: 'SHA512'},
      __('Encryption protocol for authentication '),
      {
         add_field_attribs: {
            'data-snmp-version': '3'
         }
      },
   ) }}

   {{ fields.nullField() }}

   {{ fields.passwordField(
      'auth_passphrase',
      item.fields['auth_passphrase'],
      __('Password'),
      {
         add_field_attribs: {
            'data-snmp-version': '3'
         }
      },
   ) }}

   {{ fields.nullField() }}

   {{ fields.dropdownArrayField(
      'encryption',
      item.fields['encryption'],
      {0: '-----', 1: 'DES', 2: 'AES128', 3: 'Triple-DES', 4: 'Cisco AES192', 5: 'Cisco AES256'},
      __('Encryption protocol for data'),
      {
         add_field_attribs: {
            'data-snmp-version': '3'
         }
      },
   ) }}

   {{ fields.nullField() }}

   {{ fields.passwordField(
      'priv_passphrase',
      item.fields['priv_passphrase'],
      __('Password'),
      {
         add_field_attribs: {
            'data-snmp-version': '3'
         }
      },
   ) }}

   <script>

      const filterFormForSNMPVersion = (version) => {
         // Hide all elements with data-snmp-version attribute by default
         $('.form-field[data-snmp-version]').hide();
         if (version === '1' || version === '2') {
            $('.form-field[data-snmp-version="1"]').show();
         } else if (version === '3') {
            $('.form-field[data-snmp-version="3"]').show();
         }
      }
      filterFormForSNMPVersion($('select[name="snmpversion"]').val());
      // If there is already a snmpversion selected, show the corresponding elements
      $('select[name="snmpversion"]').on('change', (e) => {
         const selection = $(e.currentTarget).val();
         filterFormForSNMPVersion(selection);
      });
   </script>
{% endblock %}
