use notedown_ast::AST;

pub trait Slugify {
    fn slugify(&self, sp: char) -> String;
}

impl Slugify for Vec<AST> {
    fn slugify(&self, s: char) -> String {
        let mut out = String::new();
        for span in self {
            if !out.is_empty() {
                out.push(s);
            }
            out.push_str(&span.slugify(s));
        }
        return out;
    }
}

impl Slugify for AST {
    fn slugify(&self, sp: char) -> String {
        match self {
            AST::None => "".to_owned(),
            AST::Newline => unimplemented!(),
            AST::Statements(_) => unimplemented!(),
            AST::Header(_, _) => unimplemented!(),
            AST::Paragraph(v) => v.slugify(sp),
            AST::Highlight(_) => unimplemented!(),
            AST::Math(_) => unimplemented!(),
            AST::Table(_) => unimplemented!(),
            AST::List(_) => unimplemented!(),
            AST::Text(t) => t.slugify(sp),
            AST::Raw(_) => unimplemented!(),
            AST::Code(_) => unimplemented!(),
            AST::Emphasis(_) => unimplemented!(),
            AST::Strong(v) => v.slugify(sp),
            AST::Underline(_) => unimplemented!(),
            AST::Strikethrough(_) => unimplemented!(),
            AST::Undercover(_) => unimplemented!(),
            AST::MathInline(_) => unimplemented!(),
            AST::MathDisplay(_) => unimplemented!(),
            AST::Link(_) => unimplemented!(),
            AST::Escaped(_) => unimplemented!(),
            AST::Command(_) => unimplemented!(),
        }
    }
}

impl Slugify for &str {
    fn slugify(&self, sp: char) -> String {
        self.trim().replace(" ", &sp.to_string()).to_lowercase().to_owned()
    }
}


impl Slugify for String {
    fn slugify(&self, sp: char) -> String {
        Slugify::slugify(&self.as_str(),sp)
    }
}