<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| 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!
|
*/
Route::get('/', function () {
    return Helper::isInstalled() ? view('auth.login') : redirect()->route('LaravelInstaller::welcome');
})->middleware('guest');

Auth::routes(['register' => false]);
Route::get('logout', function () {
    return Auth::logout();
});

Route::get('lang/{lang}', 'CommonController@languageSwitcher')->name('localization');

Route::group(['prefix' => 'install', 'as' => 'LaravelInstallerModified::', 'middleware' => ['install']], function () {
    Route::post('environment/modify/saveWizard', 'CommonController@installerSaveWizard')->name('environmentSaveWizard');
    Route::get('modify/database', 'CommonController@installerDatabase')->name('database');
});

// all types of auth routes start
Route::group(['middleware' => ['auth']], function () {
    Route::group(['prefix' => 'dashboard', 'as' => 'dashboard-'], function () {
        Route::get('', 'CommonController@dashboardSwitcher')->name('page');
        Route::layout('partial.__blank')->group(function () {
            Route::livewire('notice', 'dashboard-notice')->name('notice');
            Route::livewire('holiday', 'dashboard-holiday')->name('holiday');
            Route::livewire('holiday-list', 'dashboard-holiday-list')->name('holiday-list');
            Route::livewire('leave', 'dashboard-leave')->name('leave');
            Route::livewire('leave-list', 'dashboard-leave-list')->name('leave-list');
            Route::livewire('worked', 'dashboard-worked')->name('worked');

            // only for admin
            Route::livewire('user', 'dashboard-user')->name('user');
            Route::livewire('present', 'dashboard-present')->name('present');
        });
    });

    Route::get('/home', 'CommonController@index')->name('home');
    Route::view('holiday', 'common.holiday.index')->name('holiday');

    Route::view('update-password', 'common.update-password')->name('update-password');
    Route::view('update-info', 'common.update-info')->name('update-info');

    // leave routes for all auth user
    Route::group(['prefix' => 'leave', 'as' => 'leave-'], function () {
        Route::view('', 'common.leave.index')->name('list');
        Route::livewire('/apply', 'leave-apply')->layout('layouts.user.master')->name('apply');
        Route::get('category/json', 'CommonController@jsonLeaveCategoryList')->name('category-list-json');
        Route::get('status/json', 'CommonController@jsonLeaveStatusList')->name('status-list-json');
    });

    Route::view('notice', 'common.notice.index')->name('notice-list');

    // report
    Route::group(['prefix' => 'report', 'as' => 'report-'], function () {
        Route::view('', 'common.report.index')->name('table');
        Route::get('download', 'CommonController@reportDownload')->name('download');
    });

    // only admin routes start
    Route::group(['middleware' => ['admin'], 'namespace' => 'Admin', 'as' => 'admin-'], function () {
        // user routes for admin
        Route::group(['prefix' => 'user', 'as' => 'user-'], function () {
            Route::get('', 'UserController@index')->name('list');
            Route::get('json', 'UserController@jsonList')->name('list-json');
            Route::patch('{user}', 'UserController@update')->name('update');
            Route::post('{user}/punch', 'UserController@punchHit')->name('punch');
            Route::get('{user}/punch/status', 'UserController@getPunchStatus')->name('punch-status');
            Route::get('{user}/force/login', 'UserController@forceLogin')->name('force-login');
        });

        // designation routes for admin
        Route::group(['prefix' => 'designation', 'as' => 'designation-'], function () {
            Route::get('', 'DesignationController@index')->name('list');
            Route::post('{designation}/bulk-apply', 'DesignationController@bulkApply')->name('bulk-apply');
            Route::get('json', 'DesignationController@jsonList')->name('list-json');
            Route::patch('{designation}', 'DesignationController@update')->name('update');
        });

        // holiday routes for admin
        Route::group(['prefix' => 'holiday', 'as'=> 'holiday-'], function () {
            Route::post('', 'HolidayController@store')->name('save');
        });

        // leave routes for admin
        Route::group(['prefix' => 'leave', 'as' => 'leave-'], function () {
            Route::post('{leave}', 'LeaveController@statusUpdate')->name('status-update');

            // leave category routes for admin
            Route::group(['prefix' => 'category', 'as' => 'category-'], function () {
                Route::get('', 'LeaveController@allCategory')->name('list');
                Route::patch('{category}', 'LeaveController@categoryUpdate')->name('update');
            });
        });

        // admin report section
        Route::group(['prefix' => 'report', 'as' => 'report-'], function () {
            Route::view('summary', 'common.report.summary')->name('summary');
        });

        // partial route for admin start
        Route::group(['prefix' => 'partial', 'as' => 'partial-'], function () {
            Route::get('user-slide', 'PartialController@userListSlide')->name('user-slide');
            Route::get('designation-slide', 'PartialController@designationListSlide')->name('designation-slide');
            Route::get('leave-slide', 'PartialController@leaveListSlide')->name('leave-slide');
        });
        // partial route for admin end
    });
    // only admin routes end
});
// all types of auth routes end
