renderreport 0.7.2

Data-driven report generation with Typst as embedded render engine — no CLI dependency
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
//! Narrative and storytelling components: findings, timelines and recommendations.

use super::catalog::{ComponentCategory, LayoutHint};
use super::{Component, Severity};
use crate::component_catalog;
use serde::{Deserialize, Serialize};

component_catalog! {
    id: "finding",
    data: Finding,
    template: include_str!("../../templates/components/finding.typ"),
    description: "Audit finding with severity indicator and recommendation block",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Finding component for audit issues
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Finding {
    /// Finding title
    pub title: String,
    /// Severity level
    pub severity: Severity,
    /// Detailed description
    pub description: String,
    /// Recommendation for fixing
    #[serde(default)]
    pub recommendation: Option<String>,
    /// Affected URL or resource
    #[serde(default)]
    pub affected: Option<String>,
    /// Category/tag
    #[serde(default)]
    pub category: Option<String>,
    /// Label for the "Affected:" line (default: "Affected:")
    #[serde(default)]
    pub label_affected: Option<String>,
    /// Label for the "Recommendation" section header (default: "Recommendation")
    #[serde(default)]
    pub label_recommendation: Option<String>,
}

impl Finding {
    pub fn new(
        title: impl Into<String>,
        severity: Severity,
        description: impl Into<String>,
    ) -> Self {
        Self {
            title: title.into(),
            severity,
            description: description.into(),
            recommendation: None,
            affected: None,
            category: None,
            label_affected: None,
            label_recommendation: None,
        }
    }

    pub fn with_recommendation(mut self, rec: impl Into<String>) -> Self {
        self.recommendation = Some(rec.into());
        self
    }

    pub fn with_affected(mut self, affected: impl Into<String>) -> Self {
        self.affected = Some(affected.into());
        self
    }

    pub fn with_category(mut self, category: impl Into<String>) -> Self {
        self.category = Some(category.into());
        self
    }
}

impl Component for Finding {
    fn component_id(&self) -> &'static str {
        "finding"
    }

    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

component_catalog! {
    id: "roadmap-block",
    data: RoadmapBlock,
    template: include_str!("../../templates/components/roadmap_block.typ"),
    description: "Project roadmap block with phases and milestones",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::Breakable,
}

/// Roadmap block with categorized columns
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoadmapBlock {
    pub columns: Vec<RoadmapColumn>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RoadmapColumn {
    pub title: String,
    #[serde(default)]
    pub accent_color: Option<String>,
    pub items: Vec<ActionItem>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActionItem {
    pub action: String,
    pub role: String,
    pub priority: String,
    #[serde(default)]
    pub effort: Option<String>,
    pub benefit: String,
}

impl RoadmapBlock {
    pub fn new(columns: Vec<RoadmapColumn>) -> Self {
        Self { columns }
    }
}

impl Component for RoadmapBlock {
    fn component_id(&self) -> &'static str {
        "roadmap-block"
    }

    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

/// A step in a process flow
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProcessStep {
    pub label: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub icon: Option<String>,
}

component_catalog! {
    id: "process-flow",
    data: ProcessFlow,
    template: include_str!("../../templates/components/process_flow.typ"),
    description: "Horizontal or vertical process flow with numbered steps",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Linear process visualization
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProcessFlow {
    pub steps: Vec<ProcessStep>,
    #[serde(default)]
    pub title: Option<String>,
    #[serde(default)]
    pub direction: Option<String>,
}

impl ProcessFlow {
    pub fn new(steps: Vec<ProcessStep>) -> Self {
        Self {
            steps,
            title: None,
            direction: None,
        }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }

    pub fn vertical(mut self) -> Self {
        self.direction = Some("vertical".into());
        self
    }
}

impl Component for ProcessFlow {
    fn component_id(&self) -> &'static str {
        "process-flow"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

/// A timeline milestone item
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TimelineItem {
    pub date: String,
    pub title: String,
    #[serde(default)]
    pub description: Option<String>,
    #[serde(default)]
    pub status: Option<String>,
}

component_catalog! {
    id: "timeline",
    data: Timeline,
    template: include_str!("../../templates/components/timeline.typ"),
    description: "Project timeline with milestones and status indicators",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::Breakable,
}

/// Project phases / milestone timeline
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Timeline {
    pub items: Vec<TimelineItem>,
    #[serde(default)]
    pub title: Option<String>,
}

impl Timeline {
    pub fn new(items: Vec<TimelineItem>) -> Self {
        Self { items, title: None }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }
}

impl Component for Timeline {
    fn component_id(&self) -> &'static str {
        "timeline"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

component_catalog! {
    id: "problem-solution",
    data: ProblemSolution,
    template: include_str!("../../templates/components/problem_solution.typ"),
    description: "Two-column problem/solution comparison block",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Two-part problem/solution block
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProblemSolution {
    pub problem: String,
    pub solution: String,
    #[serde(default)]
    pub title: Option<String>,
    #[serde(default)]
    pub problem_label: Option<String>,
    #[serde(default)]
    pub solution_label: Option<String>,
    #[serde(default)]
    pub impact: Option<String>,
    #[serde(default)]
    pub effort: Option<String>,
}

impl ProblemSolution {
    pub fn new(problem: impl Into<String>, solution: impl Into<String>) -> Self {
        Self {
            problem: problem.into(),
            solution: solution.into(),
            title: None,
            problem_label: None,
            solution_label: None,
            impact: None,
            effort: None,
        }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }

    pub fn with_labels(mut self, problem: impl Into<String>, solution: impl Into<String>) -> Self {
        self.problem_label = Some(problem.into());
        self.solution_label = Some(solution.into());
        self
    }

    pub fn with_impact(mut self, impact: impl Into<String>) -> Self {
        self.impact = Some(impact.into());
        self
    }

    pub fn with_effort(mut self, effort: impl Into<String>) -> Self {
        self.effort = Some(effort.into());
        self
    }
}

impl Component for ProblemSolution {
    fn component_id(&self) -> &'static str {
        "problem-solution"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

component_catalog! {
    id: "before-after",
    data: BeforeAfter,
    template: include_str!("../../templates/components/before_after.typ"),
    description: "Before/after comparison with labeled panels",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Before/after comparison block
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BeforeAfter {
    pub before: String,
    pub after: String,
    #[serde(default)]
    pub label_before: Option<String>,
    #[serde(default)]
    pub label_after: Option<String>,
    #[serde(default)]
    pub title: Option<String>,
    #[serde(default)]
    pub note: Option<String>,
}

impl BeforeAfter {
    pub fn new(before: impl Into<String>, after: impl Into<String>) -> Self {
        Self {
            before: before.into(),
            after: after.into(),
            label_before: None,
            label_after: None,
            title: None,
            note: None,
        }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }

    pub fn with_labels(mut self, before: impl Into<String>, after: impl Into<String>) -> Self {
        self.label_before = Some(before.into());
        self.label_after = Some(after.into());
        self
    }

    pub fn with_note(mut self, note: impl Into<String>) -> Self {
        self.note = Some(note.into());
        self
    }
}

impl Component for BeforeAfter {
    fn component_id(&self) -> &'static str {
        "before-after"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

component_catalog! {
    id: "why-it-matters",
    data: WhyItMatters,
    template: include_str!("../../templates/components/why_it_matters.typ"),
    description: "Highlighted explanation block for key insights",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Context / relevance block for storytelling
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WhyItMatters {
    pub body: String,
    #[serde(default)]
    pub title: Option<String>,
    #[serde(default)]
    pub evidence: Option<String>,
    #[serde(default)]
    pub urgency: Option<String>,
}

impl WhyItMatters {
    pub fn new(body: impl Into<String>) -> Self {
        Self {
            body: body.into(),
            title: None,
            evidence: None,
            urgency: None,
        }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }

    pub fn with_evidence(mut self, evidence: impl Into<String>) -> Self {
        self.evidence = Some(evidence.into());
        self
    }

    pub fn with_urgency(mut self, urgency: impl Into<String>) -> Self {
        self.urgency = Some(urgency.into());
        self
    }
}

impl Component for WhyItMatters {
    fn component_id(&self) -> &'static str {
        "why-it-matters"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

// ─── PhaseBlock ──────────────────────────────────────────────────────────────

component_catalog! {
    id: "phase-block",
    data: PhaseBlock,
    template: include_str!("../../templates/components/phase_block.typ"),
    description: "Project phase block with status, owner, and date range",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// A phase block for roadmap/plan displays
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PhaseBlock {
    pub phase_number: u8,
    pub phase_label: String,
    pub description: String,
    pub items: Vec<String>,
    #[serde(default)]
    pub accent_color: Option<String>,
    #[serde(default)]
    pub item_count_total: Option<usize>,
}

impl PhaseBlock {
    pub fn new(number: u8, label: impl Into<String>, description: impl Into<String>) -> Self {
        Self {
            phase_number: number,
            phase_label: label.into(),
            description: description.into(),
            items: Vec::new(),
            accent_color: None,
            item_count_total: None,
        }
    }

    pub fn with_items(mut self, items: Vec<String>) -> Self {
        self.items = items;
        self
    }

    pub fn with_total(mut self, total: usize) -> Self {
        self.item_count_total = Some(total);
        self
    }

    pub fn with_color(mut self, color: impl Into<String>) -> Self {
        self.accent_color = Some(color.into());
        self
    }
}

impl Component for PhaseBlock {
    fn component_id(&self) -> &'static str {
        "phase-block"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

// ─── ChecklistPanel ──────────────────────────────────────────────────────────

/// A single row in a ChecklistPanel
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChecklistRow {
    pub label: String,
    pub diagnosis: String,
    #[serde(default)]
    pub status: Option<String>,
}

impl ChecklistRow {
    pub fn new(label: impl Into<String>, diagnosis: impl Into<String>) -> Self {
        Self {
            label: label.into(),
            diagnosis: diagnosis.into(),
            status: None,
        }
    }

    pub fn with_status(mut self, status: impl Into<String>) -> Self {
        self.status = Some(status.into());
        self
    }
}

component_catalog! {
    id: "checklist-panel",
    data: ChecklistPanel,
    template: include_str!("../../templates/components/checklist_panel.typ"),
    description: "Checklist panel with pass/fail/warning rows",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::Breakable,
}

/// Card showing label–diagnosis pairs
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChecklistPanel {
    #[serde(default)]
    pub title: Option<String>,
    pub rows: Vec<ChecklistRow>,
}

impl ChecklistPanel {
    pub fn new(rows: Vec<ChecklistRow>) -> Self {
        Self { title: None, rows }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }
}

impl Component for ChecklistPanel {
    fn component_id(&self) -> &'static str {
        "checklist-panel"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

// ─── ImpactGrid ──────────────────────────────────────────────────────────────

/// A single card inside an ImpactGrid
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImpactGridCard {
    pub label: String,
    pub headline: String,
    pub body: String,
    #[serde(default)]
    pub status: Option<String>,
    #[serde(default)]
    pub icon: Option<String>,
}

impl ImpactGridCard {
    pub fn new(
        label: impl Into<String>,
        headline: impl Into<String>,
        body: impl Into<String>,
    ) -> Self {
        Self {
            label: label.into(),
            headline: headline.into(),
            body: body.into(),
            status: None,
            icon: None,
        }
    }

    pub fn with_status(mut self, status: impl Into<String>) -> Self {
        self.status = Some(status.into());
        self
    }

    pub fn with_icon(mut self, icon: impl Into<String>) -> Self {
        self.icon = Some(icon.into());
        self
    }
}

component_catalog! {
    id: "impact-grid",
    data: ImpactGrid,
    template: include_str!("../../templates/components/impact_grid.typ"),
    description: "Grid of impact cards with title, score, and description",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Three-column impact card layout (user / risk / conversion)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ImpactGrid {
    pub user: ImpactGridCard,
    pub risk: ImpactGridCard,
    pub conversion: ImpactGridCard,
    #[serde(default)]
    pub title: Option<String>,
}

impl ImpactGrid {
    pub fn new(user: ImpactGridCard, risk: ImpactGridCard, conversion: ImpactGridCard) -> Self {
        Self {
            user,
            risk,
            conversion,
            title: None,
        }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }
}

impl Component for ImpactGrid {
    fn component_id(&self) -> &'static str {
        "impact-grid"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

// ─── SpotlightCard ───────────────────────────────────────────────────────────

/// Visual variant for a spotlight card.
#[derive(Debug, Clone, Copy, Serialize, Deserialize, Default, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SpotlightCardVariant {
    Critical,
    #[default]
    Info,
    Feature,
    Opportunity,
}

impl SpotlightCardVariant {
    fn as_str(self) -> &'static str {
        match self {
            Self::Critical => "critical",
            Self::Info => "info",
            Self::Feature => "feature",
            Self::Opportunity => "opportunity",
        }
    }
}

component_catalog! {
    id: "spotlight-card",
    data: SpotlightCard,
    template: include_str!("../../templates/components/spotlight_card.typ"),
    description: "Spotlight card with colored severity stripe and body",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// General-purpose spotlight card with left severity stripe
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpotlightCard {
    pub title: String,
    pub body: String,
    #[serde(default)]
    pub variant: Option<String>,
    #[serde(default)]
    pub eyebrow: Option<String>,
    #[serde(default)]
    pub metric: Option<String>,
    #[serde(default)]
    pub detail: Option<String>,
    #[serde(default)]
    pub action: Option<String>,
}

impl SpotlightCard {
    pub fn new(title: impl Into<String>, body: impl Into<String>) -> Self {
        Self {
            title: title.into(),
            body: body.into(),
            variant: None,
            eyebrow: None,
            metric: None,
            detail: None,
            action: None,
        }
    }

    /// Set variant from a string (legacy convenience).
    pub fn with_variant(mut self, variant: impl Into<String>) -> Self {
        self.variant = Some(variant.into());
        self
    }

    /// Set variant from the typed enum.
    pub fn variant(mut self, variant: SpotlightCardVariant) -> Self {
        self.variant = Some(variant.as_str().to_string());
        self
    }

    pub fn with_eyebrow(mut self, eyebrow: impl Into<String>) -> Self {
        self.eyebrow = Some(eyebrow.into());
        self
    }

    pub fn with_metric(mut self, metric: impl Into<String>) -> Self {
        self.metric = Some(metric.into());
        self
    }

    pub fn with_detail(mut self, detail: impl Into<String>) -> Self {
        self.detail = Some(detail.into());
        self
    }

    pub fn with_action(mut self, action: impl Into<String>) -> Self {
        self.action = Some(action.into());
        self
    }
}

impl Component for SpotlightCard {
    fn component_id(&self) -> &'static str {
        "spotlight-card"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

component_catalog! {
    id: "recommendation-card",
    data: RecommendationCard,
    template: include_str!("../../templates/components/recommendation_card.typ"),
    description: "Recommendation card with impact, effort, and priority badges",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Recommendation card
/// Lighter than Finding: recommendation + impact + effort + priority
/// For: Audit recommendations, best practices, improvements
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RecommendationCard {
    /// Recommendation title
    pub title: String,
    /// Brief description
    pub description: String,
    /// Impact level (high | medium | low)
    #[serde(default)]
    pub impact: Option<String>,
    /// Effort required (high | medium | low)
    #[serde(default)]
    pub effort: Option<String>,
    /// Priority (critical | high | medium | low)
    #[serde(default)]
    pub priority: Option<String>,
}

impl RecommendationCard {
    pub fn new(title: impl Into<String>, description: impl Into<String>) -> Self {
        Self {
            title: title.into(),
            description: description.into(),
            impact: None,
            effort: None,
            priority: None,
        }
    }

    pub fn with_impact(mut self, impact: impl Into<String>) -> Self {
        self.impact = Some(impact.into());
        self
    }

    pub fn with_effort(mut self, effort: impl Into<String>) -> Self {
        self.effort = Some(effort.into());
        self
    }

    pub fn with_priority(mut self, priority: impl Into<String>) -> Self {
        self.priority = Some(priority.into());
        self
    }
}

impl Component for RecommendationCard {
    fn component_id(&self) -> &'static str {
        "recommendation-card"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

component_catalog! {
    id: "step-card-row",
    data: StepCardRow,
    template: include_str!("../../templates/components/step_card_row.typ"),
    description: "Horizontal row of numbered step cards",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Step card row
/// Numbered steps displayed horizontally (2-4 steps)
/// For: "How it works", process overview, methodology
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StepCardRow {
    /// Step titles
    pub titles: Vec<String>,
    /// Step descriptions
    pub descriptions: Vec<String>,
    /// Number of columns (2-4, defaults to 3)
    #[serde(default = "default_step_columns")]
    pub columns: usize,
}

fn default_step_columns() -> usize {
    3
}

impl Default for StepCardRow {
    fn default() -> Self {
        Self::new()
    }
}

impl StepCardRow {
    pub fn new() -> Self {
        Self {
            titles: Vec::new(),
            descriptions: Vec::new(),
            columns: default_step_columns(),
        }
    }

    pub fn add_step(mut self, title: impl Into<String>, description: impl Into<String>) -> Self {
        self.titles.push(title.into());
        self.descriptions.push(description.into());
        self
    }

    pub fn with_columns(mut self, columns: usize) -> Self {
        self.columns = columns.clamp(2, 4);
        self
    }
}

impl Component for StepCardRow {
    fn component_id(&self) -> &'static str {
        "step-card-row"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

// ─── Diagnosis Panel ─────────────────────────────────────────────────────────

/// A single row in a DiagnosisPanel
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiagnosisRow {
    pub label: String,
    pub diagnosis: String,
    #[serde(default)]
    pub status: Option<String>,
}

impl DiagnosisRow {
    pub fn new(label: impl Into<String>, diagnosis: impl Into<String>) -> Self {
        Self {
            label: label.into(),
            diagnosis: diagnosis.into(),
            status: None,
        }
    }

    pub fn with_status(mut self, status: impl Into<String>) -> Self {
        self.status = Some(status.into());
        self
    }
}

component_catalog! {
    id: "diagnosis-panel",
    data: DiagnosisPanel,
    template: include_str!("../../templates/components/diagnosis_panel.typ"),
    description: "Diagnosis panel with findings grouped by severity",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::Breakable,
}

/// Card with label–diagnosis rows and optional status indicators
/// For: Technical overview, module diagnosis, quick health checks
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DiagnosisPanel {
    #[serde(default)]
    pub title: Option<String>,
    pub rows: Vec<DiagnosisRow>,
}

impl DiagnosisPanel {
    pub fn new(rows: Vec<DiagnosisRow>) -> Self {
        Self { title: None, rows }
    }

    pub fn with_title(mut self, title: impl Into<String>) -> Self {
        self.title = Some(title.into());
        self
    }
}

impl Component for DiagnosisPanel {
    fn component_id(&self) -> &'static str {
        "diagnosis-panel"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

// ─── Dominant Issue Spotlight ────────────────────────────────────────────────

component_catalog! {
    id: "dominant-issue-spotlight",
    data: DominantIssueSpotlight,
    template: include_str!("../../templates/components/dominant_issue_spotlight.typ"),
    description: "Full-width spotlight for the most critical finding",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Full-width spotlight for a single dominant issue
/// For: Highlighting the biggest problem in an audit report
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DominantIssueSpotlight {
    pub title: String,
    pub severity: String,
    pub body: String,
    pub user_impact: String,
    pub recommendation: String,
    #[serde(default)]
    pub eyebrow: Option<String>,
    #[serde(default)]
    pub affected_count: Option<u32>,
    /// Label for the "user impact" field. Defaults to German ("Nutzer-Wirkung")
    /// in the template when not set — pass this explicitly for non-German reports.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub label_user_impact: Option<String>,
    /// Label for the "recommendation" field. Defaults to German ("Empfehlung")
    /// in the template when not set.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub label_recommendation: Option<String>,
    /// Suffix appended after `affected_count` (e.g. "% Anteil" / "% share").
    /// Defaults to German in the template when not set.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub label_share_suffix: Option<String>,
}

impl DominantIssueSpotlight {
    pub fn new(
        title: impl Into<String>,
        severity: impl Into<String>,
        body: impl Into<String>,
        user_impact: impl Into<String>,
        recommendation: impl Into<String>,
    ) -> Self {
        Self {
            title: title.into(),
            severity: severity.into(),
            body: body.into(),
            user_impact: user_impact.into(),
            recommendation: recommendation.into(),
            eyebrow: None,
            affected_count: None,
            label_user_impact: None,
            label_recommendation: None,
            label_share_suffix: None,
        }
    }

    pub fn with_eyebrow(mut self, eyebrow: impl Into<String>) -> Self {
        self.eyebrow = Some(eyebrow.into());
        self
    }

    pub fn with_affected_count(mut self, count: u32) -> Self {
        self.affected_count = Some(count);
        self
    }

    /// Sets the user-impact/recommendation/share-suffix labels — required for
    /// a non-German report, since the template's own defaults are German.
    pub fn with_labels(
        mut self,
        label_user_impact: impl Into<String>,
        label_recommendation: impl Into<String>,
        label_share_suffix: impl Into<String>,
    ) -> Self {
        self.label_user_impact = Some(label_user_impact.into());
        self.label_recommendation = Some(label_recommendation.into());
        self.label_share_suffix = Some(label_share_suffix.into());
        self
    }
}

impl Component for DominantIssueSpotlight {
    fn component_id(&self) -> &'static str {
        "dominant-issue-spotlight"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}

// ─── Wrong/Right Block ───────────────────────────────────────────────────────

component_catalog! {
    id: "wrong-right-block",
    data: WrongRightBlock,
    template: include_str!("../../templates/components/wrong_right_block.typ"),
    description: "Wrong vs. right comparison with annotated examples",
    category: ComponentCategory::NarrativeStorytelling,
    layout_hint: LayoutHint::KeepTogether,
}

/// Before/after comparison block (wrong vs. right)
/// For: Code examples, best practice comparisons, fix demonstrations
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct WrongRightBlock {
    pub wrong: String,
    pub right: String,
    #[serde(default)]
    pub wrong_label: Option<String>,
    #[serde(default)]
    pub right_label: Option<String>,
    #[serde(default)]
    pub is_code: bool,
    #[serde(default)]
    pub note: Option<String>,
}

impl WrongRightBlock {
    pub fn new(wrong: impl Into<String>, right: impl Into<String>) -> Self {
        Self {
            wrong: wrong.into(),
            right: right.into(),
            wrong_label: None,
            right_label: None,
            is_code: false,
            note: None,
        }
    }

    pub fn code(mut self) -> Self {
        self.is_code = true;
        self
    }

    pub fn with_labels(
        mut self,
        wrong_label: impl Into<String>,
        right_label: impl Into<String>,
    ) -> Self {
        self.wrong_label = Some(wrong_label.into());
        self.right_label = Some(right_label.into());
        self
    }

    pub fn with_note(mut self, note: impl Into<String>) -> Self {
        self.note = Some(note.into());
        self
    }
}

impl Component for WrongRightBlock {
    fn component_id(&self) -> &'static str {
        "wrong-right-block"
    }
    fn to_data(&self) -> serde_json::Value {
        serde_json::to_value(self).unwrap_or_default()
    }
}