{% extends "base.html" %}

{% block title %}Generated Assessment Links{% endblock %}

{% block content %}
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-10">
            <div class="card">
                <div class="card-header">
                    <h2>Generated Links for {{ client.name }}</h2>
                </div>
                <div class="card-body">
                    <p>The following one-time use links have been generated. Please copy and send them to the client.</p>
                    <div class="alert alert-info">
                        <strong>Note:</strong> To avoid accidental link usage, please copy the link and paste it into a new browser tab or send it to the recipient.
                    </div>
                    <ul class="list-group">
                        {% for item in links %}
                            <li class="list-group-item">
                                <h5>{{ item.assessment_name }}</h5>
                                <div class="input-group">
                                    <input type="text" class="form-control" id="link-{{ loop.index }}" value="{{ item.link }}" readonly>
                                    <div class="input-group-append">
                                        <button class="btn btn-outline-secondary btn-sm" type="button" onclick="copyLink('link-{{ loop.index }}')">Copy</button>
                                    </div>
                                </div>
                            </li>
                        {% endfor %}
                    </ul>
                </div>
                <div class="card-footer">
                    <a href="{{ url_for('admin.manage_clients') }}" class="btn btn-secondary">Back to Client Management</a>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
function copyLink(elementId) {
    const linkInput = document.getElementById(elementId);
    linkInput.select();
    document.execCommand('copy');
    alert('Link copied to clipboard!');
}
</script>
{% endblock %}
