File size: 3,865 Bytes
7d7e1a3
 
 
f31cb63
 
7d7e1a3
ebe620b
 
 
 
 
 
 
 
 
 
 
 
 
 
7d7e1a3
 
ebe620b
 
 
 
 
 
7d7e1a3
ebe620b
f31cb63
7d7e1a3
 
ebe620b
7d7e1a3
 
 
 
 
ebe620b
 
7d7e1a3
f31cb63
ebe620b
7d7e1a3
f31cb63
ebe620b
f31cb63
ebe620b
f31cb63
 
 
 
 
ebe620b
7d7e1a3
 
ebe620b
7d7e1a3
 
 
 
 
 
 
 
 
 
 
 
 
f31cb63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ebe620b
f31cb63
 
 
 
 
 
 
ebe620b
f31cb63
ebe620b
f31cb63
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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 (
    <motion.div
      key={problemId}
      initial={{ opacity: 0, y: 12 }}
      animate={{ opacity: 1, y: 0 }}
      className="rounded-2xl border border-cyan-500/30 bg-gradient-to-br from-slate-800 to-slate-900 p-5 shadow-xl"
    >
      <div className="mb-2 flex items-center gap-2 text-xs">
        <span className="rounded-full bg-cyan-500/20 px-2 py-0.5 text-cyan-200">{topicLabel}</span>
        <span className="rounded-full bg-slate-600/50 px-2 py-0.5 text-slate-200">{sectionLabel}</span>
      </div>

      <p className="text-base font-bold leading-relaxed text-slate-50">{eventText}</p>

      {/* 証憑テーブル */}
      {documents && documents.length > 0 && (
        <div className="mt-4 space-y-3">
          {documents.map((doc, di) => (
            <DocumentTable key={di} doc={doc} />
          ))}
        </div>
      )}

      {hint && (
        <div className="mt-3">
          {showHint ? (
            <p className="rounded-lg bg-amber-500/10 px-3 py-2 text-sm text-amber-200">πŸ’‘ {hint}</p>
          ) : (
            <button
              onClick={() => setShowHint(true)}
              className="text-sm text-amber-300/80 underline-offset-2 hover:underline"
            >
              γƒ’γƒ³γƒˆγ‚’θ¦‹γ‚‹
            </button>
          )}
        </div>
      )}
    </motion.div>
  )
}

function DocumentTable({ doc }: { doc: ProblemDocument }) {
  const isSummaryRow = (row: string[]) =>
    row[0] === '小計' || row[0] === '合計' || row[0].includes('梈費税')

  return (
    <div className="overflow-x-auto rounded-xl border border-slate-600">
      {doc.title && (
        <div className="border-b border-slate-600 bg-slate-700/50 px-3 py-1.5 text-xs font-semibold text-slate-300">
          {doc.title}
        </div>
      )}
      <table className="w-full text-sm">
        <thead>
          <tr className="bg-slate-700/40">
            {doc.headers.map((h, i) => (
              <th key={i} className={`px-3 py-2 text-xs font-semibold text-slate-300 ${i === 0 ? 'text-left' : 'text-right'}`}>
                {h}
              </th>
            ))}
          </tr>
        </thead>
        <tbody>
          {doc.rows.map((row, ri) => (
            <tr key={ri} className={isSummaryRow(row) ? 'border-t border-slate-600 bg-slate-700/30 font-semibold' : 'border-t border-slate-700/50'}>
              {row.map((cell, ci) => (
                <td key={ci} className={`px-3 py-1.5 tabular-nums text-slate-200 ${ci === 0 ? 'text-left' : 'text-right'}`}>
                  {cell}
                </td>
              ))}
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  )
}