guandan.dev

guandan.dev

https://git.tonybtw.com/guandan.dev.git git://git.tonybtw.com/guandan.dev.git
2,649 bytes raw
1
import { Card as Card_Type, Rank } from '../game/types'
2
import { Card } from './Card'
3
import { use_is_mobile } from '../hooks/use_is_mobile'
4
5
interface Table_Props {
6
  cards: Card_Type[]
7
  level: Rank
8
  combo_type: string
9
  last_play_seat?: number | null
10
}
11
12
export function Table({ cards, level, combo_type, last_play_seat }: Table_Props) {
13
  const is_mobile = use_is_mobile()
14
  const card_width = is_mobile ? 56 : 70
15
  const overlap = is_mobile ? 32 : 40
16
  const show_highlight = last_play_seat !== null && last_play_seat !== undefined && cards.length > 0
17
18
  return (
19
    <div
20
      style={{
21
        display: 'flex',
22
        flexDirection: 'column',
23
        alignItems: 'center',
24
        justifyContent: 'center',
25
        minHeight: is_mobile ? 100 : 180,
26
        padding: is_mobile ? 8 : 20,
27
        borderRadius: 12,
28
        transition: 'background-color 0.2s ease, box-shadow 0.2s ease',
29
        backgroundColor: show_highlight ? 'rgba(76, 175, 80, 0.15)' : 'transparent',
30
        boxShadow: show_highlight ? '0 0 20px rgba(76, 175, 80, 0.4)' : 'none',
31
      }}
32
    >
33
      <div
34
        style={{
35
          display: 'flex',
36
          position: 'relative',
37
          width: cards.length > 0 ? card_width + (cards.length - 1) * overlap : 100,
38
          height: is_mobile ? 80 : 100,
39
          justifyContent: 'center',
40
        }}
41
      >
42
        {cards.length > 0 ? (
43
          cards.map((card, index) => (
44
            <div
45
              key={`table-${card.Id}`}
46
              style={{
47
                position: 'absolute',
48
                left: index * overlap,
49
                zIndex: index,
50
              }}
51
            >
52
              <Card
53
                card={card}
54
                level={level}
55
                selected={false}
56
                on_click={() => {}}
57
                size={is_mobile ? 'small' : 'normal'}
58
              />
59
            </div>
60
          ))
61
        ) : (
62
          <div
63
            style={{
64
              display: 'flex',
65
              alignItems: 'center',
66
              justifyContent: 'center',
67
              color: '#666',
68
              fontSize: is_mobile ? 12 : 14,
69
              opacity: 0.5,
70
            }}
71
          >
72
            No cards played
73
          </div>
74
        )}
75
      </div>
76
      {combo_type && (
77
        <div
78
          style={{
79
            marginTop: is_mobile ? 6 : 12,
80
            padding: is_mobile ? '3px 8px' : '4px 12px',
81
            backgroundColor: '#333',
82
            color: '#fff',
83
            borderRadius: 4,
84
            fontSize: is_mobile ? 10 : 12,
85
            textTransform: 'uppercase',
86
          }}
87
        >
88
          {combo_type}
89
        </div>
90
      )}
91
    </div>
92
  )
93
}