{% extends "base.html" %}

{% block title %}Kunde bearbeiten{% endblock %}

{% block content %}
<div class="container py-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>Kunde bearbeiten</h2>
        <div>
            <a href="/" class="btn btn-secondary">📈 Dashboard</a>
            <a href="/create" class="btn btn-primary">➕ Neue Lizenz</a>
            <a href="/licenses" class="btn btn-secondary">📋 Lizenzen</a>
            <a href="/customers" class="btn btn-secondary">👥 Kunden</a>
            <a href="/sessions" class="btn btn-secondary">🟢 Sessions</a>
            <a href="/audit" class="btn btn-secondary">📋 Audit</a>
            <a href="/backups" class="btn btn-secondary">💾 Backups</a>
        </div>
    </div>

    <div class="card mb-4">
        <div class="card-body">
            <form method="post" action="/customer/edit/{{ customer[0] }}" accept-charset="UTF-8">
                <div class="row g-3">
                    <div class="col-md-6">
                        <label for="name" class="form-label">Kundenname</label>
                        <input type="text" class="form-control" id="name" name="name" value="{{ customer[1] }}" accept-charset="UTF-8" required>
                    </div>
                    <div class="col-md-6">
                        <label for="email" class="form-label">E-Mail</label>
                        <input type="email" class="form-control" id="email" name="email" value="{{ customer[2] or '' }}" accept-charset="UTF-8">
                    </div>
                    <div class="col-12">
                        <label class="form-label text-muted">Erstellt am</label>
                        <p class="form-control-plaintext">{{ customer[3].strftime('%d.%m.%Y %H:%M') }}</p>
                    </div>
                </div>

                <div class="mt-4">
                    <button type="submit" class="btn btn-primary">💾 Änderungen speichern</button>
                    <a href="/customers" class="btn btn-secondary">Abbrechen</a>
                </div>
            </form>
        </div>
    </div>

    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Lizenzen des Kunden</h5>
        </div>
        <div class="card-body">
            {% if licenses %}
            <div class="table-responsive">
                <table class="table table-sm">
                    <thead>
                        <tr>
                            <th>Lizenzschlüssel</th>
                            <th>Typ</th>
                            <th>Gültig von</th>
                            <th>Gültig bis</th>
                            <th>Aktiv</th>
                            <th>Aktionen</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for license in licenses %}
                        <tr>
                            <td><code>{{ license[1] }}</code></td>
                            <td>
                                {% if license[2] == 'full' %}
                                    <span class="badge bg-success">Vollversion</span>
                                {% else %}
                                    <span class="badge bg-warning">Testversion</span>
                                {% endif %}
                            </td>
                            <td>{{ license[3].strftime('%d.%m.%Y') }}</td>
                            <td>{{ license[4].strftime('%d.%m.%Y') }}</td>
                            <td>
                                {% if license[5] %}
                                    <span class="text-success">✓</span>
                                {% else %}
                                    <span class="text-danger">✗</span>
                                {% endif %}
                            </td>
                            <td>
                                <a href="/license/edit/{{ license[0] }}" class="btn btn-outline-primary btn-sm">Bearbeiten</a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <p class="text-muted mb-0">Dieser Kunde hat noch keine Lizenzen.</p>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}