<?php
    $siteName = $settings->site_name ?? config('app.name');
    $brandVersion = $settings?->updated_at?->timestamp ?? $settings?->logo_media_id ?? '1';
    $sidebarLogo = ($settings?->logo_url ?? asset('uploads/placeholders/default-logo.png')) . '?v=' . $brandVersion;
    $currentUser = auth()->user();
    $dashboardPermissions = \App\Models\Role::permissionValuesForSection('dashboard');
    $contactPermissions = \App\Models\Role::permissionValuesForSection('contacts');
    $pagePermissions = \App\Models\Role::permissionValuesForSection('pages');
    $blogPermissions = \App\Models\Role::permissionValuesForSection('blog_posts');
    $servicePermissions = \App\Models\Role::permissionValuesForSection('services');
    $settingPermissions = \App\Models\Role::permissionValuesForSection('settings');
    $mediaPermissions = \App\Models\Role::permissionValuesForSection('media');
    $userPermissions = \App\Models\Role::permissionValuesForSection('users');
    $rolePermissions = \App\Models\Role::permissionValuesForSection('roles');
    $auditPermissions = \App\Models\Role::permissionValuesForSection('audits');
    $backupPermissions = \App\Models\Role::permissionValuesForSection('backups');
    $navGroups = [
        [
            'label' => 'Dashboard',
            'type' => 'link',
            'route' => 'admin.dashboard',
            'pattern' => 'admin.dashboard',
            'permissions' => $dashboardPermissions,
        ],
        [
            'label' => 'My Business',
            'type' => 'menu',
            'permissions' => array_merge($contactPermissions, $pagePermissions, $blogPermissions, $servicePermissions),
            'items' => [
                ['label' => 'Manage Responses', 'route' => 'admin.contacts.index', 'pattern' => 'admin.contacts.*', 'permissions' => $contactPermissions],
                ['label' => 'Pages', 'route' => 'admin.pages.index', 'pattern' => 'admin.pages.*', 'permissions' => $pagePermissions],
                ['label' => 'Blog Posts', 'route' => 'admin.blog-posts.index', 'pattern' => 'admin.blog-posts.*', 'permissions' => $blogPermissions],
                ['label' => 'Services', 'route' => 'admin.services.index', 'pattern' => 'admin.services.*', 'permissions' => $servicePermissions],
            ],
        ],
        [
            'label' => 'Growth & Marketing',
            'type' => 'menu',
            'permissions' => array_merge($settingPermissions, $mediaPermissions),
            'items' => [
                ['label' => 'Settings', 'route' => 'admin.settings.edit', 'pattern' => 'admin.settings.*', 'permissions' => $settingPermissions],
                ['label' => 'Media Library', 'route' => 'admin.media.index', 'pattern' => 'admin.media.*', 'permissions' => $mediaPermissions],
            ],
        ],
        [
            'label' => 'Analytics',
            'type' => 'menu',
            'permissions' => array_merge($userPermissions, $rolePermissions, $auditPermissions),
            'items' => [
                ['label' => 'Users', 'route' => 'admin.users.index', 'pattern' => 'admin.users.*', 'permissions' => $userPermissions],
                ['label' => 'Roles', 'route' => 'admin.roles.index', 'pattern' => 'admin.roles.*', 'permissions' => $rolePermissions],
                ['label' => 'Audit Log', 'route' => 'admin.audits.index', 'pattern' => 'admin.audits.*', 'permissions' => $auditPermissions],
            ],
        ],
    ];
?>

<aside class="admin-sidebar">
    <div class="admin-site-nav">
        <div class="admin-site-nav__brand">
            <img src="<?php echo e($sidebarLogo); ?>" alt="<?php echo e($siteName); ?>">
            <div>
                <p class="admin-sidebar__title"><?php echo e($siteName); ?></p>
                <p class="admin-sidebar__subtitle">CMS workspace</p>
            </div>
        </div>

        <nav class="admin-site-nav__groups">
            <?php $__currentLoopData = $navGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $group): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php if(! $currentUser->hasAnyPermission($group['permissions'])) continue; ?>

                <?php if($group['type'] === 'link'): ?>
                    <a href="<?php echo e(route($group['route'])); ?>" class="admin-site-nav__link <?php echo e(request()->routeIs($group['pattern'] ?? $group['route']) ? 'is-active' : ''); ?>">
                        <?php echo e($group['label']); ?>

                    </a>
                <?php else: ?>
                    <?php
                        $isActive = collect($group['items'])->contains(fn ($item) => $currentUser->hasAnyPermission($item['permissions']) && request()->routeIs($item['pattern'] ?? $item['route']));
                    ?>
                    <div class="admin-site-nav__dropdown" x-data="{ open: false }">
                        <button type="button" class="admin-site-nav__link <?php echo e($isActive ? 'is-active' : ''); ?>" @click="open = !open">
                            <?php echo e($group['label']); ?>

                            <span class="admin-site-nav__caret">v</span>
                        </button>

                        <div class="admin-site-nav__menu" x-show="open" x-cloak x-transition @click.outside="open = false">
                            <?php $__currentLoopData = $group['items']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if(! $currentUser->hasAnyPermission($item['permissions'])) continue; ?>
                                <a href="<?php echo e(route($item['route'])); ?>" class="admin-site-nav__menu-link <?php echo e(request()->routeIs($item['pattern'] ?? $item['route']) ? 'is-active' : ''); ?>">
                                    <?php echo e($item['label']); ?>

                                </a>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </div>
                    </div>
                <?php endif; ?>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </nav>

        <div class="admin-site-nav__secondary">
            <?php if($currentUser->hasAnyPermission($backupPermissions)): ?>
                <a href="<?php echo e(route('admin.backups.database')); ?>" class="admin-button admin-button--ghost">Download SQL Backup</a>
            <?php endif; ?>
            <a href="<?php echo e(route('home')); ?>" class="admin-button admin-button--ghost">View site</a>
        </div>
    </div>
</aside>
<?php /**PATH /home/xsoftdev/saleemsail.xsoftdevelop.com/resources/views/admin/partials/sidebar.blade.php ENDPATH**/ ?>