use super::WriteElement;

/// [feDisplacementMap](https://www.w3.org/TR/SVG11/filters.html#feDisplacementMapElement)
#[derive(Debug)]
pub struct DisplacementMap {
    pub scale: f32,
    pub x_channel_selector: Channel,
    pub y_channel_selector: Channel,
}

impl WriteElement for DisplacementMap {
    fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
        let mut r = Vec::new();
        gen_attrs![
            r;
            self.scale != 0. => b"scale": self.scale,
            self.x_channel_selector != Channel::A => b"xChannelSelector": format!("{:?}", self.x_channel_selector),
            self.y_channel_selector != Channel::A => b"yChannelSelector": format!("{:?}", self.y_channel_selector)
        ];
        r
    }

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

#[derive(Debug, PartialEq, Eq)]
pub enum Channel {
    A,
    R,
    G,
    B,
}
