use crate::renderer::prelude::*;

#[derive(Debug, Clone)]
pub struct Scene {
    pub drawables: Vec<Drawable>,
    pub animations: Vec<(Animation, usize)>, // Animation with layer
    pub duration: f64,
}

impl Scene {
    pub fn new(duration: f64) -> Self {
        Scene {
            drawables: Vec::new(),
            animations: Vec::new(),
            duration,
        }
    }

    pub fn add_drawable(&mut self, drawable: Drawable) {
        self.drawables.push(drawable);
    }

    pub fn add_animation(&mut self, animation: Animation, layer: usize) {
        self.animations.push((animation, layer));
    }

    pub fn get_frame_at(&self, time: f64) -> Vec<Drawable> {
        let mut frame_drawables = self.drawables.clone();

        // Add animated elements
        for (animation, layer) in &self.animations {
            let interpolated_element = animation.interpolate_at(time);
            frame_drawables.push(Drawable::new(interpolated_element, *layer));
        }

        // Sort by layer
        frame_drawables.sort_by_key(|d| d.layer);
        frame_drawables
    }
}
