File size: 4,122 Bytes
40fe69e
0e0cc3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40fe69e
d30af0c
445c3cc
d30af0c
445c3cc
40fe69e
 
 
445c3cc
40fe69e
445c3cc
d30af0c
445c3cc
 
 
 
 
bb3304c
d30af0c
445c3cc
 
bb3304c
445c3cc
bb3304c
 
 
 
 
 
 
445c3cc
40fe69e
445c3cc
bb3304c
445c3cc
 
 
bb3304c
 
 
 
 
 
 
 
 
445c3cc
 
 
 
 
 
bb3304c
 
445c3cc
 
 
 
 
 
 
 
 
 
bb3304c
d30af0c
445c3cc
bb3304c
445c3cc
 
 
 
 
40fe69e
 
 
445c3cc
d30af0c
40fe69e
0e0cc3e
 
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
import { cn } from '../lib/utils'
import type { DiameterGroup } from '../lib/types'
import { t } from '../lib/i18n'
import type { Lang } from '../lib/types'

interface Props {
  lang: Lang
  groups: DiameterGroup[]
  counts: Record<number, number>
  selectedGroupId: number
  onSelectGroup: (id: number) => void
  onExpectedChange: (groupId: number, value: number | undefined) => void
}

export function GroupPanel({
  lang,
  groups,
  counts,
  selectedGroupId,
  onSelectGroup,
  onExpectedChange,
}: Props) {
  return (
    <section>
      <p className="ct-section-label mb-2 px-1">{t(lang, 'groups')}</p>

      <div className="ct-card overflow-hidden">
        {groups.map((g, idx) => {
          const count = counts[g.id] ?? 0
          const mismatch = g.expected !== undefined && g.expected !== count
          const selected = selectedGroupId === g.id

          return (
            <div key={g.id}>
              {idx > 0 && <div className="ml-4 h-px bg-[var(--hairline)]" />}

              <button
                type="button"
                onClick={() => onSelectGroup(g.id)}
                className={cn(
                  'relative flex min-h-[56px] w-full items-center gap-3 px-4 text-left transition-colors duration-150',
                  selected ? 'bg-[var(--surface-active)]' : 'active:bg-[var(--surface-2)]',
                )}
              >
                {/* selection accent — group's own colour */}
                <span
                  aria-hidden
                  className="absolute left-0 top-3 bottom-3 w-[3px] rounded-r-full transition-opacity duration-200"
                  style={{ background: g.color, opacity: selected ? 1 : 0 }}
                />

                <span
                  className="h-3 w-3 shrink-0 rounded-full ring-1 ring-[var(--hairline)] shadow-[inset_0_0_0_1px_rgba(0,0,0,0.08)]"
                  style={{ background: g.color }}
                />

                <span className="flex-1 text-[15px] font-medium text-[var(--text)]">{g.label}</span>

                <div className="flex items-center gap-2" onClick={(e) => e.stopPropagation()}>
                  {mismatch && (
                    <span
                      className="ct-badge ct-badge--warning !gap-1 !px-1.5 !py-0.5 !text-[11px]"
                      title={t(lang, 'mismatch')}
                    >
                      <span className="inline-flex h-1.5 w-1.5 rounded-full bg-[var(--warning)]" />
                      <span className="tabular-nums" style={{ fontFamily: 'var(--font-mono)' }}>
                        {g.expected}
                      </span>
                    </span>
                  )}
                  <input
                    type="number"
                    inputMode="numeric"
                    min={0}
                    placeholder={t(lang, 'expected')}
                    className="h-8 w-20 rounded-[var(--r-md)] border border-[var(--hairline-strong)] bg-[var(--surface)] px-2.5 text-center text-sm tabular-nums text-[var(--text)] shadow-[var(--shadow-inset)] placeholder:text-[var(--text-faint)] focus:border-[var(--brand)] focus:shadow-none focus:outline-none focus:ring-2 focus:ring-[var(--brand-ring)]"
                    style={{ fontFamily: 'var(--font-mono)' }}
                    value={g.expected ?? ''}
                    onChange={(e) => {
                      const v = e.target.value
                      onExpectedChange(g.id, v === '' ? undefined : Number(v))
                    }}
                  />
                </div>

                <span
                  className={cn(
                    'min-w-[2.5rem] text-right text-2xl font-bold leading-none tabular-nums',
                    mismatch ? 'text-[var(--warning)]' : 'text-[var(--brand)]',
                  )}
                  style={{ fontFamily: 'var(--font-mono)' }}
                >
                  {count}
                </span>
              </button>
            </div>
          )
        })}
      </div>

      <p className="mt-1.5 px-1 text-[11px] text-[var(--text-faint)]">{t(lang, 'selectGroup')}</p>
    </section>
  )
}