/// RFC 03 — reactive macros
use lv_tui::prelude::*;
use lv_tui::Component;

#[derive(Component)]
struct Counter {
    #[reactive(paint, copy)]
    count: i32,
}

impl Counter {
    fn new() -> Self { Self { count: 0 } }
}

impl Component for Counter {
    fn render(&self, cx: &mut RenderCx) {
        cx.line("Counter");
        cx.line(format!("count: {}", self.get_count()));
        cx.line("");
        cx.line("press + to increment, q to quit");
    }

    fn event(&mut self, event: &Event, cx: &mut EventCx) {
        if event.is_key(Key::Char('+')) {
            self.update_count(cx, |n| *n += 1);
        }
        if event.is_key(Key::Char('q')) { cx.quit(); }
    }
}

fn main() -> lv_tui::Result<()> {
    App::new(Counter::new()).run()
}
