<?php
session_start();
require '../src/db.php';
if (!isset($_SESSION['user'])) header('Location: login.php');

$id = intval($_GET['id'] ?? 0);
if ($id) {
  $stmt = $pdo->prepare("
    DELETE FROM anotaciones
    WHERE id = ? AND usuario_id = ?
  ");
  $stmt->execute([$id, $_SESSION['user']['id']]);
}

$tab = $_GET['tab'] ?? 'books';
header("Location: index.php?tab={$tab}");
exit;