import Link from "next/link"; import { useEffect, useRef } from "react"; import { IoInformation } from "react-icons/io5"; import { type QuestionCardIcon, type QuestionListItem, resolveSectionIcon, } from "@/lib/schema-adapter"; import { localizePath } from "@/translations/config"; import { useI18n } from "@/translations/provider"; import { UiIcon, type UiIconName } from "./ui-icon"; type QuestionCardProps = { item: QuestionListItem; progress?: number | null; onInfoClick?: (item: QuestionListItem) => void; onNearViewport?: (item: QuestionListItem) => void; onPrefetch?: (item: QuestionListItem) => void; onSelect?: (item: QuestionListItem) => void; }; const RADIUS = 8; const CIRCUMFERENCE = 2 * Math.PI * RADIUS; // Inline equivalents of the per-card SVGs previously loaded from `public/`: // no network request, present in the first rendered markup. const iconNameMap: Record = { profile: "person", contact: "contact", health: "health", education: "education", family: "family", marriage: "marriage", lifestyle: "lifestyle", criteria: "criteria", verification: "verification", personality: "personality", glasser: "glasser", details: "details", checklist: "checklist", family_marital: "marriage", }; export function QuestionCard({ item, progress = item.progress, onInfoClick, onNearViewport, onPrefetch, onSelect, }: QuestionCardProps) { const { dictionary: t, locale } = useI18n(); const hasProgress = typeof progress === "number" && Number.isFinite(progress); const normalizedProgress = hasProgress ? Math.max(0, Math.min(Math.round(progress), 100)) : 0; const dashOffset = CIRCUMFERENCE - (normalizedProgress / 100) * CIRCUMFERENCE; const resolvedIconKey = item.icon || resolveSectionIcon(item.slug); const iconName = iconNameMap[resolvedIconKey] ?? "details"; const cardRef = useRef(null); useEffect(() => { const node = cardRef.current; if ( !node || !onNearViewport || typeof IntersectionObserver === "undefined" ) { return; } const observer = new IntersectionObserver( ([entry]) => { if (entry.isIntersecting) { onNearViewport(item); observer.disconnect(); } }, { rootMargin: "160px 0px" }, ); observer.observe(node); return () => observer.disconnect(); }, [item, onNearViewport]); return ( { if (onSelect && !e.ctrlKey && !e.metaKey && !e.shiftKey && e.button === 0) { e.preventDefault(); onSelect(item); } }} onFocus={() => onPrefetch?.(item)} onPointerEnter={() => onPrefetch?.(item)} onPointerDown={() => onPrefetch?.(item)} >

{item.title}

{t["Estimate time"]}: {item.estimate}

{item.required ? ( {t["Required"]} ) : item.showInfoBadge ? ( ) : (
{item.note ? (

{item.note}

) : null}
); } export default QuestionCard;