<?php

use App\Helpers\Helper;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
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!
|
*/

Auth::routes();
Route::get('/', function () {
    // return view('welcome');
    return redirect(route('auth.index'));
});

Route::get('file/{file}', ['as' => 'get_file', 'uses' => 'UploadController@get_image'])->where('file', '(.*)');

Route::group(['as' => 'fetch.', 'prefix' => 'fetch'], function () {
    Route::match(['get', 'post'], 'globalfetch', ['as' => 'globalfetch', 'uses' => 'FetchController@globalfetch']);
});

Route::match(['get', 'post'], 'cek-email', ['as' => 'cek_email', 'uses' => function (Request $request) {
    $status = true;
    $message = 'Inputan email tidak ditemukan';
    if (!empty($request['email'])) {

        $cek_email = User::where('email', $request['email']);
        $id = Hashids::decode($request['id']);

        if (!empty($id)) {
            $cek_email = $cek_email->where('id', '!=', $id);
        }
        $cek_email = $cek_email->first();

        if (!empty($cek_email)) {
            $status = true;
            $message = 'Email ' . $request['email'] . ' telah digunakan';
        } else {
            $status = false;
            $message = 'Email bisa digunakan';
        }
    }

    $response = [
        'status'  => $status,
        'message' => $message,
    ];

    return response()->json($response);
}]);

Route::get('logout', function () {
    Auth::logout();
    session()->flush();
    session()->invalidate();
    return Redirect::to(route('login'))->with('message', 'logout');
});
/**COBA UPLOAD FILE */
/**
 *  Login
 */
Route::group([
    'prefix'    => 'coba',
    'namespace' => 'Coba',
    'as'        => 'coba.',
], function () {

    Route::group([
        'prefix'    => 'upload',
        'as'        => 'upload.',
    ], function () {
        Route::get('/', ['as' => 'index', 'uses' => 'UploadFile@index']);

        Route::post('upload-action', ['as' => 'upload_action', 'uses' => 'UploadFile@upload_action']);
    });
});
/**end upload file */

/**
 *  Login
 */
Route::group([
    'prefix'    => 'auth',
    'namespace' => 'Auth',
    'as'        => 'auth.',
], function () {

    Route::get('login', ['as' => 'index', 'uses' => 'LoginController@index']);
    Route::post('action-login', ['as' => 'action_login', 'uses' => 'LoginController@action_login']);
});


// Helper::declare_route();
/**
 * route admin
 */
Route::group(
    [
        'middleware'    => ['auth_cek', 'auth'],
        'as'            => 'admin.',
        'namespace'     => 'Admin',
    ],
    function () {
        //profil
        Route::group([
            'prefix'    => 'profile',
            'namespace' => 'Profile',
            'as'        => 'profile.',
        ], function () {

            Route::get('update', ['as' => 'update', 'uses' => 'ProfileController@update']);
            Route::post('/update-action', ['as' => 'update_action', 'uses' => 'ProfileController@update_action']);
        });
        //end profile

        /**
         * Prefik admin.
         * Dashboard Controller
         */
        Route::get('dashboard', ['as' => 'dashboard', 'uses' => 'DashboardController@index']);
        Route::group([
            'prefix' => 'dashboard',
            'as' => 'dashboard.',
        ], function () {
            Route::get('dashboard-order-transfusi/{year?}', ['as' => 'transfusi', 'uses' => 'DashboardController@graph_order_transfusi']);
            Route::post('dashboard-modal-order-transfusi', ['as' => 'modal_transfusi', 'uses' => 'DashboardController@modal_graph_detail_order_transfusi']);

            Route::get('dashboard-order-dropping/{year?}', ['as' => 'dropping', 'uses' => 'DashboardController@graph_order_dropping']);
            Route::post('dashboard-modal-order-dropping', ['as' => 'modal_dropping', 'uses' => 'DashboardController@modal_graph_detail_order_dropping']);

            Route::get('dashboard-kantong-darah/{year?}', ['as' => 'kantong_darah', 'uses' => 'DashboardController@graph_kantong_darah']);
            Route::post('dashboard-modal-kantong-darah', ['as' => 'modal_kantong_darah', 'uses' => 'DashboardController@modal_graph_kantong_darah']);
        });



        Route::group(
            [
                'prefix'    => 'news',
                'as'        => 'news.',
                'namespace' => 'Raharja',

            ],
            function () {
                Route::get('/', ['as' => 'index', 'uses' => 'NewsController@index']);
                Route::get('/get-data/{udd_id?}', ['as' => 'get_data', 'uses' => 'NewsController@getData']);
                Route::get('create', ['as' => 'create', 'uses' => 'NewsController@create']);
                Route::get('update/{news_id}', ['as' => 'update', 'uses' => 'NewsController@update']);
                Route::get('/delete-action/{news_id}', ['as' => 'delete_action', 'uses' => 'NewsController@delete_action']);

                Route::post('create-action', ['as' => 'create_action', 'uses' => 'NewsController@create_action']);
                Route::post('update-action', ['as' => 'update_action', 'uses' => 'NewsController@update_action']);
            }
        );
        Route::group(
            [
                'prefix'    => 'tips',
                'as'        => 'tips.',
                'namespace' => 'Raharja',

            ],
            function () {
                Route::get('/', ['as' => 'index', 'uses' => 'TipsController@index']);
                Route::get('/get-data/{udd_id?}', ['as' => 'get_data', 'uses' => 'TipsController@getData']);
                Route::get('create', ['as' => 'create', 'uses' => 'TipsController@create']);
                Route::get('update/{news_id}', ['as' => 'update', 'uses' => 'TipsController@update']);
                Route::get('/delete-action/{news_id}', ['as' => 'delete_action', 'uses' => 'TipsController@delete_action']);

                Route::post('create-action', ['as' => 'create_action', 'uses' => 'TipsController@create_action']);
                Route::post('update-action', ['as' => 'update_action', 'uses' => 'TipsController@update_action']);
            }
        );
        Route::group(
            [
                'prefix'    => 'master_points',
                'as'        => 'master-points.',
                'namespace' => 'Raharja',

            ],
            function () {
                Route::get('/', ['as' => 'index', 'uses' => 'MasterPointsController@index']);
                Route::get('/get-data/{udd_id?}', ['as' => 'get_data', 'uses' => 'MasterPointsController@getData']);
                Route::get('create', ['as' => 'create', 'uses' => 'MasterPointsController@create']);
                Route::get('update/{news_id}', ['as' => 'update', 'uses' => 'MasterPointsController@update']);
                Route::get('/delete-action/{news_id}', ['as' => 'delete_action', 'uses' => 'MasterPointsController@delete_action']);

                Route::post('create-action', ['as' => 'create_action', 'uses' => 'MasterPointsController@create_action']);
                Route::post('update-action', ['as' => 'update_action', 'uses' => 'MasterPointsController@update_action']);
            }
        );
        Route::group(
            [
                'prefix'    => 'message',
                'as'        => 'message.',
                'namespace' => 'Raharja',

            ],
            function () {
                Route::get('/', ['as' => 'index', 'uses' => 'MessageController@index']);
                Route::get('/get-data/{udd_id?}', ['as' => 'get_data', 'uses' => 'MessageController@getData']);
                Route::get('create', ['as' => 'create', 'uses' => 'MessageController@create']);
                Route::get('/delete-action/{data_id}', ['as' => 'delete_action', 'uses' => 'MessageController@delete_action']);
                Route::get('select_user', ['as' => 'select_user', 'uses' => 'MessageController@selectUser']);
                Route::get('send/{data_id}', ['as' => 'send', 'uses' => 'MessageController@send']);

                Route::post('create-action', ['as' => 'create_action', 'uses' => 'MessageController@create_action']);
            }
        );
        Route::group(
            [
                'prefix'    => 'trivia',
                'as'        => 'trivia.',
                'namespace' => 'Trivia',

            ],
            function () {
                Route::get('/', ['as' => 'index', 'uses' => 'TriviaController@index']);
                Route::get('/get-data/{udd_id?}', ['as' => 'get_data', 'uses' => 'TriviaController@getData']);
                Route::get('create', ['as' => 'create', 'uses' => 'TriviaController@create']);
                Route::get('update/{trivia_id}', ['as' => 'update', 'uses' => 'TriviaController@update']);
                Route::get('/delete-action/{trivia_id}', ['as' => 'delete_action', 'uses' => 'TriviaController@delete_action']);

                Route::post('create-action', ['as' => 'create_action', 'uses' => 'TriviaController@create_action']);
                Route::post('update-action', ['as' => 'update_action', 'uses' => 'TriviaController@update_action']);
            }
        );
        Route::group(
            [
                'prefix'    => 'kelompok_driver',
                'as'        => 'kelompok-driver.',
                'namespace' => 'Raharja',

            ],
            function () {
                Route::get('/', ['as' => 'index', 'uses' => 'KelompokDriverController@index']);
                Route::get('/get-data/{data_id?}', ['as' => 'get_data', 'uses' => 'KelompokDriverController@getData']);
                Route::get('create', ['as' => 'create', 'uses' => 'KelompokDriverController@create']);
                Route::get('update/{data_id}', ['as' => 'update', 'uses' => 'KelompokDriverController@update']);
                Route::get('/delete-action/{data_id}', ['as' => 'delete_action', 'uses' => 'KelompokDriverController@delete_action']);

                Route::post('create-action', ['as' => 'create_action', 'uses' => 'KelompokDriverController@create_action']);
                Route::post('update-action', ['as' => 'update_action', 'uses' => 'KelompokDriverController@update_action']);
            }
        );
        Route::group(
            [
                'prefix'    => 'event_organisasi',
                'as'        => 'event-organisasi.',
                'namespace' => 'Raharja',

            ],
            function () {
                Route::get('/', ['as' => 'index', 'uses' => 'EventOrganisasiController@index']);
                Route::get('/get-data/{data_id?}', ['as' => 'get_data', 'uses' => 'EventOrganisasiController@getData']);
                Route::get('create', ['as' => 'create', 'uses' => 'EventOrganisasiController@create']);
                Route::get('update/{data_id}', ['as' => 'update', 'uses' => 'EventOrganisasiController@update']);
                Route::get('kelompok-driver/{data_id}', ['as' => 'kelompok_driver', 'uses' => 'EventOrganisasiController@kelompokDriver']);
                Route::get('/delete-action/{data_id}', ['as' => 'delete_action', 'uses' => 'EventOrganisasiController@delete_action']);
                Route::get('/get-data-kelompok-driver/{data_id?}', ['as' => 'get_data_kelompok_driver', 'uses' => 'EventOrganisasiController@getDataKelompokDriver']);
                Route::get('/delete-kelompok-driver/{data_id}', ['as' => 'delete_kelompok_driver', 'uses' => 'EventOrganisasiController@deleteKelompokDriver']);
                Route::get('select_kelompok_driver', ['as' => 'select_kelompok_driver', 'uses' => 'EventOrganisasiController@selectKelompokDriver']);

                Route::post('create-action', ['as' => 'create_action', 'uses' => 'EventOrganisasiController@create_action']);
                Route::post('update-action', ['as' => 'update_action', 'uses' => 'EventOrganisasiController@update_action']);
                Route::post('add_kelompok_driver', ['as' => 'add_kelompok_driver', 'uses' => 'EventOrganisasiController@addKelompokDriver']);
            }
        );

        // end route raharja

    }
);

// Helper::declare_route();


app('App\Http\Controllers\Admin\User_management\PermissionController')->route();
app('App\Http\Controllers\Admin\User_management\UserController')->route();
app('App\Http\Controllers\Admin\User_management\RoleController')->route();
app('App\Http\Controllers\Admin\TransportationController')->route();
