//! # RUSTELO Client
//!
//! <div align="center">
//!  <img src="../logos/rustelo_dev-logo-h.svg" alt="RUSTELO" width="300" />
//! </div>
//!
//! Frontend client library for the RUSTELO web application framework, built
//! with Leptos and WebAssembly.
//!
//! ## Overview
//!
//! The RUSTELO client provides a reactive, high-performance frontend experience
//! using Rust compiled to WebAssembly. It features component-based
//! architecture, state management, internationalization, and seamless
//! server-side rendering.
//!
//! ## Features
//!
//! - **⚡ Reactive UI** - Built with Leptos for fast, reactive user interfaces
//! - **🎨 Component System** - Reusable UI components with props and state
//! - **🌐 Internationalization** - Multi-language support with fluent
//! - **🔐 Authentication** - Complete auth flow with JWT and OAuth2
//! - **📱 Responsive Design** - Mobile-first design with Tailwind CSS
//! - **🚀 WebAssembly** - High-performance client-side rendering
//!
//! ## Architecture
//!
//! The client is organized into several key modules:
//!
//! - [`app`] - Minimal hydration component for WebAssembly
//! - [`components`] - Reusable UI components and forms
//! - [`pages`] - Individual page components (Home, About, etc.)
//! - [`auth`] - Authentication components and context
//! - [`state`] - Global state management and themes
//! - [`i18n`] - Internationalization and language support
//! - [`utils`] - Client-side utilities and helpers
//!
//! ## Quick Start
//!
//! ```rust,ignore
//! use rustelo_client::app::App;
//! use leptos::prelude::*;
//!
//! // Hydrate SSR content with client reactivity
//! leptos::mount::hydrate_body(|| view! { <App /> });
//! ```
//!
//! ## Component Usage
//!
//! ### Authentication Components
//!
//! ```rust,ignore
//! use rustelo_client::auth::{AuthProvider, LoginForm};
//! use leptos::prelude::*;
//!
//! view! {
//!   <AuthProvider>
//!     <LoginForm />
//!   </AuthProvider>
//! }
//! ```
//!
//! ### Form Components
//!
//! ```rust,ignore
//! use rustelo_client::rustelo_components_leptos::{ContactForm, SupportForm};
//! use leptos::prelude::*;
//!
//! view! {
//!   <ContactForm />
//!   <SupportForm />
//! }
//! ```
//!
//! ## State Management
//!
//! ### Theme Management
//!
//! ```rust,ignore
//! use rustelo_client::state::theme::{ThemeProvider, use_theme_state, Theme};
//! use leptos::prelude::*;
//!
//! #[component]
//! fn MyComponent() -> impl IntoView {
//!   let theme_state = use_theme_state();
//!
//!   view! {
//!     <button on:click=move |_| theme_state.toggle()>
//!       "Toggle Theme"
//!     </button>
//!   }
//! }
//! ```
//!
//! ## Internationalization
//!
//! ```rust,ignore
//! use rustelo_client::i18n::{I18nProvider, use_i18n};
//! use leptos::prelude::*;
//!
//! #[component]
//! fn MyComponent() -> impl IntoView {
//!   let i18n = use_i18n();
//!
//!   view! {
//!     <p>{i18n.t("welcome_message")}</p>
//!   }
//! }
//! ```
//!
//! ## WebAssembly Integration
//!
//! The client is designed to run efficiently in WebAssembly environments:
//!
//! - **Small Bundle Size** - Optimized for fast loading
//! - **Memory Efficient** - Careful memory management
//! - **Browser APIs** - Safe access to web APIs through web-sys
//! - **Error Handling** - Comprehensive error boundaries
//!
//! ## Development
//!
//! ### Building
//!
//! ```bash
//! # Development build
//! cargo build --target wasm32-unknown-unknown
//!
//! # Production build
//! cargo build --release --target wasm32-unknown-unknown
//!
//! # Using cargo-leptos
//! cargo leptos build
//! ```
//!
//! ### Testing
//!
//! ```bash
//! # Run tests
//! cargo test
//!
//! # Run tests in browser
//! wasm-pack test --headless --chrome
//! ```
//!
//! ## Performance
//!
//! Optimized for performance with:
//!
//! - **Lazy Loading** - Components loaded on demand
//! - **Virtual DOM** - Efficient rendering with fine-grained reactivity
//! - **Code Splitting** - Reduced initial bundle size
//! - **Caching** - Smart caching of static assets
//!
//! ## Browser Support
//!
//! - **Modern Browsers** - Chrome 80+, Firefox 72+, Safari 13.1+, Edge 80+
//! - **WebAssembly** - Required for optimal performance
//! - **JavaScript Fallback** - Graceful degradation where possible
//!
//! ## Contributing
//!
//! Contributions are welcome! Please see our [Contributing Guidelines](https://github.com/yourusername/rustelo/blob/main/CONTRIBUTING.md).
//!
//! ## License
//!
//! This project is licensed under the MIT License - see the [LICENSE](https://github.com/yourusername/rustelo/blob/main/LICENSE) file for details.

#![recursion_limit = "256"]

pub mod app;
pub mod auth;
// pub mod components;
pub mod config;
// Removed: pub mod defs; (unused route definitions)
pub mod highlight;
pub mod i18n;
// pub mod pages;
pub mod routing;
pub mod state;
pub mod utils;

// Re-export console control functions for easy access
pub use rustelo_core_lib::utils::console_control;
use rustelo_core_lib::PageTranslator;
pub use rustelo_core_lib::{safe_console_error, safe_console_log, safe_console_warn};

// Implement PageTranslator for the client's UseI18n type
impl PageTranslator for crate::i18n::UseI18n {
    fn t(&self, key: &str) -> String {
        self.t(key)
    }

    fn localized_url(&self, path: &str) -> String {
        self.localized_url(path)
    }

    fn lang_code(&self) -> String {
        self.lang_code()
    }
}

#[cfg(feature = "hydrate-entrypoint")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn hydrate() {
    console_error_panic_hook::set_once();

    // Mark start of hydration
    crate::utils::hydration_debug::set_hydrating(true);
    web_sys::console::log_1(&"[HYDRATION] Starting standard Leptos hydration process...".into());

    // Get the current path from the window location
    let initial_path = if let Some(window) = web_sys::window() {
        window.location().pathname().unwrap_or_default()
    } else {
        String::new()
    };

    web_sys::console::log_1(
        &format!("[HYDRATION] Initial path for hydration: {}", initial_path).into(),
    );

    // Use hydrate_body with __RESOLVED_RESOURCES now available
    leptos::mount::hydrate_body(move || {
        web_sys::console::log_1(
            &format!(
                "[HYDRATION] Creating App component for hydration with path: {}",
                initial_path
            )
            .into(),
        );
        view! { <crate::app::AppComponent initial_path=initial_path /> }
    });

    // Mark end of hydration
    crate::utils::hydration_debug::set_hydrating(false);
    web_sys::console::log_1(&"[HYDRATION] Standard Leptos hydration process completed".into());
}
