trackWork 0.15.0

A terminal-based time tracking application for managing work sessions
use ratatui::{
    layout::{Constraint, Direction, Layout},
    Frame,
};

use crate::app::{App, InputMode};
use crate::passphrase;
use crate::settings;
use crate::tasks;
use crate::whats_new;

use super::top_bar::draw_top_bar;
use super::bottom_bar::draw_bottom_bar;
use super::drawers::{draw_timeline, draw_weekly_stats};
use super::main_element::{draw_entries, draw_suggestions_modal, draw_operations_menu, draw_hotkeys};

/// Main dashboard drawing function
pub fn draw_dashboard(f: &mut Frame, app: &App) {
    // Check if we're in passphrase prompt mode
    if matches!(app.input_mode, InputMode::PassphrasePrompt { .. }) {
        passphrase::draw_passphrase_prompt(f, app);
        return;
    }

    // Check if we're in passphrase change mode
    if matches!(app.input_mode, InputMode::PassphraseChange { .. }) {
        passphrase::draw_passphrase_change(f, app);
        return;
    }

    // Check if we're in settings mode
    if matches!(app.input_mode, InputMode::Settings { .. }) {
        settings::draw_settings(f, app);
        return;
    }

    // Check if we're in the Triggers sub-settings screen
    if matches!(app.input_mode, InputMode::Triggers { .. }) {
        crate::triggers::draw_triggers(f, app);
        return;
    }

    // Check if we're in What's New mode
    if matches!(app.input_mode, InputMode::WhatsNew) {
        whats_new::draw_whats_new(f, app);
        return;
    }

    // Check if we're in Tasks mode
    if matches!(app.input_mode, InputMode::Tasks { .. }) {
        tasks::draw_tasks(f, app);
        return;
    }

    // Check if we're in the weekly summary mode
    if matches!(app.input_mode, InputMode::WeekSummary { .. }) {
        super::week_summary::draw_week_summary(f, app);
        return;
    }

    // Main dashboard layout: top bar, content area, bottom bar
    let main_chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints([
            Constraint::Length(3), // Header
            Constraint::Min(10),   // Main area (timeline + entries + stats)
            Constraint::Length(3), // Footer / Help
        ])
        .split(f.area());

    // Content area layout: timeline, entries list, weekly stats
    let content_chunks = Layout::default()
        .direction(Direction::Horizontal)
        .constraints([
            Constraint::Length(35), // Timeline (left side)
            Constraint::Min(40),    // Entries list (middle)
            Constraint::Length(30), // Weekly stats (right side)
        ])
        .split(main_chunks[1]);

    // Draw all components
    draw_top_bar(f, app, main_chunks[0]);
    draw_timeline(f, app, content_chunks[0]);
    draw_entries(f, app, content_chunks[1]);
    draw_weekly_stats(f, app, content_chunks[2]);
    draw_bottom_bar(f, app, main_chunks[2]);

    // Draw suggestions modal on top if creating with suggestions
    if let InputMode::Creating { suggestions, .. } = &app.input_mode {
        if !suggestions.is_empty() {
            draw_suggestions_modal(f, app);
        }
    }

    // Draw operations menu overlay
    if matches!(app.input_mode, InputMode::OperationsMenu { .. }) {
        draw_operations_menu(f, app);
    }

    if matches!(app.input_mode, InputMode::Hotkeys) {
        draw_hotkeys(f, app);
    }
}