<?php

/*
|--------------------------------------------------------------------------
| Frontend Livewire Components
|--------------------------------------------------------------------------
*/
use App\Livewire\Home;
use App\Livewire\AboutUs;
use App\Livewire\ContactUs;
use App\Livewire\Services\ServicesOverview;
use App\Livewire\Services\ServiceCategoryView;
use App\Livewire\Services\ServiceDetail;
use App\Livewire\Work;
use App\Livewire\PrivacyPolicy;
use App\Livewire\WorkDetail;
use App\Livewire\ChaloBharat;
use App\Livewire\Careers;
use App\Livewire\CareerDetail;
use App\Livewire\Blogs\BlogIndex;
use App\Livewire\Blogs\BlogView;
use App\Livewire\Common\ThankYou;
use App\Livewire\Common\NotFound;


/*
|--------------------------------------------------------------------------
| Admin Livewire Components
|--------------------------------------------------------------------------
*/

use App\Livewire\Admin\Dashboard;
use App\Livewire\Admin\Menu\Create;
use App\Livewire\Admin\Menu\Edit;
use App\Livewire\Admin\Menu\MenuList;
use App\Livewire\Admin\Projects\ProjectDetail;
use App\Livewire\Admin\Projects\ProjectDetailView;
use App\Livewire\Admin\Services\ServiceCategoryEdit;
use App\Livewire\Admin\Blogs\BlogList;
use App\Livewire\Admin\Blogs\BlogCreate;
use App\Livewire\Admin\Blogs\BlogEdit;

use App\Livewire\Admin\Careers\CareerList;
use App\Livewire\Admin\Careers\CareerCreate;
use App\Livewire\Admin\Careers\CareerEdit;

use Illuminate\Support\Facades\Route;


Route::get(
    '/public/index.php/services/celebrity-influencer-marketing/celebrity-influencer-marketing',
    function () {
        return redirect('/services/celebrity-influencer-marketing', 301);
    }
);

/*
|--------------------------------------------------------------------------
| FRONTEND / PUBLIC ROUTES
|--------------------------------------------------------------------------
*/

// =======================
// Core Pages
// =======================
Route::get('/', Home::class)->name('home');
Route::get('/about-us', AboutUs::class)->name('about');
Route::get('/work', Work::class)->name('work');
Route::get('/work/{slug}', WorkDetail::class)->name('work.detail');
Route::get('/contact-us', ContactUs::class)->name('contact');
Route::get('/chalobharat', ChaloBharat::class)->name('chalobharat');
Route::get('/careers', Careers::class)->name('careers');
Route::get('/careers/{slug}', CareerDetail::class)->name('career.detail');
Route::get('/privacy-policy', PrivacyPolicy::class)->name('privacy-policy');

// =======================
// Services
// =======================
Route::get('/services', ServicesOverview::class)->name('services.index');

Route::get('/services/{categorySlug}/{serviceSlug}', ServiceDetail::class)
    ->name('services.category.service');

Route::get('/services/{slug}', ServiceCategoryView::class)
    ->name('services.category.view');

// =======================
// Blogs
// =======================
Route::get('/blogs', BlogIndex::class)->name('blogs.index');
Route::get('/blogs/{slug}', BlogView::class)->name('blogs.view');

// =======================
// Other Pages
// =======================
Route::get('/thank-you', ThankYou::class)->name('thank.you');

/*
|--------------------------------------------------------------------------
| ADMIN AUTH ENTRY (HIDDEN LOGIN)
|--------------------------------------------------------------------------
*/

Route::view('/ignite', 'auth.ignite')
    ->middleware(['guest', 'throttle:5,1'])
    ->name('admin.login');

// Block default admin access
Route::get('/admin', fn () => abort(404));

/*
|--------------------------------------------------------------------------
| ADMIN PANEL ROUTES
|--------------------------------------------------------------------------
*/

Route::prefix('console')
    ->middleware(['auth'])
    ->name('admin.')
    ->group(function () {

        // =======================
        // Dashboard
        // =======================
        Route::get('/dashboard', Dashboard::class)->name('dashboard');

        // =======================
        // Menus
        // =======================
        Route::get('/menus', MenuList::class)->name('menus.list');
        Route::get('/menus/add', Create::class)->name('menus.create');
        Route::get('/menus/{id}/edit', Edit::class)->name('menus.edit');

        // =======================
        // Services CMS
        // =======================
        
        Route::get('/services-page', \App\Livewire\Admin\Services\ServicesPageCMS::class)
            ->name('services.page');

        Route::get('/services-page-cms', \App\Livewire\Admin\Services\ServicesPageCMSList::class)
            ->name('services.page.list');
            
        // Edit existing
        Route::get('/services-page/edit/{category}', \App\Livewire\Admin\Services\ServicesPageEdit::class)
            ->name('services.page.edit');
            
        Route::get('/services', \App\Livewire\Admin\Services\ServicesList::class)
            ->name('services');

        Route::get('/services/categories', \App\Livewire\Admin\Services\ServiceCategories::class)
            ->name('service.categories');

        Route::get('/services/categories/{id}/edit', ServiceCategoryEdit::class)
            ->name('services.categories.edit');

        Route::get('/services/create', \App\Livewire\Admin\Services\ServiceCreate::class)
            ->name('services.create');

        Route::get('/services/{id}/edit', \App\Livewire\Admin\Services\ServiceEdit::class)
            ->name('services.edit');

        Route::get('/services/category/{category:slug}', \App\Livewire\Admin\Services\CategoryView::class)
            ->name('services.category.view');

        // =======================
        // Projects / Works CMS
        // =======================
        Route::get('/projects', \App\Livewire\Admin\Projects\ProjectsList::class)
            ->name('projects');

        Route::get('/projects/create', \App\Livewire\Admin\Projects\ProjectCreate::class)
            ->name('projects.create');

        Route::get('/projects/{id}/edit', \App\Livewire\Admin\Projects\ProjectEdit::class)
            ->name('projects.edit');


        // =======================
        // Project Details CMS
        // =======================
        Route::get('/projects-details', ProjectDetailView::class)
            ->name('projects.details.view');

        Route::get('/projects-details/edit/{project_id?}', ProjectDetail::class)
            ->name('projects.details.edit');
            
        /*
        |--------------------------------------------------------------------------
        | Contact Lead Section
        |--------------------------------------------------------------------------
        */
        Route::get('/contact-leads', \App\Livewire\Admin\ContactLeads::class)
                ->name('contact.leads');

        // =======================
        // Blogs CMS
        // =======================
        Route::get('/blogs', BlogList::class)->name('blogs');
        Route::get('/blogs/create', BlogCreate::class)->name('blogs.create');
        Route::get('/blogs/{id}/edit', BlogEdit::class)->name('blogs.edit');
        
        
        Route::get('/job-openings', CareerList::class)->name('console.job-openings');
        Route::get('/job-openings/create', CareerCreate::class)->name('console.job-openings.create');
        Route::get('/job-openings/{id}/edit', CareerEdit::class)->name('console.job-openings.edit');

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

/*
|--------------------------------------------------------------------------
| GLOBAL FALLBACK (404)
|--------------------------------------------------------------------------
*/

Route::view('/login', 'auth.ignite')->name('login');

Route::fallback(NotFound::class);
