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

if (!empty($row['nama_file'])) deleteFile('dokumen', $row['nama_file']);
Database::execute("DELETE FROM dokumen WHERE id=?", [$id]);
auditLog('DELETE','dokumen',$id,$row['nama_dokumen']);
setFlash('success','Dokumen '.$row['nama_dokumen'].' berhasil dihapus.');
redirect(BASE_URL.'/modules/dokumen/index.php');
