<?php
include __DIR__ . '/includes/header.php';

if (!$user) {
    header('Location: /auth/login.php');
    exit;
}

$site_certificate = getSetting('site_certificate', '');
?>

<div class="container py-4">
    <div class="d-flex align-items-center gap-3 mb-4">
        <a href="/profile.php" class="btn btn-outline-light btn-sm rounded-circle" style="width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center;">
            <i class="bi bi-arrow-left"></i>
        </a>
        <h4 class="text-white fw-bold mb-0"><?= __('reg_certificate') ?></h4>
    </div>

    <div class="card bg-surface border-secondary rounded-4 overflow-hidden shadow-lg animate__animated animate__fadeIn">
        <div class="card-body p-4 text-center">
            <?php 
            if ($site_certificate): 
                $certs = json_decode($site_certificate, true);
                if (!is_array($certs)) $certs = [$site_certificate];
                ?>
                <div class="mb-3 text-white-50 small">
                    <i class="bi bi-shield-check me-2 text-primary"></i><?= __('platform_certificate') ?>
                </div>
                
                <div class="row g-4 justify-content-center">
                    <?php foreach ($certs as $cert): ?>
                        <div class="col-12 col-md-6 col-lg-4">
                            <div class="certificate-wrapper p-2 bg-white rounded-3 shadow-sm d-inline-block mw-100">
                                <img src="<?= htmlspecialchars($cert) ?>" alt="Certificate" class="img-fluid rounded-2" style="max-height: 60vh;">
                            </div>
                            <div class="mt-3">
                                <button class="btn btn-primary btn-sm rounded-pill px-3" onclick="window.open('<?= htmlspecialchars($cert) ?>', '_blank')">
                                    <i class="bi bi-zoom-in me-2"></i><?= __('view_full_image') ?>
                                </button>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            <?php else: ?>
                <div class="py-5">
                    <i class="bi bi-image text-white-50 display-1 mb-3"></i>
                    <p class="text-white-50"><?= __('no_certificate_yet') ?></p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<style>
    .certificate-wrapper {
        transition: transform 0.3s ease;
    }
    .certificate-wrapper:hover {
        transform: scale(1.02);
    }
</style>

<?php include __DIR__ . '/includes/footer.php'; ?>
