<?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 program_kerja WHERE id=?", [$id]);
if (!$row) { setFlash('error','Program tidak ditemukan.'); redirect(BASE_URL.'/modules/program_kerja/index.php'); }

Database::execute("UPDATE kegiatan_pendampingan SET program_kerja_id=NULL WHERE program_kerja_id=?", [$id]);
Database::execute("DELETE FROM program_kerja WHERE id=?", [$id]);
auditLog('DELETE','program_kerja',$id,$row['nama_program']);
setFlash('success','Program '.$row['nama_program'].' berhasil dihapus.');
redirect(BASE_URL.'/modules/program_kerja/index.php');
