<?php

use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\SiteSettingController;
use App\Http\Controllers\Admin\HomepageStatController;
use App\Http\Controllers\Admin\ValueController;
use App\Http\Controllers\Admin\ProcessStepController;
use App\Http\Controllers\Admin\JourneyItemController;
use App\Http\Controllers\Admin\HeroSlideController;
use App\Http\Controllers\Admin\MenuController;
use App\Http\Controllers\Admin\ServiceController;
use App\Http\Controllers\Admin\ProjectController;
use App\Http\Controllers\Admin\ProjectCategoryController;
use App\Http\Controllers\Admin\ClientController;
use App\Http\Controllers\Admin\CertificationController;
use App\Http\Controllers\Admin\DownloadController;
use App\Http\Controllers\Admin\PageController;
use App\Http\Controllers\Admin\ContactMessageController;
use App\Http\Controllers\Admin\MediaController;
use App\Http\Controllers\Admin\ChangePasswordController;
use Illuminate\Support\Facades\Route;

Route::middleware('web')->group(function () {

    Route::prefix('admin')->name('admin.')->group(function () {

        // Guest routes
        Route::middleware('guest')->group(function () {
            Route::get('login', [AuthController::class, 'showLogin'])->name('login');
            Route::post('login', [AuthController::class, 'login'])->name('login.attempt');
        });

        // Authenticated admin routes
        Route::middleware(['auth', 'admin'])->group(function () {
            Route::post('logout', [AuthController::class, 'logout'])->name('logout');

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

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

            // Homepage stats
            Route::resource('stats', HomepageStatController::class)->except('show');

            // Values
            Route::resource('values', ValueController::class)->except('show');

            // Process steps
            Route::resource('process-steps', ProcessStepController::class)->except('show')->parameters(['process-steps' => 'processStep']);

            // Journey (Our Journey timeline)
            Route::resource('journey', JourneyItemController::class)->except('show');

            // Hero slides
            Route::resource('hero-slides', HeroSlideController::class)->except('show');

            // Menus
            Route::resource('menus', MenuController::class)->except('show');

            // Services
            Route::resource('services', ServiceController::class);

            // Projects
            Route::resource('project-categories', ProjectCategoryController::class)->except('show')->parameters(['project-categories' => 'projectCategory']);
            Route::resource('projects', ProjectController::class);

            // Clients
            Route::resource('clients', ClientController::class)->except('show');

            // Certifications
            Route::resource('certifications', CertificationController::class)->except('show');

            // Downloads
            Route::resource('downloads', DownloadController::class)->except('show');

            // Pages
            Route::resource('pages', PageController::class)->except('show');
            Route::get('pages/{page}/preview', [PageController::class, 'preview'])->name('pages.preview');

            // Contact messages
            Route::get('messages', [ContactMessageController::class, 'index'])->name('messages.index');
            Route::get('messages/{contactMessage}', [ContactMessageController::class, 'show'])->name('messages.show');
            Route::delete('messages/{contactMessage}', [ContactMessageController::class, 'destroy'])->name('messages.destroy');

            // Media
            Route::get('media', [MediaController::class, 'index'])->name('media.index');
            Route::post('media', [MediaController::class, 'store'])->name('media.store');
            Route::put('media/{media}', [MediaController::class, 'update'])->name('media.update');
            Route::delete('media/{media}', [MediaController::class, 'destroy'])->name('media.destroy');

            // Change password
            Route::get('change-password', [ChangePasswordController::class, 'edit'])->name('password.edit');
            Route::put('change-password', [ChangePasswordController::class, 'update'])->name('password.update');
        });
    });
});
