<?php
    $installedModuleNavItems = $installedModuleNavItems ?? [];
    $walletBalance = $walletBalance ?? null;
?>

<header class="header">
    <div class="header-left">
        <a href="<?php echo e(Route::has('dashboard') ? route('dashboard') : '#'); ?>" class="header-logo">
            <img src="<?php echo e(asset('assets/img/logo.webp')); ?>" alt="<?php echo e(config('app.name')); ?>">
            <span><?php echo e(config('app.name', 'Admin')); ?></span>
        </a>
        <button class="sidebar-toggle" title="Toggle Sidebar" type="button">
            <i class="bi bi-list"></i>
        </button>
    </div>

    <?php if(count($installedModuleNavItems) > 0): ?>
        <nav class="header-module-nav d-none d-md-flex">
            <?php $__currentLoopData = $installedModuleNavItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php
                    $routePrefix = str_contains($item['route'], '.') ? substr($item['route'], 0, strrpos($item['route'], '.')) : $item['route'];
                    $isActive = request()->routeIs($item['route']) || request()->routeIs($routePrefix.'.*');
                ?>
                <a class="header-module-link <?php echo e($isActive ? 'active' : ''); ?>"
                   href="<?php echo e(route($item['route'])); ?>">
                    <i class="<?php echo e($item['icon']); ?>"></i>
                    <span><?php echo e($item['label']); ?></span>
                </a>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </nav>
    <?php endif; ?>

    <div class="header-right">
        <div class="header-actions-desktop d-none d-md-flex">
            <button class="header-action theme-toggle" title="Toggle Theme" type="button">
                <i class="bi bi-moon icon-dark"></i>
                <i class="bi bi-sun icon-light"></i>
            </button>

            <span class="header-divider"></span>

            <?php if($walletBalance && Route::has('wallet.index')): ?>
                <a href="<?php echo e(route('wallet.index')); ?>" class="header-wallet-pill d-none d-lg-flex text-decoration-none" title="View wallet ledger">
                    <i class="bi bi-wallet2"></i>
                    <span><?php echo e(platform_money($walletBalance->balance, $walletBalance->currency)); ?></span>
                </a>
                <span class="header-divider d-none d-lg-inline-flex"></span>
            <?php elseif($walletBalance): ?>
                <div class="header-wallet-pill d-none d-lg-flex" title="Platform wallet balance">
                    <i class="bi bi-wallet2"></i>
                    <span><?php echo e(platform_money($walletBalance->balance, $walletBalance->currency)); ?></span>
                </div>
                <span class="header-divider d-none d-lg-inline-flex"></span>
            <?php endif; ?>

            <div class="header-action-wrap dropdown user-dropdown">
                <button class="dropdown-toggle user-trigger" data-bs-toggle="dropdown" aria-expanded="false" type="button">
                    <img src="<?php echo e(asset('assets/img/profile-img.webp')); ?>" alt="User" class="user-avatar">
                    <div class="user-brief d-none d-lg-block">
                        <span class="user-name"><?php echo e(auth()->user()->name ?? 'Admin'); ?></span>
                        <span class="user-role"><?php echo e(auth()->user()?->roles?->first()?->name ?? 'Administrator'); ?></span>
                    </div>
                    <i class="bi bi-chevron-down user-chevron"></i>
                </button>
                <div class="dropdown-menu dropdown-menu-end user-menu">
                    <div class="user-menu-header">
                        <img src="<?php echo e(asset('assets/img/profile-img.webp')); ?>" alt="User" class="user-menu-avatar">
                        <div class="user-menu-info">
                            <div class="user-menu-name"><?php echo e(auth()->user()->name ?? 'Admin'); ?></div>
                            <div class="user-menu-email"><?php echo e(auth()->user()->email ?? ''); ?></div>
                        </div>
                    </div>
                    <?php if($walletBalance && Route::has('wallet.index')): ?>
                        <a href="<?php echo e(route('wallet.index')); ?>" class="user-menu-wallet text-decoration-none">
                            <span class="user-menu-wallet-label">Wallet Balance</span>
                            <strong><?php echo e(platform_money($walletBalance->balance, $walletBalance->currency)); ?></strong>
                        </a>
                    <?php elseif($walletBalance): ?>
                        <div class="user-menu-wallet">
                            <span class="user-menu-wallet-label">Wallet Balance</span>
                            <strong><?php echo e(platform_money($walletBalance->balance, $walletBalance->currency)); ?></strong>
                        </div>
                    <?php endif; ?>
                    <div class="user-menu-body">
                        <?php if(Route::has('profile.edit')): ?>
                            <a class="user-menu-item" href="<?php echo e(route('profile.edit')); ?>">
                                <span class="user-menu-icon"><i class="bi bi-person"></i></span>
                                <span>My Profile</span>
                            </a>
                        <?php endif; ?>
                        <?php if(Route::has('settings.index')): ?>
                            <a class="user-menu-item" href="<?php echo e(route('settings.index')); ?>">
                                <span class="user-menu-icon"><i class="bi bi-gear"></i></span>
                                <span>Settings</span>
                            </a>
                        <?php endif; ?>
                        <?php if(Route::has('audit-logs.index')): ?>
                            <a class="user-menu-item" href="<?php echo e(route('audit-logs.index')); ?>">
                                <span class="user-menu-icon"><i class="bi bi-activity"></i></span>
                                <span>Activity Log</span>
                            </a>
                        <?php endif; ?>
                    </div>
                    <div class="user-menu-footer">
                        <?php if(Route::has('logout')): ?>
                            <form action="<?php echo e(route('logout')); ?>" method="POST">
                                <?php echo csrf_field(); ?>
                                <button type="submit" class="user-menu-logout w-100 border-0 bg-transparent">
                                    <i class="bi bi-box-arrow-right"></i>
                                    <span>Sign Out</span>
                                </button>
                            </form>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="header-actions-mobile d-flex d-md-none">
            <button class="header-action mobile-menu-toggle" title="More" type="button">
                <i class="bi bi-three-dots-vertical"></i>
            </button>
        </div>
    </div>
</header>

<?php if(count($installedModuleNavItems) > 0): ?>
    <nav class="header-module-nav-mobile d-md-none">
        <?php $__currentLoopData = $installedModuleNavItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
                $routePrefix = str_contains($item['route'], '.') ? substr($item['route'], 0, strrpos($item['route'], '.')) : $item['route'];
                $isActive = request()->routeIs($item['route']) || request()->routeIs($routePrefix.'.*');
            ?>
            <a class="header-module-link <?php echo e($isActive ? 'active' : ''); ?>"
               href="<?php echo e(route($item['route'])); ?>">
                <i class="<?php echo e($item['icon']); ?>"></i>
                <span><?php echo e($item['label']); ?></span>
            </a>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </nav>
<?php endif; ?>
<?php /**PATH D:\RABI\rabi\module-laravel-platform\apps\admin\resources\views/vendor/eliteadmin/components/header.blade.php ENDPATH**/ ?>