<?php

use App\Http\Controllers\CategoryController;
use App\Http\Controllers\DaftarPerusahaanController;
use App\Http\Controllers\HistoryKegiatanController;
use App\Http\Controllers\HistoryPerusahaanController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\HukumController;
use App\Http\Controllers\JenisDokILController;
use App\Http\Controllers\JenisKegiatanController;
use App\Http\Controllers\JenisSanksiController;
use App\Http\Controllers\KategoriController;
use App\Http\Controllers\MenuController;
use App\Http\Controllers\PelaporanALController;
use App\Http\Controllers\PelaporanController;
use App\Http\Controllers\PenaatanController;
use App\Http\Controllers\PengumumanController;
use App\Http\Controllers\PeraturanController;
use App\Http\Controllers\PerusahaanController;
use App\Http\Controllers\PostController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RefCategoryController;
use App\Http\Controllers\RefSubCategoryController;
use App\Http\Controllers\SearchController;
use App\Http\Controllers\SekilasInfoController;
use App\Http\Controllers\SubCategoryController;
use App\Http\Controllers\SubKategoriController;
use App\Http\Controllers\TentangController;
use App\Http\Controllers\UndanganController;
use App\Http\Controllers\VerifikatorController;
use App\Http\Controllers\VerifPelaporanController;
use App\Models\Verifikator;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use Illuminate\Http\Response;

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

// Route::get('/404', function () {
//     return Inertia::render('404');
// });

Route::fallback(function () {
    $path = request()->path();

    if (str_starts_with($path, 'admin')) {
        return Inertia::render('404Admin', [
            'backUrl' => route('dashboard')
        ]);
    }

    return Inertia::render('404', [
        'backUrl' => route('home')
    ]);
});

Route::get('/pengumuman', [PengumumanController::class, 'index'])->name('pengumuman');
Route::get('/pengumuman/{slug}', [PengumumanController::class, 'show'])->name('pengumuman.show');

Route::get('/peraturan', [PeraturanController::class, 'index'])->name('peraturan');
Route::get('/peraturan/{slug}', [PeraturanController::class, 'show'])->name('peraturan.show');

Route::get('/undangan', [UndanganController::class, 'index'])->name('undangan');
Route::get('/undangan/{slug}', [UndanganController::class, 'show'])->name('undangan.show');

Route::get('/sekilasinfo/{slug}', [SekilasInfoController::class, 'show'])->name('sekilasinfo.show');

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

// Dashboard Route

Route::get('/dashboard', function () {
    return Inertia::render('dashboard');
})->middleware(['auth'])->name('dashboard');

Route::middleware(['auth'])->group(function () {
    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/kategori', [KategoriController::class, 'index'])->name('admin.kategori.index');
    Route::post('/kategori', [KategoriController::class, 'store'])->name('admin.kategori.store');
    Route::put('/kategori/{kategori}', [KategoriController::class, 'update'])->name('admin.kategori.update');
    Route::delete('/kategori/{kategori}', [KategoriController::class, 'destroy'])->name('admin.kategori.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/subkategori', [SubKategoriController::class, 'index'])->name('admin.subkategori.index');
    Route::post('/subkategori', [SubKategoriController::class, 'store'])->name('admin.subkategori.store');
    Route::put('/subkategori/{subkategori}', [SubKategoriController::class, 'update'])->name('admin.subkategori.update');
    Route::delete('/subkategori/{subkategori}', [SubKategoriController::class, 'destroy'])->name('admin.subkategori.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/jeniskegiatan', [JenisKegiatanController::class, 'index'])->name('admin.jeniskegiatan.index');
    Route::post('/jeniskegiatan', [JenisKegiatanController::class, 'store'])->name('admin.jeniskegiatan.store');
    Route::put('/jeniskegiatan/{jeniskegiatan}', [JenisKegiatanController::class, 'update'])->name('admin.jeniskegiatan.update');
    Route::delete('/jeniskegiatan/{jeniskegiatan}', [JenisKegiatanController::class, 'destroy'])->name('admin.jeniskegiatan.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/jenissanksi', [JenisSanksiController::class, 'index'])->name('admin.jenissanksi.index');
    Route::post('/jenissanksi', [JenisSanksiController::class, 'store'])->name('admin.jenissanksi.store');
    Route::put('/jenissanksi/{jenissanksi}', [JenisSanksiController::class, 'update'])->name('admin.jenissanksi.update');
    Route::delete('/jenissanksi/{jenissanksi}', [JenisSanksiController::class, 'destroy'])->name('admin.jenissanksi.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/penaatan', [PenaatanController::class, 'index'])->name('admin.penaatan.index');
    Route::post('/penaatan', [PenaatanController::class, 'store'])->name('admin.penaatan.store');
    Route::put('/penaatan/{penaatan}', [PenaatanController::class, 'update'])->name('admin.penaatan.update');
    Route::delete('/penaatan/{penaatan}', [PenaatanController::class, 'destroy'])->name('admin.penaatan.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/historykegiatan', [HistoryKegiatanController::class, 'index'])->name('admin.historykegiatan.index');
    Route::post('/historykegiatan', [HistoryKegiatanController::class, 'store'])->name('admin.historykegiatan.store');
    Route::put('/historykegiatan/{historykegiatan}', [HistoryKegiatanController::class, 'update'])->name('admin.historykegiatan.update');
    Route::delete('/historykegiatan/{historykegiatan}', [HistoryKegiatanController::class, 'destroy'])->name('admin.historykegiatan.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/verifikator', [VerifikatorController::class, 'index'])->name('admin.verifikator.index');
    Route::post('/verifikator', [VerifikatorController::class, 'store'])->name('admin.verifikator.store');
    Route::put('/verifikator/{verifikator}', [VerifikatorController::class, 'update'])->name('admin.verifikator.update');
    Route::delete('/verifikator/{verifikator}', [VerifikatorController::class, 'destroy'])->name('admin.verifikator.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/jenisdokil', [JenisDokILController::class, 'index'])->name('admin.jenisdokil.index');
    Route::post('/jenisdokil', [JenisDokILController::class, 'store'])->name('admin.jenisdokil.store');
    Route::put('/jenisdokil/{jenisdokil}', [JenisDokILController::class, 'update'])->name('admin.jenisdokil.update');
    Route::delete('/jenisdokil/{jenisdokil}', [JenisDokILController::class, 'destroy'])->name('admin.jenisdokil.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/tentang', [TentangController::class, 'index'])->name('admin.tentang.index');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/pelaporan', [PelaporanController::class, 'index'])->name('admin.pelaporan.index');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/pelaporan/al', [PelaporanALController::class, 'index'])->name('admin.pelaporanAL.index');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/verifikasi', [VerifPelaporanController::class, 'index'])->name('admin.verifikasi.index');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/hukum', [HukumController::class, 'index'])->name('admin.hukum.index');
    Route::get('/hukum/add', [HukumController::class, 'create'])->name('admin.hukum.create');
    Route::post('/hukum', [HukumController::class, 'store'])->name('admin.hukum.store');
    Route::get('/hukum/{hukum}', [HukumController::class, 'edit'])->name('admin.hukum.edit');
    Route::post('/hukum/{hukum}', [HukumController::class, 'update'])->name('admin.hukum.update');
    Route::post('/hukum/{hukum}/penaatan', [HukumController::class, 'update'])->name('admin.hukum.update');
    Route::delete('/hukum/{hukum}', [HukumController::class, 'destroy'])->name('admin.hukum.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/history_perusahaan', [HistoryPerusahaanController::class, 'index'])->name('admin.history_perusahaan.index');
    Route::get('/history_perusahaan/add', [HistoryPerusahaanController::class, 'create'])->name('admin.history_perusahaan.create');
    Route::post('/history_perusahaan', [HistoryPerusahaanController::class, 'store'])->name('admin.history_perusahaan.store');
    Route::get('/history_perusahaan/{history_perusahaan}', [HistoryPerusahaanController::class, 'edit'])->name('admin.history_perusahaan.edit');
    Route::post('/history_perusahaan/{history_perusahaan}', [HistoryPerusahaanController::class, 'update'])->name('admin.history_perusahaan.update');
    Route::delete('/history_perusahaan/{history_perusahaan}', [HistoryPerusahaanController::class, 'destroy'])->name('admin.history_perusahaan.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/post', [PostController::class, 'index'])->name('admin.post.index');
    Route::get('/post/add', [PostController::class, 'create'])->name('admin.post.create');
    Route::post('/post', [PostController::class, 'store'])->name('admin.post.store');
    Route::get('/post/{post}', [PostController::class, 'edit'])->name('admin.post.edit');
    Route::post('/post/{post}', [PostController::class, 'update'])->name('admin.post.update');
    Route::delete('/post/{post}', [PostController::class, 'destroy'])->name('admin.post.destroy');
});

Route::middleware(['auth'])->prefix('admin')->group(function () {
    Route::get('/perusahaan', [PerusahaanController::class, 'index'])->name('admin.perusahaan.index');
    Route::get('/perusahaan/add', [PerusahaanController::class, 'create'])->name('admin.perusahaan.create');
    Route::post('/perusahaan', [PerusahaanController::class, 'store'])->name('admin.perusahaan.store');
    Route::get('/perusahaan/{perusahaan}', [PerusahaanController::class, 'edit'])->name('admin.perusahaan.edit');
    Route::post('/perusahaan/{perusahaan}', [PerusahaanController::class, 'update'])->name('admin.perusahaan.update');
    Route::delete('/perusahaan/{perusahaan}', [PerusahaanController::class, 'destroy'])->name('admin.perusahaan.destroy');
});

require __DIR__.'/auth.php';
