<!--
 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>Service {{ service.service_id.service_uuid.uuid }}</h1>

    <div class="row mb-3">
        <div class="col-sm-3">
            <button type="button" class="btn btn-success" onclick="window.location.href='{{ url_for('service.home') }}'">
                <i class="bi bi-box-arrow-in-left"></i>
                Back to service list
            </button>
        </div>
        <div class="col-sm-3">
            <a id="update" class="btn btn-secondary" href="#">
                <i class="bi bi-pencil-square"></i>
                Update
            </a>
        </div>
        <div class="col-sm-3">
            <!-- <button type="button" class="btn btn-danger"><i class="bi bi-x-square"></i>Delete service</button> -->
            <button type="button" class="btn btn-danger" data-bs-toggle="modal" data-bs-target="#deleteModal">
                <i class="bi bi-x-square"></i>Delete service
              </button>
        </div>
    </div>

    <div class="row mb-3">
        <div class="col-sm-1"><b>UUID:</b></div>
        <div class="col-sm-5">
            {{ service.service_id.service_uuid.uuid }}
        </div>
        <div class="col-sm-1"><b>Type:</b></div>
        <div class="col-sm-5">
            {{ service.service_type }}
        </div>
    </div>
    <div class="row mb-3">
        <b>Endpoints:</b>
        <div class="col-sm-10">
            <ul>
            {% for endpoint in service.service_endpoint_ids %}
                <li>{{ endpoint.endpoint_uuid.uuid }}: {{ endpoint.endpoint_type }}</li>
            {% endfor %}
            </ul>
        </div>
    </div>
    <div class="row mb-3">
        <b>Configurations:</b>
        <div class="col-sm-10">
            <ul>
            {% for config in service.service_config.config_rules %}
                <li>{{ config.resource_key }}:
                    <ul>
                        {% for key, value in (config.resource_value | from_json).items() %}
                        <li><b>{{ key }}:</b> {{ value }}</li>
                        {% endfor %}
                    </ul>
                </li>
            {% endfor %}
            </ul>
        </div>
    </div>

    <!-- Modal -->
<div class="modal fade" id="deleteModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="staticBackdropLabel">Delete service?</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body">
          Are you sure you want to delete the service "{{ service.service_id.service_uuid.uuid }}"?
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">No</button>
          <a type="button" class="btn btn-danger" href="{{ url_for('service.delete', service_uuid=service.service_id.service_uuid.uuid) }}"><i class="bi bi-exclamation-diamond"></i>Yes</a>
        </div>
      </div>
    </div>
  </div>

{% endblock %}