{% extends "index.html" %}

{% block style %}
{% endblock %}

{% block tables %}
{#    <div class="container">#}
{#        <pre>Prefilter Policies: {{ prefilter_policy | tojson(indent=2) }}</pre>#}
{#    </div>#}
    <div class="container">
        <div class="container">
            <form action="{{ url_for('fmc_prefilter_download') }}" method="POST">
                <div class="mb-3">
                    <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>Rule Type</th>
                <th>Name</th>
                <th>Source Interface Objects</th>
                <th>Destination Interface Objects</th>
                <th>Source Networks</th>
                <th>Destination Networks</th>
                <th>Source Port</th>
                <th>Destination Port</th>
                <th>VLAN Tag</th>
                <th>Action</th>
                <th>Tunnel Zone</th>
                <th>Comments</th>
            </tr>
            {% for rule in rules %}
                <tr>
                    <td>{{ rule.get('ruleType') }}</td>
                    <td>{{ rule.get('name') }}</td>
                     <td>
                        {% for object in rule.get('sourceInterfaces', {'objects': [{'name': 'Any'}]}).get('objects', [{'name': 'Any'}]) %}
                           {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('destinationInterfaces', {'objects': [{'name': 'Any'}]}).get('objects', [{'name': 'Any'}]) %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('sourceNetworks', {'objects': [{'name': 'Any'}]}).get('objects', [{'type': 'Any', 'name': 'Any'}]) %}
                            {% if object.get('type') == 'NetworkGroup' %}
                                <u>{{ object.get('name') }}</u><br>
                                {% for network_group in network_group_list %}
                                    {{ network_group.get('objects', 'na') }}
                                {% endfor %}
                                <br>
                            {% else %}
                                {{ object.get('name') }}<br>
                            {% endif %}
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('destinationNetworks', {'objects': [{'name': 'Any'}]}).get('objects', [{'type': 'Any', 'name': 'Any'}]) %}
                            {% if object.get('type') == 'NetworkGroup' %}
                                <u>{{ object.get('name') }}</u><br>
                                {% for network_group in network_group_list %}
                                    {{ network_group.get('objects', 'na') }}
                                {% endfor %}
                                <br>
                            {% else %}
                                {{ object.get('name') }}<br>
                            {% endif %}
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('sourcePorts', {'objects': [{'name': 'Any'}]}).get('objects', [{'name': 'Any'}]) %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('destinationPorts', {'objects': [{'name': 'Any'}]}).get('objects', [{'name': 'Any'}]) %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('vlanTags', {'objects': [{'name': 'Any'}]}).get('objects', [{'name': 'Any'}]) %}
                            {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>

                    <td>{{ rule.get('action') }}</td>

                    <td>
                        {% for object in rule.get('tunnelZone', {'objects': [{'name': 'Any'}]}).get('objects', [{'name': 'Any'}]) %}
                                {{ object.get('name') }}<br>
                        {% endfor %}
                    </td>
                    <td>
                        {% for object in rule.get('commentHistoryList', {'comment': '-'}) %}
                            {% if object is not string %}
                                {{ object.get('comment') }}<br>
                            {% else %}
                                -
                            {% endif %}
                        {% endfor %}

{#                        {{ rule.get('commentHistoryList', "-") }}#}
{#                        {% for object in rule.get('comments', {'urlCategoriesWithReputation': [{'category': {'name': '-'}}]}).get('category', [{'name': '-'}]) %}#}
{#                            {{ object.get('name') }}<br>#}
{#                        {% endfor %}#}
                    </td>
                </tr>
            {% endfor %}
        </table>
    </div>
{#    <br>#}
{#    <div class="container">#}
{#        <pre>{{ rules | tojson(indent=2) }}</pre>#}
{#    </div>#}

{% endblock %}
