{% extends "index.html" %}

{% block style %}
{% endblock %}

{% block tables %}
{#    <div class="container">#}
{#        <pre>Access Policies: {{ access_policy | tojson(indent=2) }}</pre>#}
{#    </div>#}
    <div class="container">
        <div class="container">
            <form action="{{ url_for('fmc_download') }}" method="POST">
                <div class="mb-3">
                    <input type="hidden" name="current_access_list" value="{{ current_access_list }}">
                    <input type="hidden" name="access_lists" value="{{ current_access_list_id }}">
                    <input type="hidden" name="network_group_list" value="{{ network_group_list }}">
                    <label class="form-label" for="download" id="current_access_list">Access List: {{ current_access_list }}</label><br>
                    <input class="btn btn-primary" type="submit" id="download" name="download" value="Download">
                </div>
            </form>
        </div>
        <table class="table table-striped-columns">
            <tr>
                <th>Action</th>
                <th>Name</th>
                <th>Source Zones</th>
                <th>Destination Zones</th>
                <th>Source Networks</th>
                <th>Destination Networks</th>
                <th>Source Ports</th>
                <th>Destination Ports</th>
                <th>Source Security Group Tags</th>
                <th>Applications</th>
            </tr>
            {% for rule in rules %}
                <tr>
                    <td>{{ rule.get('action') }}</td>
                    <td>{{ rule.get('name') }}</td>
                     <td>
                        {% for object in rule.get('sourceZones', {'objects': [{'name': '-'}]}).get('objects') %}
                           {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('destinationZones', {'objects': [{'name': '-'}]}).get('objects') %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('sourceNetworks', {'objects': [{'name': '-'}]}).get('objects') %}
                            {% if object.get('type') == 'NetworkGroup' %}
                                <u>{{ object.get('name') }}</u><br>
                                {% for network_group in network_group_list %}
                                    {{ network_group.get('objects') }}
                                {% endfor %}
                                <br>
                            {% else %}
                                {{ object.get('name') }}<br>
                            {% endif %}
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('destinationNetworks', {'objects': [{'name': '-'}]}).get('objects') %}
                            {% if object.get('type') == 'NetworkGroup' %}
                                <u>{{ object.get('name') }}</u><br>
                                {% for network_group in network_group_list %}
                                    {{ network_group.get('objects') }}
                                {% endfor %}
                                <br>
                            {% else %}
                                {{ object.get('name') }}<br>
                            {% endif %}
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('sourcePorts', {'objects': [{'name': '-'}]}).get('objects') %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('destinationPorts', {'objects': [{'name': '-'}]}).get('objects') %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('sourceSecurityGroupTags', {'objects': [{'name': '-'}]}).get('objects') %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('applications', {'applications': [{'name': '-'}]}).get('applications') %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                </tr>
            {% endfor %}
        </table>
    </div>
{#    <br>#}
{#    <div class="container">#}
{#        <pre>{{ rules | tojson(indent=2) }}</pre>#}
{#    </div>#}

{% endblock %}
