<?php

namespace App\Http\Middleware;

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

class HandleInertiaRequests extends Middleware
{
    /**
     * The root template that is loaded on the first page visit.
     *
     * @var string
     */
    protected $rootView = 'app';

    /**
     * Determine the current asset version.
     */
    public function version(Request $request): ?string
    {
        return parent::version($request);
    }

    /**
     * Define the props that are shared by default.
     *
     * @return array<string, mixed>
     */
public function share(Request $request): array
{
    return array_merge(parent::share($request), [
        'auth' => [
            'user' => $request->user() ? [
                // Muat relasi role terlebih dahulu untuk mengisi role_name
                'id'        => $request->user()->id,
                'name'      => $request->user()->name,
                'email'     => $request->user()->email,
                
                // Akses Accessor Anda:
                'role_name' => $request->user()->role_name, // Ini akan bekerja setelah 'load('role')'
                
                // Tambahkan properti lain sesuai kebutuhan
                'campus_slug' => $request->user()->campus_slug,
            ] : null,
        ],
    ]);
}}
