use lv_tui::prelude::*;
use lv_tui::widgets::*;

struct App {
    content: Column,
}

impl App {
    fn new() -> Self {
        Self {
            content: Column::new()
                .child(Label::new("设置").style(Style::default().bold()))
                .child(Label::new(""))
                .child(Checkbox::new("启用通知"))
                .child(Checkbox::new("自动保存").checked())
                .child(Label::new(""))
                .child(Label::new("主题:"))
                .child(RadioGroup::new(vec![
                    Text::from("浅色"), Text::from("深色"), Text::from("跟随系统"),
                ]))
                .child(Label::new(""))
                .child(Label::new("Space 切换  ↑↓ 导航  q 退出").style(Style::default().fg(Color::Gray))),
        }
    }
}

impl Component for App {
    fn render(&self, cx: &mut RenderCx) { self.content.render(cx); }
    fn event(&mut self, event: &Event, cx: &mut EventCx) {
        if event.is_key(Key::Char('q')) { cx.quit(); return; }
        if let Event::Key(k) = event {
            if k.key == Key::Char('c') && k.modifiers.ctrl { cx.quit(); return; }
        }
        self.content.event(event, cx);
    }
    fn layout(&mut self, r: lv_tui::geom::Rect, cx: &mut lv_tui::component::LayoutCx) { self.content.layout(r, cx); }
    fn measure(&self, c: lv_tui::layout::Constraint, _cx: &mut lv_tui::component::MeasureCx) -> lv_tui::geom::Size {
        lv_tui::geom::Size { width: c.max.width, height: c.max.height }
    }
    fn focusable(&self) -> bool { false }
}

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