<?php

use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\LoginController;

use Illuminate\Support\Facades\Storage;
use Aws\S3\S3Client;
use App\Models\Mail as Mailing;
use Aws\Exception\AwsException;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Mail;

Route::middleware(['guest'])->group(function () {
    Route::post('proses_login', 'App\Http\Controllers\LoginController@proses_login')->name('proses_login')->middleware('check.status');
    Route::get('register', 'App\Http\Controllers\LoginController@register')->name('register');
    Route::post('storeRegister', 'App\Http\Controllers\LoginController@storeRegister')->name('storeRegister');
    Route::get('forgot', 'App\Http\Controllers\LoginController@forgot')->name('forgot');
    Route::post('forgotPassword', 'App\Http\Controllers\LoginController@forgotPassword')->name('forgotPassword');
    Route::get('reset/{token}', 'App\Http\Controllers\LoginController@reset')->name('reset');
    Route::post('resetPassword', 'App\Http\Controllers\LoginController@resetPassword')->name('resetPassword');
    Route::get('verify/{token}', 'App\Http\Controllers\LoginController@verify')->name('verify');
});
// page utama
Route::get('/', 'App\Http\Controllers\LoginController@index')->name('login')->middleware('check.auth');
Route::get('logout', 'App\Http\Controllers\LoginController@logout')->name('logout');
Route::group(['middleware' => ['auth','check.admin']], function () {
    Route::get('change-language/{locale}', function ($locale) {
        App::setLocale($locale);
        Config::set('app.locale', $locale);
        return back()->with('swal', swal_alert('success', 'Language Changed'));
    });
    Route::group(['prefix' => 'app'], function () {
        Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');
        Route::get('reset-datasets', [DashboardController::class, 'reset_datasets'])->name('reset-datasets');
        Route::prefix('account')->group(function () {
            Route::get('/', 'App\Http\Controllers\DashboardController@profile')->name('account');
            Route::post('update', 'App\Http\Controllers\DashboardController@update')->name('update.account');
            Route::get('activity', 'App\Http\Controllers\AdminController@activity')->name('account.activity');
        });

        Route::prefix('alternatif')->group(function () {
            //
            Route::get('/', 'App\Http\Controllers\AlternatifController@index')->name('alternatif');
            Route::get('create', 'App\Http\Controllers\AlternatifController@create')->name('alternatif.create');
            Route::post('store', 'App\Http\Controllers\AlternatifController@store')->name('alternatif.store');
            Route::get('edit/{id}', 'App\Http\Controllers\AlternatifController@edit')->name('alternatif.edit');
            Route::post('update/{id}', 'App\Http\Controllers\AlternatifController@update')->name('alternatif.update');
            Route::get('delete/{id}', 'App\Http\Controllers\AlternatifController@destroy')->name('alternatif.delete');
        });

        Route::prefix('kriteria')->group(function () {
            //
            Route::get('/', 'App\Http\Controllers\KriteriaController@index')->name('kriteria');
            Route::get('create', 'App\Http\Controllers\KriteriaController@create')->name('kriteria.create');
            Route::post('store', 'App\Http\Controllers\KriteriaController@store')->name('kriteria.store');
            Route::get('edit/{id}', 'App\Http\Controllers\KriteriaController@edit')->name('kriteria.edit');
            Route::post('update/{id}', 'App\Http\Controllers\KriteriaController@update')->name('kriteria.update');
            Route::get('delete/{id}', 'App\Http\Controllers\KriteriaController@destroy')->name('kriteria.delete');
        });

        Route::prefix('nilai')->group(function () {
            //
            Route::get('/', 'App\Http\Controllers\NilaiController@index')->name('nilai');
            Route::get('create', 'App\Http\Controllers\NilaiController@create')->name('nilai.create');
            Route::post('store', 'App\Http\Controllers\NilaiController@store')->name('nilai.store');
            Route::get('edit/{id}', 'App\Http\Controllers\NilaiController@edit')->name('nilai.edit');
            Route::post('update/{id}', 'App\Http\Controllers\NilaiController@update')->name('nilai.update');
            Route::get('delete/{id}', 'App\Http\Controllers\NilaiController@destroy')->name('nilai.delete');
        });

        Route::prefix('users')->group(function () {
            Route::get('/', 'App\Http\Controllers\UsersController@index')->name('users');
            Route::get('create', 'App\Http\Controllers\UsersController@create')->name('users.create');
            Route::post('store', 'App\Http\Controllers\UsersController@store')->name('users.store');
            Route::get('edit/{id}', 'App\Http\Controllers\UsersController@edit')->name('users.edit');
            Route::post('update/{id}', 'App\Http\Controllers\UsersController@update')->name('users.update');
            Route::get('delete/{id}', 'App\Http\Controllers\UsersController@destroy')->name('users.delete');
            Route::get('detail/{id}', 'App\Http\Controllers\UsersController@show')->name('users.show');
        });

        Route::post('analisa-alternatif', 'App\Http\Controllers\AnalisaController@alternatif')->name('analisa.alternatif');
        Route::post('analisa-alternatif-tabel/{id_kriteria}', 'App\Http\Controllers\AnalisaController@alternatifTabel')->name('analisa.alternatif.tabel');
        Route::get('analisa-alternatif-form', 'App\Http\Controllers\AnalisaController@alternatifForm')->name('analisa.alternatif.form');
        Route::post('delete-alternatif', 'App\Http\Controllers\AnalisaController@deleteAlternatif')->name('analisa.alternatif.delete');

        Route::get('analisa-kriteria', 'App\Http\Controllers\AnalisaController@kriteria')->name('analisa.kriteria');
        Route::match(['get', 'post'], 'analisa-kriteria-tabel', 'App\Http\Controllers\AnalisaController@kriteriaTabel')->name('analisa.kriteria.tabel');
        Route::post('delete-kriteria', 'App\Http\Controllers\AnalisaController@deleteKriteria')->name('analisa.kriteria.delete');

        Route::prefix('ranking')->group(function() {
            Route::get('/', 'App\Http\Controllers\RankingController@index')->name('ranking');
        });
    });
});
