blaeck 0.4.0

A component-based terminal UI framework for Rust
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
//! Box component - a container with optional border and layout properties.
//!
//! **Study this component first** when learning how Blaeck components work.
//! It demonstrates all the key patterns: props struct, builder methods, Component trait.
//!
//! The Box component is the primary container component in Blaeck, similar to
//! the Box component in Ink. It supports flexbox layout and optional borders.
//!
//! ## When to use Box
//!
//! - Grouping related elements together
//! - Adding borders or padding around content
//! - Creating row/column layouts with flexbox
//! - Controlling spacing with gap, margin, padding
//!
//! ## See also
//!
//! - [`Spacer`](super::Spacer) — Fills available space (use inside Box)
//! - [`Text`](super::Text) — Text content (common Box child)
//! - [`Modal`](super::Modal) — Pre-styled dialog boxes (built on Box)
//!
//! # Stable Layout Patterns
//!
//! When building multi-phase UIs (welcome → loading → results), maintain a **stable layout
//! structure** across states. This prevents jarring visual shifts when content changes.
//!
//! ## Bad: Different layouts per phase
//!
//! ```ignore
//! // DON'T DO THIS - causes layout shifts
//! match state.phase {
//!     Phase::Welcome => build_welcome_ui(),    // has banner
//!     Phase::Loading => build_loading_ui(),    // no banner, different structure!
//! }
//! ```
//!
//! ## Good: Stable structure, dynamic content
//!
//! ```ignore
//! // DO THIS - stable layout, content updates in place
//! Element::node::<Box>(BoxProps::column(), vec![
//!     build_header(&state),           // always present, text changes
//!     build_content(&state),          // always present, content changes
//!     build_progress(&state),         // always present, hidden when not needed
//!     build_footer(&state),           // always present, instructions change
//! ])
//! ```
//!
//! ## Using visibility to reserve space
//!
//! Use `visible: false` to hide content while preserving its layout space:
//!
//! ```ignore
//! Element::node::<Box>(
//!     BoxProps::column()
//!         .with_visible(state.phase == Phase::Loading),  // invisible until loading
//!     vec![progress_bar]
//! )
//! ```
//!
//! This is similar to CSS `visibility: hidden` - the element takes up space but
//! renders nothing, preventing layout shifts when it appears.

use crate::element::{Component, Element};
use crate::layout::{
    AlignContent, AlignItems, AlignSelf, Display, FlexDirection, FlexWrap, GridAutoFlow,
    GridPlacement, JustifyContent, LayoutStyle, Overflow, Position, TrackSize,
};
use crate::style::Color;

/// Border character set for drawing box borders.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BorderChars {
    /// Top-left corner character
    pub top_left: char,
    /// Top-right corner character
    pub top_right: char,
    /// Bottom-left corner character
    pub bottom_left: char,
    /// Bottom-right corner character
    pub bottom_right: char,
    /// Horizontal border character
    pub horizontal: char,
    /// Vertical border character
    pub vertical: char,
}

impl Default for BorderChars {
    fn default() -> Self {
        BorderStyle::Single.chars()
    }
}

/// Border style for the Box component.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BorderStyle {
    /// No border
    #[default]
    None,
    /// Single line border: ┌─┐│└─┘
    Single,
    /// Double line border: ╔═╗║╚═╝
    Double,
    /// Rounded corners: ╭─╮│╰─╯
    Round,
    /// Bold line border: ┏━┓┃┗━┛
    Bold,
    /// Classic ASCII border: +-+|+-+
    Classic,
    /// Custom border characters
    Custom(BorderChars),
}

impl BorderStyle {
    /// Get the border characters for this style.
    pub fn chars(self) -> BorderChars {
        match self {
            BorderStyle::None => BorderChars {
                top_left: ' ',
                top_right: ' ',
                bottom_left: ' ',
                bottom_right: ' ',
                horizontal: ' ',
                vertical: ' ',
            },
            BorderStyle::Single => BorderChars {
                top_left: '',
                top_right: '',
                bottom_left: '',
                bottom_right: '',
                horizontal: '',
                vertical: '',
            },
            BorderStyle::Double => BorderChars {
                top_left: '',
                top_right: '',
                bottom_left: '',
                bottom_right: '',
                horizontal: '',
                vertical: '',
            },
            BorderStyle::Round => BorderChars {
                top_left: '',
                top_right: '',
                bottom_left: '',
                bottom_right: '',
                horizontal: '',
                vertical: '',
            },
            BorderStyle::Bold => BorderChars {
                top_left: '',
                top_right: '',
                bottom_left: '',
                bottom_right: '',
                horizontal: '',
                vertical: '',
            },
            BorderStyle::Classic => BorderChars {
                top_left: '+',
                top_right: '+',
                bottom_left: '+',
                bottom_right: '+',
                horizontal: '-',
                vertical: '|',
            },
            BorderStyle::Custom(chars) => chars,
        }
    }

    /// Returns true if this border style has a visible border.
    pub fn has_border(self) -> bool {
        !matches!(self, BorderStyle::None)
    }
}

/// Per-side border visibility configuration.
#[derive(Debug, Clone, Copy, Default)]
pub struct BorderSides {
    /// Show top border
    pub top: bool,
    /// Show bottom border
    pub bottom: bool,
    /// Show left border
    pub left: bool,
    /// Show right border
    pub right: bool,
}

impl BorderSides {
    /// All sides visible (default when border_style is set).
    pub fn all() -> Self {
        Self {
            top: true,
            bottom: true,
            left: true,
            right: true,
        }
    }

    /// No sides visible.
    pub fn none() -> Self {
        Self {
            top: false,
            bottom: false,
            left: false,
            right: false,
        }
    }

    /// Only horizontal borders (top and bottom).
    pub fn horizontal() -> Self {
        Self {
            top: true,
            bottom: true,
            left: false,
            right: false,
        }
    }

    /// Only vertical borders (left and right).
    pub fn vertical() -> Self {
        Self {
            top: false,
            bottom: false,
            left: true,
            right: true,
        }
    }

    /// Only top border.
    pub fn top_only() -> Self {
        Self {
            top: true,
            bottom: false,
            left: false,
            right: false,
        }
    }

    /// Only bottom border.
    pub fn bottom_only() -> Self {
        Self {
            top: false,
            bottom: true,
            left: false,
            right: false,
        }
    }
}

/// Per-side border colors.
#[derive(Debug, Clone, Copy, Default)]
pub struct BorderColors {
    /// Color for top border
    pub top: Option<Color>,
    /// Color for bottom border
    pub bottom: Option<Color>,
    /// Color for left border
    pub left: Option<Color>,
    /// Color for right border
    pub right: Option<Color>,
}

impl BorderColors {
    /// Create border colors with the same color on all sides.
    pub fn all(color: Color) -> Self {
        Self {
            top: Some(color),
            bottom: Some(color),
            left: Some(color),
            right: Some(color),
        }
    }

    /// Get the color for the top border, falling back to the provided default.
    pub fn top_or(&self, default: Option<Color>) -> Option<Color> {
        self.top.or(default)
    }

    /// Get the color for the bottom border, falling back to the provided default.
    pub fn bottom_or(&self, default: Option<Color>) -> Option<Color> {
        self.bottom.or(default)
    }

    /// Get the color for the left border, falling back to the provided default.
    pub fn left_or(&self, default: Option<Color>) -> Option<Color> {
        self.left.or(default)
    }

    /// Get the color for the right border, falling back to the provided default.
    pub fn right_or(&self, default: Option<Color>) -> Option<Color> {
        self.right.or(default)
    }
}

/// Properties for the Box component.
///
/// # Units
///
/// All spacing values (width, height, padding, margin, gap) use terminal units:
/// - **Horizontal values** (width, padding_left/right, margin_left/right): characters
/// - **Vertical values** (height, padding_top/bottom, margin_top/bottom, gap in Column): lines
///
/// For example, `gap: 1.0` in a `FlexDirection::Column` layout adds 1 empty line between children.
///
/// # Quick Start
///
/// ```ignore
/// // Compact column layout (no spacing)
/// BoxProps::column()
///
/// // Row with gap
/// BoxProps::row().with_gap(1.0)
///
/// // Column with border
/// BoxProps::column().with_border(BorderStyle::Round)
/// ```
#[derive(Debug, Clone)]
pub struct BoxProps {
    // Layout properties
    /// Width of the box in terminal characters.
    pub width: Option<f32>,
    /// Height of the box in terminal lines.
    pub height: Option<f32>,
    /// Minimum width constraint (characters)
    pub min_width: Option<f32>,
    /// Minimum height constraint (lines)
    pub min_height: Option<f32>,
    /// Maximum width constraint (characters)
    pub max_width: Option<f32>,
    /// Maximum height constraint (lines)
    pub max_height: Option<f32>,
    /// Flex direction for child layout
    pub flex_direction: FlexDirection,
    /// How much this box should grow relative to siblings
    pub flex_grow: f32,
    /// How much this box should shrink relative to siblings
    pub flex_shrink: f32,
    /// Padding on all sides (characters horizontally, lines vertically)
    pub padding: f32,
    /// Padding on the left side (characters)
    pub padding_left: Option<f32>,
    /// Padding on the right side (characters)
    pub padding_right: Option<f32>,
    /// Padding on the top side (lines)
    pub padding_top: Option<f32>,
    /// Padding on the bottom side (lines)
    pub padding_bottom: Option<f32>,
    /// Margin on all sides (characters horizontally, lines vertically)
    pub margin: f32,
    /// Margin on the left side (characters)
    pub margin_left: Option<f32>,
    /// Margin on the right side (characters)
    pub margin_right: Option<f32>,
    /// Margin on the top side (lines)
    pub margin_top: Option<f32>,
    /// Margin on the bottom side (lines)
    pub margin_bottom: Option<f32>,
    /// Gap between children in terminal units.
    ///
    /// - In `FlexDirection::Column`: gap is in **lines** (1.0 = 1 empty line between children)
    /// - In `FlexDirection::Row`: gap is in **characters** (1.0 = 1 space between children)
    ///
    /// Default is `0.0` for compact layouts. Add gap explicitly when spacing is needed.
    pub gap: f32,
    /// How to align items along cross axis
    pub align_items: Option<AlignItems>,
    /// How to align this box (overrides parent's align_items)
    pub align_self: Option<AlignSelf>,
    /// How to align content
    pub align_content: Option<AlignContent>,
    /// How to justify content along main axis
    pub justify_content: Option<JustifyContent>,

    // === Taffy 0.9 Features ===
    /// Display mode (Flex, Grid, Block, None)
    pub display: Display,
    /// Position type (Relative, Absolute)
    pub position: Position,
    /// Flex wrap behavior
    pub flex_wrap: FlexWrap,
    /// Initial flex size before grow/shrink
    pub flex_basis: Option<f32>,
    /// Aspect ratio (width / height)
    pub aspect_ratio: Option<f32>,
    /// Overflow behavior on X axis
    pub overflow_x: Overflow,
    /// Overflow behavior on Y axis
    pub overflow_y: Overflow,

    // Inset (for absolute positioning)
    /// Top inset for absolute positioning
    pub inset_top: Option<f32>,
    /// Bottom inset for absolute positioning
    pub inset_bottom: Option<f32>,
    /// Left inset for absolute positioning
    pub inset_left: Option<f32>,
    /// Right inset for absolute positioning
    pub inset_right: Option<f32>,

    // CSS Grid properties
    /// Grid template columns (for Display::Grid)
    pub grid_template_columns: Vec<TrackSize>,
    /// Grid template rows (for Display::Grid)
    pub grid_template_rows: Vec<TrackSize>,
    /// Grid auto flow direction
    pub grid_auto_flow: GridAutoFlow,
    /// Grid column placement for this item
    pub grid_column: GridPlacement,
    /// Grid row placement for this item
    pub grid_row: GridPlacement,

    // Border properties
    /// Border style
    pub border_style: BorderStyle,
    /// Border color for all sides (can be overridden by per-side colors)
    pub border_color: Option<Color>,
    /// Per-side border colors (overrides border_color for specific sides)
    pub border_colors: BorderColors,
    /// Which sides to show borders on (None = all sides when border_style is set)
    pub border_sides: Option<BorderSides>,
    /// Dim the border color (renders border with dim style)
    pub border_dim: bool,

    // Background
    /// Background color (optional)
    pub background_color: Option<Color>,

    // Visibility
    /// Whether this box is visible.
    ///
    /// When `false`, the box still takes up space in the layout but renders nothing.
    /// This is useful for reserving space for elements that appear/disappear,
    /// preventing layout shifts. Similar to CSS `visibility: hidden`.
    ///
    /// Default is `true`.
    pub visible: bool,
}

impl Default for BoxProps {
    fn default() -> Self {
        Self {
            width: None,
            height: None,
            min_width: None,
            min_height: None,
            max_width: None,
            max_height: None,
            flex_direction: FlexDirection::default(),
            flex_grow: 0.0,
            flex_shrink: 0.0,
            padding: 0.0,
            padding_left: None,
            padding_right: None,
            padding_top: None,
            padding_bottom: None,
            margin: 0.0,
            margin_left: None,
            margin_right: None,
            margin_top: None,
            margin_bottom: None,
            gap: 0.0,
            align_items: None,
            align_self: None,
            align_content: None,
            justify_content: None,
            // Taffy 0.9 features
            display: Display::Flex,
            position: Position::Relative,
            flex_wrap: FlexWrap::NoWrap,
            flex_basis: None,
            aspect_ratio: None,
            overflow_x: Overflow::Visible,
            overflow_y: Overflow::Visible,
            inset_top: None,
            inset_bottom: None,
            inset_left: None,
            inset_right: None,
            grid_template_columns: Vec::new(),
            grid_template_rows: Vec::new(),
            grid_auto_flow: GridAutoFlow::Row,
            grid_column: GridPlacement::auto(),
            grid_row: GridPlacement::auto(),
            border_style: BorderStyle::default(),
            border_color: None,
            border_colors: BorderColors::default(),
            border_sides: None,
            border_dim: false,
            background_color: None,
            visible: true, // Default to visible
        }
    }
}

impl BoxProps {
    /// Create a new BoxProps with default values.
    pub fn new() -> Self {
        Self::default()
    }

    // ============ Layout Presets ============

    /// Create a column layout (children stacked vertically).
    ///
    /// This is the most common layout for CLI apps. Equivalent to:
    /// ```ignore
    /// BoxProps { flex_direction: FlexDirection::Column, ..Default::default() }
    /// ```
    pub fn column() -> Self {
        Self {
            flex_direction: FlexDirection::Column,
            ..Default::default()
        }
    }

    /// Create a row layout (children arranged horizontally).
    ///
    /// Equivalent to:
    /// ```ignore
    /// BoxProps { flex_direction: FlexDirection::Row, ..Default::default() }
    /// ```
    pub fn row() -> Self {
        Self {
            flex_direction: FlexDirection::Row,
            ..Default::default()
        }
    }

    // ============ Builder Methods ============

    /// Set the gap between children.
    ///
    /// - In column layout: gap is in lines (1.0 = 1 empty line)
    /// - In row layout: gap is in characters (1.0 = 1 space)
    pub fn with_gap(mut self, gap: f32) -> Self {
        self.gap = gap;
        self
    }

    /// Set padding on all sides.
    pub fn with_padding(mut self, padding: f32) -> Self {
        self.padding = padding;
        self
    }

    /// Set the border style.
    pub fn with_border(mut self, style: BorderStyle) -> Self {
        self.border_style = style;
        self
    }

    /// Set the border style and color.
    pub fn with_border_color(mut self, style: BorderStyle, color: Color) -> Self {
        self.border_style = style;
        self.border_color = Some(color);
        self
    }

    /// Set the width.
    pub fn with_width(mut self, width: f32) -> Self {
        self.width = Some(width);
        self
    }

    /// Set the height.
    pub fn with_height(mut self, height: f32) -> Self {
        self.height = Some(height);
        self
    }

    /// Set visibility. When false, the box takes up space but renders nothing.
    pub fn with_visible(mut self, visible: bool) -> Self {
        self.visible = visible;
        self
    }

    /// Hide this box (still takes up space in layout).
    pub fn hidden(mut self) -> Self {
        self.visible = false;
        self
    }

    // ============ Query Methods ============

    /// Get the effective border sides (which sides should show a border).
    pub fn effective_border_sides(&self) -> BorderSides {
        if !self.border_style.has_border() {
            return BorderSides::none();
        }
        self.border_sides.unwrap_or_else(BorderSides::all)
    }

    /// Get the color for the top border.
    pub fn top_border_color(&self) -> Option<Color> {
        self.border_colors.top_or(self.border_color)
    }

    /// Get the color for the bottom border.
    pub fn bottom_border_color(&self) -> Option<Color> {
        self.border_colors.bottom_or(self.border_color)
    }

    /// Get the color for the left border.
    pub fn left_border_color(&self) -> Option<Color> {
        self.border_colors.left_or(self.border_color)
    }

    /// Get the color for the right border.
    pub fn right_border_color(&self) -> Option<Color> {
        self.border_colors.right_or(self.border_color)
    }

    /// Convert these props to a LayoutStyle.
    pub fn to_layout_style(&self) -> LayoutStyle {
        let sides = self.effective_border_sides();

        // Calculate per-side border sizes based on visibility
        let border_top: f32 = if sides.top { 1.0 } else { 0.0 };
        let border_bottom: f32 = if sides.bottom { 1.0 } else { 0.0 };
        let border_left: f32 = if sides.left { 1.0 } else { 0.0 };
        let border_right: f32 = if sides.right { 1.0 } else { 0.0 };

        // For the base padding, we use the maximum border size if no per-side padding is set
        let max_border = border_top
            .max(border_bottom)
            .max(border_left)
            .max(border_right);

        LayoutStyle {
            // Sizing
            width: self.width,
            height: self.height,
            min_width: self.min_width,
            min_height: self.min_height,
            max_width: self.max_width,
            max_height: self.max_height,

            // Flexbox
            flex_direction: self.flex_direction,
            flex_grow: self.flex_grow,
            flex_shrink: self.flex_shrink,

            // Padding (add border to padding based on which sides have borders)
            padding: self.padding + max_border,
            padding_left: Some(self.padding_left.unwrap_or(self.padding) + border_left),
            padding_right: Some(self.padding_right.unwrap_or(self.padding) + border_right),
            padding_top: Some(self.padding_top.unwrap_or(self.padding) + border_top),
            padding_bottom: Some(self.padding_bottom.unwrap_or(self.padding) + border_bottom),

            // Margin
            margin: self.margin,
            margin_left: self.margin_left,
            margin_right: self.margin_right,
            margin_top: self.margin_top,
            margin_bottom: self.margin_bottom,

            // Gap
            gap: self.gap,

            // Alignment
            align_items: self.align_items,
            align_self: self.align_self,
            align_content: self.align_content,
            justify_content: self.justify_content,

            // Taffy 0.9 features
            display: self.display,
            position: self.position,
            flex_wrap: self.flex_wrap,
            flex_basis: self.flex_basis,
            aspect_ratio: self.aspect_ratio,
            overflow_x: self.overflow_x,
            overflow_y: self.overflow_y,
            inset_top: self.inset_top,
            inset_bottom: self.inset_bottom,
            inset_left: self.inset_left,
            inset_right: self.inset_right,
            grid_template_columns: self.grid_template_columns.clone(),
            grid_template_rows: self.grid_template_rows.clone(),
            grid_auto_columns: Vec::new(),
            grid_auto_rows: Vec::new(),
            grid_auto_flow: self.grid_auto_flow,
            grid_column: self.grid_column.clone(),
            grid_row: self.grid_row.clone(),

            // Use defaults for remaining fields
            ..Default::default()
        }
    }
}

/// A container component with flexbox layout and optional border.
///
/// Box is the primary building block for layouts in Blaeck. It wraps its
/// children and can optionally display a border around them.
///
/// # Examples
///
/// ```ignore
/// // Create a box with a border
/// Element::node::<Box>(BoxProps {
///     border_style: BorderStyle::Single,
///     padding: 1.0,
///     ..Default::default()
/// }, children)
/// ```
pub struct Box;

impl Component for Box {
    type Props = BoxProps;

    fn render(_props: &Self::Props) -> Element {
        // Box doesn't render its own content directly - it just provides
        // layout and border info. The actual rendering happens in the
        // Ink runtime which uses the layout_style and border_style from props.
        // For now, we return an empty element since children are handled separately.
        Element::empty()
    }
}

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

    #[test]
    fn test_border_chars_default() {
        let chars = BorderChars::default();
        assert_eq!(chars.top_left, '');
    }

    #[test]
    fn test_border_style_has_border() {
        assert!(!BorderStyle::None.has_border());
        assert!(BorderStyle::Single.has_border());
        assert!(BorderStyle::Double.has_border());
        assert!(BorderStyle::Round.has_border());
        assert!(BorderStyle::Bold.has_border());
        assert!(BorderStyle::Classic.has_border());
    }

    #[test]
    fn test_box_props_to_layout_style() {
        let props = BoxProps {
            width: Some(80.0),
            height: Some(24.0),
            flex_direction: FlexDirection::Row,
            padding: 2.0,
            ..Default::default()
        };
        let layout = props.to_layout_style();
        assert_eq!(layout.width, Some(80.0));
        assert_eq!(layout.height, Some(24.0));
        assert_eq!(layout.flex_direction, FlexDirection::Row);
        assert_eq!(layout.padding, 2.0);
    }

    #[test]
    fn test_box_props_with_border_adds_to_padding() {
        let props = BoxProps {
            border_style: BorderStyle::Single,
            padding: 1.0,
            ..Default::default()
        };
        let layout = props.to_layout_style();
        // Padding should be 1.0 (user padding) + 1.0 (border) = 2.0
        assert_eq!(layout.padding, 2.0);
    }

    #[test]
    fn test_box_props_without_border() {
        let props = BoxProps {
            border_style: BorderStyle::None,
            padding: 1.0,
            ..Default::default()
        };
        let layout = props.to_layout_style();
        // Padding should just be 1.0 (no border)
        assert_eq!(layout.padding, 1.0);
    }

    #[test]
    fn test_border_sides_all() {
        let sides = BorderSides::all();
        assert!(sides.top);
        assert!(sides.bottom);
        assert!(sides.left);
        assert!(sides.right);
    }

    #[test]
    fn test_border_sides_none() {
        let sides = BorderSides::none();
        assert!(!sides.top);
        assert!(!sides.bottom);
        assert!(!sides.left);
        assert!(!sides.right);
    }

    #[test]
    fn test_border_sides_horizontal() {
        let sides = BorderSides::horizontal();
        assert!(sides.top);
        assert!(sides.bottom);
        assert!(!sides.left);
        assert!(!sides.right);
    }

    #[test]
    fn test_border_sides_vertical() {
        let sides = BorderSides::vertical();
        assert!(!sides.top);
        assert!(!sides.bottom);
        assert!(sides.left);
        assert!(sides.right);
    }

    #[test]
    fn test_border_sides_top_only() {
        let sides = BorderSides::top_only();
        assert!(sides.top);
        assert!(!sides.bottom);
        assert!(!sides.left);
        assert!(!sides.right);
    }

    #[test]
    fn test_border_sides_bottom_only() {
        let sides = BorderSides::bottom_only();
        assert!(!sides.top);
        assert!(sides.bottom);
        assert!(!sides.left);
        assert!(!sides.right);
    }

    #[test]
    fn test_border_colors_all() {
        let colors = BorderColors::all(Color::Red);
        assert_eq!(colors.top, Some(Color::Red));
        assert_eq!(colors.bottom, Some(Color::Red));
        assert_eq!(colors.left, Some(Color::Red));
        assert_eq!(colors.right, Some(Color::Red));
    }

    #[test]
    fn test_border_colors_default() {
        let colors = BorderColors::default();
        assert!(colors.top.is_none());
        assert!(colors.bottom.is_none());
        assert!(colors.left.is_none());
        assert!(colors.right.is_none());
    }

    #[test]
    fn test_border_colors_fallback() {
        let colors = BorderColors {
            top: Some(Color::Red),
            ..Default::default()
        };
        assert_eq!(colors.top_or(Some(Color::Blue)), Some(Color::Red));
        assert_eq!(colors.bottom_or(Some(Color::Blue)), Some(Color::Blue));
    }

    #[test]
    fn test_box_props_effective_border_sides_default() {
        let props = BoxProps {
            border_style: BorderStyle::Single,
            ..Default::default()
        };
        let sides = props.effective_border_sides();
        assert!(sides.top);
        assert!(sides.bottom);
        assert!(sides.left);
        assert!(sides.right);
    }

    #[test]
    fn test_box_props_effective_border_sides_custom() {
        let props = BoxProps {
            border_style: BorderStyle::Single,
            border_sides: Some(BorderSides::horizontal()),
            ..Default::default()
        };
        let sides = props.effective_border_sides();
        assert!(sides.top);
        assert!(sides.bottom);
        assert!(!sides.left);
        assert!(!sides.right);
    }

    #[test]
    fn test_box_props_effective_border_sides_no_border() {
        let props = BoxProps {
            border_style: BorderStyle::None,
            border_sides: Some(BorderSides::all()),
            ..Default::default()
        };
        let sides = props.effective_border_sides();
        // Should return none because border_style is None
        assert!(!sides.top);
        assert!(!sides.bottom);
        assert!(!sides.left);
        assert!(!sides.right);
    }

    #[test]
    fn test_box_props_per_side_colors() {
        let props = BoxProps {
            border_color: Some(Color::White),
            border_colors: BorderColors {
                top: Some(Color::Red),
                bottom: Some(Color::Blue),
                ..Default::default()
            },
            ..Default::default()
        };
        assert_eq!(props.top_border_color(), Some(Color::Red));
        assert_eq!(props.bottom_border_color(), Some(Color::Blue));
        assert_eq!(props.left_border_color(), Some(Color::White));
        assert_eq!(props.right_border_color(), Some(Color::White));
    }

    #[test]
    fn test_box_props_partial_border_padding() {
        let props = BoxProps {
            border_style: BorderStyle::Single,
            border_sides: Some(BorderSides::horizontal()),
            padding: 1.0,
            ..Default::default()
        };
        let layout = props.to_layout_style();
        // Top and bottom have border (1.0), left and right don't (0.0)
        assert_eq!(layout.padding_top, Some(2.0)); // 1.0 + 1.0
        assert_eq!(layout.padding_bottom, Some(2.0)); // 1.0 + 1.0
        assert_eq!(layout.padding_left, Some(1.0)); // 1.0 + 0.0
        assert_eq!(layout.padding_right, Some(1.0)); // 1.0 + 0.0
    }
}