<?php

namespace DefStudio\GameEngine\Middleware;

use App;
use Closure;
use Illuminate\Http\Request;
use DefStudio\GameEngine\Models\User;

class SetUserLocale
{
    public function handle(Request $request, Closure $next): mixed
    {
        $user = \game_engine()->user(true);

        if ($user instanceof User) {
            App::setLocale($user->locale);
        }

        return $next($request);
    }
}
