'use client';
import { useEffect, useRef } from 'react';
import { motion } from 'framer-motion';
import { Wordmark } from '@/components/primitives/Wordmark';
import { fadeInUp } from '@/lib/motion';
// One exchange of the page's conversation: the reader's situation, then what
// creeer does about it. The answer arrives as you scroll into the pair — its
// gold rule draws down and the block comes up to full contrast — so the section
// reads as being answered rather than as a list that happens to have answers.
//
// The sides never swap from one pair to the next. Each voice keeps its own
// margin, the way a conversation reads on a page; what alternates going down is
// situación → respuesta, not left → right. Flipping sides per pair would cost
// the reader the one cue that tells them who is speaking.
//
// Three cues carry that distinction, never colour alone: the speaker label, the
// column, and the rule hanging off each block.
//
// The answer text is in the DOM at all times, at every breakpoint — opacity,
// never `display: none` or `hidden`, so screen readers still announce it and
// the static export still ships it to search engines.
//
// `activo` latches: the section turns it on when the reader reaches the pair
// and never turns it off again. An answer that faded back out once you scrolled
// past would leave the page emptier the further you read, and would re-create
// the failure this project has already hit twice — content stranded at opacity
// zero with every test green, because jsdom has no layout and no scrolling.
//
// No motion.li here on purpose: Framer propagates variants through React
// context, so the two motion.div children still inherit the stagger from the
//
the section wraps them in, even across this plain - .
export function ParDialogo({
n,
name,
situacion,
respuesta,
activo,
reducido,
onActivar,
}: {
n: number;
name: string;
situacion: string;
respuesta: string;
activo: boolean;
reducido: boolean;
onActivar: (n: number) => void;
}) {
const ref = useRef(null);
// The pair crossing the middle of the viewport is the one being answered.
// The negative margins collapse the root to a band across the centre, so
// "in view" means "where the reader is actually looking", not "anywhere on
// screen" — which with six pairs would fire all of them at once.
useEffect(() => {
const el = ref.current;
if (!el || reducido) return;
const observer = new IntersectionObserver(
([entrada]) => {
if (entrada.isIntersecting) onActivar(n);
},
{ rootMargin: '-45% 0px -45% 0px' },
);
observer.observe(el);
return () => observer.disconnect();
}, [n, reducido, onActivar]);
// Reduced motion gets the resolved state outright: everything at full
// contrast, every rule drawn. Never the dimmed half of an animation that
// will not run.
const resuelto = reducido || activo;
return (
- onActivar(n)}
onFocus={() => onActivar(n)}
className="grid gap-5 md:grid-cols-2 md:gap-12"
>
{/* Two nested layers on purpose, and they must stay nested. Framer writes
the resolved variant into the inline `style` — `opacity: 1` — and an
inline style beats a Tailwind class. Putting the reveal on the same
element as `variants` looked right in the markup and did nothing in the
browser: the answers were readable from the moment the section entered,
and only the gold rule, a transform Framer never touches, animated.
So: motion.div owns the entrance, the plain child owns the reveal. */}
{String(n).padStart(2, '0')} · {name}
«{situacion}»
{/* The rule draws itself down as the answer arrives. A transform, not
a stroke: a dash pattern on a non-uniformly scaled SVG is exactly
what broke the hilo conductor, and this has to survive any
container it lands in. */}
{respuesta}
);
}