{% extends "base.html" %}

{% block title %}Lizenz bearbeiten{% endblock %}

{% block content %}
<div class="container py-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>Lizenz 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">
        <div class="card-body">
            <form method="post" action="/license/edit/{{ license[0] }}" accept-charset="UTF-8">
                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label">Kunde</label>
                        <input type="text" class="form-control" value="{{ license[2] }}" disabled>
                        <small class="text-muted">Kunde kann nicht geändert werden</small>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label">E-Mail</label>
                        <input type="email" class="form-control" value="{{ license[3] or '-' }}" disabled>
                    </div>
                    <div class="col-md-6">
                        <label for="licenseKey" class="form-label">Lizenzschlüssel</label>
                        <input type="text" class="form-control" id="licenseKey" name="license_key" value="{{ license[1] }}" required>
                    </div>
                    <div class="col-md-6">
                        <label for="licenseType" class="form-label">Lizenztyp</label>
                        <select class="form-select" id="licenseType" name="license_type" required>
                            <option value="full" {% if license[4] == 'full' %}selected{% endif %}>Vollversion</option>
                            <option value="test" {% if license[4] == 'test' %}selected{% endif %}>Testversion</option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label for="validFrom" class="form-label">Gültig von</label>
                        <input type="date" class="form-control" id="validFrom" name="valid_from" value="{{ license[5].strftime('%Y-%m-%d') }}" required>
                    </div>
                    <div class="col-md-4">
                        <label for="validUntil" class="form-label">Gültig bis</label>
                        <input type="date" class="form-control" id="validUntil" name="valid_until" value="{{ license[6].strftime('%Y-%m-%d') }}" required>
                    </div>
                    <div class="col-md-4 d-flex align-items-end">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="isActive" name="is_active" {% if license[7] %}checked{% endif %}>
                            <label class="form-check-label" for="isActive">
                                Lizenz ist aktiv
                            </label>
                        </div>
                    </div>
                </div>

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