"use client" import { useEffect, useState } from "react" import Link from "next/link" import { History, ChevronRight, X } from "lucide-react" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Button } from "@/components/ui/button" type RecentPlan = { id: string title: string lastVisited: number } export function RecentPlans({ lang, dict }: { lang: string, dict: { title: string, noPlans: string, clear: string } }) { const [plans, setPlans] = useState([]) const [mounted, setMounted] = useState(false) useEffect(() => { setMounted(true) const stored = localStorage.getItem("csp_recent_plans") if (stored) { try { const parsed = JSON.parse(stored) setPlans(parsed.sort((a: RecentPlan, b: RecentPlan) => b.lastVisited - a.lastVisited)) } catch (e) { console.error("Failed to parse recent plans", e) } } }, []) const removePlan = (id: string, e: React.MouseEvent) => { e.preventDefault() e.stopPropagation() const newPlans = plans.filter(p => p.id !== id) setPlans(newPlans) localStorage.setItem("csp_recent_plans", JSON.stringify(newPlans)) } if (!mounted || plans.length === 0) return null return ( {dict.title} {plans.map((plan) => (
{plan.title}
))}
) }