//! Bottom status bar — filename, index/total, dimensions, zoom level.

use iced::widget::{container, row, text};
use iced::{Element, Length};

use super::theme;

/// State for the status bar.
#[derive(Debug, Clone, Default)]
pub struct StatusBar {
    pub filename: String,
    pub current_index: usize,
    pub total: usize,
    pub width: u32,
    pub height: u32,
    pub format: String,
    pub zoom_pct: u32,
}

/// Messages the status bar can emit. Currently empty — the status bar is
/// display-only and emits no messages.
#[derive(Debug, Clone, Copy)]
pub enum StatusMessage {}

pub fn view(state: &StatusBar) -> Element<'static, StatusMessage> {
    let position_text = if state.total == 0 {
        "—".to_string()
    } else {
        format!("{}/{}", state.current_index + 1, state.total)
    };

    let dims_text = if state.width == 0 {
        String::new()
    } else {
        format!("{}×{}", state.width, state.height)
    };

    let zoom_text = if state.zoom_pct == 0 {
        String::new()
    } else {
        format!("{}%", state.zoom_pct)
    };

    let fmt_text = state.format.clone();

    let content = row![
        text(state.filename.clone())
            .color(theme::TEXT_SECONDARY)
            .size(11),
        text("  ·  ").color(theme::TEXT_SECONDARY).size(11),
        text(position_text).color(theme::TEXT_PRIMARY).size(11),
        text("  ·  ").color(theme::TEXT_SECONDARY).size(11),
        text(dims_text).color(theme::TEXT_SECONDARY).size(11),
        text("  ·  ").color(theme::TEXT_SECONDARY).size(11),
        text(fmt_text).color(theme::TEXT_SECONDARY).size(11),
        text("  ·  ").color(theme::TEXT_SECONDARY).size(11),
        text(zoom_text).color(theme::TEXT_PRIMARY).size(11),
    ]
    .padding(iced::Padding {
        top: 0.0,
        right: 10.0,
        bottom: 0.0,
        left: 10.0,
    })
    .align_y(iced::Alignment::Center);

    container(content)
        .width(Length::Fill)
        .height(Length::Fixed(22.0))
        .align_y(iced::Alignment::Center)
        .style(|_theme| container::Style {
            background: Some(theme::BG_CHROME.into()),
            border: iced::Border {
                color: theme::BG_CHROME_BORDER,
                width: 0.0,
                radius: 0.0.into(),
            },
            ..Default::default()
        })
        .into()
}
