<?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 redirect('login');
});

Route::controller(App\Http\Controllers\Auth\AdminLoginController::class)->group(function () {
    Route::get('admin/login', 'showLoginForm')->name('admin.login');
    Route::post('admin/login', 'login')->name('admin.postlogin');
});

Route::middleware('auth')->group(function () {
    Route::prefix('admin')->middleware('role:admin')->name('admin.')->group(function () {
        Route::get('dashboard', [App\Http\Controllers\Admin\DashboardController::class, 'index'])->name('dashboard');
        Route::get('profile', [App\Http\Controllers\Admin\DashboardController::class, 'profile'])->name('profile');

        // User
        Route::resource('users', App\Http\Controllers\Admin\UserController::class);

        // Addcition
        Route::resource('addictions', App\Http\Controllers\Admin\AddictionController::class);

        // Addcition
        Route::resource('likerts', App\Http\Controllers\Admin\LikertController::class);

        // Factor
        Route::resource('factors', App\Http\Controllers\Admin\FactorController::class);

        // Item
        Route::resource('items', App\Http\Controllers\Admin\ItemController::class);

        // History
        Route::resource('histories', App\Http\Controllers\Admin\HistoryController::class);
    });

    Route::middleware('role:user')->name('user.')->group(function () {
        Route::get('/home', [HomeController::class, 'index'])->name('dashboard');
        Route::get('dashboard', [App\Http\Controllers\User\DashboardController::class, 'index'])->name('dashboard');
        Route::get('history', [App\Http\Controllers\User\DashboardController::class, 'history'])->name('history');
        Route::get('addiction', [App\Http\Controllers\User\DashboardController::class, 'addiction'])->name('addiction');
        Route::post('addiction', [App\Http\Controllers\User\DashboardController::class, 'storeAddiction'])->name('addiction.store');
    });
});

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
