<?php
require_once '../../config/config.php';
require_once '../../config/database.php';
require_once '../../core/helpers.php';
requireRole('admin');

$id  = (int)($_GET['id'] ?? 0);
$row = Database::fetchOne("SELECT * FROM kegiatan_pendampingan WHERE id=?", [$id]);
if (!$row) { setFlash('error','Kegiatan tidak ditemukan.'); redirect(BASE_URL.'/modules/kegiatan/index.php'); }

// Hapus foto & file terkait
$fotos = Database::fetchAll("SELECT nama_file FROM foto_kegiatan WHERE kegiatan_id=?", [$id]);
foreach ($fotos as $f) deleteFile('foto_kegiatan', $f['nama_file']);

$files = Database::fetchAll("SELECT nama_file FROM file_laporan WHERE kegiatan_id=?", [$id]);
foreach ($files as $f) deleteFile('dokumen', $f['nama_file']);

Database::execute("DELETE FROM kegiatan_pendampingan WHERE id=?", [$id]);
auditLog('DELETE','kegiatan_pendampingan',$id,$row['nama_kegiatan']);
setFlash('success','Kegiatan berhasil dihapus.');
redirect(BASE_URL.'/modules/kegiatan/index.php');
