<!--
 Copyright 2022-2023 ETSI TeraFlowSDN - TFS OSG (https://tfs.etsi.org/)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
{% extends 'base.html' %}
<style>
    .dashed-table {
        border-collapse: collapse;
    }
    .dashed-table td, .dashed-table th {
        border: 1px dashed black !important;
    }
</style>
{% block content %}
    <h1>Label Switched Paths Database (LSPDB)</h1>
    <br>

    {% if lspdb %}
        <table class="dashed-table" border="1">
            <thead>
                <tr>
                    <th>LSP UUID</th>
                    <th>SRP</th>
                    <th>LSP</th>
                    <th>Path</th>
                    <th>Association List</th>
                </tr>
            </thead>
            <tbody>
                {% for lsp in lspdb %}
                    <tr>
                        <td>{{ lsp.lsp_uuid }}</td>
                        <td>{{ lsp.srp }}</td>
                        <td>
                            <details>
                                <summary>{{ lsp.lsp.split('[')[1].split(']')[0].split(',')[0] }}</summary>
                                <div>
                                    {% set before_lsp_identifiers = lsp.lsp[5:].split('lspIdentifiers_tlv=')[0] %}{# Remove "LSP [" from the beginning #}
                                    {% for subfield in before_lsp_identifiers.split(',') %}
                                        <div>{{ subfield }}</div>
                                    {% endfor %}
                                    {% set lsp_content = lsp.lsp[:-1].split('IPv4LSPIdentifiersTLV ')[1] %}
                                    <div>lspIdentifiers_tlv=IPv4LSPIdentifiersTLV:</div>
                                    {% for subfield in lsp_content.split(',') %}
                                        <div>{{ subfield }}</div>
                                    {% endfor %}
                                </div>
                            </details>
                        </td>
                        <td>
                            <details>
                                <summary>{{ lsp.path.split('[')[1].split(']')[0].split(',')[0] }}</summary>
                                <div>
                                    {% set path_content = lsp.path[6:-1] %} {# Remove "Path [" from the beginning and "]" from the end #}
                                    {% for subfield in path_content.split(',') %}
                                        <div>{{ subfield }}</div>
                                    {% endfor %}
                                </div>
                            </details>
                        </td>
                        <td>
                            <details>
                                <summary>Association List</summary>
                                <div>{{ lsp.associationlist }}</div>
                            </details>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>No LSP data available.</p>
    {% endif %}
{% endblock %}
<style>
    .dashed-table td, .dashed-table th {
        border-right: 1px dashed black;
    }
    
    .dashed-table td:last-child, .dashed-table th:last-child {
        border-right: none;
    }
</style>