
<?php
    $conversationRoute = $conversationRoute ?? (request()->routeIs('googlechat.*') ? 'googlechat.show' : 'chat.show');
    $conversations = collect($conversations ?? [])->take(5);
    $recentCreatives = collect($recentCreatives ?? [])->take(5);
    $recentPromptPages = collect($recentPromptPages ?? [])->take(5);

    $isCreative = request()->routeIs('creatives.*');
    $isLanding = request()->routeIs('landing-pages.*') || request()->routeIs('catalog-landing-pages.*') || request()->routeIs('prompt-landing-pages.*');
    $isChat = request()->routeIs('chat.*') || request()->routeIs('chats.*') || request()->routeIs('googlechat.*');
    $isPerformance = request()->routeIs('campaigns.*');

    // Expand only one section at a time by default based on current context
    $activeSection = $isCreative ? 'creativeNav' : ($isLanding ? 'landingPageNav' : 'chatNav');
?>
<aside class="mb-sidebar">
    <div class="mb-side-top">
        <a href="<?php echo e(route('home')); ?>" class="mb-logo" aria-label="<?php echo e(config('app.name')); ?> home">
            <?php echo $__env->make('partials.mb.logo', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
        </a>
        <button class="mb-icon-btn" data-action="toggle-sidebar" aria-label="Toggle sidebar"><i class="bi bi-layout-sidebar"></i></button>
    </div>

    <div class="mb-side-scroll">
        <div class="mb-nav-row<?php echo e(request()->routeIs('home') || request()->routeIs('dashboard') ? ' active' : ''); ?>">
            <a href="<?php echo e(route('home')); ?>" class="mb-nav<?php echo e(request()->routeIs('home') || request()->routeIs('dashboard') ? ' active' : ''); ?>" title="Home" wire:navigate>
                <i class="bi bi-house-door"></i><span class="mb-label">Home</span>
            </a>
        </div>

        <div class="mb-rail-search">
            <a href="<?php echo e(route(request()->routeIs('googlechat.*') ? 'googlechat.new' : 'chat.new')); ?>" class="mb-nav" title="New chat">
                <i class="bi bi-plus-lg"></i><span class="mb-label">New chat</span>
            </a>
        </div>

        <div class="mb-nav-row<?php echo e($isChat ? ' active' : ''); ?>">
            <a href="<?php echo e(route('chats.index')); ?>" class="mb-nav<?php echo e($isChat ? ' active' : ''); ?>" title="Chats" wire:navigate>
                <i class="bi bi-chat-dots"></i><span class="mb-label">Chats</span>
            </a>
            <button type="button" class="mb-nav-toggle" data-action="toggle-nav" data-target="chatNav" aria-expanded="<?php echo e($activeSection === 'chatNav' ? 'true' : 'false'); ?>" aria-controls="chatNav" aria-label="Toggle chats">
                <i class="bi bi-chevron-down"></i>
            </button>
        </div>
        <div class="mb-chats">
            <div class="mb-chats-panel<?php echo e($activeSection === 'chatNav' ? '' : ' is-closed'); ?>" id="chatNav">
                <div class="mb-side-head">
                    <span>Recent chats</span>
                    
                    <a href="<?php echo e(route(request()->routeIs('googlechat.*') ? 'googlechat.new' : 'chat.new')); ?>"
                       class="mb-icon-btn mb-icon-sm" title="New chat" aria-label="New chat"><i class="bi bi-plus-lg"></i></a>
                    <button type="button" class="mb-icon-btn mb-icon-sm" data-action="open-chat-search" aria-label="Search chats" aria-expanded="false" aria-controls="chatSearch"><i class="bi bi-search"></i></button>
                    <a href="<?php echo e(route('chats.index')); ?>" class="mb-side-head-link" wire:navigate>All</a>
                </div>
                <form class="mb-chat-search" id="chatSearch" method="GET" action="<?php echo e(route('chats.index')); ?>" <?php if(! request()->routeIs('chats.index') || ! request()->filled('q')): ?> hidden <?php endif; ?>>
                    <label class="mb-search">
                        <i class="bi bi-search"></i>
                        <input type="search" name="q" id="chatSearchInput" value="<?php echo e(request()->routeIs('chats.index') ? request('q') : ''); ?>" placeholder="Search chats…" aria-label="Search chats">
                    </label>
                </form>
                <div class="mb-chat-list" id="chatList">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $conversations; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $conversation): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <?php
                            $conversationKey = $conversation->id;
                            $conversationTitle = $conversation->title ?: 'Untitled';
                        ?>
                        <a class="mb-chat-row<?php echo e(($conversationId ?? null) === $conversationKey ? ' active' : ''); ?>"
                           href="<?php echo e(route($conversationRoute, ['conversation' => $conversationKey])); ?>"
                           data-id="<?php echo e($conversationKey); ?>"
                           data-title="<?php echo e($conversationTitle); ?>"
                           title="<?php echo e($conversationTitle); ?>">
                            <span class="mb-hist-dot"></span>
                            <span class="mb-chat-name"><?php echo e($conversationTitle); ?></span>
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($conversation->updated_at ?? $conversation->created_at): ?>
                                <span class="mb-hist-time"><?php echo e(($conversation->updated_at ?? $conversation->created_at)->diffForHumans(null, true)); ?></span>
                            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </a>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
                <div class="mb-chat-hint" id="chatEmpty" <?php if($conversations->isNotEmpty()): ?> hidden <?php endif; ?>>No chats yet.</div>
                <div class="mb-chat-hint" id="chatSearchEmpty" hidden>No matching chats. Press Enter to search the listing.</div>
            </div>
        </div>

        <div class="mb-nav-row<?php echo e($isPerformance ? ' active' : ''); ?>">
            <a href="<?php echo e(route('campaigns.performance')); ?>" class="mb-nav<?php echo e($isPerformance ? ' active' : ''); ?>" title="Campaign performance" wire:navigate>
                <i class="bi bi-graph-up-arrow"></i><span class="mb-label">Campaign performance</span>
            </a>
        </div>

        
        <div class="mb-nav-row<?php echo e($isCreative ? ' active' : ''); ?>">
            <a href="<?php echo e(route('creatives.index')); ?>" class="mb-nav<?php echo e($isCreative ? ' active' : ''); ?>" title="AdStudio" wire:navigate>
                <i class="bi bi-palette"></i><span class="mb-label">AdStudio</span>
            </a>
            <button type="button" class="mb-nav-toggle" data-action="toggle-nav" data-target="creativeNav" aria-expanded="<?php echo e($activeSection === 'creativeNav' ? 'true' : 'false'); ?>" aria-controls="creativeNav" aria-label="Toggle AdStudio">
                <i class="bi bi-chevron-down"></i>
            </button>
        </div>
        <div class="mb-nav-panel<?php echo e($activeSection === 'creativeNav' ? '' : ' is-closed'); ?>" id="creativeNav">
            <div class="mb-side-head">
                <span>Recent creatives</span>
                <a href="<?php echo e(route('creatives.index')); ?>" class="mb-side-head-link" wire:navigate>All</a>
            </div>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($recentCreatives->isEmpty()): ?>
                <div class="mb-nav-empty">No creatives yet</div>
            <?php else: ?>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $recentCreatives; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $itemName = $item->title ?? $item->prompt ?? $item->product_url ?? ('Creative #'.$item->id);
                        // The design's dot only knows completed/generating/queued/failed; our
                        // "processing" (queued job actively rendering) reads as "generating" too.
                        $itemDot = $item->status === 'processing' ? 'generating' : $item->status;
                    ?>
                    <a class="mb-hist<?php echo e(request()->routeIs('creatives.show') && request()->route('creative')?->id === $item->id ? ' active' : ''); ?>"
                       href="<?php echo e(route('creatives.show', $item)); ?>" wire:navigate
                       title="<?php echo e($itemName); ?> - <?php echo e($item->status); ?>">
                        <span class="mb-hist-dot is-<?php echo e($itemDot); ?>"></span>
                        <span class="mb-hist-name"><?php echo e($itemName); ?></span>
                        <span class="mb-hist-time"><?php echo e($item->created_at->diffForHumans(null, true)); ?></span>
                    </a>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>

        <div class="mb-nav-row<?php echo e($isLanding ? ' active' : ''); ?>">
            <a href="<?php echo e(route('landing-pages.index', ['tab' => request('tab', 'catalog')])); ?>" class="mb-nav<?php echo e($isLanding ? ' active' : ''); ?>" title="Landing Pages">
                <i class="bi bi-layout-text-window-reverse"></i><span class="mb-label">Landing Pages</span>
            </a>
            <button type="button" class="mb-nav-toggle" data-action="toggle-nav" data-target="landingPageNav" aria-expanded="<?php echo e($activeSection === 'landingPageNav' ? 'true' : 'false'); ?>" aria-controls="landingPageNav" aria-label="Toggle Landing Pages">
                <i class="bi bi-chevron-down"></i>
            </button>
        </div>
        <div class="mb-nav-panel<?php echo e($activeSection === 'landingPageNav' ? '' : ' is-closed'); ?>" id="landingPageNav">
            <div class="mb-side-head">
                <span>Recent landing pages</span>
                <a href="<?php echo e(route('landing-pages.index', ['tab' => request('tab', 'catalog')])); ?>" class="mb-side-head-link">All</a>
            </div>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($recentPromptPages->isEmpty()): ?>
                <div class="mb-nav-empty">No landing pages yet</div>
            <?php else: ?>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $recentPromptPages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $itemDot = match ($item->status) {
                            'searching', 'analysing', 'generating' => 'generating',
                            'pending_approval' => 'queued',
                            'approved' => 'completed',
                            'rejected' => 'failed',
                            default => $item->status,
                        };
                    ?>
                    <a class="mb-hist<?php echo e(request()->routeIs('prompt-landing-pages.show') && (int) request()->route('page')?->id === $item->id ? ' active' : ''); ?>"
                       href="<?php echo e(route('prompt-landing-pages.show', $item)); ?>"
                       title="<?php echo e($item->displayTitle()); ?> - <?php echo e($item->status); ?>">
                        <span class="mb-hist-dot is-<?php echo e($itemDot); ?>"></span>
                        <span class="mb-hist-name"><?php echo e($item->displayTitle()); ?></span>
                        <span class="mb-hist-time"><?php echo e($item->created_at->diffForHumans(null, true)); ?></span>
                    </a>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
    </div>

    <div class="mb-side-bottom">
        <div class="mb-user" data-pop="user" role="button" tabindex="0" aria-haspopup="menu">
            <span class="mb-avatar"><?php echo e(strtoupper(substr(auth()->user()?->name ?? '?', 0, 1))); ?></span>
            <span class="mb-user-text">
                <div class="mb-user-name"><?php echo e(auth()->user()?->name); ?></div>
                <div class="mb-user-plan"><?php echo e(auth()->user()?->email); ?></div>
            </span>
            <span class="mb-icon-btn mb-user-gear ms-auto" aria-hidden="true"><i class="bi bi-gear"></i></span>
        </div>
    </div>

    <?php echo $__env->make('partials.mb.user-menu', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
</aside>
<?php /**PATH /var/www/php85/koushik/arb.admedia.com/resources/views/partials/mb/sidebar.blade.php ENDPATH**/ ?>