{% extends "base.html" %}
{% load i18n %}
{% load bootstrap_icons %}

{% block title %}{% trans "Networks" %} - {{ compute.name }}{% endblock %}

{% block page_heading %}{{ compute.name }} - {% trans "Networks" %}{% endblock page_heading %}

{% block page_heading_extra %}{% include 'create_net_block.html' %}{% endblock page_heading_extra %}

{% block content %}
    <div class="row">
        <div class="col-lg-12">
            <nav aria-label="breadcrumb">
            <ol class="breadcrumb shadow-sm">
                <li class="breadcrumb-item">
                    <a href="{% url 'overview' compute.id %}">{% bs_icon 'laptop' %}  {% trans "Overview" %}</a>
                </li>
                <li class="breadcrumb-item">
                   <a href="{% url 'instances' compute.id %}">{% bs_icon 'server' %}  {% trans "Instances" %}</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="{% url 'storages' compute.id %}">{% bs_icon 'device-hdd' %}  {% trans "Storages" %}</a>
                </li>
                <li class="breadcrumb-item">
                    <span class="fw-bold">{% bs_icon 'hdd-network' %}  {% trans "Networks" %}</span>
                </li>
                <li class="breadcrumb-item">
                    <a href="{% url 'interfaces' compute.id %}">{% bs_icon 'wifi' %}  {% trans "Interfaces" %}</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="{% url 'nwfilters' compute.id %}">{% bs_icon 'filter' %}  {% trans "NWFilters" %}</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="{% url 'virtsecrets' compute.id %}">{% bs_icon 'key' %}  {% trans "Secrets" %}</a>
                </li>
            </ol>
            </nav>
        </div>
    </div>

    <div class="row">
        {% if not networks %}
            <div class="col-lg-12">
                <div class="alert alert-warning shadow-sm">
                    {% bs_icon 'exclamation-triangle' %} <strong>{% trans "Warning" %} :</strong> {% trans "Hypervisor doesn't have any Network" %}
                </div>
            </div>
        {% else %}
            {% for pool in networks %}
            <div class="col-6 col-md-4">
                <div class="mb-3 card {% if pool.status %}border-success{% else %}border-danger{% endif %} shadow-sm">
                    <div class="card-header {% if pool.status %}bg-success{% else %}bg-danger{% endif %}">
                        <h6 class="my-0 card-title">
                            <a class="card-link text-light" href="{% url 'network' compute.id pool.name %}">{{ pool.name }}</a></h6>
                    </div>
                    <div class="px-1 card-body">
                        <dl class="row">
                            <dt class="col-6">{% trans "Device" %}</dt>
                            <dd class="col-6">{{ pool.device }}</dd>
                            <dt class="col-6">{% trans "Forward" %}</dt>
                            <dd class="col-6">{{ pool.forward|upper }}</dd>
                        </dl>
                    </div>
                </div>
            </div>
            {% endfor %}
        {% endif %}
    </div>
{% endblock %}
{% block script %}
<script>
    $(document).ready(function () {
        $('#forward_select').change(function (eventObject) {
            if ($(this).val() == 'bridge') {
                $('.bridge_name_form_group').show();
                $('.bridge_name_form_group_dhcp').hide();
            } else if ($(this).val() == 'macvtap') {
                $('#bridge_label').text("Dev Name");
                $('#bridge_name').attr("placeholder", "eth0");
                $('.bridge_name_form_group').show();
                $('.bridge_name_form_group_dhcp').hide();
                $('.openvswitch').hide();
            } else {
                $('.bridge_name_form_group').hide();
                $('.bridge_name_form_group_dhcp').show();
            }
        }).change();

        $('#enable_ipv6').change(function (eventObject) {
            if ($(this).is(':checked')) {
                $('.ipv6_group').show();
            } else {
                $('.ipv6_group').hide();
            }
        }).change();
    });
</script>
{% endblock %}