|
| 1 | +import { RefreshCw, ShieldCheck } from 'lucide-react'; |
| 2 | +import type { CodexBinarySnapshot } from '../model'; |
| 3 | + |
| 4 | +export default function CodexBinarySummaryPanel({ |
| 5 | + snapshot, |
| 6 | + message, |
| 7 | + loading, |
| 8 | + managedBusy, |
| 9 | + onEnableManagedPath, |
| 10 | + onRefresh, |
| 11 | + t, |
| 12 | +}: { |
| 13 | + snapshot: CodexBinarySnapshot | null; |
| 14 | + message: string; |
| 15 | + loading: boolean; |
| 16 | + managedBusy: boolean; |
| 17 | + onEnableManagedPath: () => void; |
| 18 | + onRefresh: () => void; |
| 19 | + t: (key: string) => string; |
| 20 | +}) { |
| 21 | + return ( |
| 22 | + <section className="border-2 border-[var(--border-color)] bg-[var(--bg-main)] p-3 shadow-[5px_5px_0_var(--shadow-color)] sm:p-4"> |
| 23 | + <div className="grid gap-3 xl:grid-cols-[minmax(0,1fr)_auto] xl:items-start"> |
| 24 | + <div className="min-w-0 space-y-1.5"> |
| 25 | + <div className="flex min-w-0 flex-col gap-1.5 lg:flex-row lg:items-center"> |
| 26 | + <div className="min-w-0 truncate text-xl font-black text-[var(--text-primary)]"> |
| 27 | + {snapshot?.currentVersion?.displayName || t('codex_binary.no_active')} |
| 28 | + </div> |
| 29 | + <div className="flex flex-wrap items-center gap-1.5"> |
| 30 | + {snapshot?.doctor.severity === 'error' ? <StatusPill severity="error" text={snapshot.doctor.message} /> : null} |
| 31 | + {snapshot?.managedConfig ? ( |
| 32 | + <StatusPill |
| 33 | + severity={snapshot.managedConfig.isPathConfigured ? 'ok' : 'warning'} |
| 34 | + text={snapshot.managedConfig.isPathConfigured ? t('codex_binary.managed_path_enabled') : t('codex_binary.managed_path_disabled')} |
| 35 | + /> |
| 36 | + ) : null} |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + |
| 41 | + <div className="flex flex-wrap items-center gap-2 xl:justify-end"> |
| 42 | + {snapshot?.managedConfig && !snapshot.managedConfig.isPathConfigured ? ( |
| 43 | + <button |
| 44 | + type="button" |
| 45 | + onClick={onEnableManagedPath} |
| 46 | + disabled={managedBusy} |
| 47 | + className="btn-swiss whitespace-nowrap bg-[var(--text-primary)] !px-2.5 !py-1.5 !text-[0.5625rem] !text-[var(--bg-main)] disabled:cursor-not-allowed disabled:opacity-50" |
| 48 | + > |
| 49 | + <ShieldCheck className="h-3.5 w-3.5" /> |
| 50 | + {managedBusy ? t('codex_binary.managing') : t('codex_binary.enable_managed')} |
| 51 | + </button> |
| 52 | + ) : null} |
| 53 | + <button |
| 54 | + type="button" |
| 55 | + onClick={onRefresh} |
| 56 | + disabled={loading} |
| 57 | + className="btn-swiss whitespace-nowrap !px-2.5 !py-1.5 !text-[0.5625rem] disabled:cursor-not-allowed disabled:opacity-50" |
| 58 | + > |
| 59 | + <RefreshCw className={`h-3.5 w-3.5 ${loading ? 'animate-spin' : ''}`} /> |
| 60 | + {t('codex_binary.refresh')} |
| 61 | + </button> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + {snapshot?.managedConfig ? ( |
| 65 | + <div className="mt-2 grid gap-x-5 gap-y-1 border-t border-[var(--border-color)] pt-2 text-[0.5625rem] font-semibold text-[var(--text-muted)] md:grid-cols-3"> |
| 66 | + <ManagedMeta label={t('codex_binary.managed_bin_dir')} value={snapshot.managedConfig.binDir} /> |
| 67 | + <ManagedMeta label={t('codex_binary.resolved_codex_path')} value={snapshot.managedConfig.resolvedCodexPath || t('codex_binary.resolved_codex_missing')} /> |
| 68 | + <ManagedMeta label={t('codex_binary.managed_profile_target')} value={snapshot.managedConfig.profilePath || t('codex_binary.managed_profile_unknown')} strong /> |
| 69 | + </div> |
| 70 | + ) : null} |
| 71 | + {message ? <div className="mt-2 border-t border-[var(--border-color)] pt-2 text-xs font-semibold text-[var(--text-muted)]">{message}</div> : null} |
| 72 | + </section> |
| 73 | + ); |
| 74 | +} |
| 75 | + |
| 76 | +function StatusPill({ severity, text }: { severity: string; text: string }) { |
| 77 | + const color = severity === 'ok' ? 'bg-[var(--accent-green)] text-white' : severity === 'error' ? 'bg-[var(--accent-red)] text-white' : 'bg-[var(--accent-yellow)] text-[var(--text-primary)]'; |
| 78 | + return <span className={`inline-flex items-center px-2 py-1 text-[0.5625rem] font-black ${color}`}>{text}</span>; |
| 79 | +} |
| 80 | + |
| 81 | +function ManagedMeta({ label, value, strong }: { label: string; value: string; strong?: boolean }) { |
| 82 | + return ( |
| 83 | + <div className="min-w-0 truncate"> |
| 84 | + <span className="font-black uppercase tracking-[0.12em] text-[var(--text-primary)]">{label}: </span> |
| 85 | + <span className={strong ? 'text-[var(--text-primary)]' : ''}>{value}</span> |
| 86 | + </div> |
| 87 | + ); |
| 88 | +} |
0 commit comments