use super::*;

#[derive(Clone, Debug)]
pub struct Function {
    pub name: String,
    pub generic: Vec<Typing>,
    pub version: String,
    pub class: Rc<Class>,
    pub parameters: Parameter,
}

impl SignatureContainer for Function {
    fn get_signature(&self) -> Html {
        let head = Html::from("def");
        let name = html! {<span class="function">{&self.name}</span>};
        let generic = match self.generic.len() {
            0 => EMPTY_HTML,
            _ => build_generics(&self.generic),
        };
        let left = match self.name.len() > 4 {
            true => html! {<>{"("}<br/>{IndentHtml}</>},
            false => html! {"("},
        };
        let right = match self.name.len() > 4 {
            true => html! {<><br/>{")"}</>},
            false => html! {")"},
        };
        let comma: Html = match self.name.len() > 4 {
            true => html! {<>{","}<br/>{IndentHtml}</>},
            false => html! {", "},
        };
        let items: Html = vec![left]
            .into_iter()
            .chain(self.parameters.clone().into_vec().into_iter().intersperse(comma))
            .chain(vec![right].into_iter())
            .collect();

        html! {<code class="signature">{head}{" "}{name}{generic}{items}</code>}
    }

    fn get_id(&self) -> String {
        format!("function.{}", self.name)
    }

    fn get_class(&self) -> String {
        format!("def-function")
    }

    fn get_children(&self) -> Option<Html> {
        Some(html! {
        <p>
        {"Returns the match associated with the capture group at index"} <code>{"P"}</code>{"."}
                {"If i does not correspond to a capture group, or if the capture group
                did not participate in the match, then"}<code>{"None"}</code>{"is returned."}
                <br/>
                {"中文测试中文测试中文怎么样"}
                <br/>
                {"ab ab ab ab ab ab ab ab ab"}
        </p>
        })
    }
}