<?php
session_start();
header('Content-Type: application/json');
include '../config/database.php';
$db = new Database();
$conn = $db->getConnection();

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

$stmt = $conn->prepare("SELECT g.*, u.nama as nama_gembala FROM gereja g 
                        LEFT JOIN users u ON g.gembala_id = u.id WHERE g.id=?");
$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']);
}
?>