{% 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="/customers-licenses{% if request.args.get('show_test') == 'true' %}?show_test=true{% endif %}" class="btn btn-secondary">📋 Zurück zur Übersicht</a>
        </div>
    </div>

    <div class="card">
        <div class="card-body">
            <form method="post" action="/license/edit/{{ license[0] }}" accept-charset="UTF-8">
                {% if request.args.get('show_test') == 'true' %}
                    <input type="hidden" name="show_test" value="true">
                {% endif %}
                <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 class="col-md-6">
                        <label for="deviceLimit" class="form-label">Gerätelimit</label>
                        <select class="form-select" id="deviceLimit" name="device_limit" required>
                            {% for i in range(1, 11) %}
                            <option value="{{ i }}" {% if license[10] == i %}selected{% endif %}>{{ i }} {% if i == 1 %}Gerät{% else %}Geräte{% endif %}</option>
                            {% endfor %}
                        </select>
                        <small class="form-text text-muted">Maximale Anzahl gleichzeitig aktiver Geräte</small>
                    </div>
                </div>

                <div class="form-check mt-3">
                    <input class="form-check-input" type="checkbox" id="isTest" name="is_test" {% if license[9] %}checked{% endif %}>
                    <label class="form-check-label" for="isTest">
                        <i class="fas fa-flask"></i> Als Testdaten markieren
                        <small class="text-muted">(wird von der Software ignoriert)</small>
                    </label>
                </div>

                <div class="mt-4">
                    <button type="submit" class="btn btn-primary">💾 Änderungen speichern</button>
                    <a href="/customers-licenses{% if request.args.get('show_test') == 'true' %}?show_test=true{% endif %}" class="btn btn-secondary">Abbrechen</a>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}