{% import 'macro_functions.html.twig' as mf %}

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

<div class="card-body overflow-auto">
    <h3>{{ 'Details'|trans }}</h3>
    <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>{{ service.pinged_at|format_date }} ({{ service.pinged_at|timeago }} ago)</td>
            </tr>
        </tbody>
    </table>
</div>

<div class="card-footer text-center">
    {{ order_actions }}
</div>

<div class="card-body">
    <h3>{{ 'License configuration'|trans }}</h3>

    <form action="{{ 'api/admin/servicelicense/update'|link }}" method="post" class="api-form" data-api-msg="{{ 'License updated'|trans }}">
        <input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'License key'|trans }}:</label>
            <div class="col">
                <textarea type="text" class="form-control" name="license_key" required>{{ request.license_key|default(service.license_key) }}</textarea>
            </div>
        </div>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Plugin'|trans }}:</label>
            <div class="col">
                <input type="text" class="form-control" name="plugin" value="{{ request.plugin|default(service.plugin) }}" required>
            </div>
        </div>

        <h3>{{"License validation rules"|trans}}</h3>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Validate IP'|trans }}:</label>
            <div class="col">
                <label for="validateIPYes">{{ 'Yes'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_ip" id="validateIPYes" value="1"{% if service.validate_ip  %} checked{% endif %}>
                <label for="validateIPNo">{{ 'No'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_ip" id="validateIPNo" value="0"{% if not service.validate_ip %} checked{% endif %}>
            </div>
        </div>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Valid IPs (one per line)'|trans }}:</label>
            <div class="col">
                <textarea type="text" class="form-control" name="ips">{% for v in service.ips %}{{ v }}{{ constant("PHP_EOL") }}{% endfor %}</textarea>
            </div>
        </div>

        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Validate host'|trans }}:</label>
            <div class="col">
                <label for="validateHostYes">{{ 'Yes'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_host" id="validateHostYes" value="1"{% if service.validate_host  %} checked{% endif %}>
                <label for="validateHostNo">{{ 'No'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_host" id="validateHostNo" value="0"{% if not service.validate_host %} checked{% endif %}>
            </div>
        </div>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Valid hosts (one per line)'|trans }}:</label>
            <div class="col">
                <textarea type="text" class="form-control" name="hosts">{% for v in service.hosts %}{{ v }}{{ constant("PHP_EOL") }}{% endfor %}</textarea>
            </div>
        </div>

        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Validate path'|trans }}:</label>
            <div class="col">
                <label for="validatePathYes">{{ 'Yes'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_path" id="validatePathYes" value="1"{% if service.validate_path  %} checked{% endif %}>
                <label for="validatePathNo">{{ 'No'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_path" id="validatePathNo" value="0"{% if not service.validate_path %} checked{% endif %}>
            </div>
        </div>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Valid paths (one per line)'|trans }}:</label>
            <div class="col">
                <textarea type="text" class="form-control" name="paths">{% for v in service.paths %}{{ v }}{{constant("PHP_EOL")}}{% endfor %}</textarea>
            </div>
        </div>

        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Validate version'|trans }}:</label>
            <div class="col">
                <label for="validateVerYes">{{ 'Yes'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_version" id="validateVerYes" value="1"{% if service.validate_version  %} checked{% endif %}>
                <label for="validateVerNo">{{ 'No'|trans }}</label>
                <input type="radio" class="form-check-input" name="validate_version" id="validateVerNo" value="0"{% if not service.validate_version %} checked{% endif %}>
            </div>
        </div>
        <div class="mb-3 row">
            <label class="form-label col-3 col-form-label">{{ 'Valid versions (one per line)'|trans }}:</label>
            <div class="col">
                <textarea type="text" class="form-control" name="versions">{% for v in service.versions %}{{ v }}{{constant("PHP_EOL")}}{% endfor %}</textarea>
            </div>
        </div>
        <input type="hidden" name="order_id" value="{{ order.id }}">
        <input type="submit" value="{{ 'Update'|trans }}" class="btn btn-primary w-100">
    </form>
    <hr>
</div>
