import React, { useState, useEffect, useMemo, useCallback } from "react"; import { motion } from "framer-motion"; import SEOHead from "./components/SEOHead"; import MobileOptimizedHeader from "./components/MobileOptimizedHeader"; import EnhancedTextInput from "./components/EnhancedTextInput"; import ImprovedCategoryFilter from "./components/ImprovedCategoryFilter"; import PerformanceOptimizedFontCard from "./components/PerformanceOptimizedFontCard"; import InfoSection from "./components/InfoSection"; import SocialButtons from "./components/SocialButtons"; import { fontTransforms, getFontsByCategory, transformText, getPopularFonts, } from "./components/FontTransforms"; // kleine Helper const sArr = (v) => (Array.isArray(v) ? v : []); const sStr = (v) => (v ?? "").toString(); const sObj = (v) => (v ?? {}); export default function Home() { const [inputText, setInputText] = useState("Hello Instagram!"); const [selectedCategory, setSelectedCategory] = useState("all"); const [isMobile, setIsMobile] = useState(false); const [animationsEnabled, setAnimationsEnabled] = useState(() => { if (typeof window !== "undefined") { const hasReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches; const cores = typeof navigator !== "undefined" ? navigator.hardwareConcurrency : 8; const isLowEndDevice = (cores ?? 8) < 4; return !hasReducedMotion && !isLowEndDevice; } return true; }); // Mobile Detection useEffect(() => { const checkMobile = () => { if (typeof window !== "undefined") { setIsMobile( window.innerWidth < 768 || /iPhone|iPad|iPod|Android/i.test(navigator.userAgent) ); } }; checkMobile(); if (typeof window !== "undefined") { window.addEventListener("resize", checkMobile); return () => window.removeEventListener("resize", checkMobile); } }, []); // Debounce const [debouncedText, setDebouncedText] = useState(inputText); useEffect(() => { const delay = isMobile ? 200 : 100; const t = setTimeout(() => setDebouncedText(inputText), delay); return () => clearTimeout(t); }, [inputText, isMobile]); // Fonts const availableFonts = useMemo( () => sArr(getFontsByCategory?.(selectedCategory)), [selectedCategory] ); const popularFonts = useMemo(() => sArr(getPopularFonts?.()), []); const fontCounts = useMemo(() => { const totalFonts = Object.keys(sObj(fontTransforms)).length; const counts = { all: totalFonts }; Object.values(sObj(fontTransforms)).forEach((font) => { const cat = font?.category ?? "other"; counts[cat] = (counts[cat] || 0) + 1; }); return counts; }, []); // Analytics const handleFontCopy = useCallback((fontName, text) => { if (typeof window !== "undefined" && window.gtag) { window.gtag("event", "font_copied", { font_name: fontName, text_length: sStr(text).length, category: fontTransforms?.[fontName]?.category, }); } }, []); const handleQuickShare = useCallback(async () => { if (typeof window === "undefined") return; const shareData = { title: "FancyText - Cool Fonts! 🔥", text: "Check out this app for cool Instagram & TikTok fonts! 30+ fonts for free ✨", url: window.location.href, }; if (navigator.share) { try { await navigator.share(shareData); } catch (err) { if (err.name !== "AbortError") console.error("Share failed:", err); } } else { try { await navigator.clipboard.writeText(`${shareData.text}\n${shareData.url}`); alert("Link copied! 📋"); } catch (err) { console.error("Copy failed:", err); } } }, []); return (