{% extends "hosting/base_short.html" %}
{% load staticfiles bootstrap3 i18n %}
{% block content %}
<div class="dashboard-container">
    <div class="dashboard-container-head">
        <h3 class="dashboard-title-thin"><img src="{% static 'hosting/img/vm.svg' %}" class="un-icon"> {% trans "Virtual Machines" %}</h3>
        {% if messages %}
            <div class="alert alert-warning">
                {% for message in messages %}
                <span>{{ message }}</span>
                {% endfor %}
            </div>
        {% endif %}
        {% if not error %}
            <div class="dashboard-subtitle">
                <p>{% trans 'To create a new virtual machine, click "Create VM"' %}
                {% if show_create_ssh_key_msg %}
                     {% url 'hosting:create_ssh_key' as create_ssh_url %}
                     <br/>{% blocktrans %}To access your VM, <a href="{{create_ssh_url}}">add your SSH key here</a>{% endblocktrans %}
                {% endif %}
                </p>
                <div class="text-right">
                    <a class="btn btn-vm" href="{% url 'hosting:create_virtual_machine' %}"><span class="css-plus"></span> <span>{% trans "CREATE VM" %}</span></a>
                </div>
            </div>
        {% endif %}
    </div>

    {% if not error %}
        <table class="table table-switch">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>IPv4</th>
                    <th>IPv6</th>
                    <th>{% trans "Status" %}</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
                {% for vm in vms %}
                    <tr>
                        <td data-header="ID">{{vm.vm_id}}</td>
                        <td data-header="IPv4">{% if vm.ipv4 %}{{vm.ipv4}}{% endif %}</td>
                        <td data-header="IPv6">{% if vm.ipv6 %}{{vm.ipv6}}{% endif %}</td>
                        <td data-header="{% trans 'Status' %}">
                            <strong>
                                {% if vm.state == 'ACTIVE' %}
                                    <span class="vm-status-active">{{vm.state|title}}</span>
                                {% elif  vm.state == 'FAILED' %}
                                    <span class="vm-status-failed">{{vm.state|title}}</span>
                                {% else %}
                                    <span class="vm-status">{{vm.state|title}}</span>
                                {% endif %}
                            </strong>
                        </td>
                        <td class="text-right last-td">
                            <a class="btn btn-vm-detail" href="{% url 'hosting:virtual_machines' vm.vm_id %}">{% trans "View Detail" %}</a>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}

    {% if is_paginated %}
        <div class="pagination">
            <span class="page-links">
                {% if page_obj.has_previous %}
                    <a href="{{request.path}}?page={{ page_obj.previous_page_number }}">{% trans "previous" %}</a>
                {% endif %}
                <span class="page-current">
                    {% trans "Page" %} {{ page_obj.number }} {% trans "of" %} {{ page_obj.paginator.num_pages }}.
                </span>
                {% if page_obj.has_next %}
                    <a href="{{request.path}}?page={{ page_obj.next_page_number }}">{% trans "next" %}</a>
                {% endif %}
            </span>
        </div>
    {% endif %}
</div>
{%endblock%}
