<?php
// admin/view-certificate.php - View Certificate
require_once '../includes/config.php';

$cert_id = $_GET['id'] ?? 0;
$stmt = $pdo->prepare("SELECT c.*, t.* FROM certificates c LEFT JOIN certificate_templates t ON c.template_style = t.id WHERE c.id = ?");
$stmt->execute([$cert_id]);
$cert = $stmt->fetch();

if(!$cert) { die("Certificate not found"); }

$bg = $cert['bg_color'] ?? '#ffffff';
$border = $cert['border_color'] ?? '#6C5CE7';
$text = $cert['text_color'] ?? '#1a1a2e';
$accent = $cert['accent_color'] ?? '#ffc107';
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <title>Certificate - <?= htmlspecialchars($cert['student_name']) ?></title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Serif+Bengali:wght@400;700&display=swap');
        * { margin:0; padding:0; box-sizing:border-box; }
        body { display:flex; justify-content:center; align-items:center; min-height:100vh; background:#f0f0f0; padding:20px; }
        .certificate {
            width:842px; height:595px; padding:50px; position:relative;
            background:<?= $bg ?>; border:8px solid <?= $border ?>;
            font-family:'Noto Serif Bengali',serif; color:<?= $text ?>;
            box-shadow:0 20px 60px rgba(0,0,0,0.3);
        }
        .cert-border-inner { border:3px solid <?= $accent ?>; height:100%; padding:40px; text-align:center; position:relative; }
        .cert-logo { font-size:1.8rem; color:<?= $border ?>; margin-bottom:10px; }
        .cert-title { font-size:2.5rem; font-weight:700; color:<?= $border ?>; margin:10px 0; letter-spacing:3px; }
        .cert-subtitle { font-size:1rem; color:#888; margin-bottom:20px; }
        .cert-body { font-size:1.1rem; line-height:2; }
        .cert-name { font-size:2rem; font-weight:700; color:<?= $border ?>; margin:10px 0; text-decoration:underline; text-underline-offset:8px; }
        .cert-course { font-size:1.3rem; color:<?= $accent ?>; font-weight:700; }
        .cert-footer { display:flex; justify-content:space-between; margin-top:40px; text-align:left; }
        .cert-date { font-size:0.9rem; }
        .cert-signature { text-align:center; }
        .cert-signature .sign-line { width:200px; border-top:2px solid <?= $text ?>; margin:40px auto 5px; }
        .cert-number { position:absolute; bottom:15px; right:25px; font-size:0.7rem; color:#888; }
        .cert-verify { position:absolute; bottom:15px; left:25px; font-size:0.7rem; color:#888; }
        .print-btn { position:fixed; top:20px; right:20px; background:#6C5CE7; color:white; border:none; padding:10px 25px; border-radius:50px; cursor:pointer; font-weight:600; font-size:1rem; z-index:1000; }
        .print-btn:hover { background:#5a4bd1; }
        @media print { body { background:white; } .print-btn { display:none; } .certificate { box-shadow:none; } }
    </style>
</head>
<body>
<button class="print-btn" onclick="window.print()"><i class="fas fa-print me-1"></i> প্রিন্ট / PDF</button>

<div class="certificate">
    <div class="cert-border-inner">
        <div class="cert-logo"><i class="fas fa-graduation-cap"></i> বাংলা LMS</div>
        <div class="cert-title">CERTIFICATE</div>
        <div class="cert-subtitle">কোর্স সম্পন্ন করার স্বীকৃতি</div>
        <div class="cert-body">
            <p>এতদ্বারা প্রত্যয়ন করা যাচ্ছে যে</p>
            <div class="cert-name"><?= htmlspecialchars($cert['student_name']) ?></div>
            <p>সফলভাবে সম্পন্ন করেছেন</p>
            <div class="cert-course">"<?= htmlspecialchars($cert['course_name']) ?>"</div>
            <p style="margin-top:10px;">গ্রেড: <strong><?= $cert['grade'] ?></strong></p>
        </div>
        <div class="cert-footer">
            <div class="cert-date">তারিখ: <?= date('d F Y', strtotime($cert['completion_date'])) ?></div>
            <div class="cert-signature"><div class="sign-line"></div><strong><?= htmlspecialchars($cert['instructor_name']) ?></strong><br><small>ইন্সট্রাক্টর</small></div>
        </div>
        <div class="cert-number">সার্টিফিকেট নং: <?= $cert['certificate_number'] ?></div>
        <div class="cert-verify">ভেরিফাই: onesbd.com/LMS/verify-certificate.php?code=<?= $cert['verification_code'] ?></div>
    </div>
</div>
</body>
</html>