<?php
require 'vendor/autoload.php';
use Dompdf\Dompdf;

$pdo = new PDO("mysql:host=localhost;dbname=job_portal;charset=utf8", "root", "");
$id = $_GET['id'] ?? 0;

// Fetch resume from DB
$stmt = $pdo->prepare("SELECT * FROM resumes WHERE id=?");
$stmt->execute([$id]);
$resume = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$resume) { die("Resume not found!"); }

// अगर PDF डाउनलोड करना है
if (isset($_GET['download'])) {
    ob_start();
    include "resume_template.php";
    $html = ob_get_clean();

    $dompdf = new Dompdf();
    $dompdf->loadHtml($html);
    $dompdf->setPaper('A4','portrait');
    $dompdf->render();
    $dompdf->stream("resume.pdf", ["Attachment" => true]);
    exit;
}
?>

<!DOCTYPE html>
<html>
<head>
  <title>View Resume</title>
  <style>
    body { font-family: Arial; margin:20px; }
    .section { margin-bottom:20px; }
    .section h3 { border-bottom:1px solid #ccc; }
  </style>
</head>
<body>

<?php include "resume_template.php"; ?>

<a href="view_resume.php?id=<?= $resume['id'] ?>&download=1">Download as PDF</a>

</body>
</html>
