<?php
if (! defined('ABSPATH')) {
    exit;
} $pgo_tree = isset($args['tree']) && is_array($args['tree']) ? $args['tree'] : array();
$pgo_archive_url = isset($args['archive_url']) ? $args['archive_url'] : '';
$pgo_all_active = ! empty($args['all_active']);

if (empty($pgo_tree)) {
    return;
} $pgo_render_cat_nodes = function (array $nodes, $depth) use (&$pgo_render_cat_nodes) { $list_class = $depth > 0 ? 'mt-1 ml-2 flex flex-col gap-1 border-l border-neutral-200 pl-3' : 'flex flex-col gap-1'; ?>
	<ul class="<?php echo esc_attr($list_class); ?>">
		<?php foreach ($nodes as $node) : ?>
			<li>
				<?php $pgo_has_children = ! empty($node['children']); ?>
				<a
					href="<?php echo esc_url($node['url']); ?>"
					class="group flex items-center gap-2 rounded-md px-2 py-1.5 text-sm transition <?php echo ! empty($node['is_active']) ? 'bg-brand-600 text-white font-medium' : 'text-neutral-700 hover:bg-neutral-100'; ?>"
					<?php echo ! empty($node['is_active']) ? 'aria-current="page"' : ''; ?>
				>
					<span class="min-w-0 flex-1 truncate"><?php echo esc_html($node['name']); ?></span>
					<span class="text-xs tabular-nums <?php echo ! empty($node['is_active']) ? 'text-white/80' : 'text-neutral-400'; ?>"><?php echo (int) $node['count']; ?></span>
					<?php if ($pgo_has_children) : ?>
						<svg class="h-3.5 w-3.5 flex-none transition-transform <?php echo ! empty($node['is_open']) ? 'rotate-90' : ''; ?> <?php echo ! empty($node['is_active']) ? 'text-white/70' : 'text-neutral-400'; ?>" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
							<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"></path>
						</svg>
					<?php endif; ?>
				</a>
				<?php if (! empty($node['children']) && ! empty($node['is_open'])) : ?>
					<?php $pgo_render_cat_nodes($node['children'], $depth + 1); ?>
				<?php endif; ?>
			</li>
		<?php endforeach; ?>
	</ul>
	<?php
}; ?>
<nav class="puffergo-product-filter" aria-label="<?php esc_attr_e('Product categories', 'puffergo'); ?>">
	<h2 class="mb-3 text-xs font-semibold uppercase tracking-wide text-neutral-500"><?php esc_html_e('Categories', 'puffergo'); ?></h2>
	<a
		href="<?php echo esc_url($pgo_archive_url); ?>"
		class="mb-1 flex items-center rounded-md px-2 py-1.5 text-sm transition <?php echo $pgo_all_active ? 'bg-brand-600 text-white font-medium' : 'text-neutral-700 hover:bg-neutral-100'; ?>"
		<?php echo $pgo_all_active ? 'aria-current="page"' : ''; ?>
	>
		<?php esc_html_e('All products', 'puffergo'); ?>
	</a>
	<?php $pgo_render_cat_nodes($pgo_tree, 0); ?>
</nav>
<?php
