"use client"; import { useState, useRef } from "react"; import Image from "next/image"; import type { BucketItem } from "@/interface/love"; import { Check, Heart, Smile, Plane, Utensils, Home, Compass } from "lucide-react"; import LoveSectionHeading from "./LoveSectionHeading"; interface LoveBucketListProps { items: BucketItem[]; } export default function LoveBucketList({ items }: LoveBucketListProps) { const [activeFilter, setActiveFilter] = useState("all"); const categories = [ { key: "all", label: "全部清单" }, { key: "travel", label: "携手旅行" }, { key: "food", label: "浪漫美食" }, { key: "daily", label: "生活日常" }, { key: "adventure", label: "共同冒险" } ]; // 过滤 const filteredItems = items.filter( (item) => activeFilter === "all" || item.category === activeFilter ); // 统计 const total = items.length; const completed = items.filter((i) => i.completed).length; const percent = total > 0 ? Math.round((completed / total) * 100) : 0; return (
{/* 头部:统一巨字标题 + 进度环看板 */}
{/* 精美进度环看板 */}
{percent}%
已点亮愿望
{completed} / {total}
{/* 检索分类 Tabs */}
{categories.map((cat) => ( ))}
{/* Bento Grid 卡片列表 */}
{filteredItems.map((item) => ( ))} {filteredItems.length === 0 && (
该分类下还没有计划的愿望。
)}
); } // 独立的单卡片组件,实现局部 Canvas 纸屑动效 function BucketCard({ item }: { item: BucketItem }) { const canvasRef = useRef(null); const [showThoughts, setShowThoughts] = useState(false); const getCategoryIcon = (cat: string) => { switch (cat) { case "travel": return ; case "food": return ; case "daily": return ; case "adventure": return ; default: return null; } }; const getCategoryName = (cat: string) => { switch (cat) { case "travel": return "旅行"; case "food": return "美食"; case "daily": return "日常"; case "adventure": return "冒险"; default: return cat; } }; const fireConfetti = () => { const canvas = canvasRef.current; if (!canvas) return; if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return; const ctx = canvas.getContext("2d"); if (!ctx) return; canvas.width = canvas.clientWidth; canvas.height = canvas.clientHeight; const particles: any[] = []; const colors = ["#D97706", "#B45309", "#E11D48", "#F59E0B", "#059669", "#FBBF24"]; // 创建喷发粒子 for (let i = 0; i < 45; i++) { particles.push({ x: canvas.width / 2, y: canvas.height - 15, vx: (Math.random() - 0.5) * 8, vy: -Math.random() * 6 - 4, r: Math.random() * 3 + 1.5, color: colors[Math.floor(Math.random() * colors.length)], alpha: 1, decay: Math.random() * 0.02 + 0.02 }); } const draw = () => { ctx.clearRect(0, 0, canvas.width, canvas.height); let alive = false; particles.forEach((p) => { if (p.alpha > 0) { alive = true; p.x += p.vx; p.y += p.vy; p.vy += 0.22; // 重力 p.alpha -= p.decay; ctx.save(); ctx.globalAlpha = p.alpha; ctx.fillStyle = p.color; ctx.beginPath(); ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2); ctx.fill(); ctx.restore(); } }); if (alive) { requestAnimationFrame(draw); } }; draw(); }; const handleCardClick = () => { if (item.completed) { fireConfetti(); if (item.thoughts || item.cover) { setShowThoughts(!showThoughts); } } }; return (
{/* 粒子 Canvas */} {/* 正面卡片默认展示 */} {!showThoughts ? ( <>
{getCategoryIcon(item.category)} {getCategoryName(item.category)} {item.completed && ( )}

{item.title}

{/* 底部已点亮信息 / 拟真 Completed 印章 */}
{item.completed ? ( <> {item.completedDate} {/* 拟物斜印章印记 */}
已点亮
) : ( 待打卡点亮 )}
) : ( /* 反面卡片展示想法回忆 */
{item.cover ? (
{`${item.title}

“{item.thoughts || "完成这件事的感动,都藏在合照里。"}”

点亮日期: {item.completedDate}
) : (

“{item.thoughts}”

点亮日期: {item.completedDate}
)}
)}
); }