<?php

/**
 * ITSWEBER CMS – Admin Routes
 */

/** @var \App\Core\Router $router */

// Admin login / logout
$router->get('/admin/login', 'App\Http\Controllers\Admin\AuthController@loginForm');
$router->post('/admin/login', 'App\Http\Controllers\Admin\AuthController@login');
$router->get('/admin/logout', 'App\Http\Controllers\Admin\AuthController@logout');

// Password reset (public – no auth middleware required)
$router->get('/admin/forgot-password', 'App\Http\Controllers\Admin\AuthController@forgotPasswordForm');
$router->post('/admin/forgot-password', 'App\Http\Controllers\Admin\AuthController@forgotPasswordSend');
$router->get('/admin/reset-password', 'App\Http\Controllers\Admin\AuthController@resetPasswordForm');
$router->post('/admin/reset-password', 'App\Http\Controllers\Admin\AuthController@resetPasswordSave');

// Admin routes (protected by middleware)
$router->group('/admin', [\App\Http\Middleware\AuthMiddleware::class], function ($router) {
    // Dashboard
    $router->get('', 'App\Http\Controllers\Admin\DashboardController@index');
    $router->get('/dashboard', 'App\Http\Controllers\Admin\DashboardController@index');

    // Pages (static routes before parameterised – ADR-014)
    $router->get('/pages', 'App\Http\Controllers\Admin\PageController@index');
    $router->get('/pages/create', 'App\Http\Controllers\Admin\PageController@create');
    $router->post('/pages/store', 'App\Http\Controllers\Admin\PageController@store');
    $router->get('/pages/edit/{id}', 'App\Http\Controllers\Admin\PageController@edit');
    $router->post('/pages/update/{id}', 'App\Http\Controllers\Admin\PageController@update');
    $router->post('/pages/delete/{id}', 'App\Http\Controllers\Admin\PageController@delete');
    $router->post('/pages/clone/{id}', 'App\Http\Controllers\Admin\PageController@clonePage');

    // Preview – draft/published content rendered in frontend theme (auth-protected)
    $router->get('/preview/page/{id}', 'App\Http\Controllers\Admin\PreviewController@previewPage');
    $router->get('/preview/blog/{id}', 'App\Http\Controllers\Admin\PreviewController@previewBlog');

    // Blog (static routes before parameterised – ADR-014)
    $router->get('/blog', 'App\Http\Controllers\Admin\BlogController@index');
    $router->get('/blog/create', 'App\Http\Controllers\Admin\BlogController@create');
    $router->post('/blog/store', 'App\Http\Controllers\Admin\BlogController@store');
    $router->get('/blog/edit/{id}', 'App\Http\Controllers\Admin\BlogController@edit');
    $router->post('/blog/update/{id}', 'App\Http\Controllers\Admin\BlogController@update');
    $router->post('/blog/delete/{id}', 'App\Http\Controllers\Admin\BlogController@delete');
    $router->post('/blog/clone/{id}', 'App\Http\Controllers\Admin\BlogController@clonePost');

    // Blog categories
    $router->get('/blog/categories', 'App\Http\Controllers\Admin\BlogCategoryController@index');
    $router->post('/blog/categories/store', 'App\Http\Controllers\Admin\BlogCategoryController@store');
    $router->post('/blog/categories/update/{id}', 'App\Http\Controllers\Admin\BlogCategoryController@update');
    $router->post('/blog/categories/delete/{id}', 'App\Http\Controllers\Admin\BlogCategoryController@delete');

    // Blog tags (static routes BEFORE parameterised – ADR-014)
    $router->get('/blog/tags', 'App\Http\Controllers\Admin\BlogTagController@index');
    $router->post('/blog/tags/update/{id}', 'App\Http\Controllers\Admin\BlogTagController@update');
    $router->post('/blog/tags/delete/{id}', 'App\Http\Controllers\Admin\BlogTagController@delete');

    // Gallery – album list / create / edit / delete
    $router->get('/gallery', 'App\Http\Controllers\Admin\GalleryController@index');
    $router->get('/gallery/create', 'App\Http\Controllers\Admin\GalleryController@create');
    $router->post('/gallery/store', 'App\Http\Controllers\Admin\GalleryController@store');
    $router->get('/gallery/edit/{id}', 'App\Http\Controllers\Admin\GalleryController@edit');
    $router->post('/gallery/update/{id}', 'App\Http\Controllers\Admin\GalleryController@update');
    $router->post('/gallery/delete/{id}', 'App\Http\Controllers\Admin\GalleryController@delete');

    // Gallery – image management (static routes BEFORE parameterised – ADR-014)
    $router->post('/gallery/images/reorder', 'App\Http\Controllers\Admin\GalleryController@reorderImages');
    $router->post('/gallery/images/update/{id}', 'App\Http\Controllers\Admin\GalleryController@updateImage');
    $router->post('/gallery/images/delete/{id}', 'App\Http\Controllers\Admin\GalleryController@deleteImage');

    // Gallery – per-album image actions
    $router->get('/gallery/album/{id}/images', 'App\Http\Controllers\Admin\GalleryController@images');
    $router->post('/gallery/album/{id}/upload', 'App\Http\Controllers\Admin\GalleryController@uploadImage');
    $router->post('/gallery/album/{id}/add-from-media', 'App\Http\Controllers\Admin\GalleryController@addFromMedia'); // Phase 2.2
    $router->post('/gallery/album/{id}/set-cover/{imageId}', 'App\Http\Controllers\Admin\GalleryController@setCover');

    // Media – central manager (Phase 4a) – static routes BEFORE parameterised (ADR-014)
    $router->get('/media',                          'App\Http\Controllers\Admin\MediaController@index');
    $router->get('/media/optimize',                 'App\Http\Controllers\Admin\MediaController@optimize');
    $router->post('/media/optimize',                'App\Http\Controllers\Admin\MediaController@runOptimize');
    $router->get('/media/picker-images',            'App\Http\Controllers\Admin\MediaController@pickerImages');
    $router->get('/media/picker-data',              'App\Http\Controllers\Admin\MediaController@pickerImages'); // Phase 2.2: alias for gallery picker
    $router->post('/media/upload',                  'App\Http\Controllers\Admin\MediaController@upload');
    $router->post('/media/folders/create',          'App\Http\Controllers\Admin\MediaController@createFolder');
    $router->post('/media/folders/rename/{id}',     'App\Http\Controllers\Admin\MediaController@renameFolder');
    $router->post('/media/folders/delete/{id}',     'App\Http\Controllers\Admin\MediaController@deleteFolder');
    $router->get('/media/edit/{id}',                'App\Http\Controllers\Admin\MediaController@edit');
    $router->post('/media/update/{id}',             'App\Http\Controllers\Admin\MediaController@update');
    $router->post('/media/move/{id}',               'App\Http\Controllers\Admin\MediaController@move');
    $router->post('/media/delete/{id}',             'App\Http\Controllers\Admin\MediaController@delete');

    // Menus – overview (list all menus with their items)
    $router->get('/menus', 'App\Http\Controllers\Admin\MenuController@index');
    $router->post('/menus/save', 'App\Http\Controllers\Admin\MenuController@save');             // legacy compat

    // Menu items CRUD (specific static routes BEFORE parameterised routes – ADR-014 pattern)
    $router->post('/menus/items/store', 'App\Http\Controllers\Admin\MenuController@storeItem');
    $router->post('/menus/items/reorder', 'App\Http\Controllers\Admin\MenuController@reorder');
    $router->post('/menus/items/update/{id}', 'App\Http\Controllers\Admin\MenuController@updateItem');
    $router->post('/menus/items/delete/{id}', 'App\Http\Controllers\Admin\MenuController@deleteItem');

    // Themes – static routes BEFORE parameterised (ADR-014 pattern)
    $router->get('/themes', 'App\Http\Controllers\Admin\ThemeController@index');
    $router->get('/themes/upload', 'App\Http\Controllers\Admin\ThemeController@uploadForm');    // Phase 10a
    $router->post('/themes/upload', 'App\Http\Controllers\Admin\ThemeController@handleUpload'); // Phase 10a
    $router->post('/themes/activate', 'App\Http\Controllers\Admin\ThemeController@activate');
    $router->post('/themes/uninstall', 'App\Http\Controllers\Admin\ThemeController@uninstall'); // Phase 13a

    // Plugins – static routes BEFORE parameterised (ADR-014 pattern) – Phase 16/17
    $router->get('/plugins', 'App\Http\Controllers\Admin\PluginController@index');
    $router->get('/plugins/upload', 'App\Http\Controllers\Admin\PluginController@uploadForm');
    $router->post('/plugins/upload', 'App\Http\Controllers\Admin\PluginController@handleUpload');
    $router->post('/plugins/uninstall', 'App\Http\Controllers\Admin\PluginController@uninstall');
    $router->post('/plugins/activate', 'App\Http\Controllers\Admin\PluginController@activate');
    $router->post('/plugins/deactivate', 'App\Http\Controllers\Admin\PluginController@deactivate');

    // Users
    $router->get('/users', 'App\Http\Controllers\Admin\UserController@index');
    $router->get('/users/create', 'App\Http\Controllers\Admin\UserController@create');
    $router->post('/users/store', 'App\Http\Controllers\Admin\UserController@store');
    $router->get('/users/edit/{id}', 'App\Http\Controllers\Admin\UserController@edit');
    $router->post('/users/update/{id}', 'App\Http\Controllers\Admin\UserController@update');
    $router->post('/users/delete/{id}', 'App\Http\Controllers\Admin\UserController@delete');

    // Settings
    $router->get('/settings', 'App\Http\Controllers\Admin\SettingsController@index');
    $router->post('/settings/save', 'App\Http\Controllers\Admin\SettingsController@save');
    $router->post('/settings/language', 'App\Http\Controllers\Admin\SettingsController@language');

    // Consent / Cookie-Einstellungen (Phase 6d)
    $router->get('/consent', 'App\Http\Controllers\Admin\ConsentController@index');
    $router->post('/consent/save', 'App\Http\Controllers\Admin\ConsentController@save');

    // Homepage sections
    $router->get('/homepage', 'App\Http\Controllers\Admin\HomepageController@index');
    $router->post('/homepage/save', 'App\Http\Controllers\Admin\HomepageController@save');     // legacy compat
    // Section-level save and toggle (specific routes BEFORE parameterised catch-alls)
    $router->post('/homepage/section/{id}/save', 'App\Http\Controllers\Admin\HomepageController@updateSection');
    $router->post('/homepage/section/{id}/toggle', 'App\Http\Controllers\Admin\HomepageController@toggleSection');
    $router->post('/homepage/section/{id}/move', 'App\Http\Controllers\Admin\HomepageController@moveSection');

    // Events (Phase 4b) – static routes BEFORE parameterised (ADR-014)
    $router->get('/events', 'App\Http\Controllers\Admin\EventController@index');
    $router->get('/events/create', 'App\Http\Controllers\Admin\EventController@create');
    $router->post('/events/store', 'App\Http\Controllers\Admin\EventController@store');
    $router->post('/events/upload-image', 'App\Http\Controllers\Admin\EventController@uploadImage'); // Phase 4b.1
    $router->get('/events/categories', 'App\Http\Controllers\Admin\EventCategoryController@index');
    $router->post('/events/categories/store', 'App\Http\Controllers\Admin\EventCategoryController@store');
    $router->post('/events/categories/update/{id}', 'App\Http\Controllers\Admin\EventCategoryController@update');
    $router->post('/events/categories/delete/{id}', 'App\Http\Controllers\Admin\EventCategoryController@delete');
    $router->get('/events/edit/{id}', 'App\Http\Controllers\Admin\EventController@edit');
    $router->post('/events/update/{id}', 'App\Http\Controllers\Admin\EventController@update');
    $router->post('/events/delete/{id}', 'App\Http\Controllers\Admin\EventController@delete');

    // Downloads (Phase 8) – static routes BEFORE parameterised (ADR-014)
    $router->get('/downloads', 'App\Http\Controllers\Admin\DownloadController@index');
    $router->get('/downloads/create', 'App\Http\Controllers\Admin\DownloadController@create');
    $router->post('/downloads/store', 'App\Http\Controllers\Admin\DownloadController@store');
    $router->post('/downloads/upload-file', 'App\Http\Controllers\Admin\DownloadController@uploadFile');
    $router->post('/downloads/upload-image', 'App\Http\Controllers\Admin\DownloadController@uploadImage');
    $router->get('/downloads/categories', 'App\Http\Controllers\Admin\DownloadCategoryController@index');
    $router->post('/downloads/categories/store', 'App\Http\Controllers\Admin\DownloadCategoryController@store');
    $router->post('/downloads/categories/update/{id}', 'App\Http\Controllers\Admin\DownloadCategoryController@update');
    $router->post('/downloads/categories/delete/{id}', 'App\Http\Controllers\Admin\DownloadCategoryController@delete');
    $router->get('/downloads/edit/{id}', 'App\Http\Controllers\Admin\DownloadController@edit');
    $router->post('/downloads/update/{id}', 'App\Http\Controllers\Admin\DownloadController@update');
    $router->post('/downloads/delete/{id}', 'App\Http\Controllers\Admin\DownloadController@delete');

    // System
    $router->get('/system', 'App\Http\Controllers\Admin\SystemController@index');

    // Backup, Restore & Update (Phase 6e)
    $router->get('/backup',                         'App\Http\Controllers\Admin\BackupController@index');
    $router->post('/backup/create',                 'App\Http\Controllers\Admin\BackupController@createBackup');
    $router->post('/backup/restore',                'App\Http\Controllers\Admin\BackupController@restoreUpload');
    $router->post('/backup/restore/execute',        'App\Http\Controllers\Admin\BackupController@restoreExecute');
    $router->post('/backup/update',                 'App\Http\Controllers\Admin\BackupController@updateUpload');
    $router->post('/backup/update/execute',         'App\Http\Controllers\Admin\BackupController@updateExecute');

    // FTP Backup (Phase 3.0.4)
    $router->get('/backup/ftp',                     'App\Http\Controllers\Admin\BackupController@ftpSettings');
    $router->post('/backup/ftp/save',               'App\Http\Controllers\Admin\BackupController@saveFtpSettings');
    $router->post('/backup/ftp/test',               'App\Http\Controllers\Admin\BackupController@testFtpConnection');
    $router->post('/backup/ftp/backup',             'App\Http\Controllers\Admin\BackupController@runFtpBackup');

    // Settings – branding upload (Phase 6e)
    $router->post('/settings/branding/upload',      'App\Http\Controllers\Admin\SettingsController@uploadBranding');

    // Maintenance mode (Phase 19)
    $router->get('/maintenance',         'App\Http\Controllers\Admin\MaintenanceController@index');
    $router->post('/maintenance/enable', 'App\Http\Controllers\Admin\MaintenanceController@enable');
    $router->post('/maintenance/disable','App\Http\Controllers\Admin\MaintenanceController@disable');
    $router->get('/maintenance/preview','App\Http\Controllers\Admin\MaintenanceController@preview');
});
