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
mod children;
#[cfg(feature = "json")]
mod json;
#[cfg(feature = "parse")]
mod parse;
#[cfg(feature = "print")]
mod print;
#[cfg(feature = "render")]
mod render;

pub use children::MjHeadChild;

pub const NAME: &str = "mj-head";

#[derive(Debug, Default)]
#[cfg_attr(feature = "print", derive(mrml_print_macros::MrmlPrintComponent))]
#[cfg_attr(feature = "print", mrml_print(tag = "NAME"))]
#[cfg_attr(feature = "json", derive(mrml_json_macros::MrmlJsonComponent))]
#[cfg_attr(feature = "json", mrml_json(tag = "NAME"))]
pub struct MjHead {
    pub children: Vec<MjHeadChild>,
}

#[cfg(feature = "render")]
impl MjHead {
    pub fn breakpoint(&self) -> Option<&crate::mj_breakpoint::MjBreakpoint> {
        self.children
            .iter()
            .flat_map(|item| {
                item.as_mj_breakpoint().into_iter().chain(
                    item.as_mj_include()
                        .into_iter()
                        .filter(|item| item.attributes.kind.is_mjml())
                        .flat_map(|inner| {
                            inner
                                .children
                                .iter()
                                .filter_map(|child| child.as_mj_breakpoint())
                        }),
                )
            })
            .last()
    }

    pub fn preview(&self) -> Option<&crate::mj_preview::MjPreview> {
        self.children
            .iter()
            .flat_map(|item| {
                item.as_mj_preview().into_iter().chain(
                    item.as_mj_include()
                        .into_iter()
                        .filter(|item| item.attributes.kind.is_mjml())
                        .flat_map(|inner| {
                            inner
                                .children
                                .iter()
                                .filter_map(|child| child.as_mj_preview())
                        }),
                )
            })
            .last()
    }

    pub fn title(&self) -> Option<&crate::mj_title::MjTitle> {
        self.children
            .iter()
            .flat_map(|item| {
                item.as_mj_title().into_iter().chain(
                    item.as_mj_include()
                        .into_iter()
                        .filter(|item| item.attributes.kind.is_mjml())
                        .flat_map(|inner| {
                            inner
                                .children
                                .iter()
                                .filter_map(|child| child.as_mj_title())
                        }),
                )
            })
            .last()
    }

    pub fn children(&self) -> &Vec<MjHeadChild> {
        &self.children
    }
}