
<?php
    $standardTypes = ['inbox', 'drafts', 'sent', 'archive', 'junk', 'trash'];

    if ($depth === 0) {
        // Standart klasörler + üstü olmayan özel klasörler. Bir klasörün altındaki
        // özel klasörler aşağıdaki özyinelemeli çağrıda, üstüne girintili çizilir.
        $nodes = $folders
            ->filter(fn ($f) => in_array($f->type, $standardTypes, true) || $f->parent_id === null)
            ->sortBy([['sort_order', 'asc'], ['name', 'asc']])
            ->values();
    } else {
        // Alt seviyede yalnızca özel klasörler; standart olanlar zaten kökte çizildi
        $nodes = $folders->where('parent_id', $parentId)->where('type', 'custom')->sortBy('name')->values();
    }
?>

<?php $__currentLoopData = $nodes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $folder): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php
        $unread = (int) $folder->messages_unread;
        $children = $folders->where('parent_id', $folder->id)
            ->where('type', 'custom')
            ->reject(fn ($c) => $c->id === $folder->id);
    ?>

    <button type="button"
            class="mail-folder <?php echo e($unread > 0 && $folder->showsUnreadBadge() ? 'has-unread' : ''); ?> <?php echo e($depth > 0 ? 'mail-folder-sub' : ''); ?>"
            data-scope="folder"
            data-folder-id="<?php echo e($folder->id); ?>"
            data-account-id="<?php echo e($folder->account_id); ?>"
            data-folder-type="<?php echo e($folder->type); ?>"
            data-pinned="<?php echo e($folder->is_pinned ? '1' : '0'); ?>"
            data-label="<?php echo e($folder->label()); ?>"
            title="<?php echo e($folder->label()); ?>">
        <i class="fas <?php echo e($folder->icon()); ?> mail-folder-icon"></i>
        <span class="mail-folder-name"><?php echo e($folder->label()); ?></span>
        <span class="mail-folder-count" data-folder-count="<?php echo e($folder->id); ?>">
            <?php if($folder->showsUnreadBadge()): ?>
                <?php echo e($unread ?: ''); ?>

            <?php else: ?>
                <?php echo e($folder->messages_total ?: ''); ?>

            <?php endif; ?>
        </span>
    </button>

    <?php if($children->isNotEmpty() && $depth < 3): ?>
        <?php echo $__env->make('agency.mail.partials._folders', [
            'folders' => $folders,
            'parentId' => $folder->id,
            'depth' => $depth + 1,
            'account' => $account,
        ], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>
    <?php endif; ?>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
<?php /**PATH C:\xampp\htdocs\acente\resources\views/agency/mail/partials/_folders.blade.php ENDPATH**/ ?>