<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        channels: __DIR__.'/../routes/channels.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Menggunakan string fully qualified class name untuk menghindari error saat compile
        // Pastikan file ada di app/Http/Middleware/BypassNgrok.php
        if (class_exists(\App\Http\Middleware\BypassNgrok::class)) {
            $middleware->append(\App\Http\Middleware\BypassNgrok::class);
        }

        // 🔥 SOLUSI TOTAL: Buang semua kata 'guest:' dan 'authenticated:'
        // Parameter ke-1 otomatis dibaca sebagai 'guest', parameter ke-2 sebagai 'authenticated'
        $middleware->redirectTo('/login', '/dashboard');
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();

