<div role="tabpanel" class="tab-pane fade" id="tab-config-identity-provider" role="tabpanel" aria-labelledby="tab-config-identity-provider">
  <div class="card mb-4">
    <div class="card-header d-flex fs-5">
      <button class="btn d-md-none flex-grow-1 text-start" data-bs-target="#collapse-tab-config-identity-provider" data-bs-toggle="collapse" aria-controls="collapse-tab-config-identity-provider">
        {{ lang.admin.iam }}
      </button>
      <span class="d-none d-md-block">{{ lang.admin.iam }}</span>
    </div>
    <div id="collapse-tab-config-identity-provider" class="card-body collapse" data-bs-parent="#admin-content">
      <p class="offset-sm-3 mb-4">{{ lang.admin.iam_description|raw }}</p>
      <div class="row mb-4">
        <div class="col-md-3 d-flex align-items-center justify-content-md-end">
          <label class="control-label" for="iam_realm">{{ lang.admin.iam }}:</label>
        </div>
        <div class="col-12 col-md-9 col-lg-4">
          <select
            data-style="btn btn-secondary"
            data-id="iam_provider"
            title="{{ lang.admin.iam_provider }}"
            name="iam_provider" id="iam_provider" class="full-width-select form-control" required>
              <option value="keycloak" {% if not iam_settings.authsource or iam_settings.authsource == 'keycloak' %}selected{% endif %}>Keycloak</option>
              <option value="generic-oidc" {% if iam_settings.authsource == 'generic-oidc' %}selected{% endif %}>Generic-OIDC</option>
              <option value="ldap" {% if iam_settings.authsource == 'ldap' %}selected{% endif %}>LDAP</option>
          </select>
        </div>
      </div>
      <div id="keycloak_settings" class="{% if iam_settings.authsource and iam_settings.authsource != 'keycloak' %}d-none{% endif %}">
        <form class="form-horizontal" autocapitalize="none" data-id="iam_keycloak" autocorrect="off" role="form" method="post">
          <input type="hidden" name="authsource" value="keycloak">
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
                <label class="control-label" for="iam_keycloak_url">{{ lang.admin.iam_server_url }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_keycloak_url" name="server_url" value="{{ iam_settings.server_url }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_keycloak_realm">{{ lang.admin.iam_realm }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_keycloak_realm" name="realm" value="{{ iam_settings.realm }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_keycloak_clientid">{{ lang.admin.iam_client_id }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_keycloak_clientid" name="client_id" value="{{ iam_settings.client_id }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_keycloak_clientsecret">{{ lang.admin.iam_client_secret }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="reveal-password-input input-group">
                <input type="password" class="password-field form-control" id="iam_keycloak_clientsecret" name="client_secret" value="{{ iam_settings.client_secret }}" required>
                <button class="toggle-password btn btn-secondary" type="button"><i class="bi bi-eye"></i></button>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_redirect_url }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="row px-2 align-items-center">
                <span class="col-10 p-0 pe-2">
                  <input type="text" class="form-control"  name="redirect_url" value="{{ iam_settings.redirect_url }}" required>
                </span>
                <div class="col-2 p-0 d-flex">
                  <button class="btn btn-sm d-block d-sm-inline btn-secondary ms-auto iam_redirect_add_keycloak"><i class="bi bi-plus-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2" id="iam_keycloak_redirect_list">
            <input type="hidden" name="redirect_url_extra" value="">
            {% for key, url in iam_settings.redirect_url_extra %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-10 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="redirect_url_extra" value="{{ iam_settings.redirect_url_extra[key] }}">
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_keycloak_redirect_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
            {% endfor %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-10 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="redirect_url_extra" value="">
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_keycloak_redirect_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-4">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_keycloak_version">{{ lang.admin.iam_version }}:</label>
            </div>
            <div class="col-sm-4">
              <input type="text" class="form-control" id="iam_keycloak_version" name="version" value="{{ iam_settings.version }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_mapping }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="row px-2 align-items-center">
                <span class="col-5 p-0 pe-2">{{ lang.user.attribute }}</span>
                <span class="col-5 p-0 pe-2">{{ lang.mailbox.template }}</span>
                <div class="col-2 p-0 d-flex">
                  <button class="btn btn-sm d-block d-sm-inline btn-secondary ms-auto iam_rolemap_add_keycloak"><i class="bi bi-plus-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2" id="iam_keycloak_mapping_list">
            <input type="hidden" name="mappers" value="">
            <input type="hidden" name="templates" value="">
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_default_template_description }}"></i>
                  <span>{{ lang.admin.iam_default_template}}</span>
                </div>
                <div class="col-5 p-0 pe-2 align-content-end">
                  <select data-live-search="true" name="default_template" class="form-control" title="-- {{ lang.mailbox.template }} --">
                  <option value="" {% if not iam_settings.default_template %}selected{% endif %}>-- {{ lang.mailbox.template }} --</option>
                  {% for mbox_template in mbox_templates %}
                    <option {% if mbox_template.template == iam_settings.default_template %}selected{% endif %}>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex"></div>
              </div>
            </div>
            {% for key, role in iam_settings.mappers %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="mappers" value="{{ iam_settings.mappers[key] }}" required>
                </div>
                <div class="col-5 p-0 pe-2">
                  <select data-live-search="true" name="templates" class="form-control" title="-- {{ lang.mailbox.template }} --" required>
                  {% for mbox_template in mbox_templates %}
                    <option{% if mbox_template.template == iam_settings.templates[key] %} selected{% endif %}>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_keycloak_rolemap_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
            {% endfor %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="mappers" value="">
                </div>
                <div class="col-5 p-0 pe-2">
                  <select data-live-search="true" name="templates" class="form-control" title="-- {{ lang.mailbox.template }} --">
                  <option value="" selected>-- {{ lang.mailbox.template }} --</option>
                  {% for mbox_template in mbox_templates %}
                    <option>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_keycloak_rolemap_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2 mt-4">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end"></div>
            <div class="col-12 col-md-9">
              <span>{{ lang.admin.iam_extra_permission|raw }}</span>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-start justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_rest_flow }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="mailpassword_flow" value="1" {% if iam_settings.mailpassword_flow == 1 %}checked{% endif %}>
              </div>
              <p class="text-muted">
                <small>
                  {{ lang.admin.iam_auth_flow_info|raw }}
                </small>
              </p>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.ignore_ssl_error }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="ignore_ssl_error" value="1" {% if iam_settings.ignore_ssl_error == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_login_provisioning }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="login_provisioning"  value="1" {% if iam_settings.login_provisioning == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_periodic_full_sync }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="periodic_sync"  value="1" {% if iam_settings.periodic_sync == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_import_users }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="import_users"  value="1" {% if iam_settings.import_users == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_sync_interval }}</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input class="form-control" type="number" min="1" name="sync_interval" style="width: 80px;"  {% if iam_settings.sync_interval %}value="{{ iam_settings.sync_interval }}"{% else %}value="15"{% endif %}>
            </div>
          </div>
          <div class="row mt-4 mb-2">
            <div class="offset-md-3 col-12 col-md-9 d-flex flex-wrap">
              <div class="btn-group mb-2">
                <button class="btn btn-sm d-block d-sm-inline btn-secondary iam_test_connection iam_test_connection" data-id="iam_keycloak"><i class="bi bi-play"></i> {{ lang.admin.iam_test_connection }}</button>
                <button class="btn btn-sm d-block d-sm-inline btn-success" data-item="identity-provider" data-action="edit_selected" data-id="iam_keycloak" data-api-url='edit/identity-provider' data-api-attr='{}'><i class="bi bi-check-lg"></i> {{ lang.admin.save }}</button>
              </div>
              <button class="btn btn-sm d-block d-sm-inline btn-danger ms-auto mb-2" data-item="identity-provider" data-action="delete_selected" data-id="iam_keycloak" data-api-url='delete/identity-provider'><i class="bi bi-trash"></i> {{ lang.mailbox.remove }}</button>
            </div>
          </div>
        </form>
      </div>
      <div id="generic_oidc_settings" class="{% if not iam_settings.authsource or iam_settings.authsource != 'generic-oidc' %}d-none{% endif %}">
        <form class="form-horizontal" autocapitalize="none" data-id="iam_generic" autocorrect="off" role="form" method="post">
          <input type="hidden" name="authsource" value="generic-oidc">
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_authorize_url">{{ lang.admin.iam_authorize_url }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_authorize_url" name="authorize_url" value="{{ iam_settings.authorize_url }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_token_url">{{ lang.admin.iam_token_url }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_token_url" name="token_url" value="{{ iam_settings.token_url }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_userinfo_url">{{ lang.admin.iam_userinfo_url }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_userinfo_url" name="userinfo_url" value="{{ iam_settings.userinfo_url }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_client_id">{{ lang.admin.iam_client_id }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_client_id" name="client_id" value="{{ iam_settings.client_id }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_client_secret">{{ lang.admin.iam_client_secret }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="reveal-password-input input-group">
                <input type="password" class="password-field form-control" id="iam_client_secret" name="client_secret" value="{{ iam_settings.client_secret }}" required>
                <button class="toggle-password btn btn-secondary" type="button"><i class="bi bi-eye"></i></button>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_redirect_url }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="row px-2 align-items-center">
                <span class="col-10 p-0 pe-2">
                  <input type="text" class="form-control" name="redirect_url" value="{{ iam_settings.redirect_url }}" required>
                </span>
                <div class="col-2 p-0 d-flex">
                  <button class="btn btn-sm d-block d-sm-inline btn-secondary ms-auto iam_redirect_add_generic"><i class="bi bi-plus-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2" id="iam_generic_redirect_list">
            <input type="hidden" name="redirect_url_extra" value="">
            {% for key, url in iam_settings.redirect_url_extra %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-10 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="redirect_url_extra" value="{{ iam_settings.redirect_url_extra[key] }}">
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_generic_redirect_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
            {% endfor %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-10 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="redirect_url_extra" value="">
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_generic_redirect_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-4">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_client_scopes">{{ lang.admin.iam_client_scopes }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" placeholder="openid profile email mailcow_template" class="form-control" id="iam_client_scopes" name="client_scopes" value="{{ iam_settings.client_scopes }}">
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_mapping }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="row px-2 align-items-center">
                <span class="col-5 p-0 pe-2">{{ lang.user.attribute }}</span>
                <span class="col-5 p-0 pe-2">{{ lang.mailbox.template }}</span>
                <div class="col-2 p-0 d-flex">
                  <button class="btn btn-sm d-block d-sm-inline btn-secondary ms-auto iam_rolemap_add_generic"><i class="bi bi-plus-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2" id="iam_generic_mapping_list">
            <input type="hidden" name="mappers" value="">
            <input type="hidden" name="templates" value="">
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_default_template_description }}"></i>
                  <span>{{ lang.admin.iam_default_template}}</span>
                </div>
                <div class="col-5 p-0 pe-2 align-content-end">
                  <select data-live-search="true" name="default_template" class="form-control" title="-- {{ lang.mailbox.template }} --">
                  <option value="" {% if not iam_settings.default_template %}selected{% endif %}>-- {{ lang.mailbox.template }} --</option>
                  {% for mbox_template in mbox_templates %}
                    <option {% if mbox_template.template == iam_settings.default_template %}selected{% endif %}>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex"></div>
              </div>
            </div>
            {% for key, role in iam_settings.mappers %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="mappers" value="{{ iam_settings.mappers[key] }}" required>
                </div>
                <div class="col-5 p-0 pe-2">
                  <select data-live-search="true" name="templates" class="form-control" title="-- {{ lang.mailbox.template }} --" required>
                  {% for mbox_template in mbox_templates %}
                    <option{% if mbox_template.template == iam_settings.templates[key] %} selected{% endif %}>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_generic_rolemap_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
            {% endfor %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="mappers" value="">
                </div>
                <div class="col-5 p-0 pe-2">
                  <select data-live-search="true" name="templates" class="form-control" title="-- {{ lang.mailbox.template }} --">
                  <option value="" selected>-- {{ lang.mailbox.template }} --</option>
                  {% for mbox_template in mbox_templates %}
                    <option>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_generic_rolemap_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.ignore_ssl_error }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="ignore_ssl_error" value="1" {% if iam_settings.ignore_ssl_error == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-4">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_login_provisioning }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="login_provisioning"  value="1" {% if iam_settings.login_provisioning == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mt-4 mb-2">
            <div class="offset-md-3 col-12 col-md-9 d-flex flex-wrap">
              <div class="btn-group mb-2">
                <button class="btn btn-sm d-block d-sm-inline btn-secondary iam_test_connection" data-id="iam_generic"><i class="bi bi-play"></i> {{ lang.admin.iam_test_connection }}</button>
                <button class="btn btn-sm d-block d-sm-inline btn-success" data-item="identity-provider" data-action="edit_selected" data-id="iam_generic" data-api-url='edit/identity-provider' data-api-attr='{}'><i class="bi bi-check-lg"></i> {{ lang.admin.save }}</button>
              </div>
              <button class="btn btn-sm d-block d-sm-inline btn-danger ms-auto mb-2" data-item="identity-provider" data-action="delete_selected" data-id="iam_generic" data-api-url='delete/identity-provider'><i class="bi bi-trash"></i> {{ lang.mailbox.remove }}</button>
            </div>
          </div>
        </form>
      </div>
      <div id="ldap_settings" class="{% if not iam_settings.authsource or iam_settings.authsource != 'ldap' %}d-none{% endif %}">
        <form class="form-horizontal" autocapitalize="none" data-id="iam_ldap" autocorrect="off" role="form" method="post">
          <input type="hidden" name="authsource" value="ldap">
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill mx-2 ms-0" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_host_info }}"></i>
              <label class="control-label" for="iam_ldap_host">{{ lang.admin.iam_host }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4 d-flex">
              <input type="text" class="form-control" id="iam_ldap_host" name="host" value="{{ iam_settings.host }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_ldap_port">{{ lang.admin.iam_port }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="number" class="form-control" id="iam_ldap_port" name="port" value="{{ iam_settings.port }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill mx-2 ms-0" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_use_ssl_info }}"></i>
              <label class="control-label">{{ lang.admin.iam_use_ssl }}</label>
            </div>
            <div class="col-12 col-md-9 d-flex align-items-center">
              <div class="form-check form-switch">
                <input class="form-check-input"
                       type="checkbox"
                       role="switch"
                       id="use_ssl"
                       name="use_ssl"
                       value="1"
                       onchange="if(this.checked) document.getElementById('use_tls').checked = false"
                       {% if iam_settings.use_ssl == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill mx-2 ms-0" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_use_tls_info }}"></i>
              <label class="control-label">{{ lang.admin.iam_use_tls }}</label>
            </div>
            <div class="col-12 col-md-9 d-flex align-items-center">
              <div class="form-check form-switch">
                <input class="form-check-input"
                       type="checkbox"
                       role="switch"
                       id="use_tls"
                       name="use_tls"
                       value="1"
                       onchange="if(this.checked) document.getElementById('use_ssl').checked = false"
                       {% if iam_settings.use_tls == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-4">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.ignore_ssl_error }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="ignore_ssl_error" value="1" {% if iam_settings.ignore_ssl_error == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_ldap_basedn">{{ lang.admin.iam_basedn }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_ldap_basedn" name="basedn" value="{{ iam_settings.basedn }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_ldap_username_field">{{ lang.admin.iam_username_field }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" placeholder="mail" id="iam_ldap_username_field" name="username_field" value="{{ iam_settings.username_field }}">
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_ldap_filter">{{ lang.admin.filter }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" placeholder="" id="iam_ldap_filter" name="filter" value="{{ iam_settings.filter }}">
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_ldap_attribute_field">{{ lang.admin.iam_attribute_field }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_ldap_attribute_field" name="attribute_field" value="{{ iam_settings.attribute_field }}" required>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_ldap_binddn">{{ lang.admin.iam_binddn }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input type="text" class="form-control" id="iam_ldap_binddn" name="binddn" value="{{ iam_settings.binddn }}" required>
            </div>
          </div>
          <div class="row mb-4">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label" for="iam_ldap_bindpass">{{ lang.admin.iam_bindpass }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="reveal-password-input input-group">
                <input type="password" class="password-field form-control" id="iam_ldap_bindpass" name="bindpass" value="{{ iam_settings.bindpass }}" required>
                <button class="toggle-password btn btn-secondary" type="button"><i class="bi bi-eye"></i></button>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_mapping }}:</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <div class="row px-2 align-items-center">
                <span class="col-5 p-0 pe-2">{{ lang.user.attribute }}</span>
                <span class="col-5 p-0 pe-2">{{ lang.mailbox.template }}</span>
                <div class="col-2 p-0 d-flex">
                  <button class="btn btn-sm d-block d-sm-inline btn-secondary ms-auto iam_rolemap_add_ldap"><i class="bi bi-plus-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2" id="iam_ldap_mapping_list">
            <input type="hidden" name="mappers" value="">
            <input type="hidden" name="templates" value="">
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <i style="font-size: 16px; cursor: pointer;" class="bi bi-patch-question-fill" data-bs-toggle="tooltip" data-bs-html="true" data-bs-placement="bottom" title="{{ lang.admin.iam_default_template_description }}"></i>
                  <span>{{ lang.admin.iam_default_template }}</span>
                </div>
                <div class="col-5 p-0 pe-2 align-content-end">
                  <select data-live-search="true" name="default_template" class="form-control" title="-- {{ lang.mailbox.template }} --">
                  <option value="" {% if not iam_settings.default_template %}selected{% endif %}>-- {{ lang.mailbox.template }} --</option>
                  {% for mbox_template in mbox_templates %}
                    <option {% if mbox_template.template == iam_settings.default_template %}selected{% endif %}>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex"></div>
              </div>
            </div>
            {% for key, role in iam_settings.mappers %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="mappers" value="{{ iam_settings.mappers[key] }}" required>
                </div>
                <div class="col-5 p-0 pe-2">
                  <select data-live-search="true" name="templates" class="form-control" title="-- {{ lang.mailbox.template }} --" required>
                  {% for mbox_template in mbox_templates %}
                    <option{% if mbox_template.template == iam_settings.templates[key] %} selected{% endif %}>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_ldap_rolemap_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
            {% endfor %}
            <div class="offset-md-3 col-12 col-md-9 col-lg-4 mb-2">
              <div class="row px-2">
                <div class="col-5 p-0 pe-2">
                  <input type="text" class="form-control me-2" name="mappers" value="">
                </div>
                <div class="col-5 p-0 pe-2">
                  <select data-live-search="true" name="templates" class="form-control" title="-- {{ lang.mailbox.template }} --">
                  <option value="" selected>-- {{ lang.mailbox.template }} --</option>
                  {% for mbox_template in mbox_templates %}
                    <option>
                      {{ mbox_template.template }}
                    </option>
                  {% endfor %}
                  </select>
                </div>
                <div class="col-2 p-0 d-flex">
                  <button class="iam_ldap_rolemap_del btn btn-sm d-block d-sm-inline btn-secondary ms-auto"><i class="bi bi-x-lg"></i></button>
                </div>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_login_provisioning }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="login_provisioning"  value="1" {% if iam_settings.login_provisioning == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_periodic_full_sync }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="periodic_sync"  value="1" {% if iam_settings.periodic_sync == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_import_users }}</label>
            </div>
            <div class="col-12 col-md-9">
              <div class="form-check form-switch">
                <input class="form-check-input" type="checkbox" role="switch" name="import_users"  value="1" {% if iam_settings.import_users == 1 %}checked{% endif %}>
              </div>
            </div>
          </div>
          <div class="row mb-2">
            <div class="col-md-3 d-flex align-items-center justify-content-md-end">
              <label class="control-label">{{ lang.admin.iam_sync_interval }}</label>
            </div>
            <div class="col-12 col-md-9 col-lg-4">
              <input class="form-control" type="number" min="1" name="sync_interval" style="width: 80px;"  {% if iam_settings.sync_interval %}value="{{ iam_settings.sync_interval }}"{% else %}value="15"{% endif %}>
            </div>
          </div>
          <div class="row mt-4 mb-2">
            <div class="offset-md-3 col-12 col-md-9 d-flex flex-wrap">
              <div class="btn-group mb-2">
                <button class="btn btn-sm d-block d-sm-inline btn-secondary iam_test_connection iam_test_connection" data-id="iam_ldap"><i class="bi bi-play"></i> {{ lang.admin.iam_test_connection }}</button>
                <button class="btn btn-sm d-block d-sm-inline btn-success" data-item="identity-provider" data-action="edit_selected" data-id="iam_ldap" data-api-url='edit/identity-provider' data-api-attr='{}'><i class="bi bi-check-lg"></i> {{ lang.admin.save }}</button>
              </div>
              <button class="btn btn-sm d-block d-sm-inline btn-danger ms-auto mb-2" data-item="identity-provider" data-action="delete_selected" data-id="iam_ldap" data-api-url='delete/identity-provider'><i class="bi bi-trash"></i> {{ lang.mailbox.remove }}</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
