"use client"; import { useEffect, useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { Disc3, Gamepad2, Zap, Quote as QuoteIcon } from "lucide-react"; import { useTranslations } from "next-intl"; import Image from "next/image"; interface CustomActivity { [key: string]: unknown; } interface StatusData { music: { isPlaying: boolean; track: string; artist: string; albumArt: string; url: string; } | null; gaming: { isPlaying: boolean; name: string; image: string | null; state?: string | number; details?: string | number; } | null; coding: { isActive: boolean; project?: string; file?: string; language?: string; } | null; customActivities?: Record; } const techQuotes = { de: [ { content: "Informatik hat nicht mehr mit Computern zu tun als Astronomie mit Teleskopen.", author: "Edsger W. Dijkstra" }, { content: "Einfachheit ist die Voraussetzung für Verlässlichkeit.", author: "Edsger W. Dijkstra" }, { content: "Wenn Debugging der Prozess des Entfernens von Fehlern ist, dann muss Programmieren der Prozess des Einbauens sein.", author: "Edsger W. Dijkstra" }, { content: "Gelöschter Code ist gedebuggter Code.", author: "Jeff Sickel" }, { content: "Zuerst löse das Problem. Dann schreibe den Code.", author: "John Johnson" }, { content: "Jedes Programm kann um mindestens einen Faktor zwei vereinfacht werden. Jedes Programm hat mindestens einen Bug.", author: "Kernighan's Law" }, { content: "Code lesen ist schwieriger als Code schreiben — deshalb schreibt jeder neu.", author: "Joel Spolsky" }, { content: "Die beste Performance-Optimierung ist der Übergang von nicht-funktionierend zu funktionierend.", author: "J. Osterhout" }, { content: "Mach es funktionierend, dann mach es schön, dann mach es schnell — in dieser Reihenfolge.", author: "Kent Beck" }, { content: "Software ist wie Entropie: Es ist schwer zu fassen, wiegt nichts und gehorcht dem zweiten Hauptsatz der Thermodynamik.", author: "Norman Augustine" }, { content: "Gute Software ist nicht die, die keine Bugs hat — sondern die, deren Bugs keine Rolle spielen.", author: "Bruce Eckel" }, { content: "Der einzige Weg, schnell zu gehen, ist, gut zu gehen.", author: "Robert C. Martin" }, ], en: [ { content: "Computer Science is no more about computers than astronomy is about telescopes.", author: "Edsger W. Dijkstra" }, { content: "Simplicity is prerequisite for reliability.", author: "Edsger W. Dijkstra" }, { content: "If debugging is the process of removing software bugs, then programming must be the process of putting them in.", author: "Edsger W. Dijkstra" }, { content: "Deleted code is debugged code.", author: "Jeff Sickel" }, { content: "First, solve the problem. Then, write the code.", author: "John Johnson" }, { content: "Any program can be simplified by at least a factor of two. Every program has at least one bug.", author: "Kernighan's Law" }, { content: "It's harder to read code than to write it — that's why everyone rewrites.", author: "Joel Spolsky" }, { content: "The best performance optimization is the transition from a non-working state to a working state.", author: "J. Osterhout" }, { content: "Make it work, make it right, make it fast — in that order.", author: "Kent Beck" }, { content: "Software is like entropy: it is difficult to grasp, weighs nothing, and obeys the second law of thermodynamics.", author: "Norman Augustine" }, { content: "Good software isn't software with no bugs — it's software whose bugs don't matter.", author: "Bruce Eckel" }, { content: "The only way to go fast is to go well.", author: "Robert C. Martin" }, ] }; function getSafeGamingText(details: string | number | undefined, state: string | number | undefined, fallback: string): string { if (typeof details === 'string' && details.trim().length > 0) return details; if (typeof state === 'string' && state.trim().length > 0) return state; return fallback; } export default function ActivityFeed({ onActivityChange, locale = 'en' }: { onActivityChange?: (active: boolean) => void; locale?: string; }) { const [data, setData] = useState(null); const [hasActivity, setHasActivity] = useState(false); const [quoteIndex, setQuoteIndex] = useState(() => Math.floor(Math.random() * (techQuotes[locale as keyof typeof techQuotes] || techQuotes.en).length)); const [loading, setLoading] = useState(true); const t = useTranslations("home.about.activity"); const allQuotes = techQuotes[locale as keyof typeof techQuotes] || techQuotes.en; useEffect(() => { const fetchData = async () => { try { const res = await fetch("/api/n8n/status"); if (!res.ok) throw new Error(); const json = await res.json(); const activityData = Array.isArray(json) ? json[0] : json; setData(activityData); const isActive = Boolean( activityData.coding?.isActive || activityData.gaming?.isPlaying || activityData.music?.isPlaying || Object.values(activityData.customActivities || {}).some((act) => Boolean((act as { enabled?: boolean })?.enabled)) ); setHasActivity(isActive); onActivityChange?.(isActive); } catch { setHasActivity(false); onActivityChange?.(false); } finally { setLoading(false); } }; fetchData(); const statusInterval = setInterval(fetchData, 30000); // Pick a random quote every 10 seconds (never the same one twice in a row) const quoteInterval = setInterval(() => { setQuoteIndex((prev) => { let next; do { next = Math.floor(Math.random() * allQuotes.length); } while (next === prev && allQuotes.length > 1); return next; }); }, 10000); return () => { clearInterval(statusInterval); clearInterval(quoteInterval); }; }, [onActivityChange]); if (loading) { return
; } if (!hasActivity) { return (

“{allQuotes[quoteIndex].content}”

— {allQuotes[quoteIndex].author}

{t("idleStatus")}
); } return (
{data?.coding?.isActive && (
{t("codingNow")}

{data.coding.project}

{data.coding.file}

)} {data?.gaming?.isPlaying && (
{t("gaming")}
{data.gaming.image && (
{data.gaming.name}
)}

{data.gaming.name}

{getSafeGamingText(data.gaming.details, data.gaming.state, t("inGame"))}

)} {data?.music?.isPlaying && (
{t("listening")}
{/* Simple Animated Music Bars */}
{[0, 1, 2].map((i) => ( ))}
Album Art

{data.music.track}

{data.music.artist}

{/* Subtle Spotify branding gradient */}
)}
); }