{% extends "shared/frontend/base.html" %}

{% block title %}Kundehardware - BMC Hub{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-4">
    <h1 class="h3 mb-0">Kundehardware</h1>
    <div class="d-flex gap-2">
        <a href="/hardware" class="btn btn-outline-secondary btn-sm">BMC Assets</a>
        <a href="/hardware/new" class="btn btn-primary btn-sm">Nyt Hardware</a>
    </div>
</div>

<div class="card mb-3">
    <div class="card-body">
        <form method="get" action="/hardware/customers" class="row g-3 align-items-end">
            <div class="col-12 col-md-3">
                <label for="asset_type" class="form-label">Type</label>
                <select name="asset_type" id="asset_type" class="form-select form-select-sm">
                    <option value="">Alle typer</option>
                    <option value="pc" {% if current_asset_type == 'pc' %}selected{% endif %}>PC</option>
                    <option value="laptop" {% if current_asset_type == 'laptop' %}selected{% endif %}>Laptop</option>
                    <option value="printer" {% if current_asset_type == 'printer' %}selected{% endif %}>Printer</option>
                    <option value="skærm" {% if current_asset_type == 'skærm' %}selected{% endif %}>Skærm</option>
                    <option value="telefon" {% if current_asset_type == 'telefon' %}selected{% endif %}>Telefon</option>
                    <option value="server" {% if current_asset_type == 'server' %}selected{% endif %}>Server</option>
                    <option value="netværk" {% if current_asset_type == 'netværk' %}selected{% endif %}>Netværk</option>
                    <option value="andet" {% if current_asset_type == 'andet' %}selected{% endif %}>Andet</option>
                </select>
            </div>
            <div class="col-12 col-md-3">
                <label for="status" class="form-label">Status</label>
                <select name="status" id="status" class="form-select form-select-sm">
                    <option value="">Alle status</option>
                    <option value="active" {% if current_status == 'active' %}selected{% endif %}>Aktiv</option>
                    <option value="faulty_reported" {% if current_status == 'faulty_reported' %}selected{% endif %}>Fejl rapporteret</option>
                    <option value="in_repair" {% if current_status == 'in_repair' %}selected{% endif %}>Under reparation</option>
                    <option value="replaced" {% if current_status == 'replaced' %}selected{% endif %}>Udskiftet</option>
                    <option value="retired" {% if current_status == 'retired' %}selected{% endif %}>Udtjent</option>
                    <option value="unsupported" {% if current_status == 'unsupported' %}selected{% endif %}>Ikke supporteret</option>
                </select>
            </div>
            <div class="col-12 col-md-4">
                <label for="q" class="form-label">Søg</label>
                <input type="text" name="q" id="q" class="form-control form-control-sm" value="{{ search_query or '' }}" placeholder="Model, serial, kunde...">
            </div>
            <div class="col-12 col-md-2">
                <button type="submit" class="btn btn-primary btn-sm w-100">Filtrer</button>
            </div>
        </form>
    </div>
</div>

{% if hardware and hardware|length > 0 %}
<div class="card">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Hardware</th>
                        <th>Kunde</th>
                        <th>Type</th>
                        <th>Serienr.</th>
                        <th>Status</th>
                        <th>AnyDesk</th>
                        <th class="text-end">Handling</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in hardware %}
                    <tr>
                        <td class="fw-semibold">{{ item.brand or 'Unknown' }} {{ item.model or '' }}</td>
                        <td>{{ item.customer_name or 'Ukendt kunde' }}</td>
                        <td>{{ item.asset_type|title }}</td>
                        <td>{{ item.serial_number or 'Ingen serienummer' }}</td>
                        <td>{{ item.status|replace('_', ' ')|title }}</td>
                        <td>
                            {% if item.anydesk_link %}
                                <a href="{{ item.anydesk_link }}" target="_blank">{{ item.anydesk_id or 'Åbn' }}</a>
                            {% elif item.anydesk_id %}
                                <a href="anydesk://{{ item.anydesk_id }}" target="_blank">{{ item.anydesk_id }}</a>
                            {% else %}
                                —
                            {% endif %}
                        </td>
                        <td class="text-end">
                            <a href="/hardware/{{ item.id }}" class="btn btn-outline-secondary btn-sm">Se</a>
                            <a href="/hardware/{{ item.id }}/edit" class="btn btn-outline-primary btn-sm">Rediger</a>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% else %}
<div class="text-center py-5 text-muted">
    <h5>Ingen kundehardware fundet</h5>
    <p class="mb-0">Der er ingen kundeejede enheder, der matcher filtre.</p>
</div>
{% endif %}
{% endblock %}
