<?php
session_start();
header('Content-Type: application/json');
if(!isset($_SESSION['user_id'])) die(json_encode(['status'=>'error','message'=>'Akses ditolak']));

include '../config/database.php';
$db = new Database();
$conn = $db->getConnection();

$id = $_GET['id'] ?? 0;

// PASTIIN SELECT * ATAU SEBUTIN kaum
$sql = "SELECT j.*, g.nama_gereja FROM jemaat j LEFT JOIN gereja g ON j.gereja_id=g.id WHERE j.id=?";
$stmt = $conn->prepare($sql);
$stmt->execute([$id]);
$data = $stmt->fetch(PDO::FETCH_ASSOC);

if($data){
    echo json_encode(['status'=>'success','data'=>$data]);
} else {
    echo json_encode(['status'=>'error','message'=>'Data tidak ditemukan']);
}
?>