<?php

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

return Application::configure(basePath: dirname(__DIR__))

    /*
    |--------------------------------------------------------------------------
    | Routing
    |--------------------------------------------------------------------------
    */
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        channels: __DIR__.'/../routes/channels.php',
        health: '/up',
    )

    /*
    |--------------------------------------------------------------------------
    | Middleware
    |--------------------------------------------------------------------------
    */
    ->withMiddleware(function (Middleware $middleware): void {

        // Custom Middleware Alias
        $middleware->alias([
            'admin.auth' => \App\Http\Middleware\AdminAuthMiddleware::class,
            'subscriptions' => \App\Http\Middleware\CheckSubscription::class,
            'user.activity' => \App\Http\Middleware\UpdateUserActivity::class,
        ]);

        // Web Middleware Stack
        $middleware->web(append: [

            // 🔥 Localization Middleware (IMPORTANT)
            \App\Http\Middleware\SetLocale::class,

            // Existing middleware
            \App\Http\Middleware\NoIndexPrivatePages::class,
        ]);
    })

    /*
    |--------------------------------------------------------------------------
    | Exceptions
    |--------------------------------------------------------------------------
    */
    ->withExceptions(function (Exceptions $exceptions): void {
        // Customize exception handling if needed
    })

    ->create();