//! File editor UI component
//!
//! Renders an editable code editor with syntax highlighting and line numbers.

use iced::{
    Background,
    Element,
    Length,
    widget::container,
};

use crate::{
    app::Message,
    file_editor_state::FileEditorState,
    theme::*,
};

/// Render the file editor view for a given file state
pub fn view(state: &FileEditorState, tab_index: usize) -> Element<'_, Message> {
    // Use the CodeEditor's view, mapping its messages to our Message enum
    let editor_view = state
        .editor
        .view()
        .map(move |msg| Message::EditorAction(tab_index, msg));

    container(editor_view)
        .width(Length::Fill)
        .height(Length::Fill)
        .padding(
            iced::Padding::new(Spacing::MEDIUM)
                .left(Spacing::LARGE)
                .right(Spacing::LARGE),
        )
        .style(|_theme| container::Style {
            background: Some(Background::Color(Aubergine::_900)),
            ..Default::default()
        })
        .into()
}
