<?php

namespace App\Providers;

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\ServiceProvider;
use Inertia\Inertia;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Inertia::share([
            'locale' => function () {
                $locale = Session::get('locale', config('app.locale'));
                App::setLocale($locale);
                return $locale;
            },
            'translations' => function () {
                $locale = Session::get('locale', config('app.locale'));
                App::setLocale($locale);
                return trans('messages');
            },
        ]);
        // App::setLocale(Session::get('locale', config('app.locale')));
    }
}
