use super::WriteElement;
use std::fmt::Display;

/// [feMorphology](https://www.w3.org/TR/SVG11/filters.html#feMorphologyElement)
#[derive(Debug)]
pub struct Morphology {
    operator: Operator,
    radius: (f32, f32),
}

impl WriteElement for Morphology {
    fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
        gen_attrs![
            b"operator": self.operator,
            b"radius": format!("{} {}", self.radius.0, self.radius.1)
        ]
    }

    fn tag_name(&self) -> &'static str {
        "feMorphology"
    }
}

#[derive(Debug)]
enum Operator {
    Erode,
    Dilate,
}

impl Display for Operator {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(match self {
            Operator::Erode => "erode",
            Operator::Dilate => "dilate",
        })
    }
}
