// src/movement/lib.rs

use crate::movement::MovementAction;

#[inline]
pub fn move_focus<T: Copy + Eq>(
    order: &[T],
    current: &mut T,
    action: MovementAction,
) -> bool {
    if order.is_empty() {
        return false;
    }
    if let Some(pos) = order.iter().position(|k| *k == *current) {
        match action {
            MovementAction::Previous | MovementAction::Up | MovementAction::Left => {
                if pos > 0 {
                    *current = order[pos - 1];
                    return true;
                }
            }
            MovementAction::Next | MovementAction::Down | MovementAction::Right => {
                if pos + 1 < order.len() {
                    *current = order[pos + 1];
                    return true;
                }
            }
            _ => {}
        }
    }
    false
}
