<?php

use FluxCms\Core\Http\Controllers\Admin\BlogController;
use FluxCms\Core\Http\Controllers\Admin\ComponentController;
use FluxCms\Core\Http\Controllers\Admin\DashboardController;
use FluxCms\Core\Http\Controllers\Admin\MediaController;
use FluxCms\Core\Http\Controllers\Admin\NavigationController;
use FluxCms\Core\Http\Controllers\Admin\PageController as AdminPageController;
use FluxCms\Core\Http\Controllers\PageController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Flux CMS Admin Routes
|--------------------------------------------------------------------------
|
| These routes are for the CMS admin interface. They are protected by
| authentication and authorization middleware.
|
*/

Route::middleware(['web', 'auth', 'flux-cms:cms-access'])
    ->prefix(config('flux-cms.routes.admin_prefix', 'admin/cms'))
    ->name('admin.cms.')
    ->group(function () {

        // Dashboard
        Route::get('/', DashboardController::class)->name('index');

        // Pages Management
        Route::resource('pages', AdminPageController::class)->except(['show']);

        // Blog Management
        Route::get('blog', [BlogController::class, 'index'])->name('blog.index');
        Route::get('blog/{blogPost}/edit', [BlogController::class, 'edit'])->name('blog.edit');

        // Media Management
        Route::get('media', MediaController::class)->name('media.index');

        // Navigation Management
        Route::get('navigation', NavigationController::class)->name('navigation.index');

        // Component Library
        Route::get('components', ComponentController::class)->name('components.index');
    });

/*
|--------------------------------------------------------------------------
| Flux CMS Preview Routes
|--------------------------------------------------------------------------
|
| These routes allow authenticated users to preview unpublished content.
|
*/

Route::middleware(['web', 'auth', 'flux-cms:cms-access'])
    ->prefix('preview')
    ->name('cms.preview.')
    ->group(function () {
        Route::get('/pages/{page}', [PageController::class, 'preview'])->name('page');
    });
