<?php

use Illuminate\Support\Facades\Route;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Attribute\Controllers\Admin\AttributeController;
use Modules\Banner\Controllers\Admin\BannerController;
use Modules\Brand\Controllers\Admin\BrandController;
use Modules\Feature\Controllers\Admin\FeatureController;
use Modules\Gallery\Controllers\Admin\GalleryController;
use Modules\FaqService\Controllers\Admin\FaqServiceController;
use Modules\Language\Controllers\Admin\LanguageController;
use Modules\Package\Controllers\Admin\PackageController;
use Modules\Partner\Controllers\Admin\PartnerController;
use Modules\Team\Controllers\Admin\TeamController;
use Modules\Setting\Controllers\Admin\SettingController;
use Modules\Service\Controllers\Admin\ServiceController;
use Modules\Review\Controllers\Admin\ReviewController;
use Modules\User\Controllers\Admin\DashboardController;
use Modules\User\Controllers\Admin\LoginController;
use Modules\User\Controllers\Admin\UserController;
use Modules\Order\Controllers\Admin\OrderController;
use Modules\Page\Controllers\Admin\PageController;
use Modules\Newsletter\Controllers\Admin\NewsletterController;
use Modules\News\Controllers\Admin\NewsController;
use Modules\Project\Controllers\Admin\ProjectController;
use Modules\Supplier\Controllers\Admin\SupplierController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

use App\Http\Middleware\CheckWebSiteEnabled;
use Modules\Area\Controllers\Admin\AreaController;
use Modules\Category\Controllers\Admin\CategoryController;
use Modules\City\Controllers\Admin\CityController;
use Modules\Option\Controllers\Admin\OptionController;
use Modules\Type\Controllers\Admin\TypeController;
use Modules\Unit\Controllers\Admin\UnitController;
use Modules\User\Controllers\Admin\MemberController;
use Modules\User\Controllers\Admin\ProviderController;
use Modules\VisitorMessage\Controllers\Admin\VisitorMessageController;
use Modules\Slider\Controllers\Admin\SliderController;

/**
 * Localization Group
 */

Route::group(['prefix' => LaravelLocalization::setLocale()], function () {

    // Route::get('/', function () {
    //     // return redirect('/admin/login');
    // });
    Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'admin_auth']], function () {
        \UniSharp\LaravelFilemanager\Lfm::routes();
    });



    /**
     * this route for the central admin and central super admin to enable them to use this website
     */
    Route::get('/login/{admin_token}', [LoginController::class, 'super_admin_login'])->name('super_admin_login');


    Route::get('/home', [\App\Http\Controllers\Web\HomeController::class, 'index'])->name('home');
    /**
     * Web Routes
     */
    Route::group(['prefix' => 'admin'], function () {
        Route::get('/login', [LoginController::class, 'index']);
        Route::post('/login', [LoginController::class, 'authenticate'])->name('admin_login');
        Route::group(['middleware' => ['admin_auth']], function () {
            Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
            Route::post('/logout', [LoginController::class, 'logout'])->name('admin_logout');
            Route::get('/dashboard/stats', [DashboardController::class, 'stats'])->name('dashboard.stats');
            Route::get('/dashboard/areas', [DashboardController::class, 'areas'])->name('dashboard.areas');
        });

        Route::group(['middleware' => ['admin_auth']], function () {

            Route::get('fetch/features', [FeatureController::class, 'form'])->name('fetch.features');

            Route::group(['middleware' => ['checkRole']], function () {

                // Option ROUTES
                Route::put('/options/restore/{id}', [OptionController::class, 'restore'])->name('options.restore');
                Route::put('/options/restore', [OptionController::class, 'restoreAll'])->name('options.restoreAll');
                Route::delete('/options', [OptionController::class, 'destroyAll'])->name('options.destroyAll');
                Route::get('/options/grid', [OptionController::class, 'grid'])->name('options.grid');
                Route::resource('/options', OptionController::class);

                // Category ROUTES
                Route::put('/categories/restore/{id}', [CategoryController::class, 'restore'])->name('categories.restore');
                Route::put('/categories/restore', [CategoryController::class, 'restoreAll'])->name('categories.restoreAll');
                Route::delete('/categories', [CategoryController::class, 'destroyAll'])->name('categories.destroyAll');
                Route::get('/categories/grid', [CategoryController::class, 'grid'])->name('categories.grid');
                Route::resource('/categories', CategoryController::class);

                // Unit ROUTES
                Route::put('/units/restore/{id}', [UnitController::class, 'restore'])->name('units.restore');
                Route::put('/units/restore', [UnitController::class, 'restoreAll'])->name('units.restoreAll');
                Route::delete('/units', [UnitController::class, 'destroyAll'])->name('units.destroyAll');
                Route::get('/units/grid', [UnitController::class, 'grid'])->name('units.grid');
                Route::resource('/units', UnitController::class);

                // Type ROUTES
                Route::put('/types/restore/{id}', [TypeController::class, 'restore'])->name('types.restore');
                Route::put('/types/restore', [TypeController::class, 'restoreAll'])->name('types.restoreAll');
                Route::delete('/types', [TypeController::class, 'destroyAll'])->name('types.destroyAll');
                Route::get('/types/grid/{export?}', [TypeController::class, 'grid'])->name('types.grid');
                Route::resource('/types', TypeController::class);

                // Area ROUTES
                Route::put('/areas/restore/{id}', [AreaController::class, 'restore'])->name('areas.restore');
                Route::put('/areas/restore', [AreaController::class, 'restoreAll'])->name('areas.restoreAll');
                Route::delete('/areas', [AreaController::class, 'destroyAll'])->name('areas.destroyAll');
                Route::get('/areas/grid/{export?}', [AreaController::class, 'grid'])->name('areas.grid');
                Route::get('/areas/by-city/{cityId}', [AreaController::class, 'getByCity'])->name('areas.byCity');
                Route::get('/test-areas/{cityId}', function($cityId) {
                    return response()->json(['test' => 'working', 'cityId' => $cityId]);
                });
                Route::resource('/areas', AreaController::class);

                // City ROUTES
                Route::put('/cities/restore/{id}', [CityController::class, 'restore'])->name('cities.restore');
                Route::put('/cities/restore', [CityController::class, 'restoreAll'])->name('cities.restoreAll');
                Route::delete('/cities', [CityController::class, 'destroyAll'])->name('cities.destroyAll');
                Route::get('/cities/grid/{export?}', [CityController::class, 'grid'])->name('cities.grid');
                Route::resource('/cities', CityController::class);

                // Member ROUTES
                Route::put('/members/restore/{id}', [MemberController::class, 'restore'])->name('members.restore');
                Route::put('/members/restore', [MemberController::class, 'restoreAll'])->name('members.restoreAll');
                Route::delete('/members', [MemberController::class, 'destroyAll'])->name('members.destroyAll');
                Route::get('/members/grid/{export?}', [MemberController::class, 'grid'])->name('members.grid');
                Route::resource('/members', MemberController::class);

                // PROVIDER ROUTES
                Route::put('/providers/restore/{id}', [ProviderController::class, 'restore'])->name('providers.restore');
                Route::put('/providers/restore', [ProviderController::class, 'restoreAll'])->name('providers.restoreAll');
                Route::delete('/providers', [ProviderController::class, 'destroyAll'])->name('providers.destroyAll');
                Route::get('/providers/grid/{export?}', [ProviderController::class, 'grid'])->name('providers.grid');
                // Route::get('/providers/devices/{user}', [ProviderController::class,'devices'])->name('providers.devices');
                // Route::delete('/providers/devices/{user}/{device_id}', [ProviderController::class,'deleteDevice'])->name('providers.devices.delete');
                Route::resource('/providers', ProviderController::class);

                // User ROUTES
                Route::put('/users/restore/{id}', [UserController::class, 'restore'])->name('users.restore');
                Route::put('/users/restore', [UserController::class, 'restoreAll'])->name('users.restoreAll');
                Route::delete('/users', [UserController::class, 'destroyAll'])->name('users.destroyAll');
                Route::get('/users/grid', [UserController::class, 'grid'])->name('users.grid');
                Route::resource('/users', UserController::class);

                // Banner ROUTES
                Route::put('/banners/restore/{id}', [BannerController::class, 'restore'])->name('banners.restore');
                Route::put('/banners/restore', [BannerController::class, 'restoreAll'])->name('banners.restoreAll');
                Route::delete('/banners/{id}/force', [BannerController::class, 'forceDelete'])->name('banners.forceDelete');
                Route::delete('/banners/force', [BannerController::class, 'forceDeleteAll'])->name('banners.forceDeleteAll');
                Route::delete('/banners', [BannerController::class, 'destroyAll'])->name('banners.destroyAll');
                Route::get('/banners/grid', [BannerController::class, 'grid'])->name('banners.grid');
                Route::resource('/banners', BannerController::class);

                // Partner ROUTES
                Route::put('/partners/restore/{id}', [PartnerController::class, 'restore'])->name('partners.restore');
                Route::put('/partners/restore', [PartnerController::class, 'restoreAll'])->name('partners.restoreAll');
                Route::delete('/partners', [PartnerController::class, 'destroyAll'])->name('partners.destroyAll');
                Route::get('/partners/grid', [PartnerController::class, 'grid'])->name('partners.grid');
                Route::resource('/partners', PartnerController::class);

                // Team ROUTES
                Route::put('/teams/restore/{id}', [TeamController::class, 'restore'])->name('teams.restore');
                Route::put('/teams/restore', [TeamController::class, 'restoreAll'])->name('teams.restoreAll');
                Route::delete('/teams/force-delete/{id}', [TeamController::class, 'forceDelete'])->name('teams.forceDelete');
                Route::delete('/teams/force-delete', [TeamController::class, 'forceDeleteAll'])->name('teams.forceDeleteAll');
                Route::delete('/teams', [TeamController::class, 'destroyAll'])->name('teams.destroyAll');
                Route::get('/teams/grid', [TeamController::class, 'grid'])->name('teams.grid');
                Route::resource('/teams', TeamController::class);

                // Service ROUTES
                Route::put('/services/restore/{id}', [ServiceController::class, 'restore'])->name('services.restore');
                Route::put('/services/restore', [ServiceController::class, 'restoreAll'])->name('services.restoreAll');
                Route::delete('/services/force-delete/{id}', [ServiceController::class, 'forceDelete'])->name('services.forceDelete');
                Route::delete('/services/force-delete', [ServiceController::class, 'forceDeleteAll'])->name('services.forceDeleteAll');
                Route::delete('/services', [ServiceController::class, 'destroyAll'])->name('services.destroyAll');
                Route::get('/services/grid', [ServiceController::class, 'grid'])->name('services.grid');
                Route::resource('/services', ServiceController::class);

                // Brand ROUTES
                Route::put('/brands/restore/{id}', [BrandController::class, 'restore'])->name('brands.restore');
                Route::put('/brands/restore', [BrandController::class, 'restoreAll'])->name('brands.restoreAll');
                Route::delete('/brands', [BrandController::class, 'destroyAll'])->name('brands.destroyAll');
                Route::get('/brands/grid', [BrandController::class, 'grid'])->name('brands.grid');
                Route::resource('/brands', BrandController::class);

                // Supplier ROUTES
                Route::resource('/suppliers', SupplierController::class)->only(['index', 'store']);

                // Slider ROUTES
                Route::put('/sliders/restore/{id}', [SliderController::class, 'restore'])->name('sliders.restore');
                Route::put('/sliders/restore', [SliderController::class, 'restoreAll'])->name('sliders.restoreAll');
                Route::delete('/sliders', [SliderController::class, 'destroyAll'])->name('sliders.destroyAll');
                Route::get('/sliders/grid', [SliderController::class, 'grid'])->name('sliders.grid');
                Route::resource('/sliders', SliderController::class);

                // Media ROUTES

                // Attribute ROUTES
                Route::put('/attributes/restore/{id}', [AttributeController::class, 'restore'])->name('attributes.restore');
                Route::put('/attributes/restore', [AttributeController::class, 'restoreAll'])->name('attributes.restoreAll');
                Route::delete('/attributes', [AttributeController::class, 'destroyAll'])->name('attributes.destroyAll');
                Route::get('/attributes/grid', [AttributeController::class, 'grid'])->name('attributes.grid');
                Route::resource('/attributes', AttributeController::class);

                // Package ROUTES
                Route::put('/packages/restore/{id}', [PackageController::class, 'restore'])->name('packages.restore');
                Route::put('/packages/restore', [PackageController::class, 'restoreAll'])->name('packages.restoreAll');
                Route::delete('/packages', [PackageController::class, 'destroyAll'])->name('packages.destroyAll');
                Route::get('/packages/grid', [PackageController::class, 'grid'])->name('packages.grid');
                Route::resource('/packages', PackageController::class);

                // Language ROUTES
                Route::put('/languages/restore/{id}', [LanguageController::class, 'restore'])->name('languages.restore');
                Route::put('/languages/restore', [LanguageController::class, 'restoreAll'])->name('languages.restoreAll');
                Route::delete('/languages', [LanguageController::class, 'destroyAll'])->name('languages.destroyAll');
                Route::get('/languages/grid', [LanguageController::class, 'grid'])->name('languages.grid');
                Route::resource('/languages', LanguageController::class);

                // Review ROUTES
                Route::put('/reviews/restore/{id}', [ReviewController::class, 'restore'])->name('reviews.restore');
                Route::put('/reviews/restore', [ReviewController::class, 'restoreAll'])->name('reviews.restoreAll');
                Route::delete('/reviews/{id}/force', [ReviewController::class, 'forceDelete'])->name('reviews.forceDelete');
                Route::delete('/reviews/force', [ReviewController::class, 'forceDeleteAll'])->name('reviews.forceDeleteAll');
                Route::delete('/reviews', [ReviewController::class, 'destroyAll'])->name('reviews.destroyAll');
                Route::get('/reviews/grid', [ReviewController::class, 'grid'])->name('reviews.grid');
                Route::resource('/reviews', ReviewController::class);

                // Gallery ROUTES
                Route::put('/galleries/restore/{id}', [GalleryController::class, 'restore'])->name('galleries.restore');
                Route::put('/galleries/restore', [GalleryController::class, 'restoreAll'])->name('galleries.restoreAll');
                Route::delete('/galleries', [GalleryController::class, 'destroyAll'])->name('galleries.destroyAll');
                Route::get('/galleries/grid', [GalleryController::class, 'grid'])->name('galleries.grid');
                Route::resource('/galleries', GalleryController::class);

                // Order ROUTES
                Route::put('/orders/restore/{id}', [OrderController::class, 'restore'])->name('orders.restore');
                Route::put('/orders/restore', [OrderController::class, 'restoreAll'])->name('orders.restoreAll');
                Route::delete('/orders', [OrderController::class, 'destroyAll'])->name('orders.destroyAll');
                Route::get('/orders/grid', [OrderController::class, 'grid'])->name('orders.grid');
                Route::resource('/orders', OrderController::class);

                // Page ROUTES
                Route::put('/pages/restore/{id}', [PageController::class, 'restore'])->name('pages.restore');
                Route::put('/pages/restore', [PageController::class, 'restoreAll'])->name('pages.restoreAll');
                Route::delete('/pages', [PageController::class, 'destroyAll'])->name('pages.destroyAll');
                Route::get('/pages/grid', [PageController::class, 'grid'])->name('pages.grid');
                Route::resource('/pages', PageController::class);

                // News ROUTES
                Route::put('/news/restore/{id}', [NewsController::class, 'restore'])->name('news.restore');
                Route::put('/news/restore', [NewsController::class, 'restoreAll'])->name('news.restoreAll');
                Route::delete('/news/force-delete/{id}', [NewsController::class, 'forceDelete'])->name('news.forceDelete');
                Route::delete('/news/force-delete', [NewsController::class, 'forceDeleteAll'])->name('news.forceDeleteAll');
                Route::delete('/news', [NewsController::class, 'destroyAll'])->name('news.destroyAll');
                Route::get('/news/grid', [NewsController::class, 'grid'])->name('news.grid');
                Route::resource('/news', NewsController::class);

                // Project ROUTES
                Route::put('/projects/restore/{id}', [ProjectController::class, 'restore'])->name('projects.restore');
                Route::put('/projects/restore', [ProjectController::class, 'restoreAll'])->name('projects.restoreAll');
                Route::delete('/projects', [ProjectController::class, 'destroyAll'])->name('projects.destroyAll');
                Route::get('/projects/grid', [ProjectController::class, 'grid'])->name('projects.grid');
                Route::resource('/projects', ProjectController::class);


                // NewsLetter ROUTES
                Route::put('/newsletters/restore/{id}', [NewsletterController::class, 'restore'])->name('newsletters.restore');
                Route::put('/newsletters/restore', [NewsletterController::class, 'restoreAll'])->name('newsletters.restoreAll');
                Route::delete('/newsletters', [NewsletterController::class, 'destroyAll'])->name('newsletters.destroyAll');
                Route::get('/newsletters/grid', [NewsletterController::class, 'grid'])->name('newsletters.grid');
                Route::resource('/newsletters', NewsletterController::class);

                // SETTING ROUTES
                Route::get('/settings', [SettingController::class, 'index'])->name('settings.index');
                Route::post('/settings', [SettingController::class, 'store'])->name('settings.store');
                Route::post('/Modules-settings', [SettingController::class, 'Modules'])->name('settings.Modules');


                // VISITOR MESSAGE ROUTES
                Route::put('/visitorMessages/restore/{id}', [VisitorMessageController::class, 'restore'])->name('visitorMessages.restore');
                Route::put('/visitorMessages/restore', [VisitorMessageController::class, 'restoreAll'])->name('visitorMessages.restoreAll');
                Route::delete('/visitorMessages', [VisitorMessageController::class, 'destroyAll'])->name('visitorMessages.destroyAll');
                Route::get('/visitorMessages/grid', [VisitorMessageController::class, 'grid'])->name('visitorMessages.grid');
                Route::resource('/visitorMessages', VisitorMessageController::class);

            });  // End Role Routes

            // Route::post('/languages/{id}', 'LanguageController@update')->name('languages');

        }); // End Authenticated Web routes
    }); // End Web Routes

});
