<div class="modal fade" id="add-recipient-modal" tabindex="-1" role="dialog" aria-labelledby="add-endpoint-modal-title"
    aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="add-recipient-modal-title">{{ i18n("endpoint_notifications.add_new_recipient") }}</h5>
                <div class="modal-close">
                    <div class="confirm-closing" style="display: none;">
                        <span class='mx-2' style="vertical-align: middle;"><b>{{ i18n("endpoint_notifications.validation.abort_add_recipient") }}</b></span>
                        <div class="btn-group btn-group-sm">
                            <button class="btn btn-secondary cancel" type="button">{{ i18n("cancel") }}</button>
                            <button data-bs-dismiss="modal" class="btn btn-danger confirm" type="button">{{ i18n("abort") }}</button>
                        </div>
                    </div>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
            </div>
            <form autocomplete="off">
                <div class="modal-body">
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-3" for="recipient-name-input">
                            <b>{{ i18n("endpoint_notifications.recipient_name") }}</b>
                        </label>
                        <div class="col-sm-7">
                            <input minlength="1" required name="recipient_name" type="text" class="form-control" id="recipient-name-input">
                        </div>
                    </div>
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-3" for="recipient-type-select">
                            <b>{{ i18n("endpoint_notifications.recipient_select") }}</b>
                        </label>
                        <div class="col-sm-7">
                            <select required name="endpoint" class="form-select" id="endpoint-select">
                                {% for i, endpoint in ipairs(endpoint_list) do %}
                    {% if not endpoint.endpoint_conf.builtin then %}
                                        <option {{ (i == 1 and "selected" or "") }} data-endpoint-key="{{ endpoint.endpoint_key }}" value="{{ endpoint.endpoint_id }}">
                                            {{ endpoint.endpoint_conf_name }}
                                        </option>
                    {% end %}
                                {% end %}
                            </select>
                        </div>
                    </div>
                    <div class="recipient-template-container" id="recipient-template-container-add-id" style="display: none;">

                    </div>
                    <hr>
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-3" for="add-recipient-notifications-type">
                            <b>{{ i18n("endpoint_notifications.notifications_type") }}</b>
                        </label>
                        <div class="col-sm-7">
                            <select required name="recipient_notifications_type" class="form-select" id="add-recipient-notifications-type">
                                {% for id, notification_info in pairsByField(notification_types, 'title', asc) do %}
                                    <option {{ternary((id == alerts), 'selected', '')}} value="{{ id }}">{{ notification_info.title }}</option>
                                {% end %}
                            </select>
                            <small>{{ i18n('endpoint_notifications.notifications_type_notes') }}</small>
                        </div>
                    </div>
                    <div id="alert_filters">
                        <hr>
                        <div class="mb-3 row">
                            <label class="col-form-label col-sm-3" for="advanced-view">
                                <b>{{ i18n("prefs.advanced_view") }}</b>
                            </label>
                            <div class="col-sm-7">
                                <div class="form-check form-switch mt-2" id="advanced-view">
                                    <input name="show_advanced_prefs"  class="form-check-input" type="checkbox" role="switch">
                                </div>
                            </div>
                        </div>
                        <hr>
                        <div class="mb-3 row">
                            <label class="col-form-label col-sm-3" for="add-recipient-silence-alerts">
                                <b>{{ i18n("endpoint_notifications.silence_multiple_alerts") }}</b>
                            </label>
                            <div class="col-sm-7">
                                <div class="form-check form-switch mt-2" id="add-recipient-silence-alerts">
                                    <input name="recipient_silence_alerts"  class="form-check-input" type="checkbox" role="switch" checked>
                                </div>
                                <div><small>{{ i18n('endpoint_notifications.silence_multiple_alerts_notes') }}</small></div>
                            </div>
                        </div>
                        <div class="mb-3 row advanced-pref" hidden>
                            <label class="col-form-label col-sm-3">
                                <b>{{ i18n("filter_alerts_by") }}</b>
                            </label>
                            <div class="col-sm-7">
                                <div class=" btn-group" role="group">
                                    <input type="radio" class="btn-check" name="options" id="generic_tab" autocomplete="off" checked />
                                    <label class="btn btn-primary" for="generic_tab">{{ i18n('filter_per_properties') }}</label>

                                    <input type="radio" class="btn-check" name="options" id="per_alerts_tab" autocomplete="off" />
                                    <label class="btn btn-secondary" for="per_alerts_tab">{{ i18n('filter_per_alerts') }}</label>
                                </div>
                                <div><small>{{ i18n('endpoint_notifications.alerts_filter_type') }}</small></div>
                            </div>
                        </div>
                        <div id="generic_recipient">
                            <div class="mb-3 row">
                                <label class="col-form-label col-sm-3" for="recipient-severity-select">
                                    <b>{{ i18n("endpoint_notifications.recipient_severity") }}</b>
                                </label>
                                <div class="col-sm-7">
                                    <select required name="recipient_minimum_severity" class="form-select" id="recipient-severity-select">
                                        {% for key, alert in pairsByField(alert_severities, 'severity_id', asc) do %}
                        {% if alert.severity_id ~= 0 then %}
                                            <option {{ (alert.severity_id == 0 and 'selected' or '') }} value="{{ alert.severity_id }}">{{ i18n("endpoint_notifications.severities."..key) }}</option>
                        {% end %}
                                        {% end %}
                                    </select>
                                    <small>{{ i18n('endpoint_notifications.min_severity_note') }}</small>
                            </div>
                            </div>
                            <div class="mb-3 row advanced-pref" hidden>
                                <label class="col-form-label col-sm-3" for="add-recipient-categories-select">
                                    <b>{{ i18n("endpoint_notifications.recipient_category") }}</b>
                                </label>
                                <div class="col-sm-7">
                                    <select multiple name="recipient_check_categories" class="selectpicker col-sm-12" id="add-recipient-categories-select">
                                        {% for _, category in pairsByKeys(check_categories) do %}
                                            <option selected value="{{ category.id }}">{{ i18n(category.i18n_title) }}</option>
                                        {% end %}
                                    </select>
                                    <small>{{ i18n('endpoint_notifications.category_note') }}</small>
                                </div>
                            </div>
                            <div class="mb-3 row">
                                <label class="col-form-label col-sm-3" for="add-recipient-entities-select">
                                    <b>{{ i18n("endpoint_notifications.recipient_entities") }}</b>
                                </label>
                                <div class="col-sm-7">
                                    <select multiple name="recipient_check_entities" class="selectpicker col-sm-12" id="add-recipient-entities-select">
                                        {% for _, entity_info in pairsByKeys(check_entities) do %}
                                            <option value="{{ entity_info.entity_id }}">{{ i18n(entity_info.i18n_label) }}</option>
                                        {% end %}
                                    </select>
                                    <small>{{ i18n('endpoint_notifications.entity_note') }}</small>
                                </div>
                            </div>
                        </div>
                        <div id="per_alerts_recipient" hidden>
                            <div class="mb-3 row advanced-pref">
                                <label class="col-form-label col-sm-3" for="add_recipient_alert_select">
                                    <b>{{ i18n("endpoint_notifications.alerts") }}</b>
                                </label>
                                <div class="col-sm-7">
                                    <div>
                                        <select multiple name="recipient_alerts" class="select2 form-select" id="add_recipient_alert_select">
                                            {% for _, entities in pairsByField(checks, "entity_name", asc) do 
                                                if not table.empty(entities.alert_list) then
                                            %}
                                                <optgroup label="{{ entities.entity_name }}">
                                                {%  for _, alert in pairs(entities.alert_list) do %}
                                                <option value="{{ alert.key .. '_' .. alert.entity_id }}">{{ alert.title }}</option>
                                                {% end %}
                                                </optgroup>
                                                {%
                                                end
                                            end 
                                            %}
                                        </select>
                                    </div>
                                    <div>
                                        <small>{{ i18n('endpoint_notifications.alert_select_note') }}</small>
                                    </div>
                                </div>
                            </div>                            
                        </div>
                        <div class="mb-3 row advanced-pref" hidden>
                            <label class="col-form-label col-sm-3" for="add-recipient-host-pools-select">
                                <b>{{ i18n("host_pools.host_pools") }}</b>
                            </label>
                            <div class="col-sm-7">
                                <select multiple name="recipient_host_pools" class="selectpicker allow-no-selection col-sm-12" id="add-recipient-host-pools-select">
                                    {% for _, pool in pairsByField(pools.host_pools, "name", asc) do %}
                                        <option selected value="{{ pool.pool_id }}">{{ pool.name }}</option>
                                    {% end %}
                                </select>
                                <small>{{ i18n('endpoint_notifications.message_host_pools') }}</small>
                            </div>
                        </div>
                        <div class="mb-3 row advanced-pref" hidden>
                            <label class="col-form-label col-sm-3" for="add-recipient-am-hosts-select">
                                <b>{{ i18n("active_monitoring_stats.active_monitoring") }}</b>
                            </label>
                            <div class="col-sm-7">
                                <select multiple name="recipient_am_hosts" class="selectpicker allow-no-selection col-sm-12" id="add-recipient-am-hosts-select">
                                    {% for _, host in pairsByField(am_hosts, "name", asc) do %}
                                        <option selected value="{{ host.id }}">{{ host.name }}</option>
                                    {% end %}
                                </select>
                                <small>{{ i18n('endpoint_notifications.message_am_hosts') }}</small>
                            </div>
                        </div>

                    </div>
                    <span class="invalid-feedback"></span>
                </div>
                <div class="modal-footer">
                    <div class="me-auto">
                        <button disabled id="add-test-recipient" type="test" class="btn btn-secondary">
                            <span style="display: none;" class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
                            {{ i18n("endpoint_notifications.test_recipient") }}
                        </button>
                    </div>
                    <button type="submit" class="btn btn-primary">{{i18n("add")}}</button>
                    <div class="alert alert-info test-feedback w-100" style="display: none;">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
