sbom-tools 0.1.19

Semantic SBOM diff and analysis tool
Documentation
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
//! Centralized theme and color scheme for TUI.
//!
//! This module provides consistent styling across all TUI views and modes.

use ratatui::prelude::*;
use std::sync::RwLock;

/// Color scheme for the TUI application.
/// Provides semantic colors for different UI elements.
#[derive(Debug, Clone, Copy)]
pub struct ColorScheme {
    // Change status colors
    pub added: Color,
    pub removed: Color,
    pub modified: Color,
    pub unchanged: Color,

    // Severity colors
    pub critical: Color,
    pub high: Color,
    pub medium: Color,
    pub low: Color,
    pub info: Color,

    // License category colors
    pub permissive: Color,
    pub copyleft: Color,
    pub weak_copyleft: Color,
    pub proprietary: Color,
    pub unknown_license: Color,

    // UI element colors
    pub primary: Color,
    pub secondary: Color,
    pub accent: Color,
    pub muted: Color,
    pub border: Color,
    pub border_focused: Color,
    pub background: Color,
    pub background_alt: Color,
    pub text: Color,
    pub text_muted: Color,
    pub selection: Color,
    pub highlight: Color,

    // Status colors
    pub success: Color,
    pub warning: Color,
    pub error: Color,

    // Badge foreground colors (for text on colored backgrounds)
    pub badge_fg_dark: Color, // For badges on bright backgrounds (yellow, cyan)
    pub badge_fg_light: Color, // For badges on dark backgrounds (magenta, red, blue)

    // Side-by-side view colors
    pub selection_bg: Color,        // Background for selected row
    pub search_highlight_bg: Color, // Background for search matches
    pub error_bg: Color,            // Background for removed/error highlights
    pub success_bg: Color,          // Background for added/success highlights

    // Source view scope highlighting
    pub scope_bg: Color, // Subtle background for enclosing bracket scope
}

impl Default for ColorScheme {
    fn default() -> Self {
        Self::dark()
    }
}

impl ColorScheme {
    /// Const dark theme for static initialization
    const fn dark_const() -> Self {
        Self {
            // Change status
            added: Color::Green,
            removed: Color::Red,
            modified: Color::Yellow,
            unchanged: Color::Gray,

            // Severity
            critical: Color::Magenta,
            high: Color::Red,
            medium: Color::Yellow,
            low: Color::Cyan,
            info: Color::Blue,

            // License categories
            permissive: Color::Green,
            copyleft: Color::Yellow,
            weak_copyleft: Color::Cyan,
            proprietary: Color::Red,
            unknown_license: Color::DarkGray,

            // UI elements
            primary: Color::Cyan,
            secondary: Color::Blue,
            accent: Color::Yellow,
            muted: Color::DarkGray,
            border: Color::DarkGray,
            border_focused: Color::Cyan,
            background: Color::Reset,
            background_alt: Color::Rgb(30, 30, 40),
            text: Color::White,
            text_muted: Color::Gray,
            selection: Color::Rgb(50, 50, 70),
            highlight: Color::Yellow,

            // Status
            success: Color::Green,
            warning: Color::Yellow,
            error: Color::Red,

            // Badge foregrounds
            badge_fg_dark: Color::Black,
            badge_fg_light: Color::White,

            // Side-by-side view colors
            selection_bg: Color::Rgb(60, 60, 80),
            search_highlight_bg: Color::Rgb(100, 80, 0),
            error_bg: Color::Rgb(80, 30, 30),
            success_bg: Color::Rgb(30, 80, 30),

            // Source view scope highlighting
            scope_bg: Color::Rgb(35, 35, 50),
        }
    }

    /// Dark theme (default)
    #[must_use]
    pub const fn dark() -> Self {
        Self {
            // Change status
            added: Color::Green,
            removed: Color::Red,
            modified: Color::Yellow,
            unchanged: Color::Gray,

            // Severity
            critical: Color::Magenta,
            high: Color::Red,
            medium: Color::Yellow,
            low: Color::Cyan,
            info: Color::Blue,

            // License categories
            permissive: Color::Green,
            copyleft: Color::Yellow,
            weak_copyleft: Color::Cyan,
            proprietary: Color::Red,
            unknown_license: Color::DarkGray,

            // UI elements
            primary: Color::Cyan,
            secondary: Color::Blue,
            accent: Color::Yellow,
            muted: Color::DarkGray,
            border: Color::DarkGray,
            border_focused: Color::Cyan,
            background: Color::Reset,
            background_alt: Color::Rgb(30, 30, 40),
            text: Color::White,
            text_muted: Color::Gray,
            selection: Color::Rgb(50, 50, 70),
            highlight: Color::Yellow,

            // Status
            success: Color::Green,
            warning: Color::Yellow,
            error: Color::Red,

            // Badge foregrounds
            badge_fg_dark: Color::Black,
            badge_fg_light: Color::White,

            // Side-by-side view colors
            selection_bg: Color::Rgb(60, 60, 80),
            search_highlight_bg: Color::Rgb(100, 80, 0),
            error_bg: Color::Rgb(80, 30, 30),
            success_bg: Color::Rgb(30, 80, 30),

            // Source view scope highlighting
            scope_bg: Color::Rgb(35, 35, 50),
        }
    }

    /// Light theme
    #[must_use]
    pub const fn light() -> Self {
        Self {
            // Change status
            added: Color::Rgb(0, 128, 0),
            removed: Color::Rgb(200, 0, 0),
            modified: Color::Rgb(180, 140, 0),
            unchanged: Color::Rgb(100, 100, 100),

            // Severity
            critical: Color::Rgb(128, 0, 128),
            high: Color::Rgb(200, 0, 0),
            medium: Color::Rgb(180, 140, 0),
            low: Color::Rgb(0, 128, 128),
            info: Color::Rgb(0, 0, 200),

            // License categories
            permissive: Color::Rgb(0, 128, 0),
            copyleft: Color::Rgb(180, 140, 0),
            weak_copyleft: Color::Rgb(0, 128, 128),
            proprietary: Color::Rgb(200, 0, 0),
            unknown_license: Color::Rgb(100, 100, 100),

            // UI elements
            primary: Color::Rgb(0, 100, 150),
            secondary: Color::Rgb(0, 0, 150),
            accent: Color::Rgb(180, 140, 0),
            muted: Color::Rgb(150, 150, 150),
            border: Color::Rgb(180, 180, 180),
            border_focused: Color::Rgb(0, 100, 150),
            background: Color::Rgb(255, 255, 255),
            background_alt: Color::Rgb(240, 240, 245),
            text: Color::Rgb(30, 30, 30),
            text_muted: Color::Rgb(100, 100, 100),
            selection: Color::Rgb(200, 220, 240),
            highlight: Color::Rgb(180, 140, 0),

            // Status
            success: Color::Rgb(0, 128, 0),
            warning: Color::Rgb(180, 140, 0),
            error: Color::Rgb(200, 0, 0),

            // Badge foregrounds (reversed for light theme)
            badge_fg_dark: Color::Rgb(30, 30, 30),
            badge_fg_light: Color::White,

            // Side-by-side view colors (lighter for light theme)
            selection_bg: Color::Rgb(200, 220, 240),
            search_highlight_bg: Color::Rgb(255, 230, 150),
            error_bg: Color::Rgb(255, 200, 200),
            success_bg: Color::Rgb(200, 255, 200),

            // Source view scope highlighting
            scope_bg: Color::Rgb(235, 240, 250),
        }
    }

    /// High contrast theme (accessibility)
    #[must_use]
    pub const fn high_contrast() -> Self {
        Self {
            // Change status
            added: Color::Green,
            removed: Color::LightRed,
            modified: Color::LightYellow,
            unchanged: Color::White,

            // Severity
            critical: Color::LightMagenta,
            high: Color::LightRed,
            medium: Color::LightYellow,
            low: Color::LightCyan,
            info: Color::LightBlue,

            // License categories
            permissive: Color::LightGreen,
            copyleft: Color::LightYellow,
            weak_copyleft: Color::LightCyan,
            proprietary: Color::LightRed,
            unknown_license: Color::Gray,

            // UI elements
            primary: Color::LightCyan,
            secondary: Color::LightBlue,
            accent: Color::LightYellow,
            muted: Color::Gray,
            border: Color::White,
            border_focused: Color::LightCyan,
            background: Color::Black,
            background_alt: Color::Rgb(20, 20, 20),
            text: Color::White,
            text_muted: Color::Gray,
            selection: Color::White,
            highlight: Color::LightYellow,

            // Status
            success: Color::LightGreen,
            warning: Color::LightYellow,
            error: Color::LightRed,

            // Badge foregrounds
            badge_fg_dark: Color::Black,
            badge_fg_light: Color::White,

            // Side-by-side view colors (high contrast)
            selection_bg: Color::Rgb(50, 50, 80),
            search_highlight_bg: Color::Rgb(120, 100, 0),
            error_bg: Color::Rgb(100, 30, 30),
            success_bg: Color::Rgb(30, 100, 30),

            // Source view scope highlighting
            scope_bg: Color::Rgb(25, 25, 40),
        }
    }

    /// Get color for severity level
    #[must_use]
    pub fn severity_color(&self, severity: &str) -> Color {
        match severity.to_lowercase().as_str() {
            "critical" => self.critical,
            "high" => self.high,
            "medium" | "moderate" => self.medium,
            "low" => self.low,
            "info" | "informational" | "none" => self.info,
            _ => self.text_muted,
        }
    }

    /// Get a subtle background tint for severity (used for row highlighting)
    #[must_use]
    pub fn severity_bg_tint(&self, severity: &str) -> Color {
        match severity.to_lowercase().as_str() {
            "critical" => Color::Rgb(50, 15, 50),
            "high" => Color::Rgb(50, 15, 15),
            "medium" => Color::Rgb(45, 40, 10),
            "low" => Color::Rgb(15, 35, 40),
            _ => Color::Reset,
        }
    }

    /// Get color for change status
    #[must_use]
    pub fn change_color(&self, status: &str) -> Color {
        match status.to_lowercase().as_str() {
            "added" | "new" | "introduced" => self.added,
            "removed" | "deleted" | "resolved" => self.removed,
            "modified" | "changed" | "updated" => self.modified,
            _ => self.unchanged,
        }
    }

    /// Get color for license category
    #[must_use]
    pub fn license_color(&self, category: &str) -> Color {
        match category.to_lowercase().as_str() {
            "permissive" => self.permissive,
            "copyleft" | "strong copyleft" => self.copyleft,
            "weak copyleft" => self.weak_copyleft,
            "proprietary" | "commercial" => self.proprietary,
            _ => self.unknown_license,
        }
    }

    /// Get appropriate foreground color for severity badges
    /// Returns light fg for dark backgrounds (critical, high, info) and dark fg for bright backgrounds
    #[must_use]
    pub fn severity_badge_fg(&self, severity: &str) -> Color {
        match severity.to_lowercase().as_str() {
            "critical" | "high" | "info" | "informational" => self.badge_fg_light,
            _ => self.badge_fg_dark,
        }
    }

    /// Get KEV (Known Exploited Vulnerabilities) badge color
    /// Returns a bright red/orange color to indicate active exploitation
    #[must_use]
    pub const fn kev(&self) -> Color {
        Color::Rgb(255, 100, 50) // Bright orange-red for urgency
    }

    /// Get KEV badge foreground color
    #[must_use]
    pub const fn kev_badge_fg(&self) -> Color {
        self.badge_fg_dark
    }

    /// Get direct dependency badge background color (green - easy to fix)
    #[must_use]
    pub const fn direct_dep(&self) -> Color {
        Color::Rgb(46, 160, 67) // GitHub green
    }

    /// Get transitive dependency badge background color (gray - harder to fix)
    #[must_use]
    pub const fn transitive_dep(&self) -> Color {
        Color::Rgb(110, 118, 129) // Muted gray
    }

    /// Get appropriate foreground color for change status badges
    /// All change colors (green, red, yellow) work best with dark foreground
    #[must_use]
    pub const fn change_badge_fg(&self) -> Color {
        self.badge_fg_dark
    }

    /// Get appropriate foreground color for license category badges
    #[must_use]
    pub fn license_badge_fg(&self, category: &str) -> Color {
        match category.to_lowercase().as_str() {
            "proprietary" | "commercial" => self.badge_fg_light,
            _ => self.badge_fg_dark,
        }
    }

    /// Chart color palette for visualizations
    #[must_use]
    pub const fn chart_palette(&self) -> [Color; 5] {
        [
            self.primary,
            self.success,
            self.warning,
            self.critical,
            self.secondary,
        ]
    }
}

/// Global theme instance (runtime switchable)
static THEME: RwLock<Theme> = RwLock::new(Theme::dark_const());

/// Theme configuration
#[derive(Debug, Clone)]
pub struct Theme {
    pub colors: ColorScheme,
    pub name: &'static str,
}

impl Default for Theme {
    fn default() -> Self {
        Self::dark()
    }
}

impl Theme {
    /// Const dark theme for static initialization
    const fn dark_const() -> Self {
        Self {
            colors: ColorScheme::dark_const(),
            name: "dark",
        }
    }

    #[must_use]
    pub const fn dark() -> Self {
        Self {
            colors: ColorScheme::dark(),
            name: "dark",
        }
    }

    #[must_use]
    pub const fn light() -> Self {
        Self {
            colors: ColorScheme::light(),
            name: "light",
        }
    }

    #[must_use]
    pub const fn high_contrast() -> Self {
        Self {
            colors: ColorScheme::high_contrast(),
            name: "high-contrast",
        }
    }

    #[must_use]
    pub fn from_name(name: &str) -> Self {
        match name.to_lowercase().as_str() {
            "light" => Self::light(),
            "high-contrast" | "highcontrast" | "hc" => Self::high_contrast(),
            _ => Self::dark(),
        }
    }

    /// Get the next theme in the rotation
    #[must_use]
    pub fn next(&self) -> Self {
        match self.name {
            "dark" => Self::light(),
            "light" => Self::high_contrast(),
            _ => Self::dark(),
        }
    }
}

/// Get the current theme name
pub fn current_theme_name() -> &'static str {
    THEME.read().expect("THEME lock not poisoned").name
}

/// Set the current theme
pub fn set_theme(theme: Theme) {
    *THEME.write().expect("THEME lock not poisoned") = theme;
}

/// Toggle to the next theme in rotation (dark -> light -> high-contrast -> dark)
pub fn toggle_theme() -> &'static str {
    let mut theme = THEME.write().expect("THEME lock not poisoned");
    *theme = theme.next();
    theme.name
}

/// Convenience function to get current colors
pub fn colors() -> ColorScheme {
    THEME.read().expect("THEME lock not poisoned").colors
}

// ============================================================================
// Style Helpers
// ============================================================================

/// Common style presets for consistent UI elements
pub struct Styles;

impl Styles {
    /// Header title style
    #[must_use]
    pub fn header_title() -> Style {
        Style::default().fg(colors().primary).bold()
    }

    /// Section title style
    #[must_use]
    pub fn section_title() -> Style {
        Style::default().fg(colors().primary).bold()
    }

    /// Subsection title style
    #[must_use]
    pub fn subsection_title() -> Style {
        Style::default().fg(colors().primary)
    }

    /// Normal text style
    #[must_use]
    pub fn text() -> Style {
        Style::default().fg(colors().text)
    }

    /// Muted/secondary text style
    #[must_use]
    pub fn text_muted() -> Style {
        Style::default().fg(colors().text_muted)
    }

    /// Label text style
    #[must_use]
    pub fn label() -> Style {
        Style::default().fg(colors().muted)
    }

    /// Value text style (for data values)
    #[must_use]
    pub fn value() -> Style {
        Style::default().fg(colors().text).bold()
    }

    /// Highlighted/accent style
    #[must_use]
    pub fn highlight() -> Style {
        Style::default().fg(colors().highlight).bold()
    }

    /// Selection style (for selected items)
    #[must_use]
    pub fn selected() -> Style {
        Style::default()
            .bg(colors().selection)
            .fg(colors().text)
            .bold()
    }

    /// Border style (unfocused)
    #[must_use]
    pub fn border() -> Style {
        Style::default().fg(colors().border)
    }

    /// Border style (focused)
    #[must_use]
    pub fn border_focused() -> Style {
        Style::default().fg(colors().border_focused)
    }

    /// Status bar background style
    #[must_use]
    pub fn status_bar() -> Style {
        Style::default().bg(colors().background_alt)
    }

    /// Keyboard shortcut style
    #[must_use]
    pub fn shortcut_key() -> Style {
        Style::default().fg(colors().accent)
    }

    /// Shortcut description style
    #[must_use]
    pub fn shortcut_desc() -> Style {
        Style::default().fg(colors().text_muted)
    }

    /// Success style
    #[must_use]
    pub fn success() -> Style {
        Style::default().fg(colors().success)
    }

    /// Warning style
    #[must_use]
    pub fn warning() -> Style {
        Style::default().fg(colors().warning)
    }

    /// Error style
    #[must_use]
    pub fn error() -> Style {
        Style::default().fg(colors().error)
    }

    /// Added item style
    #[must_use]
    pub fn added() -> Style {
        Style::default().fg(colors().added)
    }

    /// Removed item style
    #[must_use]
    pub fn removed() -> Style {
        Style::default().fg(colors().removed)
    }

    /// Modified item style
    #[must_use]
    pub fn modified() -> Style {
        Style::default().fg(colors().modified)
    }

    /// Critical severity style
    #[must_use]
    pub fn critical() -> Style {
        Style::default().fg(colors().critical).bold()
    }

    /// High severity style
    #[must_use]
    pub fn high() -> Style {
        Style::default().fg(colors().high).bold()
    }

    /// Medium severity style
    #[must_use]
    pub fn medium() -> Style {
        Style::default().fg(colors().medium)
    }

    /// Low severity style
    #[must_use]
    pub fn low() -> Style {
        Style::default().fg(colors().low)
    }
}

// ============================================================================
// Badge Rendering Helpers
// ============================================================================

/// Render a status badge with consistent styling
#[must_use]
pub fn status_badge(status: &str) -> Span<'static> {
    let scheme = colors();
    let (label, color, symbol) = match status.to_lowercase().as_str() {
        "added" | "new" | "introduced" => ("ADDED", scheme.added, "+"),
        "removed" | "deleted" | "resolved" => ("REMOVED", scheme.removed, "-"),
        "modified" | "changed" | "updated" => ("MODIFIED", scheme.modified, "~"),
        _ => ("UNCHANGED", scheme.unchanged, "="),
    };

    Span::styled(
        format!(" {symbol} {label} "),
        Style::default()
            .fg(scheme.change_badge_fg())
            .bg(color)
            .bold(),
    )
}

/// Render a severity badge with consistent styling
#[must_use]
pub fn severity_badge(severity: &str) -> Span<'static> {
    let scheme = colors();
    let (label, bg_color, is_unknown) = match severity.to_lowercase().as_str() {
        "critical" => ("CRITICAL", scheme.critical, false),
        "high" => ("HIGH", scheme.high, false),
        "medium" | "moderate" => ("MEDIUM", scheme.medium, false),
        "low" => ("LOW", scheme.low, false),
        "info" | "informational" => ("INFO", scheme.info, false),
        "none" => ("NONE", scheme.muted, false),
        _ => ("UNKNOWN", scheme.muted, true),
    };
    let fg_color = scheme.severity_badge_fg(severity);

    let style = if is_unknown {
        Style::default().fg(fg_color).bg(bg_color).dim()
    } else {
        Style::default().fg(fg_color).bg(bg_color).bold()
    };

    Span::styled(format!(" {label} "), style)
}

/// Render a compact severity indicator (single char)
#[must_use]
pub fn severity_indicator(severity: &str) -> Span<'static> {
    let scheme = colors();
    let (symbol, bg_color, is_unknown) = match severity.to_lowercase().as_str() {
        "critical" => ("C", scheme.critical, false),
        "high" => ("H", scheme.high, false),
        "medium" | "moderate" => ("M", scheme.medium, false),
        "low" => ("L", scheme.low, false),
        "info" | "informational" => ("I", scheme.info, false),
        "none" => ("-", scheme.muted, false),
        _ => ("U", scheme.muted, true),
    };
    let fg_color = scheme.severity_badge_fg(severity);

    let style = if is_unknown {
        Style::default().fg(fg_color).bg(bg_color).dim()
    } else {
        Style::default().fg(fg_color).bg(bg_color).bold()
    };

    Span::styled(format!(" {symbol} "), style)
}

/// Render a count badge
#[must_use]
pub fn count_badge(count: usize, bg_color: Color) -> Span<'static> {
    let scheme = colors();
    Span::styled(
        format!(" {count} "),
        Style::default()
            .fg(scheme.badge_fg_dark)
            .bg(bg_color)
            .bold(),
    )
}

/// Render a filter/group badge showing current state
#[must_use]
pub fn filter_badge(label: &str, value: &str) -> Vec<Span<'static>> {
    let scheme = colors();
    vec![
        Span::styled(format!("{label}: "), Style::default().fg(scheme.text_muted)),
        Span::styled(
            format!(" {value} "),
            Style::default()
                .fg(scheme.badge_fg_dark)
                .bg(scheme.accent)
                .bold(),
        ),
    ]
}

// ============================================================================
// Mode Indicator
// ============================================================================

/// Render a mode indicator badge
#[must_use]
pub fn mode_badge(mode: &str) -> Span<'static> {
    let scheme = colors();
    let color = match mode.to_lowercase().as_str() {
        "diff" => scheme.modified,
        "view" => scheme.primary,
        "multi-diff" | "multidiff" => scheme.added,
        "timeline" => scheme.secondary,
        "matrix" => scheme.high,
        _ => scheme.muted,
    };

    Span::styled(
        format!(" {} ", mode.to_uppercase()),
        Style::default().fg(scheme.badge_fg_dark).bg(color).bold(),
    )
}

// ============================================================================
// Footer Hints
// ============================================================================

/// Tab-specific footer hints
pub struct FooterHints;

impl FooterHints {
    /// Get hints for a specific tab in diff mode
    #[must_use]
    pub fn for_diff_tab(tab: &str) -> Vec<(&'static str, &'static str)> {
        let mut hints = Self::global();

        match tab.to_lowercase().as_str() {
            "components" => {
                hints.insert(0, ("f", "filter"));
                hints.insert(1, ("s", "sort"));
            }
            "dependencies" => {
                hints.insert(0, ("f", "filter"));
                hints.insert(1, ("t", "transitive"));
                hints.insert(2, ("h", "highlight"));
                hints.insert(3, ("Enter", "expand"));
                hints.insert(4, ("c", "component"));
            }
            "licenses" => {
                hints.insert(0, ("g", "group"));
                hints.insert(1, ("s", "sort"));
                hints.insert(2, ("r", "risk"));
                hints.insert(3, ("c", "compat"));
                hints.insert(4, ("Tab", "panel"));
            }
            "vulnerabilities" | "vulns" => {
                hints.insert(0, ("f", "filter"));
                hints.insert(1, ("s", "sort"));
                hints.insert(2, ("g", "group"));
            }
            "sidebyside" | "side-by-side" | "diff" => {
                hints.insert(0, ("←→/p", "panel"));
                hints.insert(1, ("J/K", "scroll both"));
            }
            "quality" => {
                hints.insert(0, ("v", "view"));
            }
            "compliance" => {
                hints.insert(0, ("←→", "standard"));
                hints.insert(1, ("v", "view"));
                hints.insert(2, ("g", "group"));
                hints.insert(3, ("↑↓", "select"));
            }
            "source" => {
                hints.insert(0, ("w", "panel"));
                hints.insert(1, ("v", "tree/raw"));
                hints.insert(2, ("↑↓", "scroll"));
            }
            "graphchanges" | "graph" => {
                hints.insert(0, ("↑↓", "select"));
                hints.insert(1, ("PgUp/Dn", "page"));
            }
            _ => {}
        }

        hints
    }

    /// Get hints for a specific tab in view mode
    #[must_use]
    pub fn for_view_tab(tab: &str) -> Vec<(&'static str, &'static str)> {
        let mut hints = Self::global();

        match tab.to_lowercase().as_str() {
            "tree" | "components" => {
                // g/f/search already shown in filter bar at top
                hints.insert(0, ("p", "panel"));
                hints.insert(1, ("Enter", "select"));
                hints.insert(2, ("1-4", "detail tabs"));
            }
            "vulnerabilities" | "vulns" => {
                hints.insert(0, ("f", "filter"));
                hints.insert(1, ("s", "sort"));
                hints.insert(2, ("g", "group"));
                hints.insert(3, ("d", "dedup"));
                hints.insert(4, ("Enter", "component"));
            }
            "licenses" => {
                hints.insert(0, ("g", "group"));
                hints.insert(1, ("Enter", "inspect"));
                hints.insert(2, ("K/J", "scroll"));
            }
            "dependencies" => {
                hints.insert(0, ("Enter", "expand/inspect"));
                hints.insert(1, ("", "collapse"));
                hints.insert(2, ("p", "panel"));
                hints.insert(3, ("J/K", "scroll"));
            }
            "quality" => {
                hints.insert(0, ("v", "view"));
            }
            "compliance" => {
                hints.insert(0, ("f", "filter"));
                hints.insert(1, ("←→", "standard"));
                hints.insert(2, ("↑↓", "select"));
            }
            "source" => {
                hints.insert(0, ("v", "tree/raw"));
                hints.insert(1, ("p", "panel"));
                hints.insert(2, ("H/L", "fold all"));
                hints.insert(3, ("Enter", "select"));
            }
            "algorithms" => {
                hints.insert(0, ("s", "sort"));
                hints.insert(1, ("↑↓", "select"));
                hints.insert(2, ("Enter", "detail"));
            }
            "certificates" => {
                hints.insert(0, ("↑↓", "select"));
                hints.insert(1, ("Enter", "detail"));
            }
            "keys" => {
                hints.insert(0, ("↑↓", "select"));
                hints.insert(1, ("Enter", "detail"));
            }
            "protocols" => {
                hints.insert(0, ("↑↓", "select"));
                hints.insert(1, ("Enter", "detail"));
            }
            "pqc-compliance" => {
                hints.insert(0, ("↑↓", "scroll"));
            }
            _ => {}
        }

        hints
    }

    /// Global hints (always shown)
    #[must_use]
    pub fn global() -> Vec<(&'static str, &'static str)> {
        vec![
            ("Tab", "switch"),
            ("/", "search"),
            ("e", "export"),
            ("?", "help"),
            ("q", "quit"),
        ]
    }

    /// Number of global hints (used to insert separator).
    pub const GLOBAL_COUNT: usize = 5;
}

/// Render footer hints as spans with badge-style keys.
///
/// If the hint list contains more items than `FooterHints::GLOBAL_COUNT`,
/// a `│` separator is inserted between tab-specific and global hints.
#[must_use]
pub fn render_footer_hints(hints: &[(&str, &str)]) -> Vec<Span<'static>> {
    let scheme = colors();
    let mut spans = Vec::new();
    let tab_count = hints.len().saturating_sub(FooterHints::GLOBAL_COUNT);

    for (i, (key, desc)) in hints.iter().enumerate() {
        if i > 0 {
            spans.push(Span::raw(" "));
        }
        // Insert separator between tab-specific and global hints
        if i == tab_count && tab_count > 0 {
            spans.push(Span::styled("", Style::default().fg(scheme.muted)));
        }
        spans.push(Span::styled(
            format!(" {key} "),
            Style::default()
                .fg(scheme.badge_fg_dark)
                .bg(scheme.accent)
                .bold(),
        ));
        spans.push(Span::styled(
            desc.to_string(),
            Style::default().fg(scheme.text_muted),
        ));
    }

    spans
}