use aleatico::prelude::*;
use winit::event::WindowEvent;

#[derive(Default)]
struct MyController {
    my_object: RenderItem,
}

const VERTICES: &[TexturedVertex] = &[
    TexturedVertex {
        position: [-0.5,  0.5, 0.0],
        tex_coords: [0.0, 0.0],
    }, // top-left
    TexturedVertex {
        position: [-0.5, -0.5, 0.0],
        tex_coords: [0.0, 1.0],
    }, // bottom-left
    TexturedVertex {
        position: [0.5, -0.5, 0.0],
        tex_coords: [1.0, 1.0],
    }, // bottom-right
    TexturedVertex {
        position: [0.5, 0.5, 0.0],
        tex_coords: [1.0, 0.0],
    }, // top-right
];

const INDICES: &[u16] = &[
    0, 1, 2,
    0, 2, 3,
];

impl Controller for MyController {
    fn init(&mut self, state: &mut State) {
        let mesh_id = state.renderer.create_indexed_mesh(VERTICES, INDICES).unwrap();
        let tex_bytes = include_bytes!("../../assets/Sprite-0001.png");
        let texture_id = state.renderer.create_texture(tex_bytes).unwrap();

        let material_id = state.renderer.create_material(MaterialDescriptor::textured(texture_id)).unwrap();
        self.my_object = RenderItem {
            mesh_id,
            material_id,
        };
    }

    fn resize(&mut self, _state: &mut State, _width: u32, _height: u32) {}

    fn update(&mut self, _state: &mut State) {}

    fn render(&mut self, state: &mut State) {
        state.renderer.submit(self.my_object);
    }

    fn handle_event(&mut self, _state: &mut State, _event: &WindowEvent) {}
}

fn main() {
    env_logger::init();

    let app = App::new(MyController::default());
    app.run().unwrap();
}
