// Rôle : affiche une carte Aniimo retournable et les onglets des variantes correspondantes. import { useId, useLayoutEffect, useRef, useState } from "react"; import { GuideChecklistCheckbox, GuideChecklistMark } from "../GuideChecklistControls.jsx"; import { Icon } from "../../../components/Icon.jsx"; import { Tooltip } from "../../../components/Tooltip.jsx"; import { ANIIMO_STATS, aniimoAsset } from "./utils.js"; function Attributes({ values, t }) { return {values.map((value) => {t(value)})}; } function shortForm(label) { const words = label.split(/[\s’-]+/).filter((word) => !/^(forme|de|des|du|la|le|les|d)$/i.test(word)); // Trois lettres distinguent notamment les plateaux, prairies et prismana. return (words.length === 1 ? words[0].slice(0, 3) : words.map((word) => word[0]).join("")).toLocaleUpperCase("fr"); } function CardFaces({ variant, t, content, checklist, statsMax }) { const completed = checklist.isCompleted(variant.key); const [flipped, setFlipped] = useState(false); const frontButton = useRef(null); const backButton = useRef(null); const focusAfterFlip = useRef(false); useLayoutEffect(() => { if (!focusAfterFlip.current) return; (flipped ? backButton : frontButton).current?.focus({ preventScroll: true }); focusAfterFlip.current = false; }, [flipped]); function flip() { focusAfterFlip.current = true; setFlipped((value) => !value); } const flipButton = (back, ref) => ; return (
{flipButton(false, frontButton)}
{t(variant.name)} N° {variant.aniimoId}

{t(variant.name)}

{t(variant.form)}

{variant.elements.map((element) => {t(element)})}
{flipButton(true, backButton)}

{t(variant.name)}

{t(variant.form)}

{content.elements}

{content.role}

{content.abilities}

    {variant.homeland_abilities.map((ability) =>
  • {t(ability.type)} {content.level} {ability.level}
  • )}

{content.statsTitle}

{ANIIMO_STATS.map((key) =>
{content.stats[key]} {variant.attributes.stats[key]}
)}
{content.statsTotal}{variant.attributes.total}
); } export function AniimoCard({ variants, t, content, checklist, statsMax }) { const id = useId(); const [selectedKey, setSelectedKey] = useState(variants[0].key); const variant = variants.find((item) => item.key === selectedKey) || variants[0]; // Mémoriser le repli pour ne pas restaurer un ancien onglet lorsque le filtre est retiré. if (selectedKey !== variant.key) setSelectedKey(variant.key); const multiple = variants.length > 1; function selectTab(index, target) { setSelectedKey(variants[index].key); target.parentElement.children[index].focus(); } return (
{multiple &&
{variants.map((item, index) => setSelectedKey(item.key)} onKeyDown={(event) => { const next = event.key === "ArrowRight" ? (index + 1) % variants.length : event.key === "ArrowLeft" ? (index - 1 + variants.length) % variants.length : event.key === "Home" ? 0 : event.key === "End" ? variants.length - 1 : null; if (next === null) return; event.preventDefault(); selectTab(next, event.currentTarget); }}>{shortForm(t(item.form))})}
}
); }