<?php

use Illuminate\Support\Facades\Route;
use Inertia\Inertia;

// 1. Prefix is 'cp' (Control Panel)
Route::middleware(['web'])->prefix('cp')->group(function () {
    
    // 2. Auth Middleware Group (Must be logged in, verified, and admin)
    Route::middleware(['auth', 'verified', 'admin'])->group(function () {
        
        // Redirect /cp to dashboard
        Route::get('/', function () {
            return redirect()->route('admin.dashboard');
        });

        // Dashboard
        Route::get('/dashboard', function () {
            return Inertia::render('Dashboard');
        })->name('admin.dashboard');


        // News / Posts
        Route::get('/news', function () {
            return Inertia::render('News/NewsManager');
        })->name('admin.news.index');

        // Categories
        Route::get('/categories', function () {
            return Inertia::render('Categories/CategoryManager');
        })->name('admin.categories.index');

        // Custom Pages
        Route::get('/pages', fn() => Inertia::render('Pages/PageList'))->name('admin.pages.index');
        Route::get('/pages/create', fn() => Inertia::render('Pages/PageForm'))->name('admin.pages.create');
        Route::get('/pages/{page}/edit', function (App\Models\Page $page) {
            return Inertia::render('Pages/PageForm', ['page' => $page]);
        })->name('admin.pages.edit');

        // Ad Placements 
        Route::get('/ads', function () {
            return Inertia::render('Ads/AdManager'); 
        })->name('admin.ads.index');

        // User Management
        Route::get('/users', function () {
            return Inertia::render('UserManagement/UserList');
        })->name('admin.users.index');

        // SMTP Settings
        Route::get('/settings/smtp', function () {
            return Inertia::render('Settings/Smtp'); 
        })->name('admin.settings.smtp');
        
        // SEO Settings
        Route::get('/settings/seo', function () {
            return Inertia::render('Settings/Seo'); 
        })->name('admin.settings.seo');

        // Post Settings
        Route::get('/settings/post', function () {
            return Inertia::render('Settings/PostSettings'); 
        })->name('admin.settings.post');

        Route::get('/settings/permalinks', function () {
            return Inertia::render('Settings/Permalinks'); 
        })->name('admin.settings.permalinks');

        Route::get('/settings/auth', function () {
            return Inertia::render('Settings/AuthSettings'); 
        })->name('admin.settings.auth');

        Route::get('/settings/social', function () {
            return Inertia::render('Settings/SocialSettings'); 
        })->name('admin.settings.social');

        Route::get('/rss', function () {
            return Inertia::render('Rss/RssManager');
        })->name('admin.rss.index');

        Route::get('/settings/ai', function () {
            return Inertia::render('Settings/AiProviders'); 
        })->name('admin.settings.ai');

        Route::get('/settings/scheduler', function () {
            return Inertia::render('Settings/Scheduler'); 
        })->name('admin.settings.scheduler');

        Route::get('/settings/languages', function () {
            return Inertia::render('Settings/LanguageManager'); 
        })->name('admin.settings.languages');

        Route::get('/settings/appearance', function () {
            return Inertia::render('Settings/Appearance'); 
        })->name('admin.settings.appearance');

        Route::get('/settings/pwa', function () {
            return Inertia::render('Settings/PwaSettings'); 
        })->name('admin.settings.pwa');

        Route::get('/settings/code-injection', function () {
            return Inertia::render('Settings/CodeInjection'); 
        })->name('admin.settings.code-injection');

        Route::get('/settings/maintenance', function () {
            return Inertia::render('Settings/SystemMaintenance'); 
        })->name('admin.settings.maintenance');
    });
});