#pragma once

#include <SDL3/SDL.h>

/**
 * Config - Centralized configuration constants
 * 
 * Replaces magic numbers and scattered constants throughout main.cpp
 * Organized by functional area for easy maintenance and modification
 */
namespace Config {
    
    // Window and Display Settings
    namespace Window {
        constexpr int DEFAULT_WIDTH = 1200;
        constexpr int DEFAULT_HEIGHT = 1000;
        constexpr const char* DEFAULT_TITLE = "SpaceTris (SDL3)";
        constexpr bool DEFAULT_VSYNC = true;
    }
    
    // Logical rendering dimensions (internal coordinate system)
    namespace Logical {
        constexpr int WIDTH = 1200;
        constexpr int HEIGHT = 1000;
    }
    
    // Gameplay constants
    namespace Gameplay {
        constexpr double DAS_DELAY = 170.0;        // Delayed Auto Shift delay in ms
        constexpr double ARR_RATE = 40.0;          // Auto Repeat Rate in ms
        constexpr float LEVEL_FADE_DURATION = 5000.0f; // Level background fade time in ms
        constexpr int MAX_LEVELS = 20;             // Maximum selectable starting level
        
        // Gravity speed multiplier: 1.0 = normal, 2.0 = 2x slower, 0.5 = 2x faster
        constexpr double GRAVITY_SPEED_MULTIPLIER = 2; // increase drop interval by ~100% to slow gravity
    }
    
    // UI Layout constants  
    namespace UI {
        constexpr float MIN_MARGIN = 40.0f;
        constexpr float PANEL_WIDTH = 180.0f;
        constexpr float PANEL_SPACING = 30.0f;
        constexpr float BUTTON_HEIGHT_SMALL = 60.0f;
        constexpr float BUTTON_HEIGHT_NORMAL = 70.0f;
        constexpr float BUTTON_WIDTH_SMALL = 0.4f;   // Fraction of screen width
        constexpr float BUTTON_WIDTH_NORMAL = 300.0f;
        constexpr float SETTINGS_GEAR_SIZE = 50.0f;
        constexpr float SETTINGS_GEAR_MARGIN = 10.0f;
        
        // Screen size breakpoints
        constexpr float SMALL_SCREEN_BREAKPOINT = 700.0f;
        
        // Menu positioning
        constexpr float MENU_BUTTON_Y_OFFSET = 40.0f;
        constexpr float MENU_BUTTON_Y_BASE = 0.86f;  // Fraction of screen height
    }
    
    // Loading screen constants
    namespace Loading {
        constexpr float LOGO_HEIGHT_FACTOR_LIMITED = 0.25f;  // When height < 450
        constexpr float LOGO_HEIGHT_FACTOR_NORMAL = 0.4f;
        constexpr float LOGO_MAX_WIDTH_FACTOR = 0.9f;        // Fraction of screen width
        constexpr float LOGO_MAX_WIDTH_ABSOLUTE = 600.0f;
        constexpr int LOGO_ORIGINAL_WIDTH = 872;
        constexpr int LOGO_ORIGINAL_HEIGHT = 273;
        constexpr float LOADING_TEXT_HEIGHT = 20.0f;
        constexpr float LOADING_BAR_HEIGHT = 20.0f;
        constexpr float LOADING_BAR_PADDING_LIMITED = 15.0f;
        constexpr float LOADING_BAR_PADDING_NORMAL = 35.0f;
        constexpr float LOADING_PERCENTAGE_HEIGHT = 24.0f;
        constexpr float LOADING_ELEMENT_SPACING_LIMITED = 5.0f;
        constexpr float LOADING_ELEMENT_SPACING_NORMAL = 15.0f;
        constexpr int LIMITED_HEIGHT_THRESHOLD = 450;
    }
    
    // Animation constants
    namespace Animation {
        constexpr double LOGO_ANIM_SPEED = 0.0008;  // Logo animation speed multiplier
        constexpr float STARFIELD_UPDATE_DIVISOR = 1000.0f; // Convert ms to seconds
    }
    
    // HUD and Game Display
    namespace HUD {
        constexpr float GRAVITY_DISPLAY_X = 260.0f;  // Distance from right edge
        constexpr float GRAVITY_DISPLAY_Y = 10.0f;
        constexpr float SCORE_PANEL_X_OFFSET = 120.0f; // Distance from center
        constexpr float SCORE_PANEL_BASE_Y = 220.0f;
        constexpr float CONTROLS_HINT_Y_OFFSET = 30.0f; // Distance from bottom
    }
    
    // Popup and Modal constants
    namespace Popup {
        constexpr float EXIT_CONFIRM_WIDTH = 400.0f;
        constexpr float EXIT_CONFIRM_HEIGHT = 200.0f;
        constexpr float SETTINGS_POPUP_WIDTH = 300.0f;
        constexpr float SETTINGS_POPUP_HEIGHT = 250.0f;
    }
    
    // Color definitions (commonly used colors)
    namespace Colors {
        constexpr SDL_Color WHITE = {255, 255, 255, 255};
        constexpr SDL_Color BLACK = {0, 0, 0, 255};
        constexpr SDL_Color YELLOW_TITLE = {255, 220, 0, 255};
        constexpr SDL_Color GRAY_TEXT = {220, 220, 230, 255};
        constexpr SDL_Color BLUE_HIGHLIGHT = {200, 240, 255, 255};
        constexpr SDL_Color RED_ERROR = {255, 80, 60, 255};
        constexpr SDL_Color GREEN_SUCCESS = {0, 255, 0, 255};
        constexpr SDL_Color RED_DISABLED = {255, 0, 0, 255};
        constexpr SDL_Color CONTROL_HINT = {150, 150, 170, 255};
        constexpr SDL_Color PAUSED_TEXT = {255, 255, 255, 255};
        constexpr SDL_Color PAUSED_HINT = {200, 200, 220, 255};
        constexpr SDL_Color SHADOW = {0, 0, 0, 200};
    }
    
    // Font configuration
    namespace Fonts {
        constexpr int DEFAULT_FONT_SIZE = 24;
        constexpr int PIXEL_FONT_SIZE = 16;
        constexpr const char* DEFAULT_FONT_PATH = "FreeSans.ttf";
        constexpr const char* PIXEL_FONT_PATH = "assets/fonts/PressStart2P-Regular.ttf";
    }
    
    // Asset paths
    namespace Assets {
        constexpr const char* IMAGES_DIR = "assets/images/";
        constexpr const char* MUSIC_DIR = "assets/music/";
        constexpr const char* FONTS_DIR = "assets/fonts/";
        
        // Specific asset files
        constexpr const char* LOGO_BMP = "assets/images/logo.bmp";
        constexpr const char* LOGO_SMALL_BMP = "assets/images/logo_small.bmp";
        constexpr const char* BACKGROUND_BMP = "assets/images/main_background.bmp";
        constexpr const char* BLOCKS_BMP = "assets/images/2.png";
    }
    
    // Audio settings
    namespace Audio {
        constexpr float DEFAULT_VOLUME = 1.0f;
        constexpr float LETS_GO_VOLUME = 1.0f;
        constexpr int MAX_MUSIC_TRACKS = 100;  // Maximum number of music files to scan
    }
    
    // Input settings  
    namespace Input {
        constexpr int MOUSE_BUTTON_PRIMARY = SDL_BUTTON_LEFT;
        constexpr Uint32 MODIFIER_SHIFT = SDL_KMOD_SHIFT;
        constexpr Uint32 MODIFIER_CTRL = SDL_KMOD_CTRL;
    }
    
    // Performance settings
    namespace Performance {
        constexpr float MIN_FRAME_TIME = 0.05f;  // Cap at 20 FPS minimum (prevent spiral of death)
        constexpr int STARFIELD_PARTICLE_COUNT = 200;
        constexpr int STARFIELD_3D_PARTICLE_COUNT = 200;
    }

    // Visual effects settings
    namespace Visuals {
        constexpr int PAUSE_BLUR_ITERATIONS = 8; // Number of blur passes (higher = more blur)
        constexpr int PAUSE_BLUR_OFFSET = 3;     // Pixel spread of the blur
        constexpr int PAUSE_BLUR_ALPHA = 40;     // Alpha intensity of blur layers
    }
}
