<?php

use App\Http\Controllers\Public\HomeController;
use App\Http\Controllers\Public\ProfileController as PublicProfileController;
use App\Http\Controllers\Public\DataController;
use App\Http\Controllers\Public\PotentialController as PublicPotentialController;
use App\Http\Controllers\Public\MapController;
use App\Http\Controllers\Public\PostController as PublicPostController;
use App\Http\Controllers\Public\ContactController as PublicContactController;

use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\VillageProfileController;
use App\Http\Controllers\Admin\StatisticController;
use App\Http\Controllers\Admin\OfficialController;
use App\Http\Controllers\Admin\PotentialController;
use App\Http\Controllers\Admin\PostController;
use App\Http\Controllers\Admin\GalleryController;
use App\Http\Controllers\Admin\MapPointController;
use App\Http\Controllers\Admin\ContactController;

use Illuminate\Support\Facades\Route;

// ========== HALAMAN PUBLIK ==========

Route::get('/', [HomeController::class, 'index'])->name('home');

// Profil Desa
Route::prefix('profil')->name('profil.')->group(function () {
    Route::get('/tentang', [PublicProfileController::class, 'tentang'])->name('tentang');
    Route::get('/geografis', [PublicProfileController::class, 'geografis'])->name('geografis');
    Route::get('/pemerintahan', [PublicProfileController::class, 'pemerintahan'])->name('pemerintahan');
});

// Data Desa
Route::get('/data-desa', [DataController::class, 'index'])->name('data-desa');

// Potensi Desa
Route::get('/potensi', [PublicPotentialController::class, 'index'])->name('potensi');
Route::get('/potensi/{potential}', [PublicPotentialController::class, 'show'])->name('potensi.show');

// Peta Desa
Route::get('/peta', [MapController::class, 'index'])->name('peta');
Route::get('/peta/data', [MapController::class, 'data'])->name('peta.data'); // API JSON

// Berita
Route::prefix('berita')->name('berita.')->group(function () {
    Route::get('/', [PublicPostController::class, 'berita'])->name('index');
    Route::get('/{slug}', [PublicPostController::class, 'show'])->name('show');
});

// Pengumuman
Route::prefix('pengumuman')->name('pengumuman.')->group(function () {
    Route::get('/', [PublicPostController::class, 'pengumuman'])->name('index');
    Route::get('/{slug}', [PublicPostController::class, 'show'])->name('show');
});

// Kontak
Route::get('/kontak', [PublicContactController::class, 'index'])->name('kontak');

// ========== AUTENTIKASI (Breeze) ==========
// Semua route auth dari Breeze sudah di-include lewat:
require __DIR__.'/auth.php';

// Nonaktifkan register publik — redirect ke login
Route::get('/register', function () {
    return redirect()->route('login');
})->name('register');

// ========== PANEL ADMIN ==========

Route::prefix('admin')->name('admin.')->middleware(['auth', 'admin'])->group(function () {

    // Dashboard
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');

    // Profil Desa (singleton)
    Route::prefix('profil-desa')->name('village-profile.')->group(function () {
        Route::get('/', [VillageProfileController::class, 'edit'])->name('edit');
        Route::put('/', [VillageProfileController::class, 'update'])->name('update');
    });

    // Statistik (singleton)
    Route::prefix('statistik')->name('statistic.')->group(function () {
        Route::get('/', [StatisticController::class, 'edit'])->name('edit');
        Route::put('/', [StatisticController::class, 'update'])->name('update');
    });

    // Perangkat Desa
    Route::resource('perangkat', OfficialController::class);

    // Potensi Desa
    Route::resource('potensi', PotentialController::class);

    // Berita & Pengumuman
    Route::resource('posts', PostController::class);

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

    // Peta
    Route::resource('peta', MapPointController::class);

    // Kontak (singleton)
    Route::prefix('kontak')->name('contact.')->group(function () {
        Route::get('/', [ContactController::class, 'edit'])->name('edit');
        Route::put('/', [ContactController::class, 'update'])->name('update');
    });
});
