#![allow(clippy::items_after_test_module)]

#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct Heading {
    pub level: usize,
    pub title: String,
    pub children: Vec<Self>,
}

pub(super) fn extract_headings(contents: &str) -> Vec<Heading> {
    let mut headings = Vec::new();
    let mut in_code_block = false;

    for line in contents.lines() {
        if line.trim_start().starts_with("```") {
            in_code_block = !in_code_block;
            continue;
        }

        if in_code_block {
            continue;
        }

        if line.starts_with('#') {
            let level = line.chars().take_while(|&c| c == '#').count();
            let title = line[level..].trim().to_string();

            headings.push(Heading {
                level,
                title,
                children: vec![],
            });
        }
    }

    headings
}

#[cfg(test)]
mod test_extract_headings {
    use super::extract_headings;

    #[test]
    fn test_() {}
}
