"use client"; import React, { useState } from 'react'; import Link from 'next/link'; import Image from 'next/image'; import { Post } from '@/types/types'; import { cn } from '@/lib/utils'; import { Calendar, ArrowRight, ChevronLeft, ChevronRight } from 'lucide-react'; import { FeaturedPost } from '@/components/sections/FeaturedPost'; interface PostsGridProps { posts: Post[]; featuredPost?: Post; } const POSTS_PER_PAGE = 6; const categories = [ { id: 'wszystkie', label: 'Wszystkie' }, { id: 'klimatyzacja', label: 'Klimatyzacja' }, { id: 'porady', label: 'Porady' }, ]; export function PostsGrid({ posts, featuredPost }: PostsGridProps) { const [activeCategory, setActiveCategory] = useState('wszystkie'); const [currentPage, setCurrentPage] = useState(1); const filteredPosts = posts.filter( (post) => activeCategory === 'wszystkie' || post.category === activeCategory ); const totalPages = Math.ceil(filteredPosts.length / POSTS_PER_PAGE); const startIndex = (currentPage - 1) * POSTS_PER_PAGE; const visiblePosts = filteredPosts.slice(startIndex, startIndex + POSTS_PER_PAGE); const handleCategoryChange = (categoryId: string) => { setActiveCategory(categoryId); setCurrentPage(1); // Reset paginacji przy zmianie kategorii }; const categoryLabels: Record = { 'klimatyzacja': 'Klimatyzacja', 'porady': 'Porady' }; return (
{featuredPost && currentPage === 1 && (

Artykuł wyróżniony

)}
{categories.map((category) => ( ))}
{visiblePosts.map((post) => { const dateObj = new Date(post.date); const formattedDate = dateObj.toLocaleDateString('pl-PL', { day: 'numeric', month: 'long', year: 'numeric' }); return (
{post.title}
{categoryLabels[post.category] || post.category}
{formattedDate}

{post.title}

{post.excerpt}

Czytaj więcej
); })}
{visiblePosts.length === 0 && (

Brak artykułów w tej kategorii.

)} {totalPages > 1 && (
{Array.from({ length: totalPages }).map((_, i) => { const pageNum = i + 1; // Prosta logika dla mniejszych ekranów (opcjonalnie można ukrywać strony w środku, ale flex-wrap sobie poradzi) return ( ) })}
)}
); }