<?php

use App\Http\Controllers\Admin\ContactMessageController;
use App\Http\Controllers\Admin\ContentController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\LoginController;
use App\Http\Controllers\Admin\SecteurController as AdminSecteurController;
use App\Http\Controllers\Admin\SiteSettingController;
use App\Http\Controllers\Admin\TestimonialController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\RessourcesController;
use App\Http\Controllers\SecteurController;
use Illuminate\Support\Facades\Route;

Route::get('/', HomeController::class);

Route::get('test', function () {
    return view('test');
});

Route::get('contact', [ContactController::class, 'show'])->name('contact');
Route::post('contact', [ContactController::class, 'store'])->name('contact.store');

Route::get('a-propos', function () {
    return view('a-propos');
});

Route::get('logistique-groupage', function () {
    return view('logistique-groupage');
});

Route::get('centrale-achat', function () {
    return view('centrale-achat');
});

Route::get('centrale-vente-abidjan', function () {
    return view('centrale-vente-abidjan');
});

Route::get('china-business-trip', function () {
    return view('china-business-trip');
});

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

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

Route::middleware('guest')->group(function (): void {
    Route::get('admin/login', [LoginController::class, 'show'])->name('admin.login');
    Route::post('admin/login', [LoginController::class, 'login'])->name('admin.login.submit');
});

Route::middleware(['auth', 'admin'])->prefix('admin')->group(function (): void {
    Route::post('logout', [LoginController::class, 'logout'])->name('admin.logout');
    Route::get('/', DashboardController::class)->name('dashboard');

    Route::resource('contents', ContentController::class)
        ->except(['show'])
        ->names([
            'index' => 'admin.contents.index',
            'create' => 'admin.contents.create',
            'store' => 'admin.contents.store',
            'edit' => 'admin.contents.edit',
            'update' => 'admin.contents.update',
            'destroy' => 'admin.contents.destroy',
        ]);

    Route::resource('contact-messages', ContactMessageController::class)
        ->only(['index', 'show', 'destroy'])
        ->names([
            'index' => 'admin.contact-messages.index',
            'show' => 'admin.contact-messages.show',
            'destroy' => 'admin.contact-messages.destroy',
        ]);

    Route::get('settings', [SiteSettingController::class, 'edit'])->name('admin.settings.edit');
    Route::put('settings', [SiteSettingController::class, 'update'])->name('admin.settings.update');

    Route::resource('testimonials', TestimonialController::class)
        ->except(['show'])
        ->names([
            'index' => 'admin.testimonials.index',
            'create' => 'admin.testimonials.create',
            'store' => 'admin.testimonials.store',
            'edit' => 'admin.testimonials.edit',
            'update' => 'admin.testimonials.update',
            'destroy' => 'admin.testimonials.destroy',
        ]);

    Route::resource('secteurs', AdminSecteurController::class)
        ->except(['show'])
        ->names([
            'index' => 'admin.secteurs.index',
            'create' => 'admin.secteurs.create',
            'store' => 'admin.secteurs.store',
            'edit' => 'admin.secteurs.edit',
            'update' => 'admin.secteurs.update',
            'destroy' => 'admin.secteurs.destroy',
        ]);
});
