

<?php $__env->startSection('title', 'Certificates'); ?>
<?php $__env->startSection('page-title', 'Certificates'); ?>
<?php $__env->startSection('page-subtitle', 'Manage and verify all issued certificates of completion'); ?>

<?php $__env->startSection('hero-actions'); ?>
    <a href="<?php echo e(route('self-paced.dashboard.certificates.export') . '?' . http_build_query(request()->only(['course_id', 'is_revoked', 'date_from', 'date_to']))); ?>"
       class="inline-flex items-center gap-2 px-4 py-2 bg-white/10 hover:bg-white/20 text-white text-sm font-medium rounded-lg transition border border-white/30">
        <i class="fas fa-file-csv"></i> Export CSV
    </a>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div x-data="certificateIndex()" x-init="init()">

    
    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-4 mb-5">
        <div class="flex flex-col sm:flex-row gap-3 flex-wrap">

            
            <div class="relative flex-1 min-w-[200px]">
                <span class="absolute inset-y-0 left-3 flex items-center text-gray-400 pointer-events-none">
                    <i class="fas fa-search text-sm"></i>
                </span>
                <input type="text"
                       x-model="search"
                       @input.debounce.400ms="fetchCertificates()"
                       placeholder="Search by certificate #, holder name, or course…"
                       class="w-full pl-9 pr-4 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-300 focus:border-indigo-400 transition">
            </div>

            
            <select x-model="courseId"
                    @change="fetchCertificates()"
                    class="text-sm border border-gray-200 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-300 focus:border-indigo-400 transition bg-white">
                <option value="">All Courses</option>
                <?php $__currentLoopData = $courses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $course): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($course->id); ?>"><?php echo e($course->title); ?></option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>

            
            <select x-model="isRevoked"
                    @change="fetchCertificates()"
                    class="text-sm border border-gray-200 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-300 focus:border-indigo-400 transition bg-white">
                <option value="">All Statuses</option>
                <option value="0">Valid</option>
                <option value="1">Revoked</option>
            </select>

            
            <input type="date"
                   x-model="dateFrom"
                   @change="fetchCertificates()"
                   title="Issue date from"
                   class="text-sm border border-gray-200 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-300 focus:border-indigo-400 transition bg-white">

            
            <input type="date"
                   x-model="dateTo"
                   @change="fetchCertificates()"
                   title="Issue date to"
                   class="text-sm border border-gray-200 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-300 focus:border-indigo-400 transition bg-white">

            
            <button @click="clearFilters()"
                    x-show="search || courseId || isRevoked !== '' || dateFrom || dateTo"
                    x-cloak
                    class="inline-flex items-center gap-1.5 px-3 py-2 text-sm text-gray-500 hover:text-gray-700 border border-gray-200 rounded-lg hover:bg-gray-50 transition">
                <i class="fas fa-times text-xs"></i> Clear
            </button>
        </div>
    </div>

    
    <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">

        
        <div x-show="loading" x-cloak class="flex items-center justify-center py-16">
            <i class="fas fa-spinner fa-spin text-indigo-400 text-2xl"></i>
        </div>

        <div x-show="!loading" x-cloak>
            <div class="overflow-x-auto">
                <table class="w-full text-sm">
                    <thead>
                        <tr>
                            <th class="bg-indigo-50 text-indigo-700 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide w-10">#</th>
                            <th class="bg-purple-50 text-purple-700 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide">Certificate #</th>
                            <th class="bg-blue-50 text-blue-700 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide">Holder</th>
                            <th class="bg-green-50 text-green-700 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide">Course</th>
                            <th class="bg-amber-50 text-amber-700 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide">Issue Date</th>
                            <th class="bg-teal-50 text-teal-700 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide">Status</th>
                            <th class="bg-rose-50 text-rose-700 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide">Verifications</th>
                            <th class="bg-gray-50 text-gray-600 font-semibold text-left px-4 py-3 text-xs uppercase tracking-wide">Actions</th>
                        </tr>
                    </thead>
                    <tbody id="certificates-tbody" class="divide-y divide-gray-50">
                        <?php echo $__env->make('self-paced.dashboard.certificates.partials.table', ['certificates' => $certificates], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
                    </tbody>
                </table>
            </div>

            
            <?php if($certificates->hasPages()): ?>
            <div class="px-4 py-3 border-t border-gray-100" id="certificates-pagination">
                <?php echo e($certificates->links()); ?>

            </div>
            <?php endif; ?>
        </div>
    </div>

    
    <div x-show="revokeModal.open"
         x-cloak
         class="fixed inset-0 z-50 flex items-center justify-center p-4"
         @keydown.escape.window="revokeModal.open = false">
        <div class="absolute inset-0 bg-black/40 backdrop-blur-sm" @click="revokeModal.open = false"></div>
        <div class="relative bg-white rounded-2xl shadow-2xl w-full max-w-md p-6" x-transition>
            <div class="flex items-center gap-3 mb-4">
                <div class="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center flex-shrink-0">
                    <i class="fas fa-ban text-red-500"></i>
                </div>
                <div>
                    <h3 class="text-base font-bold text-gray-900">Revoke Certificate</h3>
                    <p class="text-xs text-gray-400" x-text="'Certificate: ' + revokeModal.certNumber"></p>
                </div>
            </div>

            <form :action="revokeModal.action" method="POST">
                <?php echo csrf_field(); ?>
                <div class="mb-4">
                    <label class="block text-sm font-medium text-gray-700 mb-1">
                        <i class="fas fa-comment-alt text-gray-400 mr-1"></i> Revocation Reason <span class="text-red-500">*</span>
                    </label>
                    <textarea name="revocation_reason"
                              rows="3"
                              required
                              placeholder="Provide a reason for revoking this certificate…"
                              class="w-full text-sm border border-gray-200 rounded-lg px-3 py-2 focus:outline-none focus:ring-2 focus:ring-red-300 focus:border-red-400 transition resize-none"></textarea>
                </div>
                <div class="flex gap-3">
                    <button type="button"
                            @click="revokeModal.open = false"
                            class="flex-1 px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 hover:bg-gray-200 rounded-lg transition">
                        Cancel
                    </button>
                    <button type="submit"
                            class="flex-1 px-4 py-2 text-sm font-semibold text-white bg-red-500 hover:bg-red-600 rounded-lg transition">
                        <i class="fas fa-ban mr-1"></i> Revoke
                    </button>
                </div>
            </form>
        </div>
    </div>

</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
function certificateIndex() {
    return {
        search: '',
        courseId: '',
        isRevoked: '',
        dateFrom: '',
        dateTo: '',
        loading: false,
        revokeModal: {
            open: false,
            certId: null,
            certNumber: '',
            action: '',
        },

        init() {
            const params = new URLSearchParams(window.location.search);
            this.search    = params.get('search')     || '';
            this.courseId  = params.get('course_id')  || '';
            this.isRevoked = params.get('is_revoked') ?? '';
            this.dateFrom  = params.get('date_from')  || '';
            this.dateTo    = params.get('date_to')    || '';
        },

        fetchCertificates(page) {
            this.loading = true;
            const params = new URLSearchParams();
            if (this.search)           params.set('search',     this.search);
            if (this.courseId)         params.set('course_id',  this.courseId);
            if (this.isRevoked !== '') params.set('is_revoked', this.isRevoked);
            if (this.dateFrom)         params.set('date_from',  this.dateFrom);
            if (this.dateTo)           params.set('date_to',    this.dateTo);
            if (page)                  params.set('page',       page);

            axios.get('<?php echo e(route('self-paced.dashboard.certificates.index')); ?>?' + params.toString(), {
                headers: { 'X-Requested-With': 'XMLHttpRequest' }
            })
            .then(res => {
                document.getElementById('certificates-tbody').innerHTML = res.data.html;
                const pag = document.getElementById('certificates-pagination');
                if (pag && res.data.pagination) pag.innerHTML = res.data.pagination;
            })
            .catch(() => {})
            .finally(() => { this.loading = false; });
        },

        clearFilters() {
            this.search    = '';
            this.courseId  = '';
            this.isRevoked = '';
            this.dateFrom  = '';
            this.dateTo    = '';
            this.fetchCertificates();
        },

        openRevokeModal(certId, certNumber) {
            this.revokeModal.certId     = certId;
            this.revokeModal.certNumber = certNumber;
            this.revokeModal.action     = `/self-paced/dashboard/certificates/${certId}/revoke`;
            this.revokeModal.open       = true;
        },
    };
}
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.self-paced-dashboard', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/www/sshia.org/sshia/resources/views/self-paced/dashboard/certificates/index.blade.php ENDPATH**/ ?>