---
/**
 * Tags widget component
 * Displays a tag cloud with optional counts
 */
import { getTaxonomyTerms } from "../../taxonomies/index.js";

interface Props {
	showCount?: boolean;
	limit?: number;
}

const { showCount = false, limit = 20 } = Astro.props;

const allTags = await getTaxonomyTerms("tag");
const tags = allTags.slice(0, limit);
---

<div class="widget-tags">
	{
		tags.length > 0 ? (
			<ul class="widget-tags__cloud">
				{tags.map((tag) => (
					<li>
						<a href={`/tag/${tag.slug}`} class="widget-tags__link">
							{tag.label}
						</a>
						{showCount && tag.count !== undefined && (
							<span class="widget-tags__count">({tag.count})</span>
						)}
					</li>
				))}
			</ul>
		) : (
			<p class="widget-tags__empty">No tags yet</p>
		)
	}
</div>
