<!--
 Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)

 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' %}

{% block content %}
    <h1>TeraFlow OS SDN Controller</h1>

    {% for field, message in context_form.errors.items() %}
        <div class="alert alert-dismissible fade show" role="alert">
        <b>{{ field }}</b>: {{ message }}
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>

    {% endfor %}

    <form id="select_context" method="POST" enctype="multipart/form-data">
        {{ context_form.hidden_tag() }}
        <fieldset class="form-group">
            <legend>Select the working context, or upload a JSON descriptors file</legend>
            <div class="row mb-3">
                {{ context_form.context.label(class="col-sm-1 col-form-label") }}
                <div class="col-sm-5">
                    {% if context_form.context.errors %}
                        {{ context_form.context(class="form-select is-invalid") }}
                        <div class="invalid-feedback">
                            {% for error in context_form.context.errors %}
                                <span>{{ error }}</span>
                            {% endfor %}
                        </div>
                    {% else %}
                        {{ context_form.context(class="form-select") }}
                    {% endif %}
                </div>
                <div class="col-sm-2">
                    {{ context_form.submit(class='btn btn-primary') }}
                </div>
            </div>
        </fieldset>
    </form>

    <form id="select_context" method="POST" enctype="multipart/form-data">
        {{ context_form.hidden_tag() }}
        <fieldset class="form-group">
            <legend>Upload a JSON descriptors file</legend>
            <div class="row mb-3">
                {{ descriptor_form.descriptors.label(class="col-sm-1 col-form-label") }}
                <div class="col-sm-5">
                    {% if descriptor_form.descriptors.errors %}
                        {{ descriptor_form.descriptors(class="form-control is-invalid") }}
                        <div class="invalid-feedback">
                            {% for error in descriptor_form.descriptors.errors %}
                                <span>{{ error }}</span>
                            {% endfor %}
                        </div>
                    {% else %}
                        {{ descriptor_form.descriptors(class="form-control") }}
                    {% endif %}
                </div>
                <div class="col-sm-2">
                    {{ descriptor_form.submit(class='btn btn-primary') }}
                </div>
            </div>
        </fieldset>
    </form>

    <script src="https://d3js.org/d3.v4.min.js"></script>
    <div id="topology"></div>
    <script src="{{ url_for('static', filename='topology.js') }}"></script>

{% endblock %}
