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

// JOIN KE users PAKE gereja_id, BUKAN gembala_id
$sql = "SELECT g.*, u.nama as nama_gembala 
        FROM gereja g 
        LEFT JOIN users u ON u.gereja_id = g.id AND u.role = 'gembala' 
        ORDER BY g.nama_gereja ASC";
$stmt = $conn->prepare($sql);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode(['status'=>'success', 'data'=>$data]);
?>