<?php

use App\Http\Controllers\ProfileController;
use App\Http\Controllers\DashboardController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return auth()->check()
        ? redirect()->route('dashboard')
        : redirect()->route('login');
});

Route::middleware('auth')->group(function () {

    Route::get('/dashboard', [DashboardController::class, 'overview'])
        ->name('dashboard');

    Route::get('/dashboard/seq', function () {
        return view('dashboard.sequencing');
    });

    Route::get('/dashboard/{code}', [DashboardController::class, 'detail'])
        ->name('dashboard.detail');

    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

Route::middleware(['auth', 'role:admin'])->group(function () {
    Route::view('/admin/users', 'admin.users');
    Route::view('/admin/settings', 'admin.settings');
});

Route::get('/debug', function () {
    return response()->json([
        'host' => request()->getHost(),
        'port' => request()->getPort(),
        'scheme' => request()->getScheme(),
        'url' => url('/'),
        'full_url' => request()->fullUrl(),
    ]);
});

require __DIR__.'/auth.php';