<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\GaleriController as AdminGaleriController;
use App\Http\Controllers\Admin\KegiatanController;
use App\Http\Controllers\Admin\ProgramController;

// =====================
// Public Routes
// =====================
Route::get('/', function () {
    $galeris = \App\Models\Galeri::all();
    $kegiatans = \App\Models\Kegiatan::all();
    $programs = \App\Models\Program::all();
    return view('home', compact('galeris', 'kegiatans', 'programs'));
});

Route::view('/kontak', 'kontak');
Route::view('/tentang', 'tentang');;

Route::get('/kegiatan', function () {
    $kegiatans = \App\Models\Kegiatan::all();
    return view('kegiatan', compact('kegiatans'));
});

Route::view('/layanan', 'layanan');

Route::get('/program', function () {
    $programs = \App\Models\Program::all();
    return view('program', compact('programs'));
});


// =====================
// Admin Authentication Routes
// =====================
Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('login.submit');
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
});

// =====================
// Admin Protected Routes
// =====================
Route::middleware(['auth:admin'])->prefix('admin')->name('admin.')->group(function () {
    // Dashboard
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    // CRUD Galeri
    Route::resource('galeri', AdminGaleriController::class);

    // CRUD Kegiatan
    Route::resource('kegiatan', KegiatanController::class)->except(['create', 'store', 'destroy']);

    // CRUD Program
    Route::resource('program', ProgramController::class);

});
