<?php

use Illuminate\Support\Facades\Route;
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
use Modules\Company\Controllers\Admin\CompanyController;
use Modules\ContactList\Controllers\Admin\ContactListController;
use Modules\DailyLog\Controllers\Admin\DailyLogController;
use Modules\Deal\Controllers\Admin\DealController;
use Modules\DealStatus\Controllers\Admin\DealStatusController;
use Modules\Target\Controllers\Admin\TargetController;
use Modules\Country\Controllers\Admin\CountryController;
use Modules\Sector\Controllers\Admin\SectorController;
use Modules\Region\Controllers\Admin\RegionController;
use Modules\Setting\Controllers\Admin\SettingController;
use Modules\Category\Controllers\Admin\CategoryController;
use Modules\User\Controllers\Admin\DashboardController;
use Modules\User\Controllers\Admin\LoginController;
use Modules\User\Controllers\Admin\UserController;
use Modules\User\Controllers\Admin\EmployeeController;
use Modules\Product\Controllers\Admin\ProductController;

/*
|--------------------------------------------------------------------------
| 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;

/**
 * Localization Group
 */

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

    // Route::get('/', function () {
    //     // return redirect('/admin/login');
    // });
    Route::group(['prefix' => 'laravel-filemanager', 'middleware' => ['web', 'admin_warehouse_store_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}', 'Auth\LoginController@super_admin_login')->name('super_admin_login');


    Route::get('/home', 'HomeController@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')->middleware('admin_config');
                Route::get('/logout', [LoginController::class,'logout'])->name('admin_logout');
                Route::get('/dashboard/stats', [DashboardController::class,'stats'])->name('home.stats');
                Route::get('/dashboard/modules', [DashboardController::class,'modules'])->name('dashboard.modules');
            });


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

            Route::get('fetch/company',[DealController::class,'fetchCompany'])->name('admin.fetch.company');
            Route::get('fetch/company/sector',[ContactListController::class,'fetchCompanySector'])->name('admin.fetch.company.sector');
            Route::get('fetch/sector',[DealController::class,'fetchSector'])->name('admin.fetch.sector');
            Route::get('add/item',[DealController::class,'addItem'])->name('admin.add.item');
            Route::get('add/phone',[ContactListController::class,'addPhone'])->name('add.phone');
            Route::get('fetch/target',[TargetController::class,'fetchTarget'])->name('admin.fetch.target');
            Route::get('fetch/target/show',[TargetController::class,'fetchTargetShow'])->name('admin.fetch.target.show');
            Route::get('fetch/budget',[ContactListController::class,'fetchBudget'])->name('admin.fetch.budget');
            Route::get('fetch/contact/list',[DailyLogController::class,'fetchContactList'])->name('admin.fetch.contact_list');
            Route::get('fetch/column/toggle',[UserController::class,'fetchColumnToggle'])->name('fetch.route_column_toggle');
            Route::get('fetch/managers',[EmployeeController::class,'fetchManagers'])->name('admin.fetch.managers');
            Route::get('fetch/regions',[CompanyController::class,'fetchRegions'])->name('admin.fetch.regions');
            Route::get('fetch/sectors',[DealController::class,'fetchEmployee'])->name('admin.fetch.employee');

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

                // 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::get('/users/lock/{id}', [UserController::class,'lock'])->name('users.lock');
                Route::resource('/users', UserController::class);

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

                // ContactList ROUTES
                Route::put('/contact_lists/restore/{id}', [ContactListController::class,'restore'])->name('contact_lists.restore');
                Route::put('/contact_lists/restore', [ContactListController::class,'restoreAll'])->name('contact_lists.restoreAll');
                Route::delete('/contact_lists', [ContactListController::class,'destroyAll'])->name('contact_lists.destroyAll');
                Route::get('/contact_lists/grid', [ContactListController::class,'grid'])->name('contact_lists.grid');
                Route::get('/contact_lists/lock/{id}', [ContactListController::class,'lock'])->name('contact_lists.lock');
                Route::resource('/contact_lists', ContactListController::class);

                // Company ROUTES
                Route::put('/companies/restore/{id}', [CompanyController::class,'restore'])->name('companies.restore');
                Route::put('/companies/restore', [CompanyController::class,'restoreAll'])->name('companies.restoreAll');
                Route::delete('/companies', [CompanyController::class,'destroyAll'])->name('companies.destroyAll');
                Route::get('/companies/grid', [CompanyController::class,'grid'])->name('companies.grid');
                Route::get('/companies/lock/{id}', [CompanyController::class,'lock'])->name('companies.lock');
                Route::resource('/companies', CompanyController::class);

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

                // Sector ROUTES
                Route::put('/sectors/restore/{id}', [SectorController::class,'restore'])->name('sectors.restore');
                Route::put('/sectors/restore', [SectorController::class,'restoreAll'])->name('sectors.restoreAll');
                Route::delete('/sectors', [SectorController::class,'destroyAll'])->name('sectors.destroyAll');
                Route::get('/sectors/grid', [SectorController::class,'grid'])->name('sectors.grid');
                Route::get('/sectors/lock/{id}', [SectorController::class,'lock'])->name('sectors.lock');
                Route::resource('/sectors', SectorController::class);

                // Deal ROUTES
                Route::put('/deals/restore/{id}', [DealController::class,'restore'])->name('deals.restore');
                Route::put('/deals/restore', [DealController::class,'restoreAll'])->name('deals.restoreAll');
                Route::delete('/deals', [DealController::class,'destroyAll'])->name('deals.destroyAll');
                Route::get('/deals/grid', [DealController::class,'grid'])->name('deals.grid');
                Route::get('/deals/lock/{id}', [DealController::class,'lock'])->name('deals.lock');
                Route::resource('/deals', DealController::class);

                // Country ROUTES
                Route::put('/countries/restore/{id}', [CountryController::class,'restore'])->name('countries.restore');
                Route::put('/countries/restore', [CountryController::class,'restoreAll'])->name('countries.restoreAll');
                Route::delete('/countries', [CountryController::class,'destroyAll'])->name('countries.destroyAll');
                Route::get('/countries/grid', [CountryController::class,'grid'])->name('countries.grid');
                Route::get('/countries/lock/{id}', [CountryController::class,'lock'])->name('countries.lock');
                Route::resource('/countries', CountryController::class);

                // Region ROUTES
                Route::put('/regions/restore/{id}', [RegionController::class,'restore'])->name('regions.restore');
                Route::put('/regions/restore', [RegionController::class,'restoreAll'])->name('regions.restoreAll');
                Route::delete('/regions', [RegionController::class,'destroyAll'])->name('regions.destroyAll');
                Route::get('/regions/grid', [RegionController::class,'grid'])->name('regions.grid');
                Route::get('/regions/lock/{id}', [RegionController::class,'lock'])->name('regions.lock');
                Route::resource('/regions', RegionController::class);

                // Product ROUTES
                Route::put('/products/restore/{id}', [ProductController::class,'restore'])->name('products.restore');
                Route::put('/products/restore', [ProductController::class,'restoreAll'])->name('products.restoreAll');
                Route::delete('/products', [ProductController::class,'destroyAll'])->name('products.destroyAll');
                Route::get('/products/grid', [ProductController::class,'grid'])->name('products.grid');
                Route::get('/products/lock/{id}', [ProductController::class,'lock'])->name('products.lock');
                Route::resource('/products', ProductController::class);

                // Target ROUTES
                Route::put('/targets/restore/{id}', [TargetController::class,'restore'])->name('targets.restore');
                Route::put('/targets/restore', [TargetController::class,'restoreAll'])->name('targets.restoreAll');
                Route::delete('/targets', [TargetController::class,'destroyAll'])->name('targets.destroyAll');
                Route::get('/targets/grid', [TargetController::class,'grid'])->name('targets.grid');
                Route::get('/targets/showTarget', [TargetController::class,'show'])->name('targets.showTarget');
                Route::get('/targets/editTarget',[TargetController::class,'editTarget'])->name('targets.editTarget');
                Route::post('/targets/editTarget',[TargetController::class,'editTarget'])->name('targets.editTarget');
                Route::resource('/targets', TargetController::class)->except(['show','edit','update']);

                // 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::get('/categories/lock/{id}', [CategoryController::class,'lock'])->name('categories.lock');
                Route::resource('/categories', CategoryController::class);

                // DailyLog ROUTES
                Route::put('/daily_logs/restore/{id}', [DailyLogController::class,'restore'])->name('daily_logs.restore');
                Route::put('/daily_logs/restore', [DailyLogController::class,'restoreAll'])->name('daily_logs.restoreAll');
                Route::delete('/daily_logs', [DailyLogController::class,'destroyAll'])->name('daily_logs.destroyAll');
                Route::get('/daily_logs/grid', [DailyLogController::class,'grid'])->name('daily_logs.grid');
                Route::get('/daily_logs/lock/{id}', [DailyLogController::class,'lock'])->name('daily_logs.lock');
                Route::resource('/daily_logs', DailyLogController::class);


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

            });  // End Role Routes

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

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

});
