<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
{
    /** @return array<string, mixed> */
    public function share(Request $request): array
    {
        return array_merge(parent::share($request), [
            'auth' => fn () => [
                'user' => $request->user() ? $request->user()->only('id', 'name', 'email', 'status') : null,
            ],
            'flash' => fn () => [
                'success' => $request->session()->get('success'),
                'error' => $request->session()->get('error'),
                'info' => $request->session()->get('info'),
            ],
            'impersonating' => fn () => $request->session()->has('impersonator_id'),
            'domains' => fn () => [
                'marketing' => config('app.domains.marketing'),
                'account' => config('app.domains.account'),
                'admin' => config('app.domains.admin'),
            ],
            'panels' => fn () => config('app.panels'),
        ]);
    }
}
