use super::styles::{self, BG_CARD, GRAY_50, GRAY_70};
use crate::ui::Message;
use iced::Element;

pub(crate) fn view(content: &str) -> Element<'_, Message> {
    let header = iced::widget::row![
        iced::widget::text("Application Logs")
            .size(18)
            .color(GRAY_70),
        iced::widget::Space::new().width(iced::Length::Fill),
        iced::widget::button(
            iced::widget::text("Close")
                .size(12)
                .color(iced::Color::WHITE),
        )
        .on_press(Message::CloseLogs)
        .padding(iced::Padding::from([4.0, 12.0]))
        .style(super::styles::play_button_style),
    ]
    .align_y(iced::Alignment::Center)
    .padding(iced::Padding::from([12.0, 20.0]));

    let log_text = if content.is_empty() {
        iced::widget::text("No logs available.")
            .size(13)
            .color(GRAY_50)
    } else {
        iced::widget::text(content)
            .size(12)
            .color(GRAY_70)
            .font(iced::Font::MONOSPACE)
    };

    let log_container = iced::widget::container(log_text)
        .padding(iced::Padding::from([12.0, 16.0]))
        .width(iced::Length::Fill)
        .style(|_theme| iced::widget::container::Style {
            background: Some(iced::Background::Color(BG_CARD)),
            border: iced::border::rounded(styles::RADIUS_STANDARD),
            ..Default::default()
        });

    let body = iced::widget::scrollable(log_container)
        .width(iced::Length::Fill)
        .height(iced::Length::Fill);

    iced::widget::column![header, body]
        .width(iced::Length::Fill)
        .height(iced::Length::Fill)
        .into()
}
