#[cfg(feature = "gui")]
use eframe::egui;

#[cfg(feature = "gui")]
/// Keyboard shortcuts to control UI elements.
pub struct Shortcuts {
    /// Process filter text field.
    pub filter:            egui::KeyboardShortcut,
    /// Run mode: process name to run.
    pub run:               egui::KeyboardShortcut,
    /// Run mode: subprocess to set affinities for.
    pub subprocess:        egui::KeyboardShortcut,
    /// Toggle left (process list) sidebar.
    pub toggle_left:       egui::KeyboardShortcut,
    /// Show help information.
    pub help:              egui::KeyboardShortcut,
    /// Show CPU information.
    pub cpu:               egui::KeyboardShortcut,
    /// Switch to run mode.
    pub mode_run:          egui::KeyboardShortcut,
    /// Switch to view mode.
    pub mode_view:         egui::KeyboardShortcut,
    /// Switch to edit mode.
    pub mode_edit:         egui::KeyboardShortcut,
    /// Threads: disable SMT.
    pub no_smt:            egui::KeyboardShortcut,
    /// Apply affinities/run process.
    pub apply:             egui::KeyboardShortcut,
    /// Clear thread affinities.
    pub clear_threads:     egui::KeyboardShortcut,
    /// Set PU thread order.
    pub order_pu:          egui::KeyboardShortcut,
    /// Set cores thread order.
    pub order_cores:       egui::KeyboardShortcut,
    /// Set L3 thread order.
    pub order_l3:          egui::KeyboardShortcut,
    /// Disable any thread order.
    pub order_none:        egui::KeyboardShortcut,
    /// Ignore main thread for thread order.
    pub order_ignore_main: egui::KeyboardShortcut,
    /// Run mode: thread count to set affinities for manually.
    pub thread_count:      egui::KeyboardShortcut,
    /// Run mode: thread apply time.
    pub thread_apply_time: egui::KeyboardShortcut,
    /// Next process in list.
    pub process_next:      egui::KeyboardShortcut,
    /// Previous process in list.
    pub process_previous:  egui::KeyboardShortcut,
}

#[cfg(feature = "gui")]
impl Shortcuts {
    /// Initialize default shortcuts.
    pub fn new() -> Shortcuts {
        type Modifiers = egui::Modifiers;
        type Key       = egui::Key;
        type Shortcut  = egui::KeyboardShortcut;

        Shortcuts {
            filter:            Shortcut::new(Modifiers::CTRL, Key::F),
            run:               Shortcut::new(Modifiers::CTRL, Key::R),
            subprocess:        Shortcut::new(Modifiers::CTRL, Key::P),
            toggle_left:       Shortcut::new(Modifiers::CTRL, Key::F10),
            help:              Shortcut::new(Modifiers::NONE, Key::F1),
            cpu:               Shortcut::new(Modifiers::NONE, Key::F2),
            mode_run:          Shortcut::new(Modifiers::NONE, Key::F3),
            mode_view:         Shortcut::new(Modifiers::NONE, Key::F4),
            mode_edit:         Shortcut::new(Modifiers::NONE, Key::F5),
            no_smt:            Shortcut::new(Modifiers::CTRL, Key::N),
            apply:             Shortcut::new(Modifiers::CTRL, Key::Enter),
            clear_threads:     Shortcut::new(Modifiers::CTRL, Key::Backspace),
            order_pu:          Shortcut::new(Modifiers::CTRL, Key::Num1),
            order_cores:       Shortcut::new(Modifiers::CTRL, Key::Num2),
            order_l3:          Shortcut::new(Modifiers::CTRL, Key::Num3),
            order_none:        Shortcut::new(Modifiers::CTRL, Key::Num0),
            order_ignore_main: Shortcut::new(Modifiers::CTRL, Key::Minus),
            thread_count:      Shortcut::new(Modifiers::CTRL, Key::T),
            thread_apply_time: Shortcut::new(Modifiers::CTRL, Key::E),
            process_next:      Shortcut::new(Modifiers::NONE, Key::ArrowDown),
            process_previous:  Shortcut::new(Modifiers::NONE, Key::ArrowUp),
        }
    }
}
