use iced::{
    Background,
    Border,
    Element,
    widget::{
        container,
        row,
    },
};

use crate::{
    app::{
        Editor,
        Message,
    },
    theme::*,
    ui::components::menu_button,
};

pub fn view(editor: &Editor) -> Element<'_, Message> {
    let has_project = editor.project.is_some();

    let menu_content = row![
        iced::widget::text("File").size(14).color(Neutral::CREAM),
        menu_button("Open", true, Some(Message::OpenProjectDialog)),
        menu_button(
            "Close",
            has_project,
            has_project.then_some(Message::CloseProject)
        ),
        menu_button(
            "Save",
            has_project,
            has_project.then_some(Message::SaveProject)
        ),
    ]
    .spacing(Spacing::SMALL)
    .padding(Spacing::SMALL);

    container(menu_content)
        .width(iced::Length::Fill)
        .style(|_theme| container::Style {
            background: Some(Background::Color(Aubergine::_800)),
            border: Border {
                color: Aubergine::_600,
                width: 0.0,
                radius: 0.0.into(),
            },
            ..Default::default()
        })
        .into()
}
