{% extends "core/base.html" %}
{% block section_title %}{{ device }}{% endblock %}
{% block content %}
<div class="row">
    <div class="col">
    {% block device_details %}
        {% include "devices/device_details_block.html" %}
    {% endblock %}
    </div>

    <div class="col">
    {% block warranty %}
        {% include "devices/warranty_block.html" %}
    {% endblock %}
    </div>

    <div class="col">
    {% block ips %}
        {% include "devices/ip_block.html" %}
    {% endblock %}
    </div>
</div>

<div class="row">
{% if device.os or software_relations or backup_relations or license_list or device.host %}
    <div class="col">
        <div class="card mt-3">
            <div class="card-body">
                {% if device.host %}
                <h2>Host</h2>
                <ul>
                    <li><a href="{% url 'computer' device.host.id %}">{{ device.host }}</a></li>
                </ul>
                {% endif %}

                {% if device.os %}
                <h2>Operating System</h2>
                <ul>
                    <li>{{ device.os }}</li>
                </ul>
                {% endif %}

                {% if software_relations %}
                <h2>Software</h2>
                <ul>
                {% for relation in software_relations %}
                    <li>{{ relation.software }}</li>
                {% endfor %}
                </ul>
                {% endif %}

                {% if license_list %}
                {% block license %}
                    {% include "licenses/license_block.html" %}
                {% endblock %}
                {% endif %}

                {% if backup_relations %}
                <h2>Backup</h2>
                <ul>
                    {% for backup in backup_relations %}
                    <li><a href="{% url 'backup' backup.id %}">{{ backup }}</a></li>
                    {% endfor %}
                </ul>
                {% endif %}
            </div>
        </div>
    </div>
    {% endif %}

    {% if cpu_relations or gpu_relations or ram_relations or disks_relations or raid_disk_pairs %}
    <div class="col">
        <div class="card mt-3">
            <h2 class="card-header">Hardware</h2>
            <div class="card-body">
                {% if cpu_relations or gpu_relations or ram_relations or disks_relations or device.host %}
                <table class="table table-bordered">
                    {% if cpu_relations %}
                    <tr>
                        <td><b>CPUs:</b></td>
                        <td>
                        {% for cpu in cpu_relations %}
                            {{ cpu.amount }}x {{ cpu.cpu }}<br>
                        {% endfor %}
                        </td>
                    </tr>
                    {% endif %}

                    {% if gpu_relations %}
                    <tr>
                        <td><b>GPUs:</b></td>
                        <td>
                        {% for gpu in gpu_relations %}
                            {{ gpu.amount }}x {{ gpu.gpu }}<br>
                        {% endfor %}
                        </td>
                    </tr>
                    {% endif %}

                    {% if ram_relations %}
                    <tr>
                        <td><b>RAM Modules:</b></td>
                        <td>
                        {% for module in ram_relations %}
                            {{ module.amount }}x {{ module.ram }}<br>
                        {% endfor %}
                        </td>
                    </tr>
                    {% endif %}

                    {% if disks_relations %}
                    <tr>
                        <td><b>Disks:</b></td>
                        <td>
                        {% for disk in disks_relations %}
                            {{ disk.amount }}x {{ disk.disk }}<br>
                        {% endfor %}
                        </td>
                    </tr>
                    {% endif %}
                </table>
                {% endif %}

                {% if raid_disk_pairs %}
                <h3>RAID</h3>
                {% for raid, disks in raid_disk_pairs.items %}
                <table class="table table-bordered">
                    <tr>
                        <td><b>Type:</b></td>
                        <td>{{ raid.raid_type }}</td>
                    </tr>
                    <tr>
                        <td><b>Usable Space</b></td>
                        <td>{{ raid.usable_space }}</td>
                    </tr>
                    {% if disks %}
                    {% for disk in disks %}
                    <tr>
                        <td><b>Disk Type</b></td>
                        <td>{{ disk.disk }}</td>
                    </tr>
                    <tr>
                        <td><b>Amount</b></td>
                        <td>{{ disk.disk_amount }}</td>
                    </tr>
                    {% endfor %}
                    {% endif %}
                </table>
                {% endfor %}
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endif %}
{% endblock %}
