{% set service = admin.order_service({ 'id': order.id }) %}

<div class="card-body overflow-auto">
    <div class="mb-3">
        <h3 class="card-title mb-1">{{ 'Details'|trans }}</h3>
        <p class="text-secondary mb-0">{{ 'Review the current license, plugin, and recent validation activity for this order.'|trans }} <a href="https://docs.fossbilling.org/admin-guide/product-types/license/#validating-a-license" target="_blank" rel="noopener noreferrer">{{ 'Learn more'|trans }}</a></p>
    </div>
    <table class="table card-table table-vcenter table-striped text-nowrap">
        <tbody>
            <tr>
                <td class="text-end">{{ 'Key'|trans }}:</td>
                <td>{{ service.license_key }}</td>
            </tr>
            <tr>
                <td class="text-end">{{ 'Plugin'|trans }}:</td>
                <td>{{ service.plugin }}</td>
            </tr>
            <tr>
                <td class="text-end">{{ 'Last ping'|trans }}:</td>
                <td>{% if service.pinged_at %}{{ service.pinged_at|format_date }} ({{ service.pinged_at|timeago }} {{ 'ago'|trans }}){% else %}-{% endif %}</td>
            </tr>
        </tbody>
    </table>
</div>

<div class="card-footer d-flex flex-wrap gap-2 justify-content-end">
    {{ order_actions }}
</div>

<div class="card-body">
    <form method="post" action="{{ 'servicelicense/update'|api_url }}" {{ fb_api_form({message: 'License Updated'|trans}) }}>
        <div class="mb-5">
            <div class="mb-3">
                <h3 class="card-title mb-1">{{ 'License Configuration'|trans }}</h3>
                <p class="text-secondary mb-0">{{ 'Update the generated license key and the plugin used to validate it.'|trans }}</p>
            </div>
            <div class="row g-3">
                <div class="col-lg-6">
                    <label class="form-label">{{ 'License Key'|trans }}</label>
                    <textarea class="form-control" name="license_key" required>{{ request.license_key|default(service.license_key) }}</textarea>
                </div>
                <div class="col-lg-6">
                    <label class="form-label">{{ 'Plugin'|trans }}</label>
                    <input type="text" class="form-control" name="plugin" value="{{ request.plugin|default(service.plugin) }}" required>
                </div>
            </div>
        </div>

        <hr class="my-4" />

        <div class="mb-4">
            <div class="mb-3">
                <h3 class="card-title mb-1">{{ 'License Validation Rules'|trans }}</h3>
                <p class="text-secondary mb-0">{{ 'Define which environments are valid for this license and list the specific allowed values for each enabled rule.'|trans }}</p>
            </div>
            <div class="row g-4">
                <div class="col-12">
                    <label class="form-label">{{ 'Validate IP'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1 mb-2">
                        <label class="form-check" for="validateIPYes">
                            <input type="radio" class="form-check-input" name="validate_ip" id="validateIPYes" value="1"{% if service.validate_ip %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check" for="validateIPNo">
                            <input type="radio" class="form-check-input" name="validate_ip" id="validateIPNo" value="0"{% if not service.validate_ip %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                    <textarea class="form-control" name="ips" rows="3" placeholder="{{ 'One IP address per line'|trans }}">{% for value in service.ips %}{{ value }}{{ "\n" }}{% endfor %}</textarea>
                </div>

                <div class="col-12">
                    <label class="form-label">{{ 'Validate Host'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1 mb-2">
                        <label class="form-check" for="validateHostYes">
                            <input type="radio" class="form-check-input" name="validate_host" id="validateHostYes" value="1"{% if service.validate_host %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check" for="validateHostNo">
                            <input type="radio" class="form-check-input" name="validate_host" id="validateHostNo" value="0"{% if not service.validate_host %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                    <textarea class="form-control" name="hosts" rows="3" placeholder="{{ 'One host per line'|trans }}">{% for value in service.hosts %}{{ value }}{{ "\n" }}{% endfor %}</textarea>
                </div>

                <div class="col-12">
                    <label class="form-label">{{ 'Validate Path'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1 mb-2">
                        <label class="form-check" for="validatePathYes">
                            <input type="radio" class="form-check-input" name="validate_path" id="validatePathYes" value="1"{% if service.validate_path %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check" for="validatePathNo">
                            <input type="radio" class="form-check-input" name="validate_path" id="validatePathNo" value="0"{% if not service.validate_path %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                    <textarea class="form-control" name="paths" rows="3" placeholder="{{ 'One path per line'|trans }}">{% for value in service.paths %}{{ value }}{{ "\n" }}{% endfor %}</textarea>
                </div>

                <div class="col-12">
                    <label class="form-label">{{ 'Validate Version'|trans }}</label>
                    <div class="d-flex flex-wrap gap-3 pt-1 mb-2">
                        <label class="form-check" for="validateVerYes">
                            <input type="radio" class="form-check-input" name="validate_version" id="validateVerYes" value="1"{% if service.validate_version %} checked{% endif %}>
                            <span class="form-check-label">{{ 'Yes'|trans }}</span>
                        </label>
                        <label class="form-check" for="validateVerNo">
                            <input type="radio" class="form-check-input" name="validate_version" id="validateVerNo" value="0"{% if not service.validate_version %} checked{% endif %}>
                            <span class="form-check-label">{{ 'No'|trans }}</span>
                        </label>
                    </div>
                    <textarea class="form-control" name="versions" rows="3" placeholder="{{ 'One version per line'|trans }}">{% for value in service.versions %}{{ value }}{{ "\n" }}{% endfor %}</textarea>
                </div>
            </div>
        </div>

        <input type="hidden" name="order_id" value="{{ order.id }}">
        <div class="d-flex justify-content-end">
            <button class="btn btn-primary" type="submit">{{ 'Update'|trans }}</button>
        </div>
    </form>
</div>
