pacsea 0.8.2

A fast, friendly TUI for browsing and installing Arch and AUR packages with built-in news and security scanning
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
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
use ratatui::{
    prelude::Rect,
    style::{Modifier, Style},
    text::{Line, Span},
};

use crate::i18n;
use crate::state::modal::{
    CascadeMode, DependencyInfo, DependencySource, DependencyStatus, PreflightHeaderChips,
    PreflightSummaryData,
};
use crate::state::{AppState, PackageItem, PreflightAction};
use crate::theme::theme;
use crate::ui::helpers::ChangeLogger;
use std::fmt::Write;
use std::sync::{Mutex, OnceLock};

/// What: Bit flags for tracking incomplete preflight data.
///
/// Inputs: None (default constructed).
///
/// Output: Bit flags indicating which preflight data is incomplete.
///
/// Details: Uses a u16 to store multiple boolean flags efficiently.
#[derive(Clone, Copy, PartialEq, Eq, Default)]
struct IncompleteFlags(u16);

impl IncompleteFlags {
    /// Flag indicating preflight dependencies are incomplete.
    const PREFLIGHT_DEPS: u16 = 1 << 0;
    /// Flag indicating dependencies are incomplete.
    const DEPS: u16 = 1 << 1;
    /// Flag indicating computed dependencies are incomplete.
    const COMPUTED_DEPS: u16 = 1 << 2;
    /// Flag indicating preflight files are incomplete.
    const PREFLIGHT_FILES: u16 = 1 << 3;
    /// Flag indicating files are incomplete.
    const FILES: u16 = 1 << 4;
    /// Flag indicating preflight sandbox data is incomplete.
    const PREFLIGHT_SANDBOX: u16 = 1 << 5;
    /// Flag indicating sandbox data is incomplete.
    const SANDBOX: u16 = 1 << 6;
    /// Flag indicating dependencies are incomplete (alternative flag).
    const DEPS_INCOMPLETE: u16 = 1 << 7;
    /// Flag to show dependencies indicator.
    const SHOW_DEPS_INDICATOR: u16 = 1 << 8;
    /// Flag to show files indicator.
    const SHOW_FILES_INDICATOR: u16 = 1 << 9;
    /// Flag to show sandbox indicator.
    const SHOW_SANDBOX_INDICATOR: u16 = 1 << 10;

    /// What: Set or clear a flag bit.
    ///
    /// Inputs:
    /// - `bit`: The bit flag to set or clear.
    /// - `enabled`: Whether to set (true) or clear (false) the bit.
    ///
    /// Output: Modifies the flags in place.
    ///
    /// Details: Uses bitwise operations to set or clear the specified bit.
    const fn set(&mut self, bit: u16, enabled: bool) {
        if enabled {
            self.0 |= bit;
        } else {
            self.0 &= !bit;
        }
    }

    /// What: Check if a flag bit is set.
    ///
    /// Inputs:
    /// - `bit`: The bit flag to check.
    ///
    /// Output: Returns true if the bit is set, false otherwise.
    ///
    /// Details: Uses bitwise AND to check if the specified bit is set.
    const fn is_set(self, bit: u16) -> bool {
        self.0 & bit != 0
    }
}

/// What: State tracking for incomplete preflight data logging.
///
/// Inputs: None (constructed from current state).
///
/// Output: Captures current incomplete state for logging.
///
/// Details: Used to track and log which preflight data is incomplete.
#[derive(Clone, PartialEq, Eq)]
struct IncompleteLogState {
    /// Incomplete flags indicating what data is missing.
    flags: IncompleteFlags,
    /// Total number of items.
    item_count: usize,
    /// Number of packages with dependencies.
    packages_with_deps_count: usize,
    /// Number of dependency info entries.
    dependency_info_count: usize,
}

/// What: Emit a debug log when the incomplete-data indicator snapshot changes.
///
/// Inputs:
/// - `state`: Current incomplete-data log snapshot used for change detection.
///
/// Output: None.
///
/// Details: Uses a `ChangeLogger` so identical consecutive frames are not logged.
fn log_incomplete_state(state: &IncompleteLogState) {
    static LOGGER: OnceLock<Mutex<ChangeLogger<IncompleteLogState>>> = OnceLock::new();
    let mut logger = LOGGER
        .get_or_init(|| Mutex::new(ChangeLogger::new()))
        .lock()
        .expect("Incomplete log state mutex poisoned");
    if logger.should_log(state) {
        let flags = state.flags;
        tracing::debug!(
            "[UI] render_incomplete_data_indicator: preflight_deps_resolving={}, deps_resolving={}, computed_deps_resolving={}, files_resolving={}/{}, sandbox_resolving={}/{}, deps_incomplete={}, items={}, packages_with_deps={}, dependency_info={}, show_deps_indicator={}, show_files_indicator={}, show_sandbox_indicator={}",
            flags.is_set(IncompleteFlags::PREFLIGHT_DEPS),
            flags.is_set(IncompleteFlags::DEPS),
            flags.is_set(IncompleteFlags::COMPUTED_DEPS),
            flags.is_set(IncompleteFlags::PREFLIGHT_FILES),
            flags.is_set(IncompleteFlags::FILES),
            flags.is_set(IncompleteFlags::PREFLIGHT_SANDBOX),
            flags.is_set(IncompleteFlags::SANDBOX),
            flags.is_set(IncompleteFlags::DEPS_INCOMPLETE),
            state.item_count,
            state.packages_with_deps_count,
            state.dependency_info_count,
            flags.is_set(IncompleteFlags::SHOW_DEPS_INDICATOR),
            flags.is_set(IncompleteFlags::SHOW_FILES_INDICATOR),
            flags.is_set(IncompleteFlags::SHOW_SANDBOX_INDICATOR)
        );
    }
}

/// What: Get source badge text and color for a dependency source.
///
/// Inputs:
/// - `source`: The dependency source.
///
/// Output:
/// - Returns a tuple of (`badge_text`, `color`).
///
/// Details:
/// - Formats repository names, AUR, and local sources with appropriate colors.
fn get_source_badge(source: &DependencySource) -> (String, ratatui::style::Color) {
    let th = theme();
    match source {
        DependencySource::Official { repo } => {
            let repo_lower = repo.to_lowercase();
            let color = if crate::index::is_eos_repo(&repo_lower)
                || crate::index::is_cachyos_repo(&repo_lower)
                || crate::index::is_blackarch_repo(&repo_lower)
            {
                th.sapphire
            } else {
                th.green
            };
            (format!(" [{repo}]"), color)
        }
        DependencySource::Aur => (" [AUR]".to_string(), th.yellow),
        DependencySource::Local => (" [local]".to_string(), th.overlay1),
    }
}

/// What: Render summary data section (risk factors).
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `summary_data`: Summary data to render.
/// - `header_chips`: Header chip data for risk level.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Shows risk factors if available.
fn render_summary_data(
    app: &AppState,
    summary_data: &PreflightSummaryData,
    header_chips: &PreflightHeaderChips,
) -> Vec<Line<'static>> {
    let th = theme();
    let mut lines = Vec::new();

    let risk_color = match header_chips.risk_level {
        crate::state::modal::RiskLevel::Low => th.green,
        crate::state::modal::RiskLevel::Medium => th.yellow,
        crate::state::modal::RiskLevel::High => th.red,
    };

    if !summary_data.risk_reasons.is_empty() {
        lines.push(Line::from(Span::styled(
            i18n::t(app, "app.modals.preflight.summary.risk_factors"),
            Style::default().fg(risk_color).add_modifier(Modifier::BOLD),
        )));
        for reason in &summary_data.risk_reasons {
            let bullet = format!("{reason}");
            lines.push(Line::from(Span::styled(
                bullet,
                Style::default().fg(th.subtext1),
            )));
        }
    }
    lines.push(Line::from(""));
    lines
}

/// What: Render incomplete data indicator if data is still resolving.
///
/// Inputs:
/// - `app`: Application state for i18n and resolution flags.
/// - `items`: Packages under review.
/// - `dependency_info`: Dependency information.
///
/// Output:
/// - Returns a vector of lines to render, or empty if no incomplete data.
///
/// Details:
/// - Checks for resolving dependencies, files, and sandbox data.
fn render_incomplete_data_indicator(
    app: &AppState,
    items: &[PackageItem],
    dependency_info: &[DependencyInfo],
) -> Vec<Line<'static>> {
    let th = theme();
    let mut lines = Vec::new();

    let item_names: std::collections::HashSet<String> =
        items.iter().map(|i| i.name.clone()).collect();
    let packages_with_deps: std::collections::HashSet<String> = dependency_info
        .iter()
        .flat_map(|d| d.required_by.iter())
        .cloned()
        .collect();
    let packages_with_deps_count = packages_with_deps.len();

    // Check if deps data is incomplete for current items (when not resolving)
    let deps_resolving = app.preflight_deps_resolving || app.deps_resolving;
    let deps_incomplete = !deps_resolving
        && !item_names.is_empty()
        && packages_with_deps_count < items.len()
        && dependency_info.len() < items.len();

    // Check if we actually need to wait for data for the current items
    // Only show loading indicator if:
    // 1. Preflight-specific resolution is running (preflight_*_resolving), OR
    // 2. Global resolution is running (files_resolving, deps_resolving, etc.)
    // 3. We're missing data for current items (deps_incomplete heuristic)
    let files_resolving = app.preflight_files_resolving || app.files_resolving;
    let sandbox_resolving = app.preflight_sandbox_resolving || app.sandbox_resolving;

    // Show deps indicator when deps are resolving (matches render_deps_tab logic)
    let show_deps_indicator = deps_resolving || (deps_incomplete && dependency_info.is_empty());
    // Show files indicator when files are resolving (matches render_files_tab logic)
    let show_files_indicator = files_resolving;
    // Show sandbox indicator when sandbox is resolving
    let show_sandbox_indicator = sandbox_resolving;

    let mut flags = IncompleteFlags::default();
    flags.set(
        IncompleteFlags::PREFLIGHT_DEPS,
        app.preflight_deps_resolving,
    );
    flags.set(IncompleteFlags::DEPS, app.deps_resolving);
    flags.set(IncompleteFlags::COMPUTED_DEPS, deps_resolving);
    flags.set(
        IncompleteFlags::PREFLIGHT_FILES,
        app.preflight_files_resolving,
    );
    flags.set(IncompleteFlags::FILES, app.files_resolving);
    flags.set(
        IncompleteFlags::PREFLIGHT_SANDBOX,
        app.preflight_sandbox_resolving,
    );
    flags.set(IncompleteFlags::SANDBOX, app.sandbox_resolving);
    flags.set(IncompleteFlags::DEPS_INCOMPLETE, deps_incomplete);
    flags.set(IncompleteFlags::SHOW_DEPS_INDICATOR, show_deps_indicator);
    flags.set(IncompleteFlags::SHOW_FILES_INDICATOR, show_files_indicator);
    flags.set(
        IncompleteFlags::SHOW_SANDBOX_INDICATOR,
        show_sandbox_indicator,
    );

    log_incomplete_state(&IncompleteLogState {
        flags,
        item_count: items.len(),
        packages_with_deps_count,
        dependency_info_count: dependency_info.len(),
    });

    let has_incomplete_data =
        show_deps_indicator || show_files_indicator || show_sandbox_indicator || deps_incomplete;

    if has_incomplete_data {
        let mut resolving_parts = Vec::new();
        if show_deps_indicator {
            resolving_parts.push(i18n::t(app, "app.modals.preflight.summary.resolving_deps"));
        }
        if show_files_indicator {
            resolving_parts.push(i18n::t(app, "app.modals.preflight.summary.resolving_files"));
        }
        if show_sandbox_indicator {
            resolving_parts.push(i18n::t(
                app,
                "app.modals.preflight.summary.resolving_sandbox",
            ));
        }
        if !resolving_parts.is_empty() {
            lines.push(Line::from(""));
            let resolving_text = resolving_parts.join(", ");
            lines.push(Line::from(Span::styled(
                format!("{resolving_text}"),
                Style::default()
                    .fg(th.sapphire)
                    .add_modifier(Modifier::BOLD),
            )));
            lines.push(Line::from(Span::styled(
                i18n::t(app, "app.modals.preflight.summary.data_will_update"),
                Style::default().fg(th.subtext1),
            )));
        }
    }
    lines
}

/// What: Render dependency spans for a conflict or upgrade status.
///
/// Inputs:
/// - `dep`: Dependency information.
///
/// Output:
/// - Returns a vector of spans to render.
///
/// Details:
/// - Formats conflict or upgrade status with appropriate styling.
fn render_dependency_spans(dep: &DependencyInfo) -> Option<Vec<Span<'static>>> {
    let th = theme();
    let mut spans = Vec::new();
    spans.push(Span::styled("  ", Style::default())); // Indentation

    match &dep.status {
        DependencyStatus::Conflict { reason } => {
            spans.push(Span::styled("", Style::default().fg(th.red)));
            spans.push(Span::styled(dep.name.clone(), Style::default().fg(th.text)));
            if !dep.version.is_empty() {
                spans.push(Span::styled(
                    format!(" {}", dep.version),
                    Style::default().fg(th.overlay2),
                ));
            }
            let (source_badge, badge_color) = get_source_badge(&dep.source);
            spans.push(Span::styled(source_badge, Style::default().fg(badge_color)));
            spans.push(Span::styled(
                format!(" ({reason})"),
                Style::default().fg(th.red),
            ));
        }
        DependencyStatus::ToUpgrade { current, required } => {
            spans.push(Span::styled("", Style::default().fg(th.yellow)));
            spans.push(Span::styled(dep.name.clone(), Style::default().fg(th.text)));
            if !dep.version.is_empty() {
                let dep_version = &dep.version;
                spans.push(Span::styled(
                    format!(" {dep_version}"),
                    Style::default().fg(th.overlay2),
                ));
            }
            let (source_badge, badge_color) = get_source_badge(&dep.source);
            spans.push(Span::styled(source_badge, Style::default().fg(badge_color)));
            spans.push(Span::styled(
                format!(" ({current}{required})"),
                Style::default().fg(th.yellow),
            ));
        }
        _ => return None,
    }
    Some(spans)
}

/// What: Filter installed packages from items list.
///
/// Inputs:
/// - `items`: List of packages to check.
///
/// Output:
/// - Vector of references to packages that are already installed.
fn filter_installed_packages(items: &[PackageItem]) -> Vec<&PackageItem> {
    items
        .iter()
        .filter(|item| crate::index::is_installed(&item.name))
        .collect()
}

/// What: Filter important dependencies (conflicts and upgrades).
///
/// Inputs:
/// - `dependency_info`: List of dependency information.
///
/// Output:
/// - Vector of references to dependencies with conflicts or upgrades.
fn filter_important_deps(dependency_info: &[DependencyInfo]) -> Vec<&DependencyInfo> {
    dependency_info
        .iter()
        .filter(|d| {
            matches!(
                d.status,
                DependencyStatus::Conflict { .. } | DependencyStatus::ToUpgrade { .. }
            )
        })
        .collect()
}

/// What: Group dependencies by the packages that require them.
///
/// Inputs:
/// - `important_deps`: List of important dependencies.
///
/// Output:
/// - `HashMap` mapping package names to their dependencies.
fn group_dependencies_by_package<'a>(
    important_deps: &[&'a DependencyInfo],
) -> std::collections::HashMap<String, Vec<&'a DependencyInfo>> {
    use std::collections::HashMap;
    let mut grouped: HashMap<String, Vec<&DependencyInfo>> = HashMap::new();
    for dep in important_deps {
        for req_by in &dep.required_by {
            grouped.entry(req_by.clone()).or_default().push(*dep);
        }
    }
    grouped
}

/// What: Build summary parts for conflicts, upgrades, and installed packages.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `conflict_count`: Number of conflicts.
/// - `upgrade_count`: Number of upgrades.
/// - `installed_count`: Number of installed packages.
///
/// Output:
/// - Vector of formatted summary strings.
fn build_summary_parts(
    app: &AppState,
    conflict_count: usize,
    upgrade_count: usize,
    installed_count: usize,
) -> Vec<String> {
    let mut summary_parts = Vec::new();
    if conflict_count > 0 {
        summary_parts.push(i18n::t_fmt1(
            app,
            "app.modals.preflight.summary.conflict_singular",
            conflict_count,
        ));
    }
    if upgrade_count > 0 {
        summary_parts.push(i18n::t_fmt1(
            app,
            "app.modals.preflight.summary.upgrade_singular",
            upgrade_count,
        ));
    }
    if installed_count > 0 {
        summary_parts.push(i18n::t_fmt1(
            app,
            "app.modals.preflight.summary.installed_singular",
            installed_count,
        ));
    }
    summary_parts
}

/// What: Build display items list for rendering.
///
/// Inputs:
/// - `items`: List of packages.
/// - `grouped`: Dependencies grouped by package.
/// - `installed_packages`: List of installed packages.
///
/// Output:
/// - Vector of (`is_header`, `package_name`, `optional_dependency`) tuples.
fn build_display_items<'a>(
    items: &[PackageItem],
    grouped: &std::collections::HashMap<String, Vec<&'a DependencyInfo>>,
    installed_packages: &[&PackageItem],
) -> Vec<(bool, String, Option<&'a DependencyInfo>)> {
    use std::collections::HashSet;
    let mut display_items: Vec<(bool, String, Option<&DependencyInfo>)> = Vec::new();
    for pkg_name in items.iter().map(|p| &p.name) {
        if let Some(pkg_deps) = grouped.get(pkg_name) {
            display_items.push((true, pkg_name.clone(), None));
            let mut seen_deps = HashSet::new();
            for dep in pkg_deps {
                if seen_deps.insert(dep.name.as_str()) {
                    display_items.push((false, String::new(), Some(*dep)));
                }
            }
        }
    }
    for installed_pkg in installed_packages {
        if !grouped.contains_key(&installed_pkg.name) {
            display_items.push((true, installed_pkg.name.clone(), None));
            display_items.push((false, installed_pkg.name.clone(), None));
        }
    }
    display_items
}

/// What: Render install action dependencies (conflicts and upgrades).
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `items`: Packages under review.
/// - `dependency_info`: Dependency information.
/// - `summary_data`: Optional summary data containing package notes.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Shows conflicts and upgrades grouped by package.
/// - Displays installed packages separately.
/// - Shows package notes (e.g., "Required by installed packages") from summary data.
fn render_install_dependencies(
    app: &AppState,
    items: &[PackageItem],
    dependency_info: &[DependencyInfo],
    summary_data: Option<&PreflightSummaryData>,
) -> Vec<Line<'static>> {
    let th = theme();
    let mut lines = Vec::new();

    let installed_packages = filter_installed_packages(items);
    let important_deps = filter_important_deps(dependency_info);

    if important_deps.is_empty() && installed_packages.is_empty() {
        lines.push(Line::from(Span::styled(
            i18n::t(app, "app.modals.preflight.summary.no_conflicts_or_upgrades"),
            Style::default().fg(th.green),
        )));
        return lines;
    }

    let grouped = group_dependencies_by_package(&important_deps);
    let conflict_count = important_deps
        .iter()
        .filter(|d| matches!(d.status, DependencyStatus::Conflict { .. }))
        .count();
    let upgrade_count = important_deps
        .iter()
        .filter(|d| matches!(d.status, DependencyStatus::ToUpgrade { .. }))
        .count();
    let installed_count = installed_packages.len();

    let summary_parts = build_summary_parts(app, conflict_count, upgrade_count, installed_count);
    let header_text = if conflict_count > 0 || installed_count > 0 {
        i18n::t_fmt1(
            app,
            "app.modals.preflight.summary.issues",
            summary_parts.join(", "),
        )
    } else if upgrade_count > 0 {
        i18n::t_fmt1(
            app,
            "app.modals.preflight.summary.summary_label",
            summary_parts.join(", "),
        )
    } else {
        i18n::t(app, "app.modals.preflight.summary.summary_no_conflicts")
    };

    lines.push(Line::from(Span::styled(
        header_text,
        Style::default()
            .fg(if conflict_count > 0 || installed_count > 0 {
                th.red
            } else {
                th.yellow
            })
            .add_modifier(Modifier::BOLD),
    )));
    lines.push(Line::from(""));

    let display_items = build_display_items(items, &grouped, &installed_packages);

    // Render all items (no viewport - mouse scrolling handles it)
    for (is_header, pkg_name, dep) in &display_items {
        if *is_header {
            let style = Style::default()
                .fg(th.overlay1)
                .add_modifier(Modifier::BOLD);
            lines.push(Line::from(Span::styled(format!("{pkg_name}"), style)));

            // Show package notes from summary data (e.g., "Required by installed packages")
            if let Some(summary) = summary_data
                && let Some(pkg_summary) = summary.packages.iter().find(|p| p.name == *pkg_name)
            {
                for note in &pkg_summary.notes {
                    // Show notes about dependent packages
                    if note.contains("Required by") {
                        lines.push(Line::from(Span::styled(
                            format!("{note}"),
                            Style::default().fg(th.yellow),
                        )));
                    }
                }
            }
        } else if let Some(dep) = dep {
            if let Some(spans) = render_dependency_spans(dep) {
                lines.push(Line::from(spans));
            }
        } else if !pkg_name.is_empty() && installed_packages.iter().any(|p| p.name == *pkg_name) {
            // This is an installed package entry (not a real dependency)
            // Show "installed" status
            let spans = vec![
                Span::styled("  ", Style::default()),
                Span::styled("", Style::default().fg(th.green)),
                Span::styled(pkg_name.clone(), Style::default().fg(th.text)),
                Span::styled(" (installed)", Style::default().fg(th.subtext1)),
            ];
            lines.push(Line::from(spans));
        }
    }
    lines
}

/// Maximum number of cascade preview items to display.
const CASCADE_PREVIEW_MAX: usize = 8;

/// What: Context data for cascade rendering operations.
///
/// Inputs:
/// - `removal_targets`: Set of package names to be removed (lowercase).
/// - `allows_dependents`: Cached value of `cascade_mode.allows_dependents()`.
///
/// Output:
/// - Returns a `CascadeRenderingContext` struct.
///
/// Details:
/// - Groups related data to reduce parameter passing and variable scope.
struct CascadeRenderingContext {
    /// Set of package names to be removed (lowercase).
    removal_targets: std::collections::HashSet<String>,
    /// Whether the cascade mode allows dependents.
    allows_dependents: bool,
}

impl CascadeRenderingContext {
    /// What: Create a new cascade rendering context.
    ///
    /// Inputs:
    /// - `items`: Packages to remove.
    /// - `cascade_mode`: Removal cascade mode.
    ///
    /// Output:
    /// - Returns a `CascadeRenderingContext`.
    ///
    /// Details:
    /// - Pre-computes removal targets and `allows_dependents` flag.
    fn new(items: &[PackageItem], cascade_mode: CascadeMode) -> Self {
        let removal_targets: std::collections::HashSet<String> = items
            .iter()
            .map(|pkg| pkg.name.to_ascii_lowercase())
            .collect();
        let allows_dependents = cascade_mode.allows_dependents();
        Self {
            removal_targets,
            allows_dependents,
        }
    }

    /// What: Check if a dependency is directly dependent on removal targets.
    ///
    /// Inputs:
    /// - `dep`: Dependency information.
    ///
    /// Output:
    /// - Returns true if dependency is directly dependent.
    ///
    /// Details:
    /// - Checks if any parent in `depends_on` is in `removal_targets`.
    fn is_direct_dependent(&self, dep: &DependencyInfo) -> bool {
        dep.depends_on
            .iter()
            .any(|parent| self.removal_targets.contains(&parent.to_ascii_lowercase()))
    }
}

/// What: Display information for a cascade candidate dependency.
///
/// Inputs:
/// - `bullet`: Bullet character to display.
/// - `name_color`: Color for the dependency name.
/// - `detail`: Detail text about the dependency status.
/// - `roots`: Formatted string of packages that require this dependency.
///
/// Output:
/// - Returns a `DependencyDisplayInfo` struct.
///
/// Details:
/// - Groups all display-related data for a dependency.
struct DependencyDisplayInfo {
    /// Bullet character for display.
    bullet: &'static str,
    /// Color for the package name.
    name_color: ratatui::style::Color,
    /// Detail text to display.
    detail: String,
    /// Root packages text.
    roots: String,
}

/// What: Get bullet character and name color for a dependency based on cascade mode.
///
/// Inputs:
/// - `allows_dependents`: Whether cascade mode allows dependents.
/// - `is_direct`: Whether dependency is directly dependent.
/// - `th`: Theme colors.
///
/// Output:
/// - Returns a tuple of (`bullet`, `name_color`).
///
/// Details:
/// - Simplifies conditional logic for bullet and color selection.
const fn get_bullet_and_color(
    allows_dependents: bool,
    is_direct: bool,
    th: &crate::theme::Theme,
) -> (&'static str, ratatui::style::Color) {
    if allows_dependents {
        if is_direct {
            ("", th.red)
        } else {
            ("", th.yellow)
        }
    } else if is_direct {
        ("", th.red)
    } else {
        ("", th.yellow)
    }
}

/// What: Get detail text for a dependency status.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `status`: Dependency status.
///
/// Output:
/// - Returns detail text string.
///
/// Details:
/// - Extracts status-to-text conversion logic.
fn get_dependency_detail(app: &AppState, status: &DependencyStatus) -> String {
    match status {
        DependencyStatus::Conflict { reason } => reason.clone(),
        DependencyStatus::ToUpgrade { .. } => {
            i18n::t(app, "app.modals.preflight.summary.requires_version_change")
        }
        DependencyStatus::Installed { .. } => {
            i18n::t(app, "app.modals.preflight.summary.already_satisfied")
        }
        DependencyStatus::ToInstall => {
            i18n::t(app, "app.modals.preflight.summary.not_currently_installed")
        }
        DependencyStatus::Missing => i18n::t(app, "app.modals.preflight.summary.missing"),
    }
}

/// What: Build dependency display information.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `dep`: Dependency information.
/// - `ctx`: Cascade rendering context.
/// - `th`: Theme colors.
/// - `is_direct`: Pre-computed flag indicating if dependency is directly dependent.
///
/// Output:
/// - Returns `DependencyDisplayInfo`.
///
/// Details:
/// - Prepares all display data for a dependency in one place.
/// - Uses pre-computed `is_direct` to avoid recalculation.
fn build_dependency_display_info(
    app: &AppState,
    dep: &DependencyInfo,
    ctx: &CascadeRenderingContext,
    th: &crate::theme::Theme,
    is_direct: bool,
) -> DependencyDisplayInfo {
    let (bullet, name_color) = get_bullet_and_color(ctx.allows_dependents, is_direct, th);
    let detail = get_dependency_detail(app, &dep.status);
    let roots = if dep.required_by.is_empty() {
        String::new()
    } else {
        i18n::t_fmt1(
            app,
            "app.modals.preflight.summary.targets_label",
            dep.required_by.join(", "),
        )
    };
    DependencyDisplayInfo {
        bullet,
        name_color,
        detail,
        roots,
    }
}

/// What: Build spans for a cascade candidate dependency.
///
/// Inputs:
/// - `dep`: Dependency information.
/// - `display_info`: Display information for the dependency.
/// - `th`: Theme colors.
///
/// Output:
/// - Returns a vector of spans.
///
/// Details:
/// - Uses builder pattern to construct dependency spans.
fn build_cascade_dependency_spans(
    dep: &DependencyInfo,
    display_info: &DependencyDisplayInfo,
    th: &crate::theme::Theme,
) -> Vec<Span<'static>> {
    let mut spans = Vec::new();
    spans.push(Span::styled(
        display_info.bullet,
        Style::default().fg(th.subtext0),
    ));
    spans.push(Span::styled(
        dep.name.clone(),
        Style::default()
            .fg(display_info.name_color)
            .add_modifier(Modifier::BOLD),
    ));
    if !display_info.detail.is_empty() {
        spans.push(Span::styled("", Style::default().fg(th.subtext1)));
        spans.push(Span::styled(
            display_info.detail.clone(),
            Style::default().fg(th.subtext1),
        ));
    }
    if !display_info.roots.is_empty() {
        spans.push(Span::styled(
            display_info.roots.clone(),
            Style::default().fg(th.overlay1),
        ));
    }
    spans
}

/// What: Render cascade mode header.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `cascade_mode`: Removal cascade mode.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Renders the cascade mode information header.
fn render_cascade_mode_header(app: &AppState, cascade_mode: CascadeMode) -> Vec<Line<'static>> {
    let th = theme();
    let mode_line = i18n::t_fmt(
        app,
        "app.modals.preflight.summary.cascade_mode",
        &[&cascade_mode.flag(), &cascade_mode.description()],
    );
    vec![
        Line::from(Span::styled(
            mode_line,
            Style::default().fg(th.mauve).add_modifier(Modifier::BOLD),
        )),
        Line::from(""),
    ]
}

/// What: Render removal plan command.
///
/// Inputs:
/// - `app`: Application state for i18n and `dry_run` flag.
/// - `items`: Packages to remove.
/// - `cascade_mode`: Removal cascade mode.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Renders the removal plan preview with command.
fn render_removal_plan(
    app: &AppState,
    items: &[PackageItem],
    cascade_mode: CascadeMode,
) -> Vec<Line<'static>> {
    let th = theme();
    let removal_names: Vec<&str> = items.iter().map(|pkg| pkg.name.as_str()).collect();
    let plan_header_style = Style::default()
        .fg(th.overlay1)
        .add_modifier(Modifier::BOLD);
    let tool = match crate::logic::privilege::active_tool() {
        Ok(t) => t,
        Err(msg) => {
            return vec![
                Line::from(Span::styled(
                    i18n::t(app, "app.modals.preflight.summary.removal_plan_preview"),
                    plan_header_style,
                )),
                Line::from(Span::styled(msg, Style::default().fg(th.red))),
            ];
        }
    };
    let mut plan_command = crate::logic::privilege::build_privilege_command(
        tool,
        &format!(
            "pacman {} --noconfirm {}",
            cascade_mode.flag(),
            removal_names.join(" ")
        ),
    );
    if app.dry_run {
        plan_command = i18n::t_fmt1(
            app,
            "app.modals.preflight.summary.dry_run_prefix",
            plan_command,
        );
    }
    vec![
        Line::from(Span::styled(
            i18n::t(app, "app.modals.preflight.summary.removal_plan_preview"),
            plan_header_style,
        )),
        Line::from(Span::styled(plan_command, Style::default().fg(th.text))),
    ]
}

/// What: Get dependent summary text and style.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `dependent_count`: Number of dependent packages.
/// - `allows_dependents`: Whether cascade mode allows dependents.
///
/// Output:
/// - Returns a tuple of (text, style).
///
/// Details:
/// - Determines summary message based on dependent count and cascade mode.
fn get_dependent_summary(
    app: &AppState,
    dependent_count: usize,
    allows_dependents: bool,
) -> (String, Style) {
    let th = theme();
    if dependent_count == 0 {
        (
            i18n::t(app, "app.modals.preflight.summary.no_dependents"),
            Style::default().fg(th.green),
        )
    } else if allows_dependents {
        (
            i18n::t_fmt1(
                app,
                "app.modals.preflight.summary.cascade_will_include",
                dependent_count,
            ),
            Style::default().fg(th.yellow),
        )
    } else {
        (
            i18n::t_fmt1(
                app,
                "app.modals.preflight.summary.dependents_block_removal",
                dependent_count,
            ),
            Style::default().fg(th.red),
        )
    }
}

/// What: Render dependent summary section.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `dependent_count`: Number of dependent packages.
/// - `allows_dependents`: Whether cascade mode allows dependents.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Renders the summary of dependent packages.
fn render_dependent_summary(
    app: &AppState,
    dependent_count: usize,
    allows_dependents: bool,
) -> Vec<Line<'static>> {
    let (summary_text, summary_style) =
        get_dependent_summary(app, dependent_count, allows_dependents);
    vec![
        Line::from(Span::styled(summary_text, summary_style)),
        Line::from(""),
    ]
}

/// What: Render removal impact overview.
///
/// Inputs:
/// - `app`: Application state for i18n and `remove_preflight_summary`.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Renders the impact overview or calculating message.
fn render_impact_overview(app: &AppState) -> Vec<Line<'static>> {
    let th = theme();
    let mut lines = Vec::new();
    if app.remove_preflight_summary.is_empty() {
        lines.push(Line::from(Span::styled(
            i18n::t(app, "app.modals.preflight.summary.calculating_reverse_deps"),
            Style::default().fg(th.subtext1),
        )));
    } else {
        lines.push(Line::from(Span::styled(
            i18n::t(app, "app.modals.preflight.summary.removal_impact_overview"),
            Style::default()
                .fg(th.overlay1)
                .add_modifier(Modifier::BOLD),
        )));
        lines.push(Line::from(""));
        for summary in &app.remove_preflight_summary {
            let mut message = i18n::t_fmt(
                app,
                "app.modals.preflight.summary.dependent_singular",
                &[&summary.package, &summary.total_dependents],
            );
            if summary.direct_dependents > 0 {
                let _ = write!(
                    message,
                    " {}",
                    i18n::t_fmt1(
                        app,
                        "app.modals.preflight.summary.direct_singular",
                        summary.direct_dependents
                    )
                );
            }
            if summary.transitive_dependents > 0 {
                let _ = write!(
                    message,
                    " {}",
                    i18n::t_fmt1(
                        app,
                        "app.modals.preflight.summary.transitive_singular",
                        summary.transitive_dependents
                    )
                );
            }
            lines.push(Line::from(Span::styled(
                message,
                Style::default().fg(th.text),
            )));
        }
        lines.push(Line::from(""));
    }
    lines
}

/// What: Get impact header text and style.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `allows_dependents`: Whether cascade mode allows dependents.
///
/// Output:
/// - Returns a tuple of (text, style).
///
/// Details:
/// - Determines impact header based on cascade mode.
fn get_impact_header(app: &AppState, allows_dependents: bool) -> (String, Style) {
    let th = theme();
    let text = if allows_dependents {
        i18n::t(app, "app.modals.preflight.summary.cascade_will_remove")
    } else {
        i18n::t(app, "app.modals.preflight.summary.dependents_not_removed")
    };
    (
        text,
        Style::default().fg(th.red).add_modifier(Modifier::BOLD),
    )
}

/// What: Prepare and sort cascade candidates.
///
/// Inputs:
/// - `dependency_info`: Dependency information.
/// - `ctx`: Cascade rendering context.
///
/// Output:
/// - Returns sorted vector of cascade candidates with `is_direct` flag.
///
/// Details:
/// - Prepares cascade candidates with pre-computed `is_direct` flag to avoid recomputation.
fn prepare_cascade_candidates<'a>(
    dependency_info: &'a [DependencyInfo],
    ctx: &CascadeRenderingContext,
) -> Vec<(&'a DependencyInfo, bool)> {
    let mut candidates: Vec<(&'a DependencyInfo, bool)> = dependency_info
        .iter()
        .map(|dep| (dep, ctx.is_direct_dependent(dep)))
        .collect();
    candidates.sort_by(|a, b| b.1.cmp(&a.1).then_with(|| a.0.name.cmp(&b.0.name)));
    candidates
}

/// What: Render cascade candidates preview.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `candidates`: Prepared cascade candidates with `is_direct` flags.
/// - `ctx`: Cascade rendering context.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Renders the cascade candidates list with preview limit.
/// - Uses pre-computed `is_direct` flags to avoid recalculation.
fn render_cascade_candidates(
    app: &AppState,
    candidates: &[(&DependencyInfo, bool)],
    ctx: &CascadeRenderingContext,
) -> Vec<Line<'static>> {
    let th = theme();
    let mut lines = Vec::new();
    for (dep, is_direct) in candidates.iter().take(CASCADE_PREVIEW_MAX) {
        let display_info = build_dependency_display_info(app, dep, ctx, &th, *is_direct);
        let spans = build_cascade_dependency_spans(dep, &display_info, &th);
        lines.push(Line::from(spans));
    }
    if candidates.len() > CASCADE_PREVIEW_MAX {
        lines.push(Line::from(Span::styled(
            i18n::t_fmt1(
                app,
                "app.modals.preflight.summary.and_more_impacted",
                candidates.len() - CASCADE_PREVIEW_MAX,
            ),
            Style::default().fg(th.subtext1),
        )));
    }
    lines
}

/// What: Render cascade footer messages.
///
/// Inputs:
/// - `app`: Application state for i18n.
/// - `allows_dependents`: Whether cascade mode allows dependents.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Renders footer messages based on cascade mode.
fn render_cascade_footer(app: &AppState, allows_dependents: bool) -> Vec<Line<'static>> {
    let th = theme();
    let mut lines = vec![Line::from("")];
    let footer_text = if allows_dependents {
        i18n::t(app, "app.modals.preflight.summary.will_be_removed_auto")
    } else {
        i18n::t(app, "app.modals.preflight.summary.enable_cascade_mode")
    };
    lines.push(Line::from(Span::styled(
        footer_text,
        Style::default().fg(th.subtext1),
    )));
    lines.push(Line::from(Span::styled(
        i18n::t(app, "app.modals.preflight.summary.use_deps_tab"),
        Style::default().fg(th.subtext1),
    )));
    lines
}

/// What: Render remove action content (removal plan and cascade impact).
///
/// Inputs:
/// - `app`: Application state for i18n and data access.
/// - `items`: Packages to remove.
/// - `dependency_info`: Dependency information.
/// - `cascade_mode`: Removal cascade mode.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Shows removal plan, dependent count, and cascade impact preview.
/// - Uses helper functions and data structures to reduce complexity.
fn render_remove_action(
    app: &AppState,
    items: &[PackageItem],
    dependency_info: &[DependencyInfo],
    cascade_mode: CascadeMode,
) -> Vec<Line<'static>> {
    let mut lines = Vec::new();
    let th = theme();

    // Render cascade mode header
    lines.extend(render_cascade_mode_header(app, cascade_mode));

    // Early return for empty items
    if items.is_empty() {
        lines.push(Line::from(Span::styled(
            i18n::t(app, "app.modals.preflight.summary.no_removal_targets"),
            Style::default().fg(th.subtext1),
        )));
        return lines;
    }

    // Render removal plan
    lines.extend(render_removal_plan(app, items, cascade_mode));

    // Prepare context (caches repeated computations)
    let ctx = CascadeRenderingContext::new(items, cascade_mode);
    let dependent_count = dependency_info.len();

    // Render dependent summary
    lines.extend(render_dependent_summary(
        app,
        dependent_count,
        ctx.allows_dependents,
    ));

    // Render dependent impact section if there are dependents
    if dependent_count > 0 {
        lines.extend(render_impact_overview(app));

        // Render impact header
        let (impact_header, impact_style) = get_impact_header(app, ctx.allows_dependents);
        lines.push(Line::from(Span::styled(impact_header, impact_style)));

        // Prepare and render cascade candidates
        let candidates = prepare_cascade_candidates(dependency_info, &ctx);
        lines.extend(render_cascade_candidates(app, &candidates, &ctx));

        // Render footer
        lines.extend(render_cascade_footer(app, ctx.allows_dependents));
    }
    lines
}

/// What: Render the Summary tab content for the preflight modal.
///
/// Inputs:
/// - `app`: Application state for i18n and data access.
/// - `items`: Packages under review.
/// - `action`: Whether install or remove.
/// - `summary`: Summary data (optional).
/// - `summary_selected`: Selected index in the package list (for navigation).
/// - `conflicts_selected`: Selected index in the conflicts list (for navigation).
/// - `header_chips`: Header chip data for risk level.
/// - `dependency_info`: Dependency information.
/// - `cascade_mode`: Removal cascade mode.
/// - `content_rect`: Content area rectangle.
///
/// Output:
/// - Returns a vector of lines to render.
///
/// Details:
/// - Shows risk factors and dependency conflicts/upgrades for install.
/// - Shows removal plan and cascade impact for remove actions.
/// - Supports scrolling through the conflicts list with viewport-based rendering.
/// - Only highlights the active section (conflicts) to avoid dual cursors.
#[allow(clippy::too_many_arguments)]
pub fn render_summary_tab(
    app: &AppState,
    items: &[PackageItem],
    action: PreflightAction,
    summary: Option<&PreflightSummaryData>,
    header_chips: &PreflightHeaderChips,
    dependency_info: &[DependencyInfo],
    cascade_mode: CascadeMode,
    _content_rect: Rect,
) -> Vec<Line<'static>> {
    let th = theme();
    let mut lines = Vec::new();

    if let Some(summary_data) = summary.as_ref() {
        lines.extend(render_summary_data(app, summary_data, header_chips));
    } else {
        lines.push(Line::from(Span::styled(
            "Computing summary...",
            Style::default().fg(th.overlay1),
        )));
        lines.push(Line::from(""));
    }

    lines.extend(render_incomplete_data_indicator(
        app,
        items,
        dependency_info,
    ));

    match action {
        PreflightAction::Install if !dependency_info.is_empty() => {
            lines.extend(render_install_dependencies(
                app,
                items,
                dependency_info,
                summary,
            ));
        }
        PreflightAction::Remove => {
            lines.extend(render_remove_action(
                app,
                items,
                dependency_info,
                cascade_mode,
            ));
        }
        PreflightAction::Install | PreflightAction::Downgrade => {
            if items.is_empty() {
                lines.push(Line::from(Span::styled(
                    i18n::t(app, "app.modals.preflight.summary.no_items_selected"),
                    Style::default().fg(th.subtext1),
                )));
            } else {
                lines.push(Line::from(Span::styled(
                    i18n::t_fmt1(
                        app,
                        "app.modals.preflight.summary.packages_selected",
                        items.len(),
                    ),
                    Style::default().fg(th.text),
                )));
            }
        }
    }

    lines
}