<?php

use App\Http\Controllers\Admin\ColorThemeController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\PermissionController;
use App\Http\Controllers\Admin\RoleController;
use App\Http\Controllers\Admin\SectionController;
use App\Http\Controllers\Admin\SectionItemController;
use App\Http\Controllers\Admin\UserController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\LocaleController;
use App\Http\Controllers\SeoController;
use Illuminate\Support\Facades\Route;

Route::get('/', [HomeController::class, 'index'])->name('home')->middleware('locale');
Route::get('contact', [HomeController::class, 'contact'])->name('contact')->middleware('locale');
Route::get('privacy-policy', [HomeController::class, 'privacyPolicy'])->name('privacy-policy')->middleware('locale');
Route::get('terms-conditions', [HomeController::class, 'termsConditions'])->name('terms-conditions')->middleware('locale');
Route::get('lang/{locale}', [LocaleController::class, 'switch'])->name('locale.switch')->middleware('locale');

Route::get('robots.txt', [SeoController::class, 'robots'])->name('robots');
Route::get('sitemap.xml', [SeoController::class, 'sitemap'])->name('sitemap');

Route::middleware('guest')->group(function () {
    Route::get('login', [LoginController::class, 'create'])->name('login');
    Route::post('login', [LoginController::class, 'store']);
});
Route::post('logout', [LoginController::class, 'destroy'])->name('logout')->middleware('auth');

Route::middleware(['auth', 'active'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
    Route::resource('users', UserController::class)->except('show');
    Route::post('users/{user}/toggle-status', [UserController::class, 'toggleStatus'])->name('users.toggle-status');

    Route::resource('sections', SectionController::class)->only(['index', 'edit', 'update']);
    Route::patch('sections/{section}/toggle-status', [SectionController::class, 'toggleStatus'])->name('sections.toggle-status');
    Route::resource('sections.items', SectionItemController::class)->shallow()->except('show');
    Route::patch('items/{item}/toggle-status', [SectionItemController::class, 'toggleStatus'])->name('sections.items.toggle-status');

    Route::resource('themes', ColorThemeController::class)->except('show');
    Route::post('themes/{theme}/activate', [ColorThemeController::class, 'activate'])->name('themes.activate');

    Route::middleware('role:superadmin')->group(function () {
        Route::resource('roles', RoleController::class)->except('show');
        Route::resource('permissions', PermissionController::class)->except('show');
    });
});
