<?php
/** @var array $doc */
$bp = defined('BASE_PATH') ? BASE_PATH : '/gmind';
?>
<div class="container-fluid py-4">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card border-danger">
                <div class="card-header bg-danger text-white">
                    <h4 class="mb-0"><i class="fas fa-exclamation-triangle"></i> Confirm Delete</h4>
                </div>
                <div class="card-body">
                    <p class="lead">Are you sure you want to delete this certificate?</p>

                    <table class="table table-bordered">
                        <tr>
                            <th width="40%">Certificate No:</th>
                            <td><strong><?= htmlspecialchars($doc['certificate_no'] ?? '') ?></strong></td>
                        </tr>
                        <tr>
                            <th>Student Name:</th>
                            <td><?= htmlspecialchars($doc['student_name'] ?? '') ?></td>
                        </tr>
                        <tr>
                            <th>Enrollment No:</th>
                            <td><?= htmlspecialchars($doc['enrollment_no'] ?? '') ?></td>
                        </tr>
                        <tr>
                            <th>Course:</th>
                            <td><?= htmlspecialchars($doc['course_name'] ?? '') ?></td>
                        </tr>
                        <tr>
                            <th>Status:</th>
                            <td>
                                <span class="badge bg-<?= ($doc['status'] === 'generated') ? 'success' : 'warning' ?>">
                                    <?= htmlspecialchars($doc['status'] ?? '') ?>
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <th>Grade:</th>
                            <td><?= htmlspecialchars($doc['grade'] ?? '') ?> (<?= htmlspecialchars($doc['percentage'] ?? '') ?>%)</td>
                        </tr>
                    </table>

                    <?php if (($doc['status'] ?? '') === 'generated'): ?>
                    <div class="alert alert-warning">
                        <i class="fas fa-exclamation-triangle"></i>
                        This certificate is already approved and has a generated PDF.
                        Deleting it will also delete the PDF file. This action cannot be undone.
                    </div>
                    <?php else: ?>
                    <div class="alert alert-info">
                        <i class="fas fa-info-circle"></i>
                        This action cannot be undone.
                    </div>
                    <?php endif; ?>

                    <form method="POST" action="<?= $bp ?>/branch/cert-gen/delete/<?= (int)$doc['id'] ?>">
                        <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrfToken ?? '') ?>">
                        <div class="d-flex justify-content-between">
                            <a href="<?= $bp ?>/branch/cert-gen" class="btn btn-secondary">
                                <i class="fas fa-times"></i> Cancel
                            </a>
                            <button type="submit" class="btn btn-danger">
                                <i class="fas fa-trash"></i> Yes, Delete Permanently
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
