u0ui 0.3.16

Carbon UI: IBM Carbon v11 visuals with a shadcn-style API for GPUI Kit
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
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
//! T3 · Pull requests & issues: the PR vocabulary ([`PullRequestStateGlyph`],
//! [`ChecksGlyph`], [`ReviewDecisionBadge`], [`LabelChip`]) and the cards
//! built from it ([`PullRequestRow`], [`PullRequestStack`], [`ChecksList`],
//! [`GuideRail`], [`PullRequestDetailHeader`], [`ReactionBar`],
//! [`PullRequestTimeline`], [`ReviewForm`]) — `src/t3.css` "PR vocabulary".
use super::diff::DiffStat;
use crate::{
    components::{AvatarColor, BadgeVariant, Button, ButtonVariant},
    icons::{CarbonIcon, Icon},
    t3::craft::{self, AvatarTone, focus_handle, focus_visible, mono, press, rem, sans},
    theme::color,
    tokens::ColorRole,
};
use gpui_kit::{
    AnyElement, App, ElementId, Hsla, InteractiveElement, IntoElement, ParentElement, RenderOnce,
    SharedString, StatefulInteractiveElement as _, Styled, Window, div,
    prelude::FluentBuilder as _, px,
};
use std::rc::Rc;

/// A pull request's state (`PRS`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum PullRequestState {
    /// `open`, the default.
    #[default]
    Open,
    /// `draft`.
    Draft,
    /// `merged`.
    Merged,
    /// `closed`.
    Closed,
}

impl PullRequestState {
    /// Every state.
    pub const ALL: [PullRequestState; 4] = [Self::Open, Self::Draft, Self::Merged, Self::Closed];

    /// The `index.d.ts` name.
    pub const fn name(self) -> &'static str {
        match self {
            Self::Open => "open",
            Self::Draft => "draft",
            Self::Merged => "merged",
            Self::Closed => "closed",
        }
    }

    /// The reference label (`Open`, `Draft`, `Merged`, `Closed`).
    pub const fn label(self) -> &'static str {
        match self {
            Self::Open => "Open",
            Self::Draft => "Draft",
            Self::Merged => "Merged",
            Self::Closed => "Closed",
        }
    }

    /// `Merge` for merged, `PullRequest` otherwise.
    pub const fn icon(self) -> CarbonIcon {
        match self {
            Self::Merged => CarbonIcon::Merge,
            _ => CarbonIcon::PullRequest,
        }
    }

    /// `.t3-prglyph.t3-pr--open { color: support-success }`, `--draft`
    /// `icon-secondary`, `--merged` `tag-color-purple`, `--closed` `support-error`.
    pub fn ink(self) -> Hsla {
        color(match self {
            Self::Open => ColorRole::SupportSuccess,
            Self::Draft => ColorRole::IconSecondary,
            Self::Merged => ColorRole::TagColorPurple,
            Self::Closed => ColorRole::SupportError,
        })
    }

    /// `(background, text)` of the sidebar's mini badge (`.t3-prmini`):
    /// `.t3-pr--open` green tag, `--draft` gray, `--merged` purple,
    /// `--closed` red.
    pub fn tag_colors(self) -> (Hsla, Hsla) {
        let (bg, fg) = match self {
            Self::Open => (ColorRole::TagBackgroundGreen, ColorRole::TagColorGreen),
            Self::Draft => (ColorRole::TagBackgroundGray, ColorRole::TagColorGray),
            Self::Merged => (ColorRole::TagBackgroundPurple, ColorRole::TagColorPurple),
            Self::Closed => (ColorRole::TagBackgroundRed, ColorRole::TagColorRed),
        };
        (color(bg), color(fg))
    }

    /// The detail header's tag (`merged` purple, `open` green, else gray).
    pub const fn badge(self) -> BadgeVariant {
        match self {
            Self::Merged => BadgeVariant::Purple,
            Self::Open => BadgeVariant::Green,
            _ => BadgeVariant::Gray,
        }
    }
}

/// A status icon with its `title` (`role="img" aria-label title`).
pub(crate) fn glyph(
    icon: impl Into<Icon>,
    ink: Hsla,
    size: f32,
    title: &'static str,
) -> gpui_kit::Stateful<gpui_kit::Div> {
    craft::titled(
        div()
            .flex()
            .flex_none()
            .child(icon.into().size_length(rem(size)).color(ink)),
        "glyph",
        title,
    )
}

/// The PR state icon (`.t3-prglyph`), 16px or 20px.
#[derive(IntoElement, Clone, Copy, Debug, PartialEq)]
pub struct PullRequestStateGlyph {
    state: PullRequestState,
    size: f32,
}

impl PullRequestStateGlyph {
    /// A 16px glyph.
    pub fn new(state: PullRequestState) -> Self {
        Self { state, size: 16. }
    }

    /// The icon size in px.
    pub fn size(mut self, size: f32) -> Self {
        self.size = size;
        self
    }
}

impl RenderOnce for PullRequestStateGlyph {
    fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
        glyph(
            self.state.icon(),
            self.state.ink(),
            self.size,
            self.state.label(),
        )
    }
}

/// CI checks status (`CHK`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum ChecksStatus {
    /// `passed`, the default.
    #[default]
    Passed,
    /// `failed`.
    Failed,
    /// `running`.
    Running,
    /// `none`.
    None,
}

impl ChecksStatus {
    /// Every status.
    pub const ALL: [ChecksStatus; 4] = [Self::Passed, Self::Failed, Self::Running, Self::None];

    /// The `index.d.ts` name.
    pub const fn name(self) -> &'static str {
        match self {
            Self::Passed => "passed",
            Self::Failed => "failed",
            Self::Running => "running",
            Self::None => "none",
        }
    }

    /// The reference's accessible name.
    pub const fn label(self) -> &'static str {
        match self {
            Self::Passed => "All checks passed",
            Self::Failed => "Some checks were not successful",
            Self::Running => "Some checks haven't completed yet",
            Self::None => "No checks reported",
        }
    }

    /// `CheckmarkFilled`, `ErrorFilled`, `InProgress`, `CircleDash`.
    pub const fn icon(self) -> CarbonIcon {
        match self {
            Self::Passed => CarbonIcon::CheckmarkFilled,
            Self::Failed => CarbonIcon::ErrorFilled,
            Self::Running => CarbonIcon::InProgress,
            Self::None => CarbonIcon::CircleDash,
        }
    }

    /// `.t3-checks--passed` `support-success`, `--failed` `support-error`,
    /// `--running` `interactive`, `--none` `icon-secondary`.
    pub fn ink(self) -> Hsla {
        color(match self {
            Self::Passed => ColorRole::SupportSuccess,
            Self::Failed => ColorRole::SupportError,
            Self::Running => ColorRole::Interactive,
            Self::None => ColorRole::IconSecondary,
        })
    }
}

/// The checks status icon (`.t3-checks`, 16px).
#[derive(IntoElement, Clone, Copy, Debug, PartialEq, Eq)]
pub struct ChecksGlyph {
    status: ChecksStatus,
}

impl ChecksGlyph {
    /// A glyph.
    pub fn new(status: ChecksStatus) -> Self {
        Self { status }
    }
}

impl RenderOnce for ChecksGlyph {
    fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
        glyph(
            self.status.icon(),
            self.status.ink(),
            16.,
            self.status.label(),
        )
    }
}

/// A review decision (`REV`).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum ReviewDecision {
    /// `approved`, the default.
    #[default]
    Approved,
    /// `changes`.
    Changes,
    /// `awaiting`.
    Awaiting,
}

impl ReviewDecision {
    /// Every decision.
    pub const ALL: [ReviewDecision; 3] = [Self::Approved, Self::Changes, Self::Awaiting];

    /// The `index.d.ts` name.
    pub const fn name(self) -> &'static str {
        match self {
            Self::Approved => "approved",
            Self::Changes => "changes",
            Self::Awaiting => "awaiting",
        }
    }

    /// The reference label.
    pub const fn label(self) -> &'static str {
        match self {
            Self::Approved => "Approved",
            Self::Changes => "Changes requested",
            Self::Awaiting => "Awaiting review",
        }
    }

    /// `CheckmarkOutline`, `Edit`, `View`.
    pub const fn icon(self) -> CarbonIcon {
        match self {
            Self::Approved => CarbonIcon::CheckmarkOutline,
            Self::Changes => CarbonIcon::Edit,
            Self::Awaiting => CarbonIcon::View,
        }
    }

    /// `.t3-review--approved` `tag-color-green`, `--changes` `text-error`,
    /// `--awaiting` `text-secondary`.
    pub fn ink(self) -> Hsla {
        color(match self {
            Self::Approved => ColorRole::TagColorGreen,
            Self::Changes => ColorRole::TextError,
            Self::Awaiting => ColorRole::TextSecondary,
        })
    }
}

/// The review decision: a 12px icon and 12px label in the decision's ink
/// (`.t3-review`).
#[derive(IntoElement, Clone, Copy, Debug, PartialEq, Eq)]
pub struct ReviewDecisionBadge {
    decision: ReviewDecision,
    neutral_text: bool,
}

impl ReviewDecisionBadge {
    /// A badge.
    pub fn new(decision: ReviewDecision) -> Self {
        Self {
            decision,
            neutral_text: false,
        }
    }

    /// Keep the 12px label in `text-secondary` while the icon carries the status color
    /// (`PullRequests.dc.html`: "status colours never carry small text").
    pub fn neutral_text(mut self, neutral: bool) -> Self {
        self.neutral_text = neutral;
        self
    }
}

impl RenderOnce for ReviewDecisionBadge {
    fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
        let (icon_ink, text_ink) = if self.neutral_text {
            let icon_role = match self.decision {
                ReviewDecision::Approved => ColorRole::SupportSuccess,
                ReviewDecision::Changes => ColorRole::SupportError,
                ReviewDecision::Awaiting => ColorRole::IconSecondary,
            };
            (color(icon_role), color(ColorRole::TextSecondary))
        } else {
            let ink = self.decision.ink();
            (ink, ink)
        };
        sans(div(), 12., 400)
            .flex()
            .flex_none()
            .items_center()
            .gap(rem(4.))
            .whitespace_nowrap()
            .text_color(text_ink)
            .child(
                Icon::carbon(self.decision.icon())
                    .size_length(rem(12.))
                    .color(icon_ink),
            )
            .child(self.decision.label())
    }
}

/// A host-platform label: an 8px dot in the label's color and the name in
/// `text-primary` (`.t3-label`: a 20px pill with a 1px `border-subtle-01`
/// inset ring). The host color only paints the dot, so contrast holds.
#[derive(IntoElement, Clone, Debug)]
pub struct LabelChip {
    name: SharedString,
    color: Hsla,
}

impl LabelChip {
    /// A label `name` whose host color is `color`.
    pub fn new(name: impl Into<SharedString>, color: impl Into<Hsla>) -> Self {
        Self {
            name: name.into(),
            color: color.into(),
        }
    }
}

impl RenderOnce for LabelChip {
    fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
        sans(div(), 12., 400)
            .flex()
            .flex_none()
            .items_center()
            .gap(rem(4.))
            .h(rem(20.))
            .px(rem(8.))
            .rounded(rem(16.))
            .border_1()
            .border_color(color(ColorRole::BorderSubtle01))
            .whitespace_nowrap()
            .text_color(color(ColorRole::TextPrimary))
            .child(div().size(px(8.)).rounded_full().bg(self.color))
            .child(self.name)
    }
}

/// A label as data (`labels[]`).
#[derive(Clone, Debug, PartialEq)]
pub struct Label {
    /// `name`.
    pub name: SharedString,
    /// `color`.
    pub color: Hsla,
}

impl Label {
    /// A label.
    pub fn new(name: impl Into<SharedString>, color: impl Into<Hsla>) -> Self {
        Self {
            name: name.into(),
            color: color.into(),
        }
    }

    fn chip(&self) -> LabelChip {
        LabelChip::new(self.name.clone(), self.color)
    }
}

/// `.t3-prrow-c`: a 14px icon and a 12px `text-secondary` count.
pub(crate) fn icon_count(icon: CarbonIcon, text: impl Into<SharedString>) -> gpui_kit::Div {
    let ink = color(ColorRole::TextSecondary);
    sans(div(), 12., 400)
        .flex()
        .flex_none()
        .items_center()
        .gap(rem(4.))
        .text_color(ink)
        .child(Icon::carbon(icon).size_length(rem(14.)).color(ink))
        .child(text.into())
}

/// A 3px start bar (`box-shadow: inset 3px 0 0 <color>`).
pub(crate) fn start_bar(c: Hsla) -> AnyElement {
    div()
        .absolute()
        .left_0()
        .top_0()
        .bottom_0()
        .w(px(3.))
        .bg(c)
        .into_any_element()
}

type Handler = Rc<dyn Fn(&mut Window, &mut App)>;

/// A PR list row (`.t3-prrow`): state glyph; title, `#number` and labels;
/// repo, author, `head → base` and time; then conflicts, review, checks,
/// comments and `+/−`.
#[derive(IntoElement)]
pub struct PullRequestRow {
    id: ElementId,
    number: u32,
    title: SharedString,
    state: PullRequestState,
    repo: Option<SharedString>,
    author: SharedString,
    head: SharedString,
    base: SharedString,
    labels: Vec<Label>,
    checks: Option<ChecksStatus>,
    review: Option<ReviewDecision>,
    stat: Option<(usize, usize)>,
    comments: Option<usize>,
    time: SharedString,
    conflict: bool,
    conflict_label: SharedString,
    conflict_title: SharedString,
    unread: bool,
    selected: bool,
    divided: bool,
    show_avatar: bool,
    aligned_side: bool,
    on_click: Option<Handler>,
}

impl PullRequestRow {
    /// A row for PR `number` titled `title`.
    pub fn new(id: impl Into<ElementId>, number: u32, title: impl Into<SharedString>) -> Self {
        Self {
            id: id.into(),
            number,
            title: title.into(),
            state: PullRequestState::Open,
            repo: None,
            author: SharedString::default(),
            head: SharedString::default(),
            base: SharedString::default(),
            labels: Vec::new(),
            checks: None,
            review: None,
            stat: None,
            comments: None,
            time: SharedString::default(),
            conflict: false,
            conflict_label: "Conflicts".into(),
            conflict_title: "Has conflicts".into(),
            unread: false,
            selected: false,
            divided: true,
            show_avatar: true,
            aligned_side: false,
            on_click: None,
        }
    }

    /// The state (default open).
    pub fn state(mut self, state: PullRequestState) -> Self {
        self.state = state;
        self
    }

    /// The repository (`repo`).
    pub fn repo(mut self, repo: impl Into<SharedString>) -> Self {
        self.repo = Some(repo.into());
        self
    }

    /// The author login.
    pub fn author(mut self, author: impl Into<SharedString>) -> Self {
        self.author = author.into();
        self
    }

    /// Head and base branches.
    pub fn branches(
        mut self,
        head: impl Into<SharedString>,
        base: impl Into<SharedString>,
    ) -> Self {
        self.head = head.into();
        self.base = base.into();
        self
    }

    /// Labels.
    pub fn labels(mut self, labels: impl IntoIterator<Item = Label>) -> Self {
        self.labels = labels.into_iter().collect();
        self
    }

    /// Checks status.
    pub fn checks(mut self, checks: ChecksStatus) -> Self {
        self.checks = Some(checks);
        self
    }

    /// Review decision.
    pub fn review(mut self, review: ReviewDecision) -> Self {
        self.review = Some(review);
        self
    }

    /// Added and removed lines.
    pub fn stat(mut self, added: usize, removed: usize) -> Self {
        self.stat = Some((added, removed));
        self
    }

    /// Comment count (shown when non-zero).
    pub fn comments(mut self, comments: usize) -> Self {
        self.comments = Some(comments);
        self
    }

    /// Relative time.
    pub fn time(mut self, time: impl Into<SharedString>) -> Self {
        self.time = time.into();
        self
    }

    /// Has merge conflicts.
    pub fn conflict(mut self, conflict: bool) -> Self {
        self.conflict = conflict;
        self
    }

    /// The conflicts text and its tooltip (`Conflicts`, `Has conflicts`).
    pub fn conflict_label(
        mut self,
        label: impl Into<SharedString>,
        title: impl Into<SharedString>,
    ) -> Self {
        self.conflict_label = label.into();
        self.conflict_title = title.into();
        self
    }

    /// Unread: semibold title.
    pub fn unread(mut self, unread: bool) -> Self {
        self.unread = unread;
        self
    }

    /// Selected: `layer-selected-01` and a 3px `border-interactive` bar.
    pub fn selected(mut self, selected: bool) -> Self {
        self.selected = selected;
        self
    }

    /// Show the bottom divider rule (`true` by default; `false` inside role-grouped lists).
    pub fn divided(mut self, divided: bool) -> Self {
        self.divided = divided;
        self
    }

    /// Show the 16px author avatar in the metadata row (`true` by default).
    pub fn show_avatar(mut self, show: bool) -> Self {
        self.show_avatar = show;
        self
    }

    /// Use `PullRequests.dc.html`'s fixed-width right-aligned side columns (`128 / 16 / 32 / 76`)
    /// and `68px` min-height centered row geometry.
    pub fn aligned_side(mut self, aligned: bool) -> Self {
        self.aligned_side = aligned;
        self
    }

    /// Activation (click, Enter, Space).
    pub fn on_click(mut self, f: impl Fn(&mut Window, &mut App) + 'static) -> Self {
        self.on_click = Some(Rc::new(f));
        self
    }
}

/// `.t3-prrow-meta > span`: inline-flex, 4px gap.
fn meta_item() -> gpui_kit::Div {
    div().flex().flex_none().items_center().gap(rem(4.))
}

/// `<Avatar size="sm"><AvatarFallback color=…>` inside a row whose rule
/// shrinks the disc (`.t3-prrow-meta .cu-avatar--sm { 1rem }`, `.t3-issue
/// .cu-avatar--sm { 1.25rem }`); the fallback text stays 12px.
pub(crate) fn small_avatar(name: &str, c: AvatarColor, diameter: f32) -> gpui_kit::Div {
    craft::initials(craft::two_letters(name), AvatarTone::Avatar(c), diameter)
}

impl RenderOnce for PullRequestRow {
    fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
        let id = self.id.clone();
        let focus = focus_handle(&id, window, cx);
        let ring = focus_visible(&focus, window);
        let on_click = self.on_click.clone();
        let secondary = color(ColorRole::TextSecondary);
        let title = sans(div(), 14., if self.unread { 600 } else { 400 })
            .flex()
            .flex_wrap()
            .items_center()
            .gap(rem(8.))
            .child(self.title.clone())
            .child(
                sans(div(), 14., 400)
                    .text_color(secondary)
                    .child(format!("#{}", self.number)),
            )
            .children(self.labels.iter().map(Label::chip));
        let meta = sans(div(), 12., 400)
            .flex()
            .flex_wrap()
            .items_center()
            .gap(rem(12.))
            .text_color(secondary)
            .when_some(self.repo.clone(), |this, repo| {
                this.child(meta_item().child(repo))
            })
            .child(
                meta_item()
                    .when(self.show_avatar, |m| {
                        m.child(small_avatar(
                            if self.author.is_empty() {
                                "?"
                            } else {
                                &self.author
                            },
                            AvatarColor::Teal,
                            16.,
                        ))
                    })
                    .child(self.author.clone()),
            )
            .child(
                mono(meta_item(), 12., 400)
                    .child(
                        Icon::carbon(CarbonIcon::Branch)
                            .size_length(rem(12.))
                            .color(secondary),
                    )
                    .child(format!("{} \u{2192} {}", self.head, self.base)),
            )
            .child(meta_item().child(self.time.clone()));
        let aligned = self.aligned_side;
        let side = if aligned {
            // `PullRequests.dc.html`: `grid-template-columns: auto 128px 16px 32px 76px;
            // column-gap: 12px; align-items: center; justify-items: end`.
            div()
                .flex()
                .flex_none()
                .items_center()
                .gap(rem(12.))
                .when(self.conflict, |this| {
                    this.child(
                        craft::titled(
                            sans(div(), 12., 400),
                            "conflict",
                            self.conflict_title.clone(),
                        )
                        .flex()
                        .items_center()
                        .gap(rem(4.))
                        .text_color(color(ColorRole::TextPrimary))
                        .child(
                            Icon::carbon(CarbonIcon::WarningAltFilled)
                                .size_length(rem(14.))
                                .color(color(ColorRole::SupportWarning)),
                        )
                        .child(self.conflict_label.clone()),
                    )
                })
                .child(
                    div()
                        .flex()
                        .flex_none()
                        .justify_end()
                        .w(rem(128.))
                        .when_some(self.review, |s, r| {
                            s.child(ReviewDecisionBadge::new(r).neutral_text(true))
                        }),
                )
                .child(
                    div()
                        .flex()
                        .flex_none()
                        .justify_end()
                        .w(rem(16.))
                        .when_some(self.checks, |s, c| s.child(ChecksGlyph::new(c))),
                )
                .child(
                    div()
                        .flex()
                        .flex_none()
                        .justify_end()
                        .w(rem(32.))
                        .when_some(self.comments.filter(|n| *n > 0), |s, n| {
                            s.child(icon_count(CarbonIcon::Chat, n.to_string()))
                        }),
                )
                .child(
                    div()
                        .flex()
                        .flex_none()
                        .justify_end()
                        .w(rem(76.))
                        .when_some(self.stat, |s, (a, r)| s.child(DiffStat::new(a, r))),
                )
        } else {
            div()
                .flex()
                .flex_none()
                .items_center()
                .gap(rem(12.))
                .when(self.conflict, |this| {
                    // `.t3-conflict { 12px; text-primary } svg { fill: support-warning }`.
                    this.child(
                        craft::titled(
                            sans(div(), 12., 400),
                            "conflict",
                            self.conflict_title.clone(),
                        )
                        .flex()
                        .items_center()
                        .gap(rem(4.))
                        .text_color(color(ColorRole::TextPrimary))
                        .child(
                            Icon::carbon(CarbonIcon::WarningAltFilled)
                                .size_length(rem(14.))
                                .color(color(ColorRole::SupportWarning)),
                        )
                        .child(self.conflict_label.clone()),
                    )
                })
                .when_some(self.review, |this, r| {
                    this.child(ReviewDecisionBadge::new(r))
                })
                .when_some(self.checks, |this, c| this.child(ChecksGlyph::new(c)))
                .when_some(self.comments.filter(|n| *n > 0), |this, n| {
                    this.child(icon_count(CarbonIcon::Chat, n.to_string()))
                })
                .when_some(self.stat, |this, (a, r)| this.child(DiffStat::new(a, r)))
        };
        press(id, &focus)
            .accessibility_label(self.title.clone())
            .w_full()
            .map(|d| {
                if aligned {
                    d.items_center()
                        .min_h(rem(68.))
                        .pl(rem(16.))
                        .pr(rem(8.))
                        .py(rem(14.))
                } else {
                    d.items_start().px(rem(16.)).py(rem(12.))
                }
            })
            .gap(rem(12.))
            .when(self.divided, |this| {
                this.border_b_1()
                    .border_color(color(ColorRole::BorderSubtle01))
            })
            .text_color(color(ColorRole::TextPrimary))
            .when(self.selected, |this| {
                this.bg(color(ColorRole::LayerSelected01))
            })
            // `.t3-prrow:hover` (0,2,0) wins over `.t3-prrow--on` (0,1,0).
            .hover(|s| s.bg(color(ColorRole::LayerHover01)))
            .when_some(on_click, |this, f| this.on_click(move |_, w, cx| f(w, cx)))
            .when(self.selected, |this| {
                this.child(start_bar(color(ColorRole::BorderInteractive)))
            })
            // `.t3-prrow > .t3-prglyph { margin-top: 2px }`.
            .child(
                div()
                    .when(aligned, |d| d.self_start())
                    .mt(px(2.))
                    .child(PullRequestStateGlyph::new(self.state)),
            )
            .child(
                div()
                    .flex()
                    .flex_col()
                    .flex_1()
                    .min_w_0()
                    .gap(rem(4.))
                    .child(title)
                    .child(meta),
            )
            .child(side)
            .when(ring, |this| this.child(craft::focus_ring()))
    }
}

/// One layer of a stack (`layers[]`).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StackLayer {
    /// `number`.
    pub number: u32,
    /// `title`.
    pub title: SharedString,
    /// `state`.
    pub state: PullRequestState,
    /// `checks`.
    pub checks: Option<ChecksStatus>,
}

impl StackLayer {
    /// A layer.
    pub fn new(number: u32, title: impl Into<SharedString>, state: PullRequestState) -> Self {
        Self {
            number,
            title: title.into(),
            state,
            checks: None,
        }
    }

    /// Its checks status.
    pub fn checks(mut self, checks: ChecksStatus) -> Self {
        self.checks = Some(checks);
        self
    }
}

/// The start indent of stack layer `depth`: `margin-left: calc(var(--depth)
/// * var(--spacing-05))`.
pub fn stack_indent(depth: usize) -> f32 {
    depth as f32 * 16.
}

type StackSelectHandler = Rc<dyn Fn(u32, &mut Window, &mut App)>;

/// Stacked pull requests (`.t3-stack`): each layer 40px on `layer-01`,
/// indented 16px per depth; the current one selected with a 3px bar.
#[derive(IntoElement, Clone, Default)]
pub struct PullRequestStack {
    layers: Vec<StackLayer>,
    current: Option<u32>,
    flat: bool,
    on_select: Option<StackSelectHandler>,
}

impl PullRequestStack {
    /// An empty stack.
    pub fn new() -> Self {
        Self::default()
    }

    /// The layers, base first.
    pub fn layers(mut self, layers: impl IntoIterator<Item = StackLayer>) -> Self {
        self.layers = layers.into_iter().collect();
        self
    }

    /// The current PR number.
    pub fn current(mut self, number: u32) -> Self {
        self.current = Some(number);
        self
    }

    /// Flat sidebar layout (`margin-left: 0` and wrapping multi-line titles).
    pub fn flat(mut self, flat: bool) -> Self {
        self.flat = flat;
        self
    }

    /// Layer selected (`onSelect(number)`).
    pub fn on_select(mut self, f: impl Fn(u32, &mut Window, &mut App) + 'static) -> Self {
        self.on_select = Some(Rc::new(f));
        self
    }
}

impl RenderOnce for PullRequestStack {
    fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
        let flat = self.flat;
        let on_select = self.on_select;
        div()
            .flex()
            .flex_col()
            .gap(px(2.))
            .map(|d| {
                if flat {
                    d.w_full()
                } else {
                    d.w(rem(384.)).max_w_full()
                }
            })
            .children(self.layers.iter().enumerate().map(|(i, l)| {
                let on = Some(l.number) == self.current;
                let num = l.number;
                let cb = on_select.clone();
                let mut row = sans(div(), 14., 400)
                    .id(SharedString::from(format!("t3-stack-{num}")))
                    .relative()
                    .flex()
                    .gap(rem(8.))
                    .px(rem(12.))
                    .bg(color(if on {
                        ColorRole::LayerSelected01
                    } else {
                        ColorRole::Layer01
                    }))
                    .text_color(color(ColorRole::TextPrimary));
                row = if flat {
                    row.items_start().min_h(rem(40.)).py(rem(8.))
                } else {
                    row.items_center().h(rem(40.)).ml(rem(stack_indent(i)))
                };
                if let Some(f) = cb {
                    row = row
                        .cursor_pointer()
                        .hover(|s| s.bg(color(ColorRole::LayerHover01)))
                        .on_click(move |_, w, cx| f(num, w, cx));
                }
                row.when(on, |this| {
                    this.child(start_bar(color(ColorRole::BorderInteractive)))
                })
                .child(
                    div()
                        .when(flat, |d| d.mt(px(2.)))
                        .child(PullRequestStateGlyph::new(l.state)),
                )
                .child(
                    div()
                        .flex_none()
                        .text_color(color(ColorRole::TextSecondary))
                        .child(format!("#{}", l.number)),
                )
                .child(if flat {
                    div().flex_1().min_w_0().child(l.title.clone())
                } else {
                    div()
                        .flex_1()
                        .min_w_0()
                        .overflow_hidden()
                        .whitespace_nowrap()
                        .text_ellipsis()
                        .child(l.title.clone())
                })
                .when_some(l.checks, |this, c| {
                    this.child(
                        div()
                            .when(flat, |d| d.mt(px(2.)))
                            .child(ChecksGlyph::new(c)),
                    )
                })
            }))
    }
}

/// One CI check (`checks[]`).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Check {
    /// `name`.
    pub name: SharedString,
    /// `status`.
    pub status: ChecksStatus,
    /// `duration`.
    pub duration: SharedString,
}

impl Check {
    /// A check.
    pub fn new(
        name: impl Into<SharedString>,
        status: ChecksStatus,
        duration: impl Into<SharedString>,
    ) -> Self {
        Self {
            name: name.into(),
            status,
            duration: duration.into(),
        }
    }
}

/// The summary of a check list: failed if any failed, else running if any
/// runs, else passed; and the head text ("1 of 4 failing" / "4 checks").
pub fn checks_summary(checks: &[Check]) -> (ChecksStatus, String) {
    let failed = checks
        .iter()
        .filter(|c| c.status == ChecksStatus::Failed)
        .count();
    let status = if failed > 0 {
        ChecksStatus::Failed
    } else if checks.iter().any(|c| c.status == ChecksStatus::Running) {
        ChecksStatus::Running
    } else {
        ChecksStatus::Passed
    };
    let text = if failed > 0 {
        format!("{failed} of {} failing", checks.len())
    } else {
        format!("{} checks", checks.len())
    };
    (status, text)
}

type CheckHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>;

/// The CI checks list (`.t3-checklist` on `layer-01`; flat and full width per
/// `app-r3`): a summary head, then one 40px row per check with its glyph,
/// name, duration and a Details link.
#[derive(IntoElement)]
pub struct ChecksList {
    id: ElementId,
    checks: Vec<Check>,
    details_label: SharedString,
    show_header: bool,
    compact: bool,
    details_failed_only: bool,
    on_details: Option<CheckHandler>,
}

impl ChecksList {
    /// A checks list.
    pub fn new(id: impl Into<ElementId>) -> Self {
        Self {
            id: id.into(),
            checks: Vec::new(),
            details_label: "Details".into(),
            show_header: true,
            compact: false,
            details_failed_only: false,
            on_details: None,
        }
    }

    /// Show the summary header row (`true` by default; `false` inside a titled card).
    pub fn show_header(mut self, show: bool) -> Self {
        self.show_header = show;
        self
    }

    /// Compact card layout (`px: 0`, `36px` rows, transparent background).
    pub fn compact(mut self, compact: bool) -> Self {
        self.compact = compact;
        self
    }

    /// Show the `Details` link only on failed checks (`false` by default).
    pub fn details_failed_only(mut self, failed_only: bool) -> Self {
        self.details_failed_only = failed_only;
        self
    }

    /// The checks.
    pub fn checks(mut self, checks: impl IntoIterator<Item = Check>) -> Self {
        self.checks = checks.into_iter().collect();
        self
    }

    /// The link text (`Details`).
    pub fn details_label(mut self, label: impl Into<SharedString>) -> Self {
        self.details_label = label.into();
        self
    }

    /// A Details link was activated (check index).
    pub fn on_details(mut self, f: impl Fn(usize, &mut Window, &mut App) + 'static) -> Self {
        self.on_details = Some(Rc::new(f));
        self
    }
}

impl RenderOnce for ChecksList {
    fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
        let (status, head) = checks_summary(&self.checks);
        let id = self.id.clone();
        let compact = self.compact;
        let failed_only = self.details_failed_only;
        sans(div(), 14., 400)
            .flex()
            .flex_col()
            .when(!compact, |d| d.bg(color(ColorRole::Layer01)))
            .text_color(color(ColorRole::TextPrimary))
            .when(self.show_header, |d| {
                d.child(
                    div()
                        .flex()
                        .items_center()
                        .gap(rem(8.))
                        .p(rem(12.))
                        .border_b_1()
                        .border_color(color(ColorRole::BorderSubtle01))
                        .child(ChecksGlyph::new(status))
                        // A bare `<b>`: Carbon's reset (`b { font: inherit }`) keeps it 400.
                        .child(sans(div(), 14., 400).child(head)),
                )
            })
            .children(self.checks.iter().enumerate().map(|(i, c)| {
                let on_details = self.on_details.clone();
                let show_details = !failed_only || c.status == ChecksStatus::Failed;
                let details_btn = show_details.then(|| {
                    Button::new(craft::sub(&id, "details", i), self.details_label.clone())
                        .variant(ButtonVariant::Link)
                        .when_some(on_details, |b, f| b.on_click(move |_, w, cx| f(i, w, cx)))
                });
                let mut row = div()
                    .id(craft::sub(&id, "row", i))
                    .flex()
                    .items_center()
                    .gap(rem(8.))
                    .min_h(rem(if compact { 36. } else { 40. }))
                    .when(!compact, |r| r.px(rem(12.)))
                    .hover(|s| s.bg(color(ColorRole::LayerHover01)))
                    .child(ChecksGlyph::new(c.status));
                if failed_only && show_details {
                    row = row
                        .child(div().flex_none().child(c.name.clone()))
                        .children(details_btn)
                        .child(div().flex_1())
                        .child(craft::text(
                            c.duration.clone(),
                            12.,
                            ColorRole::TextSecondary,
                        ));
                } else {
                    row = row
                        .child(div().flex_1().min_w_0().child(c.name.clone()))
                        .child(craft::text(
                            c.duration.clone(),
                            12.,
                            ColorRole::TextSecondary,
                        ))
                        .children(details_btn);
                }
                row
            }))
    }
}

/// One guide stop (`stops[]`).
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GuideStop {
    /// `title`.
    pub title: SharedString,
    /// `files`.
    pub files: usize,
    /// `note`.
    pub note: SharedString,
}

impl GuideStop {
    /// A stop.
    pub fn new(
        title: impl Into<SharedString>,
        files: usize,
        note: impl Into<SharedString>,
    ) -> Self {
        Self {
            title: title.into(),
            files,
            note: note.into(),
        }
    }
}

/// Where a guide stop is relative to the current one.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StopState {
    /// Before the current stop (`--done`: green bullet with a check).
    Done,
    /// The current stop (`--on`: blue bullet, selected row).
    Current,
    /// After it (a neutral numbered bullet).
    Ahead,
}

impl StopState {
    /// The state of stop `i` when `current` is shown.
    pub fn of(i: usize, current: usize) -> Self {
        use std::cmp::Ordering::*;
        match i.cmp(&current) {
            Less => Self::Done,
            Equal => Self::Current,
            Greater => Self::Ahead,
        }
    }

    /// (bullet fill, bullet ink): `layer-accent-01`/`text-primary`, current
    /// `interactive`/`text-on-color`, done `support-success`/`text-on-color`.
    pub fn bullet(self) -> (Hsla, Hsla) {
        match self {
            Self::Ahead => (
                color(ColorRole::LayerAccent01),
                color(ColorRole::TextPrimary),
            ),
            Self::Current => (color(ColorRole::Interactive), color(ColorRole::TextOnColor)),
            Self::Done => (
                color(ColorRole::SupportSuccess),
                color(ColorRole::TextOnColor),
            ),
        }
    }
}

type IndexHandler = Rc<dyn Fn(usize, &mut Window, &mut App)>;

/// The PR guide route (`.t3-guide`, 18rem): one button per stop with a 20px
/// bullet joined to the next by a 1px rule; done stops show a check.
#[derive(IntoElement)]
pub struct GuideRail {
    id: ElementId,
    stops: Vec<GuideStop>,
    current: usize,
    card_style: bool,
    on_select: Option<IndexHandler>,
    files_label: SharedString,
}

impl GuideRail {
    /// A guide rail.
    pub fn new(id: impl Into<ElementId>) -> Self {
        Self {
            id: id.into(),
            stops: Vec::new(),
            current: 0,
            card_style: false,
            on_select: None,
            files_label: "files".into(),
        }
    }

    /// Full-width card layout (`PullRequestDetail.dc.html`): 3px `border-interactive`
    /// bar on the current stop and a 1px `border-strong-01` ring on upcoming bullets.
    pub fn card_style(mut self, card_style: bool) -> Self {
        self.card_style = card_style;
        self
    }

    /// The stops.
    pub fn stops(mut self, stops: impl IntoIterator<Item = GuideStop>) -> Self {
        self.stops = stops.into_iter().collect();
        self
    }

    /// The current stop index.
    pub fn current(mut self, current: usize) -> Self {
        self.current = current;
        self
    }

    /// A stop was chosen (`onSelect`).
    pub fn on_select(mut self, f: impl Fn(usize, &mut Window, &mut App) + 'static) -> Self {
        self.on_select = Some(Rc::new(f));
        self
    }

    /// The word after the file count (`files`).
    pub fn files_label(mut self, label: impl Into<SharedString>) -> Self {
        self.files_label = label.into();
        self
    }
}

impl RenderOnce for GuideRail {
    fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
        let n = self.stops.len();
        let card_style = self.card_style;
        let rows: Vec<AnyElement> = self
            .stops
            .iter()
            .enumerate()
            .map(|(i, s)| {
                let state = StopState::of(i, self.current);
                let row_id = craft::sub(&self.id, "stop", i);
                let focus = focus_handle(&row_id, window, cx);
                let ring = focus_visible(&focus, window);
                let (fill, ink) = if card_style && state == StopState::Ahead {
                    (
                        gpui_kit::transparent_black(),
                        color(ColorRole::TextSecondary),
                    )
                } else {
                    state.bullet()
                };
                let on_select = self.on_select.clone();
                let bullet = sans(div(), 12., 400)
                    .flex()
                    .flex_none()
                    .items_center()
                    .justify_center()
                    .size(rem(20.))
                    .rounded_full()
                    .bg(fill)
                    .when(card_style && state == StopState::Ahead, |b| {
                        b.border_1().border_color(color(ColorRole::BorderStrong01))
                    })
                    .text_color(ink)
                    .map(|this| match state {
                        StopState::Done => this.child(
                            Icon::carbon(CarbonIcon::Checkmark)
                                .size_length(rem(12.))
                                .color(ink),
                        ),
                        _ => this.child((i + 1).to_string()),
                    });
                press(row_id, &focus)
                    .w_full()
                    .items_start()
                    .gap(rem(12.))
                    .px(rem(12.))
                    .py(rem(8.))
                    .text_color(color(if state == StopState::Current {
                        ColorRole::TextPrimary
                    } else {
                        ColorRole::TextSecondary
                    }))
                    .when(state == StopState::Current, |this| {
                        this.bg(color(ColorRole::LayerSelected01))
                            .when(card_style, |t| {
                                t.child(start_bar(color(ColorRole::BorderInteractive)))
                            })
                    })
                    .hover(|s| s.bg(color(ColorRole::LayerHover01)))
                    .when_some(on_select, |this, f| {
                        this.on_click(move |_, w, cx| f(i, w, cx))
                    })
                    // `::after { left: calc(12px + 9.5px); top: 2rem; bottom: -0.5rem; width: 1px }`.
                    .when(i + 1 < n, |this| {
                        this.child(
                            div()
                                .absolute()
                                .left(px(21.5))
                                .top(rem(32.))
                                .bottom(rem(-8.))
                                .w(px(1.))
                                .bg(color(ColorRole::BorderSubtle01)),
                        )
                    })
                    .child(bullet)
                    .child(
                        sans(div(), 14., 400)
                            .flex()
                            .flex_col()
                            .gap(px(2.))
                            // `.t3-guide-text b`: no weight rule, so Carbon's
                            // `b { font: inherit }` keeps it 400.
                            .child(sans(div(), 14., 400).child(s.title.clone()))
                            .child(craft::text(
                                format!("{} {} \u{b7} {}", s.files, self.files_label, s.note),
                                12.,
                                ColorRole::TextSecondary,
                            )),
                    )
                    .when(ring, |this| this.child(craft::focus_ring()))
                    .into_any_element()
            })
            .collect();
        div()
            .flex()
            .flex_col()
            .map(|d| {
                if card_style {
                    d.w_full()
                } else {
                    d.w(rem(288.)).max_w_full()
                }
            })
            .children(rows)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn checks_summarise_like_the_reference() {
        let checks = [
            Check::new("build", ChecksStatus::Passed, "2m 10s"),
            Check::new("unit tests", ChecksStatus::Failed, "4m 02s"),
            Check::new("visual regression", ChecksStatus::Running, "1m"),
            Check::new("lint", ChecksStatus::Passed, "38s"),
        ];
        assert_eq!(
            checks_summary(&checks),
            (ChecksStatus::Failed, "1 of 4 failing".to_string())
        );
        assert_eq!(
            checks_summary(&checks[2..]),
            (ChecksStatus::Running, "2 checks".to_string())
        );
        assert_eq!(
            checks_summary(&checks[..1]),
            (ChecksStatus::Passed, "1 checks".to_string())
        );
    }

    #[test]
    fn stops_and_stack_geometry() {
        assert_eq!(StopState::of(0, 1), StopState::Done);
        assert_eq!(StopState::of(1, 1), StopState::Current);
        assert_eq!(StopState::of(2, 1), StopState::Ahead);
        assert_eq!(stack_indent(3), 48.);
    }

    #[test]
    fn vocabulary_colors() {
        crate::theme::tests_set(crate::tokens::CarbonTheme::White);
        assert_eq!(
            PullRequestState::Merged.ink(),
            color(ColorRole::TagColorPurple)
        );
        assert_eq!(PullRequestState::Merged.icon(), CarbonIcon::Merge);
        assert_eq!(ChecksStatus::Running.ink(), color(ColorRole::Interactive));
        assert_eq!(ReviewDecision::Changes.ink(), color(ColorRole::TextError));
        assert_eq!(StopState::Done.bullet().0, color(ColorRole::SupportSuccess));
    }
}