// Rôle : affiche la fiche détaillée d'une carte possédée : à gauche la carte en grand, à droite son nom et, pour une carte des
// Expéditions, deux onglets. « La carte » (par défaut depuis la collection) : son lore, ses informations (exemplaires, collection,
// finitions) et les actions (favori, recyclage d'un doublon, don, échange). « Amélioration » (par défaut depuis les Expéditions,
// `initialTab`) : un récapitulatif (Puissance, niveau et expérience, les quatre stats et celles que donnerait la répartition en
// cours de choix), l'amélioration (ou l'Éveil devant un palier) et la répartition des statistiques. L'équipement se règle depuis les Expéditions.
// `focus` (« plan ») ouvre « Amélioration » et fait défiler la fiche jusqu'à cette section, depuis un objet du Sac.
import { useEffect, useRef, useState } from "react";
import { Modal } from "../../components/Modal.jsx";
import { Tabs } from "../../components/Tabs.jsx";
import { recycleDuplicates, setFavorite, upgradeCard } from "./cardsApi.js";
import { AwakeningPicker } from "./AwakeningPicker.jsx";
import { CardPlan } from "./CardPlan.jsx";
import { frenchList, rarityAdjective } from "./rarityWords.js";
import { CurrencyAmount } from "./Currency.jsx";
import { readCollection } from "./collectionState.js";
import { fillTemplate } from "./dailyShare.js";
import { MaskIcon } from "./ExpeditionLabels.jsx";
import { NebulaCard } from "./NebulaCard.jsx";
import { formatEclats } from "./expeditionFormat.js";
import { formatStardust } from "./stardustFormat.js";
const STAT_IDS = ["bravoure", "endurance", "fortune", "orientation"];
const FOCUS_SELECTORS = { plan: ".nebula-card-plan" };
const TAB_IDS = ["card", "improve"];
// Récapitulatif d'une carte des Expéditions : Puissance, niveau et expérience, puis ses quatre stats (équipement compris ; la part
// de l'équipement en petit dessous). `preview` : stats sans équipement de la répartition en cours de choix, montrées « 15 → 18 ».
function CardSummary({ progress, preview, content }) {
const atCap = progress.nextCost == null;
return
{content.power} {progress.power}
{content.level} {progress.level} / {progress.maxLevel}
{atCap ?
{content.atCap} : progress.awakening ?
{fillTemplate(content.awakeningWait, { power: progress.awakening.power })} : <>
{fillTemplate(content.experienceValue, { value: progress.fieldXp })}
>}
{STAT_IDS.map((stat) => {
const base = progress.baseStats?.[stat] ?? progress.stats[stat];
const gear = progress.stats[stat] - base;
const next = preview ? progress.stats[stat] + preview[stat] - base : progress.stats[stat];
return progress.stats[stat] ? "up" : next < progress.stats[stat] ? "down" : undefined}>
{content.stats[stat]}
{next !== progress.stats[stat] ? <>{progress.stats[stat]} → {content.becomes} {next}> : progress.stats[stat]}
{gear !== 0 && 0 ? "up" : "down"}>{fillTemplate(content.gear, { value: `${gear > 0 ? "+" : "−"}${Math.abs(gear)}` })} }
;
})}
;
}
// Éveil d'une carte arrêtée devant un palier : un doublon d'elle-même (pour une mythique, sa version légendaire), ou des doublons de
// sa collection et de sa rareté, choisis dans une fenêtre comme à l'atelier. L'Éveil ne coûte pas d'Éclats.
function CardAwakening({ catalog, progress, busy, runMutation, content }) {
const [choosing, setChoosing] = useState(false);
const { awakening } = progress;
const own = catalog.editions.find((edition) => edition.id === progress.editionId);
const card = catalog.cards.find((item) => item.id === own?.cardId);
// « rare », « légendaires ou mythiques » : les raretés acceptées, accordées avec le nombre de doublons.
const acceptedIds = own?.rarity === "mythic" ? ["legendary", "mythic"] : [own?.rarity];
const accepted = (count) => frenchList(acceptedIds.map((id) => rarityAdjective(catalog, id, count)), "disjunction");
const collectionName = catalog.collections.find((item) => item.id === card?.collectionId)?.name ?? "";
const exactIsOther = awakening.exact && awakening.exact !== progress.editionId;
const plural = awakening.needed > 1 ? "s" : "";
return
{fillTemplate(content.awakeningTitle, { power: awakening.power })}
{content.awakeningText}
runMutation(() => upgradeCard(progress.editionId, "duplicate"))}>{exactIsOther ? content.awakenLegendary : content.awakenExact}
setChoosing(true)}>{fillTemplate(content.awakenChoose, { count: awakening.needed, s: plural, rarity: accepted(awakening.needed) })}
{fillTemplate(content.awakenPoolCount, { available: Math.min(awakening.available, awakening.needed), count: awakening.needed, rarity: accepted(2), collection: collectionName })}
{choosing && runMutation(() => upgradeCard(progress.editionId, "awaken", editionIds))} onClose={() => setChoosing(false)} />}
;
}
// Amélioration d'une carte rare ou mieux : Éclats, ou doublon de la même édition (l'Éveil devant un palier) ; puis la répartition
// de ses statistiques.
function CardProgress({ catalog, state, progress, eclats, locked, busy, runMutation, onPreview, content }) {
const atCap = progress.nextCost == null;
const nextAwakening = progress.awakeningsAhead?.[0];
return <>
{!atCap && progress.awakening && }
{!atCap && !progress.awakening &&
{content.upgradeTitle}
runMutation(() => upgradeCard(progress.editionId, "eclats"))}>{content.upgradeEclats}{fillTemplate(content.eclatsAmount, { value: formatEclats(progress.nextCost) })}
{progress.spare > 0 && runMutation(() => upgradeCard(progress.editionId, "duplicate"))}>{content.upgradeDuplicate} }
{fillTemplate(content.upgradeHelp, { eclats: formatEclats(eclats) })}
{/* Tant qu'un palier reste à franchir, les doublons valent plus pour l'Éveil que pour un niveau ordinaire. */}
{nextAwakening && {fillTemplate(content.nextAwakening, { power: nextAwakening })}
}
}
>;
}
// `content` : textes cards.cardSheet.
export function CardDetailModal({ catalog, state, entry, content, runMutation, busy, onClose, onStartTransfer = null, focus = null, initialTab = "card" }) {
const dialogRef = useRef(null);
useEffect(() => {
if (!focus) return undefined;
const frame = requestAnimationFrame(() => dialogRef.current?.querySelector(FOCUS_SELECTORS[focus])?.scrollIntoView({ block: "start", behavior: "smooth" }));
return () => cancelAnimationFrame(frame);
}, [focus]);
const owned = readCollection(state).entries.get(entry.edition.id);
const quantity = owned?.quantity || 0;
const spare = owned?.spare || 0;
const value = state.shop.stardustValues[entry.edition.rarity] ?? 0;
const favorites = new Set(state.favorites);
const expedition = state.expeditions?.busyEditions?.find((item) => item.editionId === entry.edition.id);
const progress = state.cardProgress?.find((item) => item.editionId === entry.edition.id);
// Aperçu de la répartition en cours de choix, lié à la répartition enregistrée : il disparaît dès qu'elle change.
const planKey = progress && `${progress.plan.id}-${progress.plan.points}-${JSON.stringify(progress.plan.allocation)}`;
const [preview, setPreview] = useState({ key: null, stats: null });
const previewStats = preview.key === planKey ? preview.stats : null;
const [tab, setTab] = useState(focus ? "improve" : initialTab);
// Sans progression (commune, destination), seulement la carte.
const activeTab = progress ? tab : "card";
const tabs = TAB_IDS.map((id) => ({ id, label: content.tabs[id] }));
const info = <>
{entry.card.description &&
{entry.card.description}
}
{content.owned} {quantity}
{content.collection} {catalog.collections.find((item) => item.id === entry.card.collectionId)?.name}
{content.finishes} {entry.edition.finishIds.map((id) => catalog.finishes.find((item) => item.id === id)?.label).join(" · ")}
runMutation(() => setFavorite(entry.edition.id, !favorites.has(entry.edition.id)))}>{favorites.has(entry.edition.id) ? content.favoriteRemove : content.favoriteAdd}
{spare > 0 && runMutation(() => recycleDuplicates(entry.edition.id))}>{fillTemplate(content.recycle, { value: formatStardust(value) })} }
{spare > 0 && onStartTransfer && <>
onStartTransfer("gift", entry.edition.id)}>{content.give}
onStartTransfer("trade", entry.edition.id)}>{content.trade}
>}
{quantity > 1 && !spare && {content.reserved}
}
>;
const improve = progress && <>
setPreview({ key: planKey, stats })} content={content} />
>;
return
{expedition &&
{fillTemplate(content.busyUntil, { date: new Date(expedition.returnsAt).toLocaleString("fr-FR", { weekday: "long", hour: "2-digit", minute: "2-digit" }) })}
}
{/* Une carte des Expéditions a deux onglets : la carte et son lore, puis son amélioration. */}
{progress &&
}
{activeTab === "improve" ? improve : info}
{content.close}
;
}