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

struct App { content: Column }

impl App {
    fn new() -> Self {
        Self { content: Column::new()
            .child(Label::new("Multi-line Label Demo").style(Style::default().bold()))
            .child(Label::new(""))
            .child(Label::new("Line 1: Hello\nLine 2: World\nLine 3: 你好世界"))
            .child(Label::new(""))
            .child(Label::new("Wrap mode (narrow):")
                .style(Style::default().fg(Color::Gray)))
            .child(Label::new(
                "This long line should wrap to multiple lines automatically when using Char wrap mode"
            ).style(Style::default().width(Length::Fixed(30))))
            .child(Label::new(""))
            .child(Label::new("q to quit").style(Style::default().fg(Color::Gray))),
        }
    }
}

impl Component for App {
    fn render(&self, cx: &mut RenderCx) {
        cx.wrap = TextWrap::Word; // enable auto-wrap
        self.content.render(cx);
    }
    fn event(&mut self, e: &Event, cx: &mut EventCx) {
        if e.is_key(Key::Char('q')) { cx.quit(); }
        self.content.event(e, 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()
}
