/// RFC 05 验收 example
///
/// 验证基础布局系统：
/// - Column 垂直排列多个子组件
/// - Label 渲染文本
/// - Column 内嵌 Counter（reactive 状态）
/// - 事件转发到子组件（Counter 可按 `+` 递增）

use lv_tui::prelude::*;
use lv_tui::Component;
use lv_tui::widgets::{Column, Label};

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

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

impl Component for Counter {


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

    fn event(&mut self, event: &Event, cx: &mut EventCx) {
        if cx.phase() != lv_tui::event::EventPhase::Target { return; }
        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(
        Column::new()
            .padding(1)
            .gap(1)
            .child(Label::new("=== lv-tui Demo ==="))
            .child(Label::new("Welcome to the column layout demo"))
            .child(Counter::new()),
    )
    .run()
}
