<?php
require_once 'db_pdo.php';
require_once 'auth.php';
require_once 'haversine_helper.php';
require_once 'penduduk_feature_helper.php';
require_admin_login(true);
header('Content-Type: application/json');

$input = json_decode(file_get_contents('php://input'), true);

if (!$input || empty($input['id'])) {
    echo json_encode(['success' => false, 'message' => 'Input tidak valid']);
    exit;
}

try {
    $stmt = $pdo->prepare("DELETE FROM rumah_ibadah WHERE id=?");
    $stmt->execute([$input['id']]);

    recalculateAllPendudukCoverage($pdo);
    refreshAllPriorityScores($pdo);

    echo json_encode(['success' => true]);
} catch (Exception $e) {
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
