{#
    (C) 2020 - ntop.org

    This is the template to generate the page to Manage Host Pool Members.
#}
{%
    local selected_pool_name
    local selected_pool_id
%}
{% if (pool:get_num_pools() > 1) then %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="card card-shadow">
            <div class="card-header">
                <div class="row">
                    <div class="col-4">
                        <div class="form-group">
                            <label>{* i18n("host_pools.select_host_pool") *}</label>
                            <div class="d-flex">
                                <select id="select-host-pool" class="form-control">
                                    {% for _, p in pairs(manage_host_members.all_pools) do %}
                                        {% if p.pool_id ~= pool.DEFAULT_POOL_ID then %}
                                            {% if (p.pool_id == tonumber(manage_host_members.pool_id_get)) then %}
                                                <option selected value="{{ p.pool_id }}">{{ p.name }}</option>
                                                {%
                                                    selected_pool_id = p.pool_id
                                                    selected_pool_name = p.name
                                                %}
                                            {% else %}
                                                <option value="{{ p.pool_id }}">{{ p.name }}</option>
                                            {% end %}
                                        {% end %}
                                    {% end %}
                                </select>
                                <a class="align-self-center edit-pool-link ml-2" href='{{ ntop.getHttpPrefix() }}/lua/admin/manage_pools.lua?pool=host&pool_id={{selected_pool_id}}'>
                                    <i class="fas fa-edit"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table id="host-members-table" class="table table-bordered table-striped w-100">
                        <thead>
                            <tr>
                                <th>{{ i18n("host_pools.member_address") }}</th>
                                <th>{{ i18n("vlan") }}</th>
                                <th>{{ i18n("actions") }}</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% else %}

<div class="row">
    <div class="col-md-12">
        <div class="alert alert-info">
            {{i18n("host_pools.no_hosts_defined")}} <a href="{{ntop.getHttpPrefix()}}/lua/admin/manage_pools.lua?page=host"><i class="fas fa-edit" aria-hidden="true"></i></a>
        </div>
    </div>
</div>

{% end %}

{* template_utils.gen("pages/modals/pools/host_pool_member.template", {
    modal_type = "add",
    pool = pool,
}) *}
{* template_utils.gen("pages/modals/pools/remove_host_pool_member.template") *}

<link href="{{ ntop.getHttpPrefix() }}/datatables/datatables.min.css" rel="stylesheet"/>
<script type="text/javascript" src="{{ ntop.getHttpPrefix() }}/js/utils/datatable-ipsorting.js"></script>
<script type="text/javascript" src="{{ ntop.getHttpPrefix() }}/js/utils/datatable-macsorting.js"></script>
<script type="text/javascript">

    let addCsrf = "{{ ntop.getRandomCSRFValue() }}";
    let editCsrf = "{{ ntop.getRandomCSRFValue() }}";
    let removeCsrf = "{{ ntop.getRandomCSRFValue() }}";

    let queryPoolId = {{ manage_host_members.pool_id_get }};
    let selectedPool = { id: queryPoolId, name:  "{{selected_pool_name}}" };
    const defaultPoolId = {{ pool.DEFAULT_POOL_ID }};

    i18n.warning ="{{ i18n('warning', {}) }}";
    i18n.showing_x_to_y_rows = "{{ i18n('showing_x_to_y_rows', {x='_START_', y='_END_', tot='_TOTAL_'}) }}";
    i18n.search = "{{ i18n('search') }}";
    i18n.delete = "{{ i18n('delete') }}";
    i18n.edit = "{{ i18n('edit') }}";
    i18n.config = "{{ i18n('config') }}";
    i18n.all = "{{ i18n('all') }}";
    i18n.used_by = "{{ i18n('used_by') }}";
    i18n.member_type = "{{ i18n('host_pools.member_type') }}";
    i18n.ipv4 = "{{ i18n('host_pools.ipv4') }}";
    i18n.ipv6 = "{{ i18n('host_pools.ipv6') }}";
    i18n.mac_filter = "{{ i18n('host_pools.mac_filter') }}";

    i18n.rest = {
        INVALID_HOST: "{{ i18n('rest_consts.INVALID_HOST') }}",
        INVALID_ARGUMENTS: "{{ i18n('rest_consts.INVALID_ARGUMENTS') }}",
        NOT_GRANTED: "{{ i18n('rest_consts.NOT_GRANTED') }}",
        BIND_POOL_MEMBER_ALREADY_BOUND: "{{ i18n('rest_consts.BIND_POOL_MEMBER_ALREADY_BOUND') }}"
    };
</script>
<script src="{{ ntop.getHttpPrefix() }}/js/pages/pools/host-members.js" type="text/javascript">
</script>