<?php
session_start();
require_once '../config.php';
if ($_SESSION['role'] !== 'kader') { exit; }

$id = $_GET['id'];

try {
    // 1. Hapus riwayat penimbangan (Foreign Key)
    $stmt1 = $pdo->prepare("DELETE FROM pemeriksaan_balita WHERE id_balita = ?");
    $stmt1->execute([$id]);

    // 2. Hapus data balita
    $stmt2 = $pdo->prepare("DELETE FROM balita WHERE id_balita = ?");
    $stmt2->execute([$id]);

    header("Location: balita_index.php?status=deleted");
    exit;
} catch (PDOException $e) {
    die("Gagal menghapus: " . $e->getMessage());
}