<?php
require_once '../includes/header.php';

$id = $_GET['id'] ?? null;
if ($id) {
    $stmt = $pdo->prepare("SELECT thumbnail FROM tutorials WHERE id = :id");
    $stmt->execute([':id' => $id]);
    $tut = $stmt->fetch();
    if ($tut) {
        if ($tut['thumbnail']) deleteFile('../assets/uploads/' . $tut['thumbnail']);
        $pdo->prepare("DELETE FROM tutorials WHERE id = :id")->execute([':id' => $id]);
        setFlash('success', 'Tutorial deleted.');
    } else {
        setFlash('danger', 'Tutorial not found.');
    }
}
header('Location: tutorials.php');
exit;