<?php
// index.php - Entry point SINERGI

// Load config
require_once __DIR__ . '/config/app.php';
require_once __DIR__ . '/config/database.php';

// Autoload core
require_once __DIR__ . '/core/Database.php';
require_once __DIR__ . '/core/Auth.php';
require_once __DIR__ . '/core/Controller.php';
require_once __DIR__ . '/core/Router.php';
require_once __DIR__ . '/core/helpers.php';

// Autoload controllers
foreach (glob(__DIR__ . '/app/controllers/*.php') as $file) {
    require_once $file;
}

// Init session
Auth::init();

// Init router
$router = new Router();

// ============================================================
// PUBLIC ROUTES (tanpa login)
// ============================================================
$router->get('/',                   [PublicController::class, 'beranda']);
$router->get('/tentang',            [PublicController::class, 'tentang']);
$router->get('/kontak',             [PublicController::class, 'kontak']);
$router->get('/lapor',              [PublicController::class, 'lapor']);
$router->post('/lapor',             [PublicController::class, 'kirimLaporan']);
$router->get('/cek-laporan',        [PublicController::class, 'cekLaporan']);
$router->post('/cek-laporan',       [PublicController::class, 'proseCekLaporan']);

// API publik (JSON)
$router->get('/api/kelurahan/{id}', [PublicController::class, 'apiKelurahan']);
$router->get('/api/rumah-ibadah',   [PublicController::class, 'apiRumahIbadah']);
$router->get('/api/warga-peta',     [PublicController::class, 'apiWargaPeta']);

// ============================================================
// AUTH ROUTES
// ============================================================
$router->get('/login',   [AuthController::class, 'showLogin']);
$router->post('/login',  [AuthController::class, 'doLogin']);
$router->get('/logout',  [AuthController::class, 'logout']);
$router->get('/forbidden', [AuthController::class, 'forbidden']);

// ============================================================
// SUPER ADMIN ROUTES
// ============================================================
$router->get('/admin/dashboard',          [AdminController::class, 'dashboard']);
$router->get('/admin/users',              [AdminController::class, 'users']);
$router->post('/admin/users/store',       [AdminController::class, 'storeUser']);
$router->post('/admin/users/{id}/update', [AdminController::class, 'updateUser']);
$router->post('/admin/users/{id}/reset-password', [AdminController::class, 'resetUserPassword']);
$router->post('/admin/users/{id}/delete', [AdminController::class, 'deleteUser']);
$router->get('/admin/rumah-ibadah',       [AdminController::class, 'rumahIbadah']);
$router->post('/admin/rumah-ibadah/store',       [AdminController::class, 'storeRumahIbadah']);
$router->post('/admin/rumah-ibadah/{id}/update', [AdminController::class, 'updateRumahIbadah']);
$router->post('/admin/rumah-ibadah/{id}/delete', [AdminController::class, 'deleteRumahIbadah']);
$router->get('/admin/wilayah',            [AdminController::class, 'wilayah']);
$router->post('/admin/kecamatan/store',   [AdminController::class, 'storeKecamatan']);
$router->post('/admin/kelurahan/store',   [AdminController::class, 'storeKelurahan']);
$router->get('/admin/kategori-bantuan',   [AdminController::class, 'kategoriBantuan']);
$router->post('/admin/kategori-bantuan/store',       [AdminController::class, 'storeKategoriBantuan']);
$router->post('/admin/kategori-bantuan/{id}/update', [AdminController::class, 'updateKategoriBantuan']);
$router->get('/admin/monitoring',         [AdminController::class, 'monitoring']);
$router->get('/admin/blind-spot',         [AdminController::class, 'blindSpot']);
$router->get('/admin/aktivitas',          [AdminController::class, 'aktivitas']);
$router->get('/admin/api/stats',          [AdminController::class, 'apiStats']);
$router->get('/admin/api/peta',           [AdminController::class, 'apiPeta']);

// ============================================================
// VERIFIKATOR ROUTES
// ============================================================
$router->get('/verifikator/dashboard',         [VerifikatorController::class, 'dashboard']);
$router->get('/verifikator/laporan',           [VerifikatorController::class, 'laporan']);
$router->get('/verifikator/laporan/{id}',      [VerifikatorController::class, 'detailLaporan']);
$router->post('/verifikator/laporan/{id}/proses', [VerifikatorController::class, 'prosesLaporan']);
$router->get('/verifikator/warga',             [VerifikatorController::class, 'warga']);
$router->get('/verifikator/warga/tambah',      [VerifikatorController::class, 'formTambahWarga']);
$router->get('/verifikator/warga/{id}',        [VerifikatorController::class, 'detailWarga']);
$router->post('/verifikator/warga/store',      [VerifikatorController::class, 'storeWarga']);
$router->post('/verifikator/warga/{id}/update',[VerifikatorController::class, 'updateWarga']);
$router->get('/verifikator/api/stats',         [VerifikatorController::class, 'apiStats']);

// ============================================================
// RUMAH IBADAH ROUTES
// ============================================================
$router->get('/rumah-ibadah/dashboard',        [RumahIbadahController::class, 'dashboard']);
$router->get('/rumah-ibadah/warga',            [RumahIbadahController::class, 'warga']);
$router->get('/rumah-ibadah/warga/{id}',       [RumahIbadahController::class, 'detailWarga']);
$router->get('/rumah-ibadah/prioritas',        [RumahIbadahController::class, 'prioritas']);
$router->get('/rumah-ibadah/bantuan',          [RumahIbadahController::class, 'bantuan']);
$router->get('/rumah-ibadah/bantuan/tambah',   [RumahIbadahController::class, 'formBantuan']);
$router->post('/rumah-ibadah/bantuan/store',   [RumahIbadahController::class, 'storeBantuan']);
$router->get('/rumah-ibadah/api/peta',         [RumahIbadahController::class, 'apiPeta']);

// ============================================================
// DINSOS ROUTES
// ============================================================
$router->get('/dinsos/dashboard',     [DinsosController::class, 'dashboard']);
$router->get('/dinsos/kemiskinan',    [DinsosController::class, 'kemiskinan']);
$router->get('/dinsos/bantuan',       [DinsosController::class, 'bantuan']);
$router->get('/dinsos/blind-spot',    [DinsosController::class, 'blindSpot']);
$router->post('/dinsos/blind-spot/{id}/assign', [DinsosController::class, 'assignBlindSpot']);
$router->get('/dinsos/kinerja',       [DinsosController::class, 'kinerja']);
$router->get('/dinsos/laporan',       [DinsosController::class, 'laporan']);
$router->get('/dinsos/akun',                          [DinsosController::class, 'akun']);
$router->post('/dinsos/akun/store',                   [DinsosController::class, 'storeAkun']);
$router->post('/dinsos/akun/{id}/update',             [DinsosController::class, 'updateAkun']);
$router->post('/dinsos/akun/{id}/reset-password',     [DinsosController::class, 'resetAkunPassword']);
$router->post('/dinsos/akun/{id}/deactivate',         [DinsosController::class, 'deactivateAkun']);
$router->get('/dinsos/api/heatmap',   [DinsosController::class, 'apiHeatmap']);
$router->get('/dinsos/api/stats',     [DinsosController::class, 'apiStats']);

// ============================================================
// WALIKOTA ROUTES
// ============================================================
$router->get('/walikota/dashboard',   [WalikotaController::class, 'dashboard']);
$router->get('/walikota/api/stats',   [WalikotaController::class, 'apiStats']);
$router->get('/walikota/api/peta',    [WalikotaController::class, 'apiPeta']);

// Dispatch
$router->dispatch();