"use client"; import { useEffect, useState } from "react"; import type { TarotContent, TarotReading } from "@/lib/tarot"; import { TarotResult } from "./TarotResult"; import { TarotFan, TarotSlots } from "./TarotSpread"; export interface TarotExample { id: string; label: string; signs: string; spread_name: string; question: string; cards: TarotReading["cards"]; content: TarotContent; } /** The fan cards the demo "picks", in order. */ const PICKS = [4, 13, 8, 17, 2]; /** * Plays a reading: the cards are picked from the fanned deck one by one, * laid out, turned over, then the written reading appears below. The text is * on the page from the start (hidden while the animation plays). */ function Demo({ example }: { example: TarotExample }) { const n = example.cards.length; const done = 3 * n + 2; const [step, setStep] = useState(0); // Without motion the end state shows at once. useEffect(() => { if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) setStep(done); }, [done]); useEffect(() => { if (step >= done) return; const picking = step <= 2 * n; const delay = step === 0 ? 900 : picking ? (step % 2 === 1 ? 420 : 520) : 680; const t = setTimeout(() => setStep((s) => s + 1), delay); return () => clearTimeout(t); }, [step, done, n]); const pickedCount = Math.min(n, Math.floor(step / 2)); const lifted = step % 2 === 1 && step < 2 * n ? PICKS[(step - 1) / 2] : null; const revealed = Math.max(0, Math.min(n, step - (2 * n + 1))); const finished = step >= done; return (
„{example.question}”
A kérdés és a képlet kitalált ({example.signs}).
{finished ? ( ) : pickedCount < n ? ( `Lapválasztás a pakliból: ${pickedCount}/${n}` ) : ( "A lapok felfordulnak…" )}