use eframe::egui;

mod position_indicator;
use position_indicator::PositionIndicator;

fn main() -> Result<(), eframe::Error> {
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default()
            .with_inner_size([800.0, 400.0])
            .with_title("Position Indicator Test"),
        ..Default::default()
    };

    eframe::run_native(
        "Position Indicator Test",
        options,
        Box::new(|_cc| Ok(Box::new(TestApp::default()))),
    )
}

#[derive(Default)]
struct TestApp {
    idle: bool,
    first_recording: bool,
    beat_count: usize,
    current_beat: usize,
    metronome_position: f32,
}

impl eframe::App for TestApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        egui::CentralPanel::default().show(ctx, |ui| {
            ui.heading("Position Indicator Test");
            ui.separator();

            ui.spacing_mut().item_spacing.y = 10.0;

            // Controls section
            ui.group(|ui| {
                ui.label("Controls:");

                ui.horizontal(|ui| {
                    ui.checkbox(&mut self.idle, "Idle");
                });

                ui.horizontal(|ui| {
                    ui.checkbox(&mut self.first_recording, "First Recording");
                });

                ui.horizontal(|ui| {
                    ui.label("Beat Count:");
                    ui.add(egui::DragValue::new(&mut self.beat_count).range(0..=16));
                });

                ui.horizontal(|ui| {
                    ui.label("Current Beat:");
                    ui.add(egui::DragValue::new(&mut self.current_beat).range(0..=16));
                });

                ui.horizontal(|ui| {
                    ui.label("Metronome Position:");
                    ui.add(
                        egui::Slider::new(&mut self.metronome_position, 0.0..=1.0)
                            .step_by(0.01)
                            .show_value(true),
                    );
                });
            });

            ui.separator();

            // Position indicator display
            ui.group(|ui| {
                ui.label("Position Indicator:");
                ui.add_space(10.0);

                let position_indicator = PositionIndicator::new(
                    self.idle,
                    self.first_recording,
                    self.beat_count,
                    self.current_beat,
                    self.metronome_position,
                );

                ui.add(position_indicator);
            });
        });
    }
}
