{#
 # ---------------------------------------------------------------------
 #
 # 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/>.
 #
 # ---------------------------------------------------------------------
 #}

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

{{ fields.textField(
   'mail_server',
   connect_opts['address'],
   __('Server'), {
       required: true
   }
) }}

{{ fields.textField(
   'server_port',
   connect_opts['port'],
   __('Port (optional)'), {
      helper: __(
         'Typical ports: IMAP (143), IMAPS (993), POP (110), POPS (995)'
      )
   }
) }}

{% set connection_options_fields %}
   <div class="d-flex flex-wrap mb-n2">
      {% set type_value = connect_opts['type'] is not empty ? ('/' ~ connect_opts['type']) : '' %}
      {% set options = {
         no_label: true,
         display_emptychoice: true,
         field_class: 'me-2',
         mb: 'mb-0',
      } %}
      {{ fields.dropdownArrayField('server_type', type_value, protocol_choices, '', options) }}
      {% set ssl_value = connect_opts['ssl'] ? '/ssl' : '' %}
      {{ fields.dropdownArrayField('server_ssl', ssl_value, {
         '/ssl': __('SSL')
      }, '', options) }}
      {% set tls_value = connect_opts['tls'] is same as(true) ? '/tls' : (connect_opts['tls'] is same as (false) ? '/notls' : '') %}
      {{ fields.dropdownArrayField('server_tls', tls_value, {
         '/tls': __('TLS'),
         '/notls': __('NO-TLS')
      }, '', options) }}
      {% set cert_value = connect_opts['validate-cert']is same as(true) ? '/validate-cert' : (connect_opts['validate-cert'] is same as(false) ? '/novalidate-cert' : '') %}
      {{ fields.dropdownArrayField('server_cert', cert_value, {
         '/novalidate-cert': __('NO-VALIDATE-CERT'),
         '/validate-cert': __('VALIDATE-CERT')
      }, '', options) }}
      {{ fields.dropdownArrayField('server_rsh', connect_opts['norsh'] == true ? '/norsh' : '', {
         '/norsh': __('NORSH'),
      }, '', options) }}
      {{ fields.dropdownArrayField('server_secure', connect_opts['secure'] == true ? '/secure' : '', {
         '/secure': __('SECURE'),
      }, '', options) }}
      {{ fields.dropdownArrayField('server_debug', connect_opts['debug'] == true ? '/debug' : '', {
         '/debug': __('DEBUG'),
      }, '', options) }}
   </div>
{% endset %}
{{ fields.htmlField(
   '',
   connection_options_fields,
   __('Connection options'),
   {
      full_width: true,
   }
) }}
{% if connect_string is not empty %}
   {{ fields.htmlField('', connect_string, __('Connection string'), {
      add_field_class: 'fw-bold',
      full_width: true,
   }) }}
{% endif %}
