1use crate::classes::ClassBuilder;
4use serde::{Deserialize, Serialize};
5use std::fmt;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9pub enum GridColumnStart {
10    Start1,
12    Start2,
14    Start3,
16    Start4,
18    Start5,
20    Start6,
22    Start7,
24    Start8,
26    Start9,
28    Start10,
30    Start11,
32    Start12,
34    Start13,
36    Auto,
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
42pub enum GridColumnEnd {
43    End1,
45    End2,
47    End3,
49    End4,
51    End5,
53    End6,
55    End7,
57    End8,
59    End9,
61    End10,
63    End11,
65    End12,
67    End13,
69    Auto,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
75pub enum GridRowStart {
76    Start1,
78    Start2,
80    Start3,
82    Start4,
84    Start5,
86    Start6,
88    Start7,
90    Auto,
92}
93
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
96pub enum GridRowEnd {
97    End1,
99    End2,
101    End3,
103    End4,
105    End5,
107    End6,
109    End7,
111    Auto,
113}
114
115impl fmt::Display for GridColumnStart {
116    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117        match self {
118            GridColumnStart::Start1 => write!(f, "col-start-1"),
119            GridColumnStart::Start2 => write!(f, "col-start-2"),
120            GridColumnStart::Start3 => write!(f, "col-start-3"),
121            GridColumnStart::Start4 => write!(f, "col-start-4"),
122            GridColumnStart::Start5 => write!(f, "col-start-5"),
123            GridColumnStart::Start6 => write!(f, "col-start-6"),
124            GridColumnStart::Start7 => write!(f, "col-start-7"),
125            GridColumnStart::Start8 => write!(f, "col-start-8"),
126            GridColumnStart::Start9 => write!(f, "col-start-9"),
127            GridColumnStart::Start10 => write!(f, "col-start-10"),
128            GridColumnStart::Start11 => write!(f, "col-start-11"),
129            GridColumnStart::Start12 => write!(f, "col-start-12"),
130            GridColumnStart::Start13 => write!(f, "col-start-13"),
131            GridColumnStart::Auto => write!(f, "col-start-auto"),
132        }
133    }
134}
135
136impl fmt::Display for GridColumnEnd {
137    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
138        match self {
139            GridColumnEnd::End1 => write!(f, "col-end-1"),
140            GridColumnEnd::End2 => write!(f, "col-end-2"),
141            GridColumnEnd::End3 => write!(f, "col-end-3"),
142            GridColumnEnd::End4 => write!(f, "col-end-4"),
143            GridColumnEnd::End5 => write!(f, "col-end-5"),
144            GridColumnEnd::End6 => write!(f, "col-end-6"),
145            GridColumnEnd::End7 => write!(f, "col-end-7"),
146            GridColumnEnd::End8 => write!(f, "col-end-8"),
147            GridColumnEnd::End9 => write!(f, "col-end-9"),
148            GridColumnEnd::End10 => write!(f, "col-end-10"),
149            GridColumnEnd::End11 => write!(f, "col-end-11"),
150            GridColumnEnd::End12 => write!(f, "col-end-12"),
151            GridColumnEnd::End13 => write!(f, "col-end-13"),
152            GridColumnEnd::Auto => write!(f, "col-end-auto"),
153        }
154    }
155}
156
157impl fmt::Display for GridRowStart {
158    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159        match self {
160            GridRowStart::Start1 => write!(f, "row-start-1"),
161            GridRowStart::Start2 => write!(f, "row-start-2"),
162            GridRowStart::Start3 => write!(f, "row-start-3"),
163            GridRowStart::Start4 => write!(f, "row-start-4"),
164            GridRowStart::Start5 => write!(f, "row-start-5"),
165            GridRowStart::Start6 => write!(f, "row-start-6"),
166            GridRowStart::Start7 => write!(f, "row-start-7"),
167            GridRowStart::Auto => write!(f, "row-start-auto"),
168        }
169    }
170}
171
172impl fmt::Display for GridRowEnd {
173    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
174        match self {
175            GridRowEnd::End1 => write!(f, "row-end-1"),
176            GridRowEnd::End2 => write!(f, "row-end-2"),
177            GridRowEnd::End3 => write!(f, "row-end-3"),
178            GridRowEnd::End4 => write!(f, "row-end-4"),
179            GridRowEnd::End5 => write!(f, "row-end-5"),
180            GridRowEnd::End6 => write!(f, "row-end-6"),
181            GridRowEnd::End7 => write!(f, "row-end-7"),
182            GridRowEnd::Auto => write!(f, "row-end-auto"),
183        }
184    }
185}
186
187pub trait GridPlacementUtilities {
189    fn grid_column_start(self, start: GridColumnStart) -> Self;
190    fn grid_column_end(self, end: GridColumnEnd) -> Self;
191    fn grid_row_start(self, start: GridRowStart) -> Self;
192    fn grid_row_end(self, end: GridRowEnd) -> Self;
193}
194
195impl GridPlacementUtilities for ClassBuilder {
196    fn grid_column_start(self, start: GridColumnStart) -> Self {
197        self.class(start.to_string())
198    }
199
200    fn grid_column_end(self, end: GridColumnEnd) -> Self {
201        self.class(end.to_string())
202    }
203
204    fn grid_row_start(self, start: GridRowStart) -> Self {
205        self.class(start.to_string())
206    }
207
208    fn grid_row_end(self, end: GridRowEnd) -> Self {
209        self.class(end.to_string())
210    }
211}
212
213#[cfg(test)]
214mod tests {
215    use super::*;
216
217    #[test]
218    fn test_grid_placement_display() {
219        assert_eq!(GridColumnStart::Start1.to_string(), "col-start-1");
220        assert_eq!(GridColumnEnd::End1.to_string(), "col-end-1");
221        assert_eq!(GridRowStart::Start1.to_string(), "row-start-1");
222        assert_eq!(GridRowEnd::End1.to_string(), "row-end-1");
223    }
224
225    #[test]
226    fn test_grid_placement_utilities() {
227        let classes = ClassBuilder::new()
228            .grid_column_start(GridColumnStart::Start1)
229            .grid_column_end(GridColumnEnd::End3)
230            .grid_row_start(GridRowStart::Start1)
231            .grid_row_end(GridRowEnd::End2)
232            .build();
233
234        let css_classes = classes.to_css_classes();
235        assert!(css_classes.contains("col-start-1"));
236        assert!(css_classes.contains("col-end-3"));
237        assert!(css_classes.contains("row-start-1"));
238        assert!(css_classes.contains("row-end-2"));
239    }
240}