"use client"; import { useState, useMemo, useTransition } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { createOfferMacro } from "@/app/admin/offers/actions"; import type { OfferListCard } from "@/lib/offer-queries"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Input } from "@/components/ui/input"; export function OfferListClient({ cards, categoryOptions, }: { cards: OfferListCard[]; categoryOptions: string[]; }) { const router = useRouter(); const [isPending, startTransition] = useTransition(); const [activeCategory, setActiveCategory] = useState(null); const [showArchived, setShowArchived] = useState(false); const [showCreateForm, setShowCreateForm] = useState(false); const [newOfferName, setNewOfferName] = useState(""); const filteredCards = useMemo(() => { return cards.filter( (c) => (activeCategory === null || c.category === activeCategory) && (showArchived || !c.is_archived) ); }, [cards, activeCategory, showArchived]); function handleCreateSubmit(formData: FormData) { startTransition(async () => { await createOfferMacro(formData); setShowCreateForm(false); setNewOfferName(""); router.refresh(); }); } const createCta = (
{showCreateForm && (
setNewOfferName(e.target.value)} className="h-9 w-48" />
)}
); return (
{/* Page header */}

Offerte

{createCta}
{/* Filter row */}
{categoryOptions.map((category) => ( ))}
{/* Card grid / empty state */} {filteredCards.length === 0 ? (

Nessuna offerta

Inizia creando la tua prima offerta

{createCta}
) : (
{filteredCards.map((card) => (

{card.internal_name}

{card.description && (

{card.description}

)}
{card.category && {card.category}} {card.is_archived && ( Archiviata )}
))}
)}
); }