use bevy::state::state::States;
use types::{ItemPosition, MenuItemType, OnPressAction};

pub mod types;

#[derive(Debug, Clone)]
pub(super) struct MenuItemInternal<NavState: States> {
    pub(super) r#type: MenuItemType,
    pub(super) pos: ItemPosition,
    pub(super) action: Option<OnPressAction<NavState>>,
}

pub(super) trait IntoMenuItemInternal<NavState: States> {
    fn item(&self) -> MenuItemInternal<NavState>;
}

impl<S: States, T: ?Sized + MenuItem<S>> IntoMenuItemInternal<S> for T {
    fn item(&self) -> MenuItemInternal<S> {
        MenuItemInternal {
            r#type: self.item_type(),
            pos: self.pos(),
            action: self.action(),
        }
    }
}

pub trait MenuItem<NavState: States> {
    fn item_type(&self) -> MenuItemType;
    fn pos(&self) -> ItemPosition;
    fn action(&self) -> Option<OnPressAction<NavState>>;
}

impl<NavState: States> MenuItem<NavState> for MenuItemType {
    fn item_type(&self) -> MenuItemType {
        self.clone()
    }

    fn pos(&self) -> ItemPosition {
        ItemPosition::default()
    }

    fn action(&self) -> Option<OnPressAction<NavState>> {
        None
    }
}

impl<NavState: States> MenuItem<NavState> for (MenuItemType, OnPressAction<NavState>) {
    fn item_type(&self) -> MenuItemType {
        self.0.clone()
    }

    fn pos(&self) -> ItemPosition {
        ItemPosition::default()
    }

    fn action(&self) -> Option<OnPressAction<NavState>> {
        Some(self.1.clone())
    }
}
