<?php
/**
 * Delete ministry - admin only
 */

$stmt = $pdo->prepare('SELECT id, name FROM ministries WHERE id = ?');
$stmt->execute([$id]);
$ministry = $stmt->fetch();

if (!$ministry) {
    header('Location: ' . BASE_PATH . '/ministries?toast_error=' . urlencode('Service group not found.'));
    exit;
}

$pdo->prepare('DELETE FROM member_ministries WHERE ministry_id = ?')->execute([$id]);
$pdo->prepare('DELETE FROM ministries WHERE id = ?')->execute([$id]);

header('Location: ' . BASE_PATH . '/ministries?toast=' . urlencode('Service group deleted.'));
exit;
