File size: 7,171 Bytes
ffdf130
 
40fe69e
ebe2f4e
40fe69e
 
 
 
ebe2f4e
 
40fe69e
 
6544822
40fe69e
ebe2f4e
40fe69e
 
6544822
40fe69e
 
 
 
 
 
 
445c3cc
40fe69e
 
 
 
445c3cc
40fe69e
 
445c3cc
 
 
 
d30af0c
445c3cc
 
 
d30af0c
445c3cc
d30af0c
445c3cc
 
 
 
d30af0c
445c3cc
d30af0c
40fe69e
 
445c3cc
 
 
d30af0c
40fe69e
445c3cc
 
 
 
 
 
d30af0c
40fe69e
 
 
 
 
ebe2f4e
 
40fe69e
 
6544822
40fe69e
ebe2f4e
40fe69e
 
6544822
40fe69e
 
 
445c3cc
ebe2f4e
d30af0c
 
ebe2f4e
 
 
 
 
 
 
 
 
 
 
d30af0c
 
ebe2f4e
 
 
 
 
 
d30af0c
ebe2f4e
 
 
 
 
 
 
d30af0c
ebe2f4e
 
 
 
 
 
445c3cc
d30af0c
 
445c3cc
 
 
 
 
 
 
 
 
d30af0c
 
445c3cc
 
 
 
 
 
 
40fe69e
 
d30af0c
445c3cc
40fe69e
445c3cc
40fe69e
445c3cc
40fe69e
445c3cc
40fe69e
445c3cc
d30af0c
 
445c3cc
 
 
 
 
 
 
 
 
 
 
 
 
ffdf130
6544822
 
 
 
 
 
 
 
 
 
 
 
ffdf130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445c3cc
40fe69e
 
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { RefreshCw } from 'lucide-react'
import { reloadAppForUpdate } from '../lib/appUpdate'
import { t } from '../lib/i18n'
import type { InferenceMode, Lang } from '../lib/types'

interface Props {
  lang: Lang
  groupCount: number | 'auto'
  inferenceMode: InferenceMode
  serverAvailable: boolean
  useTiling: boolean
  filterOutliers: boolean
  showConfidenceLabels: boolean
  onGroupCount: (value: number | 'auto') => void
  onInferenceMode: (mode: InferenceMode) => void
  onUseTiling: (value: boolean) => void
  onFilterOutliers: (value: boolean) => void
  onShowConfidenceLabels: (value: boolean) => void
  onRecluster: () => void
}

function Toggle({
  checked,
  onChange,
  label,
  description,
}: {
  checked: boolean
  onChange: (v: boolean) => void
  label: string
  description?: string
}) {
  return (
    <button
      type="button"
      role="switch"
      aria-checked={checked}
      className="flex min-h-[52px] w-full items-center justify-between gap-3 px-4 text-left transition-colors duration-150 active:bg-[var(--surface-2)]"
      onClick={() => onChange(!checked)}
    >
      <span className="flex flex-col gap-0.5">
        <span className="text-[15px] text-[var(--text)]">{label}</span>
        {description && (
          <span className="text-xs text-[var(--text-faint)]">{description}</span>
        )}
      </span>
      <span
        className={`relative h-[31px] w-[51px] shrink-0 rounded-full transition-colors duration-200 ${
          checked ? 'bg-[var(--ios-toggle)]' : 'bg-[var(--hairline)]'
        }`}
        style={{ boxShadow: 'inset 0 0 0 1px rgba(0,0,0,0.06)' }}
      >
        <span
          className={`absolute top-[2px] h-[27px] w-[27px] rounded-full bg-white shadow-md transition-all duration-200 ${
            checked ? 'left-[22px]' : 'left-[2px]'
          }`}
          style={{ boxShadow: '0 2px 6px rgba(0,0,0,0.15)' }}
        />
      </span>
    </button>
  )
}

function Separator() {
  return <div className="ml-4 h-px bg-[var(--hairline)]" />
}

export function SettingsPanel({
  lang,
  groupCount,
  inferenceMode,
  serverAvailable,
  useTiling,
  filterOutliers,
  showConfidenceLabels,
  onGroupCount,
  onInferenceMode,
  onUseTiling,
  onFilterOutliers,
  onShowConfidenceLabels,
  onRecluster,
}: Props) {
  return (
    <div className="space-y-4">
      <section>
        <p className="ct-section-label mb-2 px-1">{t(lang, 'inferenceMode')}</p>
        <div className="ct-card overflow-hidden p-3">
          <div className="flex gap-2">
            {(['server', 'local'] as InferenceMode[]).map((mode) => {
              const active = inferenceMode === mode
              const disabled = mode === 'server' && !serverAvailable
              return (
                <button
                  key={mode}
                  type="button"
                  disabled={disabled}
                  className={`flex flex-1 flex-col items-center gap-0.5 rounded-xl px-3 py-2.5 text-center transition-all duration-150 active:scale-[0.98] disabled:opacity-40 ${
                    active
                      ? 'bg-[var(--brand)] text-white shadow-[var(--shadow-brand)]'
                      : 'bg-[var(--surface-2)] text-[var(--text-dim)] active:bg-[var(--surface-active)]'
                  }`}
                  onClick={() => onInferenceMode(mode)}
                >
                  <span className="text-sm font-semibold">
                    {mode === 'server' ? t(lang, 'inferenceServer') : t(lang, 'inferenceLocal')}
                  </span>
                  <span className={`text-[10px] leading-tight ${active ? 'text-white/90' : 'text-[var(--text-faint)]'}`}>
                    {mode === 'server' ? t(lang, 'inferenceServerHint') : t(lang, 'inferenceLocalHint')}
                  </span>
                </button>
              )
            })}
          </div>
          {!serverAvailable && inferenceMode === 'local' && (
            <p className="mt-2 px-1 text-center text-[11px] text-[var(--warning)]">
              {t(lang, 'serverUnavailable')}
            </p>
          )}
        </div>
      </section>

      <section>
        <p className="ct-section-label mb-2 px-1">{t(lang, 'groupCount')}</p>
        <div className="ct-card overflow-hidden">
          <div className="flex flex-wrap gap-2 p-3">
            {(['auto', 1, 2, 3, 4, 5, 6] as (number | 'auto')[]).map((n) => {
              const active = groupCount === n
              return (
                <button
                  key={String(n)}
                  type="button"
                  className={`min-h-9 rounded-xl px-4 text-sm font-semibold transition-all duration-150 active:scale-95 ${
                    active
                      ? 'bg-[var(--brand)] text-white shadow-[var(--shadow-brand)]'
                      : 'bg-[var(--surface-2)] text-[var(--text-dim)] active:bg-[var(--surface-active)]'
                  }`}
                  onClick={() => onGroupCount(n)}
                >
                  {n === 'auto' ? t(lang, 'auto') : n}
                </button>
              )
            })}
            <button
              type="button"
              className="min-h-9 rounded-xl bg-[var(--surface-2)] px-4 text-sm font-semibold text-[var(--text-dim)] transition-all duration-150 active:scale-95 active:bg-[var(--surface-active)]"
              onClick={onRecluster}
            >
              {t(lang, 'apply')}
            </button>
          </div>
        </div>
      </section>

      <section>
        <p className="ct-section-label mb-2 px-1">{t(lang, 'settings')}</p>
        <div className="ct-card overflow-hidden">
          <Toggle
            checked={useTiling}
            onChange={onUseTiling}
            label={t(lang, 'highAccuracy')}
          />
          <Separator />
          <Toggle
            checked={filterOutliers}
            onChange={onFilterOutliers}
            label={t(lang, 'filterOutliers')}
          />
        </div>
      </section>

      <section>
        <p className="ct-section-label mb-2 px-1">{t(lang, 'debugSection')}</p>
        <div className="ct-card overflow-hidden">
          <Toggle
            checked={showConfidenceLabels}
            onChange={onShowConfidenceLabels}
            label={t(lang, 'showConfidenceLabels')}
            description={t(lang, 'showConfidenceLabelsHint')}
          />
        </div>
      </section>

      <section>
        <p className="ct-section-label mb-2 px-1">{t(lang, 'updateApp')}</p>
        <div className="ct-card overflow-hidden p-3">
          <button
            type="button"
            className="flex w-full items-center justify-center gap-2 rounded-xl border border-[var(--border)] bg-[var(--surface-2)] px-4 py-3 text-sm font-semibold text-[var(--text)] transition-all active:scale-[0.98] active:bg-[var(--surface-active)]"
            onClick={reloadAppForUpdate}
          >
            <RefreshCw size={16} />
            {t(lang, 'updateApp')}
          </button>
          <p className="mt-2 px-1 text-center text-[11px] text-[var(--text-faint)]">
            {t(lang, 'updateAppHint')}
          </p>
        </div>
      </section>
    </div>
  )
}