use std::collections::HashSet;

use winit::event::Event;

use crate::canvas::canvas_frame::{Drawable, Eventable};
use crate::drawables::rect::Rect;
use crate::drawables::sprite::Sprite;
use crate::util::vertex::VertexTypeContainer;

pub struct Slider {
    handle: Rect,
    guide: Vec<Rect>,

    scaler: u32,
    position: (f32, f32),
    size: (f32, f32),
    value: u16,
}

impl Slider {
    pub fn new(size: (f32, f32), position: (f32, f32), value: u16) -> Slider {

        // render the guide first
        let red = (1.0, 0.0, 0.0, 0.0);
        let green = (0.0, 1.0, 0.0, 0.0);
        let blue = (0.0, 1.0, 1.0, 0.0);
        let rg = (1.0, 1.0, 0.0, 0.0);

        let left_guide_bar = Rect::new((position.0, position.1), (2.0, size.1), 1, red);
        let right_guide_bar = Rect::new((position.0 + size.0, position.1), (2.0, size.1), 1, blue);
        let line = Rect::new((position.0, position.1 - (size.1 / 2.0) ), (size.0, 2.0), 1, green);

        let scale = value as f32 / u16::max_value() as f32;
        let handle = Rect::new((position.0 + (size.0 * scale), position.1), (15.0, size.1), 1, rg);

        Slider {
            handle: handle,
            guide: vec![left_guide_bar, right_guide_bar, line],
            scaler: 255,
            position,
            size,
            value,
        }
    }
}

impl Drawable for Slider {
    fn get(&self, window_size: (u32, u32)) -> Vec<VertexTypeContainer> {
        let mut vertices = self.handle.get(window_size).clone();

        vertices.extend_from_slice(
            self.guide.iter()
                .map(|x| x.get(window_size))
                .flatten()
                .collect::<Vec<VertexTypeContainer>>()
                .as_slice()
        );

        vertices.extend_from_slice(self.guide[0].get(window_size).as_slice());
        vertices
    }
}

impl<T> Eventable<T> for Slider {
    fn notify(&mut self, event: &Event<T>) -> () {
        unimplemented!()
    }
}
