<?php

use App\Http\Controllers\Admin\AdminController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PublicController;
use App\Http\Controllers\Admin\UnitController;
use App\Http\Controllers\Admin\BannerController;
use App\Http\Controllers\Admin\CourseController;
use App\Http\Controllers\Admin\ChapterController;
use App\Http\Controllers\Admin\SettingsController;
use App\Http\Controllers\Admin\AuthAdminController;
use App\Http\Controllers\Admin\ExamController;
use App\Http\Controllers\Admin\LectureController;
use App\Http\Controllers\Admin\LocalizationController;
use App\Http\Controllers\Admin\NotificationController;

Route::get('/', function () {
    return redirect()->route('login');
});
Route::get('/page/{slug}', [PublicController::class, 'page']);

Route::prefix('admin')->namespace('App\Http\Controllers\Admin')->group(function () {

    Route::controller(AuthAdminController::class)->group(function () {

        Route::get('/login', 'login')->name('login');
        Route::post('/login', 'authenticate');

        Route::middleware('auth:admin')->get('/home', 'home')->name('home');
        Route::post('/logout', 'logout');
    });

    Route::middleware('auth:admin')->group(function () {

        // Resources
        Route::resource('users', UserController::class)->except('show');
        Route::resource('categories', CategoryController::class)->except('show');
        Route::resource('courses', CourseController::class)->except('show');
        Route::resource('reviews', ReviewController::class)->except(['show', 'create', 'store']);
        Route::resource('chapters', ChapterController::class)->except('show');
        Route::resource('units', UnitController::class)->except('show');
        Route::resource('lectures', LectureController::class)->except('show');
        Route::resource('pages', PageController::class)->except('show');
        Route::resource('banners', BannerController::class)->except('show');
        Route::resource('admins', AdminController::class)->except('show');
        Route::resource('subscriptions', SubscriptionController::class)->except('show');

        // exams
        Route::get('lecture/{lecture}/exam', [ExamController::class, 'exam']);
        Route::post('exams', [ExamController::class, 'store']);
        Route::put('exams/{exam}/update', [ExamController::class, 'update']);
        Route::delete('exams/{exam}', [ExamController::class, 'delete']);

        Route::get('settings', [SettingsController::class, 'index']);
        Route::post('settings', [SettingsController::class, 'update']);

        // Ajax
        Route::get('ajax/courses', [CourseController::class, 'ajaxCourses']);
        Route::get('ajax/single-course', [CourseController::class, 'ajaxSingleCourse']);
        Route::get('ajax/chapters', [ChapterController::class, 'ajaxChapters']);
        Route::get('ajax/units', [UnitController::class, 'ajaxUnits']);
        Route::get('ajax/lectures', [LectureController::class, 'ajaxLectures']);

        // notifications
        Route::get('notification/create', [NotificationController::class, 'create']);
        Route::post('notification/send', [NotificationController::class, 'sendNotification'])->name('notification.send');

        // localization
        Route::get('localization/{locale}', LocalizationController::class)->name('localization');
    });
});

Route::group(['prefix' => 'filemanager', 'middleware' => ['auth:admin']], function () {
    \UniSharp\LaravelFilemanager\Lfm::routes();
});
