use super::UiHeadState;
use bevy::prelude::*;
use serde::{Deserialize, Serialize};

pub static HEAD_SLOTS: usize = 5;

#[derive(Component, Default)]
pub struct BackpackMarker;

#[derive(Component, Default)]
pub struct BackpackCountText;

#[derive(Component, Default)]
pub struct HeadSelector(pub usize);

#[derive(Component, Default)]
pub struct HeadImage(pub usize);

#[derive(Component, Default)]
pub struct HeadDamage(pub usize);

#[derive(Component, Default, Debug, Reflect, Serialize, Deserialize, PartialEq)]
#[reflect(Component, Default)]
pub struct BackpackUiState {
    pub heads: [Option<UiHeadState>; 5],
    pub scroll: usize,
    pub count: usize,
    pub current_slot: usize,
    pub open: bool,
}

impl BackpackUiState {
    pub fn relative_current_slot(&self) -> usize {
        self.current_slot.saturating_sub(self.scroll)
    }
}

pub fn plugin(app: &mut App) {
    app.register_type::<BackpackUiState>();
}
