ferro-json-ui 0.2.56

JSON-based server-driven UI schema types for Ferro
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
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
//! Component catalog for JSON-UI.
//!
//! Defines the available UI components with typed props. Each component
//! uses serde's tagged enum representation so JSON includes `"type": "Card"`.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::action::Action;

/// Shared size enum for components (Button, Badge, Avatar, Input).
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Size {
    Xs,
    Sm,
    #[default]
    Default,
    Lg,
}

/// Icon placement relative to button label.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum IconPosition {
    #[default]
    Left,
    Right,
}

/// Sort direction for table columns.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SortDirection {
    #[default]
    Asc,
    Desc,
}

/// Separator orientation.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum Orientation {
    #[default]
    Horizontal,
    Vertical,
}

/// Button visual variants (aligned to shadcn/ui).
#[derive(
    Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, strum::AsRefStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum ButtonVariant {
    #[default]
    Default,
    Secondary,
    Destructive,
    Outline,
    Ghost,
    Link,
}

/// Input field types.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum InputType {
    #[default]
    Text,
    Email,
    Password,
    Number,
    Textarea,
    Hidden,
    Date,
    Time,
    Url,
    Tel,
    Search,
    File,
}

/// Alert visual variants.
#[derive(
    Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, strum::AsRefStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AlertVariant {
    #[default]
    Info,
    Success,
    Warning,
    Error,
}

/// Badge visual variants (aligned to shadcn/ui).
#[derive(
    Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, strum::AsRefStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum BadgeVariant {
    #[default]
    Default,
    Secondary,
    Destructive,
    Outline,
}

/// Text element types for semantic HTML rendering.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum TextElement {
    #[default]
    P,
    H1,
    H2,
    H3,
    Span,
    Div,
    Section,
}

/// Column display format for tables.
///
/// `Badge` cells expect the row value to be an object `{variant, label}` matching
/// [`BadgeProps`]. Other variants are display hints layered over plain cell text.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ColumnFormat {
    Date,
    DateTime,
    Currency,
    Boolean,
    Badge,
    /// Cell value is an image URL string; rendered as an `<img>` thumbnail.
    Image,
}

/// Table column definition.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Column {
    pub key: String,
    pub label: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub format: Option<ColumnFormat>,
}

/// Select option (value + label pair).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct SelectOption {
    pub value: String,
    pub label: String,
}

/// Visual variant for Card chrome.
///
/// - `Bordered` (default): `border + bg-card + shadow-sm` with `p-4`.
///   Dashboard cards in dense layouts.
/// - `Elevated`: `bg-card + shadow-md` (no border) with `p-8`.
///   Auth pages, error pages, standalone marketing cards.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum CardVariant {
    #[default]
    Bordered,
    Elevated,
}

/// Props for Card component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct CardProps {
    pub title: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Optional muted secondary line rendered immediately below the title and
    /// above the description. Pattern: name → role, customer → staff,
    /// title → category. Visually `text-sm text-text-muted`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub subtitle: Option<String>,
    /// Optional small badge text rendered alongside the title. Visually a
    /// Badge-styled pill inside the Card chrome — for status indicators,
    /// counters, countdown labels, etc. Independent of the title hierarchy.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub badge: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max_width: Option<FormMaxWidth>,
    /// IDs of footer elements (resolved against `Spec.elements`).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub footer: Vec<String>,
    #[serde(default)]
    pub variant: CardVariant,
}

/// Props for Table component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct TableProps {
    pub columns: Vec<Column>,
    pub data_path: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_actions: Option<Vec<Action>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub empty_message: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sortable: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sort_column: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sort_direction: Option<SortDirection>,
}

/// Maximum width constraint for form containers.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum FormMaxWidth {
    #[default]
    Default,
    Narrow,
    Wide,
}

/// Props for Form component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct FormProps {
    pub action: Action,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub method: Option<crate::action::HttpMethod>,
    /// Form guard type. When set, the runtime JS disables the submit button
    /// until the guard condition is met. Value: `"number-gt-0"` — at least
    /// one number input must have value > 0.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub guard: Option<String>,
    /// Optional max-width constraint for the form container.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max_width: Option<FormMaxWidth>,
    /// Optional HTML `id` attribute for the rendered `<form>`. Pair with a
    /// Button's `form` prop to submit this form from a button placed outside
    /// it (e.g. in a PageHeader actions slot).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    /// HTML form `enctype` attribute. Set to `"multipart/form-data"` for forms
    /// carrying a file input. Without this, the browser default encoding
    /// (`application/x-www-form-urlencoded`) is used and file inputs are sent
    /// as plain text rather than a multipart body.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub enctype: Option<String>,
}

/// HTML button type attribute.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum ButtonType {
    #[default]
    Button,
    Submit,
}

/// Props for Button component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ButtonProps {
    pub label: String,
    #[serde(default)]
    pub variant: ButtonVariant,
    #[serde(default)]
    pub size: Size,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub icon_position: Option<IconPosition>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub button_type: Option<ButtonType>,
    /// HTML5 `form` attribute. Lets a submit button rendered outside its
    /// target `<form>` (e.g. in a PageHeader actions slot) still submit
    /// that form, by matching the form's `id`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub form: Option<String>,
}

/// Props for Input component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct InputProps {
    /// Form field name for data binding.
    pub field: String,
    pub label: String,
    #[serde(default)]
    pub input_type: InputType,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub default_value: Option<String>,
    /// Data path for pre-filling from handler data (e.g., "/data/user/name").
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_path: Option<String>,
    /// HTML step attribute for number inputs (e.g., "any", "0.01").
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub step: Option<String>,
    /// HTML datalist id for autocomplete suggestions.
    /// When set, renders `list="..."` on the input and a companion `<datalist>`
    /// whose options come from a view data key matching this id.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub list: Option<String>,
    /// HTML `accept` attribute for `input_type = "file"`. Comma-separated MIME
    /// types or extensions (e.g. `"image/jpeg,image/png,image/webp"`). Browser-
    /// side filter hint only — server-side MIME validation is the consumer's
    /// responsibility (the spec layer does not enforce file content type).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub accept: Option<String>,
}

/// Props for RichTextEditor leaf element — rendered by the Quill 2.0.3 plugin.
///
/// The plugin emits a container div (`<div data-ferro-quill ...>`) and a hidden
/// input that receives the editor's HTML on every text-change event. The form
/// handler receives standard `field=<html>` POST data on submit.
///
/// # Security
/// The editor produces user-controlled HTML. Sanitization on submit is the
/// consumer's responsibility — handle this in the form handler before
/// persisting (e.g. via `ammonia`).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct RichTextEditorProps {
    pub field: String,
    pub label: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub default_value: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// Props for Select component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct SelectProps {
    /// Form field name for data binding.
    pub field: String,
    pub label: String,
    pub options: Vec<SelectOption>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub default_value: Option<String>,
    /// Data path for pre-filling from handler data (e.g., "/data/user/name").
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_path: Option<String>,
}

/// Props for Alert component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct AlertProps {
    pub message: String,
    #[serde(default)]
    pub variant: AlertVariant,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub title: Option<String>,
}

/// Props for Badge component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct BadgeProps {
    pub label: String,
    #[serde(default)]
    pub variant: BadgeVariant,
}

/// Props for Modal component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ModalProps {
    pub id: String,
    pub title: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub trigger_label: Option<String>,
    /// IDs of footer elements (resolved against `Spec.elements`).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub footer: Vec<String>,
}

/// Props for Text component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct TextProps {
    pub content: String,
    #[serde(default)]
    pub element: TextElement,
}

/// Props for Checkbox component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct CheckboxProps {
    /// Form field name for data binding.
    pub field: String,
    /// HTML value attribute. When set, the checkbox submits this value instead of "1".
    /// Required for multi-value checkbox groups (same name, different values).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub value: Option<String>,
    pub label: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub checked: Option<bool>,
    /// Data path for pre-filling from handler data (e.g., "/data/user/name").
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// Props for CheckboxList component — multi-select checkbox group.
///
/// Each checked option submits as `field=value`. Options may be supplied
/// statically via `options` or resolved at render time from `options_path`.
/// Pre-selected values are read from `selected_path` (a `Vec<String>`).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct CheckboxListProps {
    /// Shared form field name; each checkbox submits as `field=value`.
    pub field: String,
    /// Static options list. When empty and `options_path` is set, options are
    /// resolved from the data at render time.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub options: Vec<SelectOption>,
    /// Data path to an array of `{value, label}` objects for data-driven options.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub options_path: Option<String>,
    /// Data path to a `Vec<String>` of pre-selected values.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub selected_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// Props for Switch component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct SwitchProps {
    /// Form field name for data binding.
    pub field: String,
    pub label: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub checked: Option<bool>,
    /// Data path for pre-filling from handler data (e.g., "/data/user/name").
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_path: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
    /// Auto-submit action. When set, the switch renders inside a minimal
    /// form and submits on change.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub action: Option<Action>,
    /// When true, applies `scale-75 origin-left` CSS to the switch container
    /// for compact inline display (e.g. per-row settings toggles).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub compact: Option<bool>,
}

/// Props for Separator component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct SeparatorProps {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub orientation: Option<Orientation>,
}

/// A single item in a description list.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct DescriptionItem {
    pub label: String,
    pub value: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub format: Option<ColumnFormat>,
}

/// Props for DescriptionList component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct DescriptionListProps {
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub items: Vec<DescriptionItem>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub columns: Option<u8>,
    /// Optional data-path override of `items`. When set, the renderer
    /// resolves the array at this path and decodes each entry as a
    /// `DescriptionItem`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_path: Option<String>,
}

/// A single tab within a Tabs component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct Tab {
    pub value: String,
    pub label: String,
    /// IDs of elements rendered inside this tab's panel.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub children: Vec<String>,
}

/// Props for Tabs component.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct TabsProps {
    pub default_tab: String,
    pub tabs: Vec<Tab>,
}

/// A single item in a breadcrumb trail.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct BreadcrumbItem {
    pub label: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub url: Option<String>,
}

/// Props for Breadcrumb component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct BreadcrumbProps {
    pub items: Vec<BreadcrumbItem>,
}

/// Props for Pagination component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct PaginationProps {
    pub current_page: u32,
    pub per_page: u32,
    pub total: u32,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub base_url: Option<String>,
}

/// Props for Progress component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct ProgressProps {
    /// Percentage value (0-100).
    pub value: u8,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max: Option<u8>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub label: Option<String>,
}

/// Props for Image component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct ImageProps {
    #[serde(default)]
    pub src: String,
    pub alt: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub aspect_ratio: Option<String>,
    /// Optional label shown in a skeleton placeholder that sits behind the
    /// image. When the image fails to load (or is still being generated),
    /// the `<img>` is hidden via `onerror` and the placeholder remains
    /// visible, keeping the container at its aspect-ratio size.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub placeholder_label: Option<String>,
    /// Server-rendered inline SVG string. When set, the SVG is emitted verbatim
    /// inside a `<div aria-label="{alt}">` wrapper; no `<img>` tag is produced.
    ///
    /// # Safety
    /// Content is NOT sanitized. The SVG string is emitted into the response
    /// verbatim. Pass only server-constructed SVG (e.g. bar charts, QR codes).
    /// Do NOT pass untrusted input. `alt` is required and is HTML-escaped.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub inline_svg: Option<String>,
    /// Optional data-path override of `src`. When set, the renderer resolves
    /// the value at this path against handler data and uses it as the
    /// `<img src>`. Falls back to `src` when missing or non-string.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_path: Option<String>,
}

impl ImageProps {
    /// Convenience constructor for inline-SVG images. `src` is set to the
    /// empty string; the renderer takes the SVG path when `inline_svg` is `Some`.
    ///
    /// # Safety
    /// `svg` is emitted verbatim. See [`ImageProps::inline_svg`] for the trust model.
    pub fn inline_svg(svg: impl Into<String>, alt: impl Into<String>) -> Self {
        Self {
            src: String::new(),
            alt: alt.into(),
            aspect_ratio: None,
            placeholder_label: None,
            inline_svg: Some(svg.into()),
            data_path: None,
        }
    }
}

/// Props for Avatar component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct AvatarProps {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub src: Option<String>,
    pub alt: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub fallback: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub size: Option<Size>,
}

/// Props for Skeleton loading placeholder.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct SkeletonProps {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub width: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub height: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub rounded: Option<bool>,
}

/// Props for the `RawHtml` component — server-injected HTML island.
///
/// # Safety
/// `html` is emitted into the response VERBATIM with NO sanitization. The
/// component exists to bridge server-rendered HTML fragments (e.g. a status
/// pill, a link badge) into a v2 spec where a first-class component would
/// be over-engineering.
///
/// Sanitization is the CONSUMER's responsibility — pass only server-
/// constructed HTML, or run untrusted input through a sanitiser (e.g.
/// `ammonia`) in the handler before embedding. This mirrors
/// `RichTextEditorProps` discipline (see component.rs).
///
/// For richer widgets (interactive forms, charts, OAuth flows), use the
/// first-class plugin system (`JsonUiPlugin`) instead — see
/// `docs/src/json-ui/plugins.md`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct RawHtmlProps {
    /// Server-constructed HTML emitted verbatim. NOT sanitized.
    #[serde(default)]
    pub html: String,
}

/// Props for the `StreamText` component — SSE token stream renderer.
///
/// Connects to `sse_url` via the browser `EventSource` API and appends arriving
/// tokens as plain text nodes. The SSE endpoint MUST emit `event: done` on
/// completion to prevent `EventSource` auto-reconnect.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct StreamTextProps {
    /// URL of the server-sent-events endpoint that streams tokens.
    /// Must emit `event: done` on completion.
    #[serde(default)]
    pub sse_url: String,
    /// Text shown inside the content area before the first token arrives.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub placeholder: Option<String>,
    /// Status text shown while the stream is open.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub loading_text: Option<String>,
}

/// Toast visual variants.
#[derive(
    Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema, strum::AsRefStr,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum ToastVariant {
    #[default]
    Info,
    Success,
    Warning,
    Error,
}

/// A single item in a checklist.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct ChecklistItem {
    pub label: String,
    #[serde(default)]
    pub checked: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub href: Option<String>,
}

/// A single item in a notification dropdown.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct NotificationItem {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    pub text: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub timestamp: Option<String>,
    #[serde(default)]
    pub read: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub action_url: Option<String>,
}

/// A single navigation item in the sidebar.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct SidebarNavItem {
    pub label: String,
    pub href: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    #[serde(default)]
    pub active: bool,
    /// When true, the item renders as a muted, non-clickable `<span>`
    /// instead of an `<a>` — useful for "coming soon" placeholders.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disabled: Option<bool>,
}

/// A collapsible group in the sidebar.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct SidebarGroup {
    pub label: String,
    #[serde(default)]
    pub collapsed: bool,
    pub items: Vec<SidebarNavItem>,
}

/// Props for StatCard component (live-updatable metric card).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct StatCardProps {
    pub label: String,
    pub value: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub subtitle: Option<String>,
    /// SSE target key for live updates; maps to `data-sse-target` on the value element.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sse_target: Option<String>,
    /// Resolves the initial displayed value from handler data at render time.
    /// Format: `/segment/segment` (same JSON-pointer as `data::resolve_path`).
    /// Falls back to `value` when missing or non-string. Mirrors
    /// `ImageProps.data_path` / `DescriptionListProps.data_path`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub value_path: Option<String>,
}

/// Props for Checklist component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct ChecklistProps {
    pub title: String,
    pub items: Vec<ChecklistItem>,
    #[serde(default = "default_true")]
    pub dismissible: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub dismiss_label: Option<String>,
    /// Server-side state persistence key for this checklist.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub data_key: Option<String>,
}

fn default_true() -> bool {
    true
}

/// Props for Toast component (declarative notification intent).
///
/// The JS runtime reads data attributes from the rendered element to
/// display the toast. Timeouts and dismissal are handled client-side.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct ToastProps {
    pub message: String,
    #[serde(default)]
    pub variant: ToastVariant,
    /// Seconds before auto-dismiss. Default 5.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub timeout: Option<u32>,
    #[serde(default = "default_true")]
    pub dismissible: bool,
}

/// Props for NotificationDropdown component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct NotificationDropdownProps {
    pub notifications: Vec<NotificationItem>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub empty_text: Option<String>,
}

/// Props for Sidebar component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct SidebarProps {
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub fixed_top: Vec<SidebarNavItem>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub groups: Vec<SidebarGroup>,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub fixed_bottom: Vec<SidebarNavItem>,
}

/// Props for Header component.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct HeaderProps {
    pub business_name: String,
    /// Unread notification count for badge display.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub notification_count: Option<u32>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub user_name: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub user_avatar: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub logout_url: Option<String>,
}

/// Gap size for Grid layout.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum GapSize {
    None,
    Sm,
    #[default]
    Md,
    Lg,
    Xl,
}

/// Props for Grid component — multi-column layout.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct GridProps {
    /// Number of columns (1-12) at base (mobile) viewport.
    #[serde(default = "default_grid_columns")]
    pub columns: u8,
    /// Number of columns at md breakpoint (768px+). When set, creates a responsive grid.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub md_columns: Option<u8>,
    /// Number of columns at lg breakpoint (1024px+). Optional; falls back to md.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub lg_columns: Option<u8>,
    /// Gap between grid items.
    #[serde(default)]
    pub gap: GapSize,
    /// Enables horizontal scroll mode. Children get `min-w-[280px]` and the grid
    /// uses `grid-flow-col` auto-cols layout for Trello-like horizontal scrolling.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub scrollable: Option<bool>,
}

fn default_grid_columns() -> u8 {
    2
}

/// Props for Collapsible section — expandable `<details>`/`<summary>`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct CollapsibleProps {
    pub title: String,
    #[serde(default)]
    pub expanded: bool,
}

/// Props for EmptyState component — standardized empty view.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct EmptyStateProps {
    pub title: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub action: Option<Action>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub action_label: Option<String>,
}

/// Layout variant for form sections.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "snake_case")]
pub enum FormSectionLayout {
    #[default]
    Stacked,
    TwoColumn,
}

/// Props for FormSection component — visual grouping within forms.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct FormSectionProps {
    pub title: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    /// Optional layout variant. Defaults to stacked (single column).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub layout: Option<FormSectionLayout>,
}

/// Props for PageHeader component -- page title with optional breadcrumb and action buttons.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct PageHeaderProps {
    pub title: String,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub breadcrumb: Vec<BreadcrumbItem>,
    /// IDs of action button elements rendered to the right of the title.
    #[serde(
        default,
        deserialize_with = "deserialize_actions_lax",
        skip_serializing_if = "Vec::is_empty"
    )]
    pub actions: Vec<String>,
}

/// Props for ButtonGroup component -- horizontal button row with consistent gap.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, Default)]
pub struct ButtonGroupProps {
    /// Gap between buttons. Defaults to small spacing.
    #[serde(default)]
    pub gap: GapSize,
}

/// Props for DetailPage component -- opinionated resource-detail skeleton.
///
/// Renders a PageHeader (title + breadcrumb + actions), an info Card
/// wrapping the `info` slot IDs (typically a Badge plus a DescriptionList),
/// and `Element.children` as stacked sections below the card (tabs,
/// related-resource lists, action panels). Centralizes the visual contract
/// every dashboard detail page follows so per-page rebuilds cannot drift
/// from the canonical shape.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct DetailPageProps {
    pub title: String,
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub breadcrumb: Vec<BreadcrumbItem>,
    /// IDs of action button elements rendered to the right of the title.
    #[serde(
        default,
        deserialize_with = "deserialize_actions_lax",
        skip_serializing_if = "Vec::is_empty"
    )]
    pub actions: Vec<String>,
    /// IDs of elements rendered inside the info Card
    /// (typically a Badge and a DescriptionList). Omit to skip the card.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub info: Vec<String>,
}

/// A single action item in a dropdown menu.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct DropdownMenuAction {
    pub label: String,
    pub action: Action,
    #[serde(default)]
    pub destructive: bool,
    /// When set, this item is only emitted in a DataTable row when the row's
    /// `visible_if` field is truthy (true / non-zero number / non-empty string /
    /// non-empty array or object). An absent or falsy field hides the item —
    /// fail-closed so a typo in the view spec cannot leak an action onto every
    /// row. Outside DataTable contexts (e.g. standalone `DropdownMenu` element)
    /// the field is ignored.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub visible_if: Option<String>,
}

/// Props for DropdownMenu component — trigger button with absolutely-positioned action panel.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct DropdownMenuProps {
    pub menu_id: String,
    pub trigger_label: String,
    pub items: Vec<DropdownMenuAction>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub trigger_variant: Option<ButtonVariant>,
}

/// Props for the DataTable component — Stripe-style alternating rows with DropdownMenu per row,
/// mobile card fallback, and empty state.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct DataTableProps {
    pub columns: Vec<Column>,
    pub data_path: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_actions: Option<Vec<DropdownMenuAction>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub empty_message: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_key: Option<String>,
    /// URL pattern for row click navigation. Use `{row_key}` as placeholder.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_href: Option<String>,
}

/// Props for MediaCardGrid — a responsive card grid backed by a data array.
/// Mirrors DataTable's row_key/row_actions/data_path contract but renders
/// cards with an optional screenshot image instead of table rows.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct MediaCardGridProps {
    pub data_path: String,
    /// Key in each row object whose value becomes the card title.
    pub title_key: String,
    /// Key for the subtitle/URL line below the title.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub description_key: Option<String>,
    /// Key for the screenshot image URL. No image rendered when absent or empty.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub image_key: Option<String>,
    /// Key for the URL the image links to (opens in new tab).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub image_href_key: Option<String>,
    /// CSS aspect-ratio value for the image (default "4/5").
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub image_aspect_ratio: Option<String>,
    /// CSS object-position for the cropped image: "top" | "center" | "bottom"
    /// (or any valid object-position value). Default "center".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub image_position: Option<String>,
    /// Key for the footer badge label text.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub badge_key: Option<String>,
    /// Key for the badge variant string: "outline" | "destructive" | "default".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub badge_variant_key: Option<String>,
    /// Key used for {row_key} substitution in row_action URLs.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_key: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_actions: Option<Vec<DropdownMenuAction>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub empty_message: Option<String>,
    /// Number of columns in the grid (default 3).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub columns: Option<u8>,
}

/// Props for a single column (lane) in a KanbanBoard.
///
/// A column is structure: its `id` is the lane key matched against each
/// item's `group_by` value, and `title` is the lane header. `count` and
/// `children` are only honored by static specs that set neither
/// `KanbanBoardProps.items_path` nor `group_by`; in the data-bound path the
/// renderer computes the count and renders cards from `items_path`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct KanbanColumnProps {
    pub id: String,
    pub title: String,
    #[serde(default)]
    pub count: u32,
    /// IDs of elements rendered inside this column (static specs only).
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub children: Vec<String>,
}

/// Props for KanbanBoard — horizontal scrollable columns on desktop, tab-based
/// on mobile.
///
/// A kanban is fixed lanes plus items sorted into them by a status field.
/// `columns` is structure only (lane `id` + `title`) and is always rendered —
/// an empty lane still shows its header and a zero count. Card content is
/// data-bound: `items_path` resolves a flat array of entity objects, each
/// bucketed into the column whose `id` equals the item's `group_by` value,
/// then rendered as a card via the `card_*` / `row_*` bindings. This is the
/// same prescribed-card + field-key convention used by `DataTable` and
/// `MediaCardGrid`. For fully-custom card structure, template the cards with
/// the `$each` directive inside a `KanbanColumn` instead.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct KanbanBoardProps {
    /// Lane structure — `id` + `title`. Always rendered.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub columns: Vec<KanbanColumnProps>,
    /// JSON-Pointer to a flat array of entity objects. Each item is bucketed
    /// into the column whose `id` equals the item's `group_by` value.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub items_path: Option<String>,
    /// Field on each item that selects its lane: `column.id == item[group_by]`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub group_by: Option<String>,
    /// Item field whose value becomes the card title.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub card_title_key: Option<String>,
    /// Item field whose value becomes the card subtitle/description.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub card_description_key: Option<String>,
    /// Per-card dropdown actions. `{row_key}` / `{id}` interpolate from the
    /// item, matching `DataTable` / `MediaCardGrid`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_actions: Option<Vec<DropdownMenuAction>>,
    /// Item field used for `{row_key}` substitution in action URLs
    /// (defaults to `id`).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub row_key: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub mobile_default_column: Option<String>,
    /// Placeholder text shown inside empty lanes. When `None`, empty lanes
    /// render no placeholder (back-compat). Provide a short, neutral message —
    /// e.g. "Nessun ordine", "Nothing here".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub empty_label: Option<String>,
}

/// Props for a calendar day cell.
///
/// Renders a single day in a month grid with today highlight,
/// out-of-month muting, and event count indicator.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct CalendarCellProps {
    pub day: u8,
    #[serde(default)]
    pub is_today: bool,
    #[serde(default)]
    pub is_current_month: bool,
    #[serde(default)]
    pub event_count: u32,
    /// Optional per-event Tailwind color classes (e.g. "bg-blue-500").
    /// When non-empty, colored dots are rendered instead of plain primary dots.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub dot_colors: Vec<String>,
}

/// Visual variant for action cards.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ActionCardVariant {
    #[default]
    Default,
    Setup,
    Danger,
}

/// Props for a horizontal action card with variant-colored left border.
///
/// Renders icon + title + description + chevron in a clickable row.
/// When `href` is set, the card wraps in an `<a>` element with `aria-label`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ActionCardProps {
    pub title: String,
    pub description: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub icon: Option<String>,
    #[serde(default)]
    pub variant: ActionCardVariant,
    /// Optional navigation URL. When set, the card renders as an `<a>` element.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub href: Option<String>,
}

/// Props for a touch-friendly product tile with quantity controls.
///
/// Renders product name, price, and +/- buttons that drive a hidden input
/// via JS. Used for POS-style product selection during order creation.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ProductTileProps {
    pub product_id: String,
    pub name: String,
    pub price: String,
    pub field: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub default_quantity: Option<u32>,
}

/// Lax deserializer for PageHeader.actions. Per D-19/F6:
/// Accepts: missing field (via #[serde(default)]), null, [], empty string "",
/// and array of strings. Rejects: non-empty strings, arrays of non-strings.
/// This loosens the wire-format contract for actions only — other Vec<String>
/// ID-slot fields (e.g. CardProps.footer) remain strict.
fn deserialize_actions_lax<'de, D: serde::Deserializer<'de>>(
    d: D,
) -> Result<Vec<String>, D::Error> {
    use serde::de::Error;
    let v = serde_json::Value::deserialize(d)?;
    match v {
        serde_json::Value::Null => Ok(Vec::new()),
        serde_json::Value::String(s) if s.is_empty() => Ok(Vec::new()),
        serde_json::Value::Array(arr) => arr
            .into_iter()
            .map(|item| {
                item.as_str()
                    .map(String::from)
                    .ok_or_else(|| D::Error::custom("PageHeader.actions: expected string in array"))
            })
            .collect(),
        other => Err(D::Error::custom(format!(
            "PageHeader.actions: expected null, empty string, or array of strings; got {other:?}"
        ))),
    }
}

#[cfg(test)]
mod schema_smoke_tests {
    //! Runtime `schema_for!` smoke tests per D-32.
    //!
    //! Each test asserts that the generated JSON Schema for the given Props
    //! struct is a non-empty JSON object with a populated `properties` field.
    //! This proves the `JsonSchema` derive executes without panic on every
    //! surviving Props struct — a compile-time `#[derive(JsonSchema)]` alone
    //! does not prove the generated code runs.
    //!
    //! One `#[test]` per type for clear failure localization.

    use super::*;

    fn assert_schema_nonempty_object<T: schemars::JsonSchema>(type_label: &str) {
        let schema = schemars::schema_for!(T);
        let value = serde_json::to_value(&schema).expect("schema serializes to JSON");
        assert!(
            value.is_object(),
            "{type_label}: schema must be a JSON object"
        );
        let props = value
            .get("properties")
            .and_then(|p| p.as_object())
            .map(|o| !o.is_empty())
            .unwrap_or(false);
        assert!(
            props,
            "{type_label}: schema must have a non-empty `properties` field"
        );
    }

    #[test]
    fn schema_for_card_props_generates() {
        assert_schema_nonempty_object::<CardProps>("CardProps");
    }

    #[test]
    fn schema_for_table_props_generates() {
        assert_schema_nonempty_object::<TableProps>("TableProps");
    }

    #[test]
    fn schema_for_form_props_generates() {
        assert_schema_nonempty_object::<FormProps>("FormProps");
    }

    #[test]
    fn schema_for_button_props_generates() {
        assert_schema_nonempty_object::<ButtonProps>("ButtonProps");
    }

    #[test]
    fn schema_for_input_props_generates() {
        assert_schema_nonempty_object::<InputProps>("InputProps");
    }

    #[test]
    fn schema_for_select_props_generates() {
        assert_schema_nonempty_object::<SelectProps>("SelectProps");
    }

    #[test]
    fn schema_for_alert_props_generates() {
        assert_schema_nonempty_object::<AlertProps>("AlertProps");
    }

    #[test]
    fn schema_for_badge_props_generates() {
        assert_schema_nonempty_object::<BadgeProps>("BadgeProps");
    }

    #[test]
    fn schema_for_modal_props_generates() {
        assert_schema_nonempty_object::<ModalProps>("ModalProps");
    }

    #[test]
    fn schema_for_text_props_generates() {
        assert_schema_nonempty_object::<TextProps>("TextProps");
    }

    #[test]
    fn schema_for_checkbox_props_generates() {
        assert_schema_nonempty_object::<CheckboxProps>("CheckboxProps");
    }

    #[test]
    fn schema_for_switch_props_generates() {
        assert_schema_nonempty_object::<SwitchProps>("SwitchProps");
    }

    #[test]
    fn schema_for_separator_props_generates() {
        assert_schema_nonempty_object::<SeparatorProps>("SeparatorProps");
    }

    #[test]
    fn schema_for_description_list_props_generates() {
        assert_schema_nonempty_object::<DescriptionListProps>("DescriptionListProps");
    }

    #[test]
    fn schema_for_tab_generates() {
        assert_schema_nonempty_object::<Tab>("Tab");
    }

    #[test]
    fn schema_for_tabs_props_generates() {
        assert_schema_nonempty_object::<TabsProps>("TabsProps");
    }

    #[test]
    fn schema_for_breadcrumb_props_generates() {
        assert_schema_nonempty_object::<BreadcrumbProps>("BreadcrumbProps");
    }

    #[test]
    fn schema_for_pagination_props_generates() {
        assert_schema_nonempty_object::<PaginationProps>("PaginationProps");
    }

    #[test]
    fn schema_for_progress_props_generates() {
        assert_schema_nonempty_object::<ProgressProps>("ProgressProps");
    }

    #[test]
    fn schema_for_image_props_generates() {
        assert_schema_nonempty_object::<ImageProps>("ImageProps");
    }

    #[test]
    fn image_inline_svg_factory_roundtrips_via_serde() {
        let p = ImageProps::inline_svg("<svg/>", "alt");
        let json = serde_json::to_value(&p).expect("serialization must not fail");
        let parsed: ImageProps =
            serde_json::from_value(json).expect("deserialization must not fail");
        assert_eq!(parsed.inline_svg, Some("<svg/>".to_string()));
        assert_eq!(parsed.alt, "alt");
        assert_eq!(parsed.src, "");
    }

    #[test]
    fn schema_for_avatar_props_generates() {
        assert_schema_nonempty_object::<AvatarProps>("AvatarProps");
    }

    #[test]
    fn schema_for_skeleton_props_generates() {
        assert_schema_nonempty_object::<SkeletonProps>("SkeletonProps");
    }

    #[test]
    fn schema_for_stat_card_props_generates() {
        assert_schema_nonempty_object::<StatCardProps>("StatCardProps");
    }

    #[test]
    fn schema_for_checklist_props_generates() {
        assert_schema_nonempty_object::<ChecklistProps>("ChecklistProps");
    }

    #[test]
    fn schema_for_toast_props_generates() {
        assert_schema_nonempty_object::<ToastProps>("ToastProps");
    }

    #[test]
    fn schema_for_notification_dropdown_props_generates() {
        assert_schema_nonempty_object::<NotificationDropdownProps>("NotificationDropdownProps");
    }

    #[test]
    fn schema_for_sidebar_props_generates() {
        assert_schema_nonempty_object::<SidebarProps>("SidebarProps");
    }

    #[test]
    fn schema_for_header_props_generates() {
        assert_schema_nonempty_object::<HeaderProps>("HeaderProps");
    }

    #[test]
    fn schema_for_grid_props_generates() {
        assert_schema_nonempty_object::<GridProps>("GridProps");
    }

    #[test]
    fn schema_for_collapsible_props_generates() {
        assert_schema_nonempty_object::<CollapsibleProps>("CollapsibleProps");
    }

    #[test]
    fn schema_for_empty_state_props_generates() {
        assert_schema_nonempty_object::<EmptyStateProps>("EmptyStateProps");
    }

    #[test]
    fn schema_for_form_section_props_generates() {
        assert_schema_nonempty_object::<FormSectionProps>("FormSectionProps");
    }

    #[test]
    fn schema_for_page_header_props_generates() {
        assert_schema_nonempty_object::<PageHeaderProps>("PageHeaderProps");
    }

    #[test]
    fn schema_for_button_group_props_generates() {
        assert_schema_nonempty_object::<ButtonGroupProps>("ButtonGroupProps");
    }

    #[test]
    fn schema_for_dropdown_menu_action_generates() {
        assert_schema_nonempty_object::<DropdownMenuAction>("DropdownMenuAction");
    }

    #[test]
    fn schema_for_dropdown_menu_props_generates() {
        assert_schema_nonempty_object::<DropdownMenuProps>("DropdownMenuProps");
    }

    #[test]
    fn schema_for_data_table_props_generates() {
        assert_schema_nonempty_object::<DataTableProps>("DataTableProps");
    }

    #[test]
    fn schema_for_kanban_column_props_generates() {
        assert_schema_nonempty_object::<KanbanColumnProps>("KanbanColumnProps");
    }

    #[test]
    fn schema_for_kanban_board_props_generates() {
        assert_schema_nonempty_object::<KanbanBoardProps>("KanbanBoardProps");
    }

    #[test]
    fn schema_for_calendar_cell_props_generates() {
        assert_schema_nonempty_object::<CalendarCellProps>("CalendarCellProps");
    }

    #[test]
    fn schema_for_action_card_props_generates() {
        assert_schema_nonempty_object::<ActionCardProps>("ActionCardProps");
    }

    #[test]
    fn schema_for_product_tile_props_generates() {
        assert_schema_nonempty_object::<ProductTileProps>("ProductTileProps");
    }

    #[test]
    fn card_props_round_trips_footer() {
        let original = CardProps {
            title: "Hero".to_string(),
            description: None,
            subtitle: None,
            badge: None,
            max_width: None,
            footer: vec!["btn1".to_string(), "btn2".to_string()],
            variant: CardVariant::Bordered,
        };
        let json = serde_json::to_string(&original).unwrap();
        let parsed: CardProps = serde_json::from_str(&json).unwrap();
        assert_eq!(original.footer, parsed.footer);
    }

    #[test]
    fn tab_round_trips_children() {
        let original = Tab {
            value: "overview".to_string(),
            label: "Overview".to_string(),
            children: vec!["panel1".to_string()],
        };
        let json = serde_json::to_string(&original).unwrap();
        let parsed: Tab = serde_json::from_str(&json).unwrap();
        assert_eq!(original.children, parsed.children);
    }

    #[test]
    fn card_props_omits_empty_footer_in_json() {
        let card = CardProps {
            title: "Card".to_string(),
            description: None,
            subtitle: None,
            badge: None,
            max_width: None,
            footer: Vec::new(),
            variant: CardVariant::Bordered,
        };
        let json = serde_json::to_string(&card).unwrap();
        assert!(
            !json.contains("\"footer\""),
            "empty footer must be skipped, got: {json}"
        );
    }

    #[test]
    fn card_props_round_trips_badge() {
        let original = CardProps {
            title: "Hero".to_string(),
            description: None,
            subtitle: None,
            badge: Some("Scade tra 9m".to_string()),
            max_width: None,
            footer: Vec::new(),
            variant: CardVariant::Bordered,
        };
        let json = serde_json::to_string(&original).unwrap();
        let parsed: CardProps = serde_json::from_str(&json).unwrap();
        assert_eq!(original.badge, parsed.badge);
    }

    #[test]
    fn card_props_omits_empty_badge_in_json() {
        let card = CardProps {
            title: "Card".to_string(),
            description: None,
            subtitle: None,
            badge: None,
            max_width: None,
            footer: Vec::new(),
            variant: CardVariant::Bordered,
        };
        let json = serde_json::to_string(&card).unwrap();
        assert!(
            !json.contains("\"badge\""),
            "empty badge must be skipped, got: {json}"
        );
    }

    #[test]
    fn card_props_round_trips_subtitle() {
        let original = CardProps {
            title: "Hero".to_string(),
            description: None,
            subtitle: Some("Marco Rossi".to_string()),
            badge: None,
            max_width: None,
            footer: Vec::new(),
            variant: CardVariant::Bordered,
        };
        let json = serde_json::to_string(&original).unwrap();
        let parsed: CardProps = serde_json::from_str(&json).unwrap();
        assert_eq!(original.subtitle, parsed.subtitle);
    }

    #[test]
    fn card_props_omits_empty_subtitle_in_json() {
        let card = CardProps {
            title: "Card".to_string(),
            description: None,
            subtitle: None,
            badge: None,
            max_width: None,
            footer: Vec::new(),
            variant: CardVariant::Bordered,
        };
        let json = serde_json::to_string(&card).unwrap();
        assert!(
            !json.contains("\"subtitle\""),
            "empty subtitle must be skipped, got: {json}"
        );
    }

    #[test]
    fn card_props_schema_includes_badge() {
        let schema = schemars::schema_for!(CardProps);
        let value = serde_json::to_value(&schema).expect("schema serializes to JSON");
        let props = value
            .get("properties")
            .and_then(|p| p.as_object())
            .expect("schema has a properties object");
        assert!(
            props.contains_key("badge"),
            "CardProps schema must expose a `badge` property; got keys: {:?}",
            props.keys().collect::<Vec<_>>()
        );
        // `badge: Option<String>` — schemars 1.x emits either {"type": ["string","null"]}
        // or a {"type":"string"} entry inside a oneOf/anyOf branch. We only assert
        // presence + that the rendered schema mentions a string somewhere under
        // the badge entry, which is robust to either encoding.
        let badge_schema = props.get("badge").expect("badge entry");
        let badge_json = badge_schema.to_string();
        assert!(
            badge_json.contains("\"string\""),
            "badge schema entry must mention string type; got: {badge_json}"
        );
    }

    #[test]
    fn card_props_schema_includes_subtitle() {
        let schema = schemars::schema_for!(CardProps);
        let value = serde_json::to_value(&schema).expect("schema serializes to JSON");
        let props = value
            .get("properties")
            .and_then(|p| p.as_object())
            .expect("schema has a properties object");
        assert!(
            props.contains_key("subtitle"),
            "CardProps schema must expose a `subtitle` property; got keys: {:?}",
            props.keys().collect::<Vec<_>>()
        );
        // Same robustness note as `card_props_schema_includes_badge` —
        // `subtitle: Option<String>` may surface as type-union or oneOf depending
        // on the schemars version. Assert string is mentioned in the rendered
        // entry rather than locking down the exact null encoding.
        let subtitle_schema = props.get("subtitle").expect("subtitle entry");
        let subtitle_json = subtitle_schema.to_string();
        assert!(
            subtitle_json.contains("\"string\""),
            "subtitle schema entry must mention string type; got: {subtitle_json}"
        );
    }

    #[test]
    fn schema_for_checkbox_list_props_generates() {
        assert_schema_nonempty_object::<CheckboxListProps>("CheckboxListProps");
    }

    #[test]
    fn checkbox_list_props_serde_roundtrip() {
        let json = serde_json::json!({
            "field": "services",
            "options": [{"value": "a", "label": "Alpha"}, {"value": "b", "label": "Beta"}],
            "selected_path": "/preselected"
        });
        let parsed: CheckboxListProps = serde_json::from_value(json.clone()).expect("decode");
        assert_eq!(parsed.field, "services");
        assert_eq!(parsed.options.len(), 2);
        assert_eq!(parsed.selected_path.as_deref(), Some("/preselected"));
        let reserialized = serde_json::to_value(&parsed).expect("encode");
        // None/empty fields are omitted by serde.
        assert!(reserialized.get("label").is_none());
        assert!(reserialized.get("disabled").is_none());
    }

    #[test]
    fn schema_for_rich_text_editor_props_generates() {
        assert_schema_nonempty_object::<RichTextEditorProps>("RichTextEditorProps");
    }

    #[test]
    fn rich_text_editor_props_serde_roundtrip() {
        let json = serde_json::json!({
            "field": "body",
            "label": "Body"
        });
        let parsed: RichTextEditorProps = serde_json::from_value(json).expect("decode");
        assert_eq!(parsed.field, "body");
        assert_eq!(parsed.label, "Body");
        assert!(parsed.placeholder.is_none());
        assert!(parsed.default_value.is_none());
        assert!(parsed.data_path.is_none());
        assert!(parsed.error.is_none());
        let reserialized = serde_json::to_value(&parsed).expect("encode");
        // Optional None fields are omitted.
        assert!(reserialized.get("placeholder").is_none());
        assert!(reserialized.get("error").is_none());
    }
}

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

    /// Assert AsRef<str> matches serde JSON wire format for every variant of
    /// AlertVariant, BadgeVariant, ButtonVariant, and ToastVariant.
    /// Threat T-162-08-01: strum and serde must agree on every snake_case string.
    #[test]
    fn variant_enums_strum_matches_serde_wire_format() {
        fn check<T: AsRef<str> + serde::Serialize>(variants: &[T], label: &str) {
            for v in variants {
                let json = serde_json::to_string(v).expect("serialize");
                let json_stripped = json.trim_matches('"');
                assert_eq!(
                    v.as_ref(),
                    json_stripped,
                    "strum AsRefStr drifted from serde for {label} variant"
                );
            }
        }
        check(
            &[
                AlertVariant::Info,
                AlertVariant::Success,
                AlertVariant::Warning,
                AlertVariant::Error,
            ],
            "AlertVariant",
        );
        check(
            &[
                BadgeVariant::Default,
                BadgeVariant::Secondary,
                BadgeVariant::Destructive,
                BadgeVariant::Outline,
            ],
            "BadgeVariant",
        );
        check(
            &[
                ButtonVariant::Default,
                ButtonVariant::Secondary,
                ButtonVariant::Destructive,
                ButtonVariant::Outline,
                ButtonVariant::Ghost,
                ButtonVariant::Link,
            ],
            "ButtonVariant",
        );
        check(
            &[
                ToastVariant::Info,
                ToastVariant::Success,
                ToastVariant::Warning,
                ToastVariant::Error,
            ],
            "ToastVariant",
        );
    }

    #[test]
    fn alert_variant_as_ref_str_matches_wire_format() {
        assert_eq!(AlertVariant::Success.as_ref(), "success");
        assert_eq!(AlertVariant::Warning.as_ref(), "warning");
        assert_eq!(AlertVariant::Info.as_ref(), "info");
        assert_eq!(AlertVariant::Error.as_ref(), "error");
    }
}

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

    #[test]
    fn card_variant_default_is_bordered() {
        assert_eq!(CardVariant::default(), CardVariant::Bordered);
    }

    #[test]
    fn card_variant_serializes_snake_case() {
        assert_eq!(
            serde_json::to_value(CardVariant::Bordered).unwrap(),
            serde_json::json!("bordered")
        );
        assert_eq!(
            serde_json::to_value(CardVariant::Elevated).unwrap(),
            serde_json::json!("elevated")
        );
    }

    #[test]
    fn card_variant_deserializes_snake_case() {
        assert_eq!(
            serde_json::from_value::<CardVariant>(serde_json::json!("bordered")).unwrap(),
            CardVariant::Bordered
        );
        assert_eq!(
            serde_json::from_value::<CardVariant>(serde_json::json!("elevated")).unwrap(),
            CardVariant::Elevated
        );
    }

    #[test]
    fn card_props_without_variant_defaults_to_bordered() {
        let v = serde_json::json!({"title": "x"});
        let p: CardProps = serde_json::from_value(v).unwrap();
        assert_eq!(p.variant, CardVariant::Bordered);
    }

    #[test]
    fn card_props_with_elevated_variant() {
        let v = serde_json::json!({"title": "x", "variant": "elevated"});
        let p: CardProps = serde_json::from_value(v).unwrap();
        assert_eq!(p.variant, CardVariant::Elevated);
    }

    #[test]
    fn card_props_roundtrip_preserves_variant() {
        let p = CardProps {
            title: "x".into(),
            description: None,
            subtitle: None,
            badge: None,
            max_width: None,
            footer: vec![],
            variant: CardVariant::Elevated,
        };
        let j = serde_json::to_value(&p).unwrap();
        let back: CardProps = serde_json::from_value(j).unwrap();
        assert_eq!(back.variant, CardVariant::Elevated);
    }
}

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

    #[test]
    fn kanban_board_props_serde_static_columns() {
        let v = serde_json::json!({
            "columns": [{"title": "To Do", "id": "todo", "count": 0}]
        });
        let p: KanbanBoardProps = serde_json::from_value(v).unwrap();
        assert_eq!(p.columns.len(), 1);
        assert!(p.items_path.is_none());
        assert!(p.group_by.is_none());
    }

    #[test]
    fn kanban_board_props_serde_data_bound() {
        let v = serde_json::json!({
            "columns": [{"title": "Open", "id": "open"}],
            "items_path": "/data/order",
            "group_by": "status",
            "card_title_key": "name"
        });
        let p: KanbanBoardProps = serde_json::from_value(v).unwrap();
        assert_eq!(p.columns.len(), 1);
        assert_eq!(p.items_path.as_deref(), Some("/data/order"));
        assert_eq!(p.group_by.as_deref(), Some("status"));
        assert_eq!(p.card_title_key.as_deref(), Some("name"));
    }

    #[test]
    fn kanban_board_props_serde_neither() {
        let v = serde_json::json!({});
        let p: KanbanBoardProps = serde_json::from_value(v).unwrap();
        assert!(p.columns.is_empty());
        assert!(p.items_path.is_none());
        assert!(p.group_by.is_none());
    }

    #[test]
    fn kanban_board_props_empty_columns_skipped_on_serialize() {
        let p = KanbanBoardProps {
            columns: vec![],
            items_path: Some("/data/order".into()),
            group_by: Some("status".into()),
            card_title_key: None,
            card_description_key: None,
            row_actions: None,
            row_key: None,
            mobile_default_column: None,
            empty_label: None,
        };
        let j = serde_json::to_value(&p).unwrap();
        assert!(
            j.get("columns").is_none(),
            "empty columns must be skipped, got: {j}"
        );
        assert_eq!(
            j.get("items_path").and_then(|v| v.as_str()),
            Some("/data/order")
        );
    }
}

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

    #[test]
    fn page_header_actions_missing_field() {
        let v = serde_json::json!({"title": "X"});
        let p: PageHeaderProps = serde_json::from_value(v).unwrap();
        assert!(p.actions.is_empty());
    }

    #[test]
    fn page_header_actions_null() {
        let v = serde_json::json!({"title": "X", "actions": null});
        let p: PageHeaderProps = serde_json::from_value(v).unwrap();
        assert!(p.actions.is_empty());
    }

    #[test]
    fn page_header_actions_empty_string() {
        let v = serde_json::json!({"title": "X", "actions": ""});
        let p: PageHeaderProps = serde_json::from_value(v).unwrap();
        assert!(p.actions.is_empty());
    }

    #[test]
    fn page_header_actions_empty_array() {
        let v = serde_json::json!({"title": "X", "actions": []});
        let p: PageHeaderProps = serde_json::from_value(v).unwrap();
        assert!(p.actions.is_empty());
    }

    #[test]
    fn page_header_actions_non_empty_array() {
        let v = serde_json::json!({"title": "X", "actions": ["a", "b"]});
        let p: PageHeaderProps = serde_json::from_value(v).unwrap();
        assert_eq!(p.actions, vec!["a".to_string(), "b".to_string()]);
    }

    #[test]
    fn page_header_actions_non_empty_string_rejected() {
        let v = serde_json::json!({"title": "X", "actions": "not-empty"});
        let result: Result<PageHeaderProps, _> = serde_json::from_value(v);
        assert!(result.is_err(), "non-empty string must be rejected");
    }

    #[test]
    fn page_header_actions_non_string_array_rejected() {
        let v = serde_json::json!({"title": "X", "actions": [1, 2, 3]});
        let result: Result<PageHeaderProps, _> = serde_json::from_value(v);
        assert!(result.is_err(), "array of non-strings must be rejected");
    }
}