<div class="modal show fade" tabindex="-1" role="dialog" id="{{ modal_type }}-pool">
    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">{{ i18n(modal_type) }} {{ i18n("pools.pool_name." .. pool.name) }} {{ i18n("pools.pool") }}</h5>
                <div class="modal-close">
                    <div class="confirm-closing" style="display: none;">
                        <span class='mx-2' style="vertical-align: middle;"><b>{{ i18n("host_pools.validation.abort_"..modal_type.."_pool") }}</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 role="form">
                <div class="modal-body">
                    <div class="mb-3 row">
                        <label class="col-form-label col-sm-4" for="{{ modal_type }}-pool-name-input">
                            <b>{{ i18n("pools.name") }}</b>
                        </label>
                        <div class="col-sm-7">
                            <input placeholder="{{ i18n('pools.insert_name') }}" pattern=".*\S.*" maxlength="32" minlength="1" required name="name" type="text" class="form-control" id="{{ modal_type }}-pool-name-input">
                            <small class="text-muted form-text">
                                {{ i18n("pools.name_requirements") }}
                            </small>
                        </div>
                    </div>
                    {# the host pool modal doesn't have the members field #}
                    {% if (pool.name ~= "host") then %}
                    <div class="mb-3 row members-container" {* ((table.len(pool.all_members) > 0) and '' or 'style="display: none"') *}>
                        <label class="col-form-label col-sm-4" for="{{ modal_type }}-pool-members-input">
                            <b>{{ i18n("pools.members") }}</b>
                        </label>
                        <div class="col-sm-7">
                            <select class="selectpicker" multiple name="members" id="{{ modal_type }}-pool-members-select">
                                {%
                                    local sorting_order = nil
                                    if (pool.name == "snmp" or pool.name == "network") then
                                        sorting_order = ip_address_asc
                                    else
                                        sorting_order = asc
                                    end
                                %}
                                {% for key, member in pairsByKeys(pool.all_members, sorting_order) do %}

                                    {%
                                        -- If the name field is not set then use the key as the name
                                        -- for the pool member
                                        local name = member.name or key
                                    %}

                                    {# If a member is assigned then write who is using it and disable it #}
                                    {% if (pool.assigned_members[key] ~= nil) then %}
                                        <option data-pool-id="{{pool.assigned_members[key]['pool_id']}}" disabled value="{{key}}">
                                            {{ name }} ({{ pool.instance:get_pool(pool.assigned_members[key]["pool_id"]).name}})
                                        </option>
                                    {% else %}
                                        <option value="{{key}}">{{name}}</option>
                                    {% end %}
                                {% end %}
                            </select>

                        </div>
                    </div>
                    {% elseif (pool.name == "host" and modal_type == "edit") then %}
                    <div class="mb-3 row members-container">
                        <label class="col-form-label col-sm-4" for="{{ modal_type }}-pool-members-input">
                            {{ i18n("pools.members") }}
                        </label>
                        <label class="col-form-label col-sm-7">
                            <a id="edit-link" href="{{ ntop.getHttpPrefix() }}/lua/admin/manage_host_members.lua?pool=0"><i class="fas fa-edit"></i> {{ i18n("host_pools.edit_host_pool_member") }}</a>
                        </label>
                    </div>
                    {% end %}

                    <span class="invalid-feedback" id="{{ modal_type }}-modal-feedback"></span>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">
                        {% if modal_type == "add" then %}
                            {{ i18n("add") }}
                        {% else %}
                            {{ i18n("apply") }}
                        {% end %}
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
