import { useState } from 'react' import { motion } from 'framer-motion' import { useGame } from '../store/gameStore' import { TOPIC_MASTER } from '../data/accounts' import type { ProblemDocument } from '../types' interface Props { // 第2問/第3問から直接 props で渡す場合(省略時は gameStore から取得) eventText?: string hint?: string | null documents?: ProblemDocument[] sectionLabel?: string topicLabel?: string problemId?: string } export function EventCard(props: Props) { // props がなければ gameStore から読む(第1問) const storeProblem = useGame((s) => s.problem) const storeTopic = useGame((s) => s.topic) const [showHint, setShowHint] = useState(false) const eventText = props.eventText ?? storeProblem?.event_text const hint = props.hint !== undefined ? props.hint : storeProblem?.hint const documents = props.documents ?? storeProblem?.documents const sectionLabel = props.sectionLabel ?? '第1問 仕訳' const topicLabel = props.topicLabel ?? (TOPIC_MASTER[storeTopic]?.label ?? storeTopic) const problemId = props.problemId ?? storeProblem?.id ?? 'card' if (!eventText) return null return (
{topicLabel} {sectionLabel}

{eventText}

{/* 証憑テーブル */} {documents && documents.length > 0 && (
{documents.map((doc, di) => ( ))}
)} {hint && (
{showHint ? (

💡 {hint}

) : ( )}
)}
) } function DocumentTable({ doc }: { doc: ProblemDocument }) { const isSummaryRow = (row: string[]) => row[0] === '小計' || row[0] === '合計' || row[0].includes('消費税') return (
{doc.title && (
{doc.title}
)} {doc.headers.map((h, i) => ( ))} {doc.rows.map((row, ri) => ( {row.map((cell, ci) => ( ))} ))}
{h}
{cell}
) }