<?php

use App\Http\Controllers\Backend\AdminController;
use App\Http\Controllers\Backend\AuthenticateController;
use App\Http\Controllers\Backend\SubCategoryController;
use App\Http\Controllers\Backend\SubCategoryWhereElseController;
use App\Http\Controllers\Backend\ArticleController;
use App\Http\Controllers\Backend\ArticleWhereElseController;
use App\Http\Controllers\Backend\UserController;
use App\Http\Controllers\Backend\VideoController;
use App\Http\Controllers\Backend\SoundController;
use App\Http\Controllers\Backend\ImageController;
use App\Http\Controllers\Backend\DocumentController;
use App\Http\Controllers\Backend\FolderController;
use Illuminate\Support\Facades\Route;

/* ===== Backend: Not Authenticate ===== */

Route::get('', [AuthenticateController::class, 'index'])->name('index');
Route::get('login', [AuthenticateController::class, 'login'])->name('login');
Route::post('authenticate', [AuthenticateController::class, 'authenticate'])->name('authenticate');

Route::get('forgot-password', [AuthenticateController::class, 'forgotPassword'])->name('forgotPassword');
Route::post('post-forgot-password', [AuthenticateController::class, 'updateForgotPassword'])->name('updateForgotPassword');

Route::get('reset-password/{token}', [AuthenticateController::class, 'resetPassword'])->name('resetPassword');
Route::post('post-reset-password', [AuthenticateController::class, 'updateResetPassword'])->name('updateResetPassword');

/* ===== Backend: Authenticate ===== */
Route::group(["middleware" => ["role: 0|1|2"]], function () {
    Route::get('logout', [AuthenticateController::class, 'logout'])->name('logout');
    
    Route::get('dashboard', [AdminController::class, 'index'])->name('dashboard');

    // Subcategory for Category
    Route::get('no-where-else/sub-category/{fromDate?}/{toDate?}', [SubCategoryController::class, 'index']);
    Route::get('no-where-else/add-sub-category', [SubCategoryController::class, 'add']);
    Route::post('no-where-else/insert-sub-category', [SubCategoryController::class, 'insert']);
    Route::get('no-where-else/edit-sub-category/{id}', [SubCategoryController::class, 'edit']);
    Route::post('no-where-else/update-sub-category', [SubCategoryController::class, 'update']);
    Route::post('no-where-else/delete-sub-category', [SubCategoryController::class, 'delete']);

    // Article
    Route::get('no-where-else/article/{fromDate?}/{toDate?}', [ArticleController::class, 'index']);
    Route::get('no-where-else/add-article', [ArticleController::class, 'add']);
    Route::post('no-where-else/insert-article', [ArticleController::class, 'insert']);
    Route::get('no-where-else/edit-article/{id}', [ArticleController::class, 'edit']);
    Route::post('no-where-else/update-article', [ArticleController::class, 'update']);
    Route::post('no-where-else/delete-article', [ArticleController::class, 'delete']);


    // Subcategory for Category 2
    Route::get('where-else/sub-category/{fromDate?}/{toDate?}', [SubCategoryWhereElseController::class, 'index']);
    Route::get('where-else/add-sub-category', [SubCategoryWhereElseController::class, 'add']);
    Route::post('where-else/insert-sub-category', [SubCategoryWhereElseController::class, 'insert']);
    Route::get('where-else/edit-sub-category/{id}', [SubCategoryWhereElseController::class, 'edit']);
    Route::post('where-else/update-sub-category', [SubCategoryWhereElseController::class, 'update']);
    Route::post('where-else/delete-sub-category', [SubCategoryWhereElseController::class, 'delete']);

    // Sub Article
    Route::get('where-else/article/{fromDate?}/{toDate?}', [ArticleWhereElseController::class, 'index']);
    Route::get('where-else/add-article', [ArticleWhereElseController::class, 'add']);
    Route::post('where-else/insert-article', [ArticleWhereElseController::class, 'insert']);
    Route::get('where-else/edit-article/{id}', [ArticleWhereElseController::class, 'edit']);
    Route::post('where-else/update-article', [ArticleWhereElseController::class, 'update']);
    Route::post('where-else/delete-article', [ArticleWhereElseController::class, 'delete']);


    // Video
    Route::get('video', [VideoController::class, 'index'])->name('video-index');
    Route::get('video/add/{folderId?}', [VideoController::class, 'add'])->name('video-add');
    Route::post('video/insert', [VideoController::class, 'insert'])->name('video-insert');
    Route::post('video/delete', [VideoController::class, 'delete'])->name('video-delete');


    Route::get('video/folder/{folderId}', [VideoController::class, 'folder'])->name('video-folder');
    Route::get('video/add-folder', [VideoController::class, 'addFolder'])->name('video-add-folder');
    Route::post('video/insert-folder', [VideoController::class, 'insertFolder'])->name('video-insert-folder');
    Route::get('video/edit-folder/{folderId}', [VideoController::class, 'editFolder'])->name('video-edit-folder');
    Route::post('video/update-folder', [VideoController::class, 'updateFolder'])->name('video-update');
    Route::post('video/delete-folder', [VideoController::class, 'deleteFolder'])->name('video-delete');
    Route::get('video/download-folder/{folderId}', [VideoController::class, 'downloadFolder']);

    // Sound
    Route::get('sound', [SoundController::class, 'index'])->name('sound-index');
    Route::get('sound/add/{folderId?}', [SoundController::class, 'add'])->name('sound-add');
    Route::post('sound/insert', [SoundController::class, 'insert'])->name('sound-insert');
    Route::post('sound/delete', [SoundController::class, 'delete'])->name('sound-delete');

    Route::get('sound/folder/{folderId}', [SoundController::class, 'folder'])->name('sound-folder');
    Route::get('sound/add-folder', [SoundController::class, 'addFolder'])->name('sound-add-folder');
    Route::post('sound/insert-folder', [SoundController::class, 'insertFolder'])->name('sound-insert-folder');
    Route::get('sound/edit-folder/{folderId}', [SoundController::class, 'editFolder'])->name('sound-edit-folder');
    Route::post('sound/update-folder', [SoundController::class, 'updateFolder'])->name('sound-update');
    Route::post('sound/delete-folder', [SoundController::class, 'deleteFolder'])->name('sound-delete');
    Route::get('sound/download-folder/{folderId}', [SoundController::class, 'downloadFolder']);

    // Image
    Route::get('image', [ImageController::class, 'index'])->name('image-index');
    Route::get('image/add/{folderId?}', [ImageController::class, 'add'])->name('image-add');
    Route::post('image/insert', [ImageController::class, 'insert'])->name('image-insert');
    Route::post('image/delete', [ImageController::class, 'delete'])->name('image-delete');

    Route::get('image/folder/{folderId}', [ImageController::class, 'folder'])->name('image-folder');
    Route::get('image/add-folder', [ImageController::class, 'addFolder'])->name('image-add-folder');
    Route::post('image/insert-folder', [ImageController::class, 'insertFolder'])->name('image-insert-folder');
    Route::get('image/edit-folder/{folderId}', [ImageController::class, 'editFolder'])->name('image-edit-folder');
    Route::post('image/update-folder', [ImageController::class, 'updateFolder'])->name('image-update');
    Route::post('image/delete-folder', [ImageController::class, 'deleteFolder'])->name('image-delete');
    Route::get('image/download-folder/{folderId}', [ImageController::class, 'downloadFolder']);

    // Document
    Route::get('document', [DocumentController::class, 'index'])->name('document-index');
    Route::get('document/add/{folderId?}', [DocumentController::class, 'add'])->name('document-add');
    Route::post('document/insert', [DocumentController::class, 'insert'])->name('document-insert');
    Route::post('document/delete', [DocumentController::class, 'delete'])->name('document-delete');

    Route::get('document/folder/{folderId}', [DocumentController::class, 'folder'])->name('document-folder');
    Route::get('document/add-folder', [DocumentController::class, 'addFolder'])->name('document-add-folder');
    Route::post('document/insert-folder', [DocumentController::class, 'insertFolder'])->name('document-insert-folder');
    Route::get('document/edit-folder/{folderId}', [DocumentController::class, 'editFolder'])->name('document-edit-folder');
    Route::post('document/update-folder', [DocumentController::class, 'updateFolder'])->name('document-update');
    Route::post('document/delete-folder', [DocumentController::class, 'deleteFolder'])->name('document-delete');
    Route::get('document/download-folder/{folderId}', [DocumentController::class, 'downloadFolder']);

    Route::get('user', [UserController::class, 'index'])->name('user-index');
    Route::get('user/add', [UserController::class, 'add'])->name('user-add');
    Route::get('user/edit/{id}', [UserController::class, 'edit'])->name('user-edit');
    Route::post('user/update', [UserController::class, 'update'])->name('user-update');
    Route::post('user/insert', [UserController::class, 'insert'])->name('user-insert');
    Route::post('user/delete', [UserController::class, 'delete'])->name('user-delete');




    Route::post('no-where-else/article-upload-image', [ArticleController::class, 'uploadImage']);
    Route::post('where-else/article-upload-image', [ArticleWhereElseController::class, 'uploadImage']);

    // Ck Editor
    // Route::post('ck-editor/upload', [CkEditorHelperController::class, 'upload'])->name('ck-editor-upload');
});
