/*
 * This file is part of sdbclient
 * Copyright (C) 2022 Jonni Liljamo <jonni@liljamo.com>
 *
 * Licensed under GPL-3.0-only.
 * See LICENSE for licensing information.
 */
use bevy::{
    prelude::*,
    ui::{JustifyContent, Size, Style, Val},
};
use crate::constants::TEXT_COLOR;
use super::{MenuButtonAction, NORMAL_BUTTON};
/// Tag component for tagging entities on menu screen
#[derive(Component)]
pub struct OnMainMenuScreen;
pub fn main_menu_setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font = asset_server.load("fonts/FiraMono-Regular.ttf");
    let button_style = Style {
        size: Size::new(Val::Px(250.), Val::Px(65.)),
        margin: UiRect::all(Val::Px(20.)),
        justify_content: JustifyContent::Center,
        align_items: AlignItems::Center,
        ..Default::default()
    };
    let button_text_style = TextStyle {
        font: font.clone(),
        font_size: 40.0,
        color: TEXT_COLOR,
    };
    commands
        .spawn((
            NodeBundle {
                style: Style {
                    size: Size::new(Val::Percent(100.), Val::Percent(100.)),
                    align_items: AlignItems::Center,
                    justify_content: JustifyContent::Center,
                    flex_direction: FlexDirection::Column,
                    ..Default::default()
                },
                ..Default::default()
            },
            OnMainMenuScreen,
        ))
        .with_children(|parent| {
            // Game title, currently text
            // TODO: Change to a fancy image logo
            parent.spawn(
                TextBundle::from_section(
                    "Deck Builder",
                    TextStyle {
                        font: font.clone(),
                        font_size: 80.0,
                        color: TEXT_COLOR,
                    },
                )
                .with_style(Style {
                    margin: UiRect::all(Val::Px(50.)),
                    ..Default::default()
                }),
            );
            // Main menu buttons
            for (action, text) in [
                (MenuButtonAction::Play, "Play"),
                (MenuButtonAction::Account, "Account"),
                (MenuButtonAction::Settings, "Settings"),
                (MenuButtonAction::Exit, "Exit"),
            ] {
                parent
                    .spawn((
                        ButtonBundle {
                            style: button_style.clone(),
                            background_color: NORMAL_BUTTON.into(),
                            ..Default::default()
                        },
                        action,
                    ))
                    .with_children(|parent| {
                        parent.spawn(TextBundle::from_section(text, button_text_style.clone()));
                    });
            }
        });
}