<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/

Route::get('/lang/{locale}', function (string $locale) {
    if (in_array($locale, ['en', 'or'])) {
        session(['locale' => $locale]);
    }
    return back();
})->name('lang.switch');

Route::livewire('/', 'pages::home')->name('home');

Route::livewire('/category/{slug}', 'pages::category')->name('category');

Route::livewire('/article/{slug}', 'pages::article')->name('article');

Route::livewire('/gallery', 'pages::gallery')->name('gallery');

Route::livewire('/about', 'pages::about')->name('about');

Route::livewire('/contact', 'pages::contact')->middleware('throttle:10,1')->name('contact');

Route::livewire('/career', 'pages::career')->name('career');

Route::livewire('/legal/{slug}', 'pages::legal')->name('legal');

Route::livewire('/search', 'pages::search')->name('search');

Route::livewire('/youtube', 'pages::youtube')->name('youtube');
Route::livewire('/instagram', 'pages::instagram')->name('instagram');
Route::livewire('/facebook', 'pages::facebook')->name('facebook');

Route::livewire('/faq', 'pages::faq')->name('faq');

Route::livewire('/login', 'pages::admin.login')->middleware('throttle:5,1')->name('login');

Route::middleware(['auth'])->prefix('admin')->name('admin.')->group(function () {
    Route::livewire('/', 'pages::admin.dashboard')->name('dashboard');
    Route::livewire('/categories', 'pages::admin.categories')->name('categories');
    
    Route::livewire('/inquiries', 'pages::admin.inquiries')->name('inquiries');
    Route::livewire('/inquiries/{inquiry}', 'pages::admin.inquiry-view')->name('inquiries.view');
    
    Route::livewire('/blog', 'pages::admin.blog-list')->name('blog');
    Route::livewire('/blog/create', 'pages::admin.blog-create')->name('blog.create');
    Route::livewire('/blog/{post}/edit', 'pages::admin.blog-edit')->name('blog.edit');

    Route::livewire('/faqs', 'pages::admin.faqs')->name('faqs');
    Route::livewire('/faqs/create', 'pages::admin.faq-create')->name('faqs.create');
    Route::livewire('/faqs/{faq}/edit', 'pages::admin.faq-edit')->name('faqs.edit');

    Route::livewire('/gallery', 'pages::admin.gallery')->name('gallery');
    Route::livewire('/gallery/create', 'pages::admin.gallery-create')->name('gallery.create');

    Route::livewire('/legal', 'pages::admin.legal')->name('legal');
    Route::livewire('/legal/{page:slug}/edit', 'pages::admin.legal-edit')->name('legal.edit');

    Route::livewire('/career', 'pages::admin.career-manage')->name('career.manage');

    Route::livewire('/profile', 'pages::admin.profile')->name('profile');
    Route::livewire('/social', 'pages::admin.social-posts')->name('social');
    Route::livewire('/breaking', 'pages::admin.breaking-list')->name('breaking');
    Route::livewire('/breaking/create', 'pages::admin.breaking-create')->name('breaking.create');
    Route::livewire('/breaking/{breakingNews}/edit', 'pages::admin.breaking-edit')->name('breaking.edit');
    Route::livewire('/subscribers', 'pages::admin.subscribers')->name('subscribers');
    Route::livewire('/settings', 'pages::admin.settings')->name('settings');

    // Superadmin-only: User Management
    Route::middleware(['role:superadmin'])->group(function () {
        Route::livewire('/users', 'pages::admin.users')->name('users');
        Route::livewire('/users/create', 'pages::admin.user-create')->name('users.create');
        Route::livewire('/users/{user}/edit', 'pages::admin.user-edit')->name('users.edit');
        Route::livewire('/roles', 'pages::admin.roles')->name('roles');
        Route::livewire('/activity-logs', 'pages::admin.activity-logs')->name('activity-logs');
    });
});

Route::post('/logout', function () {
    auth()->logout();
    request()->session()->invalidate();
    request()->session()->regenerateToken();
    return redirect('/');
})->name('logout');
