#![forbid(unsafe_code)]
#![warn(missing_docs)]
//! # tools-tui-shared
//!
//! Shared TUI utilities and widgets for the Tools ecosystem using Ratatui 0.30.0-beta.0.
//!
//! This library provides:
//! - Reusable widgets (Menu, Form, Table, `StatusBar`, Help)
//! - Advanced features (Monitoring, History, Search, Logs, `ThemeBuilder`)
//! - Layout managers (Dashboard, `MasterDetail`, Modal)
//! - Event handling system with configurable key bindings
//! - Theme system for consistent styling
//! - Terminal lifecycle management with RAII patterns
//! - Multi-tool dashboard integration helpers
//!
//! ## Architecture Principles
//!
//! All components follow `RataTui` guidelines:
//! - **R-STATE-SEPARATION**: State completely separated from rendering
//! - **R-WIDGET-COMPOSITION**: Complex UIs built from simple widgets
//! - **R-RESPONSIVE-LAYOUT**: Percentage-based constraints
//! - **R-EFFICIENT-RENDERING**: Only update changed portions
//! - **R-CONSISTENT-THEMING**: Unified theme system
//! - **R-EVENT-LOOP**: Non-blocking event polling
//! - **R-GRACEFUL-SHUTDOWN**: RAII terminal guards
//!
//! ## Rust Guideline Compliance
//!
//! - ✅ **M-UNSAFE**: Zero unsafe code (forbid)
//! - ✅ **M-PANIC-IS-STOP**: All functions return Result<T>
//! - ✅ **M-ERRORS-CANONICAL-STRUCTS**: Specific error types via thiserror
//! - ✅ **M-PUBLIC-DEBUG**: All public types implement Debug
//! - ✅ **M-PUBLIC-DISPLAY**: User-facing types implement Display
//! - ✅ **M-SIMPLE-ABSTRACTIONS**: Clean trait boundaries
//! - ✅ **M-AVOID-WRAPPERS**: `RataTui` types hidden behind clean APIs
//!
//! ## Quick Start
//!
//! ```ignore
//! use tools_tui_shared::prelude::*;
//! use ratatui::backend::CrosstermBackend;
//! use ratatui::Terminal;
//! use std::io;
//!
//! // Pseudocode example - AppState is a trait, implement it in your app
//! struct MyAppState {
//!     counter: i32,
//!     should_quit: bool,
//! }
//!
//! // In your main function:
//! async fn example() -> Result<()> {
//!     // Setup terminal with RAII guard
//!     let _guard = TerminalGuard::setup()?;
//!
//!     // Create terminal
//!     let backend = CrosstermBackend::new(io::stdout());
//!     let mut terminal = Terminal::new(backend)?;
//!
//!     // Create app state (R-STATE-SEPARATION)
//!     let mut app_state = MyAppState {
//!         counter: 0,
//!         should_quit: false,
//!     };
//!
//!     // Create theme
//!     let theme = Theme::dark();
//!
//!     // Application loop
//!     loop {
//!         // Render only if changed
//!         terminal.draw(|frame| {
//!             // Your rendering code here
//!         })?;
//!
//!         // Handle events
//!         // ...
//!
//!         if app_state.should_quit { break; }
//!     }
//!     Ok(())
//! }
//! ```
//!
//! ## Module Overview
//!
//! - [`widgets`] - Reusable UI widgets
//! - [`layouts`] - Layout managers for complex UIs
//! - [`events`] - Event handling and key bindings
//! - [`app`] - State management traits
//! - [`config`] - Theme and configuration
//! - [`terminal`] - Terminal lifecycle management
//! - [`integration`] - Multi-tool integration helpers
//!
//! ## Features
//!
//! - `interactive`: Enable interactive widgets (`TextArea`, Select, etc.)
//! - `test-util`: Testing utilities (feature-gated per M-TEST-UTIL-FEATURE-GATED)
//! - `serde`: Serialization support for config types

pub mod app;
pub mod config;
pub mod events;
pub mod integration;
pub mod layouts;
pub mod plugin;
pub mod terminal;
pub mod utils;
pub mod widgets;

// Re-export commonly used types
pub mod prelude {
    //! Convenience re-exports for common types
    pub use crate::app::{AppState, Focus, NavigationAction, Screen};
    pub use crate::config::{KeyBindings, Status, Theme};
    pub use crate::events::{AppEvent, EventHandler};
    pub use crate::integration::{
        Project, ProjectSelector, ToolMetrics, ToolRegistry, ToolSummary, ToolSummaryProvider,
    };
    pub use crate::layouts::{DashboardLayout, MasterDetailLayout, ModalLayout};
    pub use crate::plugin::{Plugin, PluginContext, PluginError, PluginRegistry, PluginResult};
    pub use crate::terminal::{TerminalGuard, TerminalSize};
    pub use crate::utils::list::{clamp_index, navigate_down, navigate_up};
    pub use crate::utils::terminal::{is_terminal_large_enough, is_terminal_recommended_size};
    pub use crate::utils::text::{center_text, normalize_spaces, truncate_with_ellipsis};
    pub use crate::widgets::{
        AppFooter,
        AppHeader,
        ColorValue,
        // Advanced features
        CommandHistory,
        FieldType,
        Form,
        FormField,
        Help,
        HelpEntry,
        HistoryEntry,
        LogEntry,
        LogFilter,
        LogLevel,
        LogViewer,
        Menu,
        MenuItem,
        Metric,
        MonitoringDashboard,
        SearchManager,
        SearchQuery,
        SearchResult,
        StatusBar,
        StatusItem,
        Table,
        TableColumn,
        TableRow,
        ThemeBuilder,
        ThemeCustomization,
    };

    // Common RataTui types
    pub use ratatui::backend::Backend;
    pub use ratatui::layout::{Alignment, Constraint, Direction, Layout, Margin, Rect};
    pub use ratatui::style::{Color, Modifier, Style};
    pub use ratatui::text::{Line, Span};
    pub use ratatui::widgets::{Block, Borders, Padding, Widget};
    pub use ratatui::Frame;

    // Common crossterm types
    pub use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent};

    // Error handling
    pub use anyhow::{anyhow, Result};
}

/// Library version
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_version_exists() {
        // Verify VERSION constant is accessible at runtime
        let version = VERSION;
        assert!(!version.is_empty());
    }
}
