use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use slate_platform::{DefaultPlatform, DefaultWindow, WindowId};
use crate::app::AppContext;
use crate::erased_view::ErasedView;
use crate::event::{
ImeCommitHandler, ImeLifecycleHandler, ImePreeditHandler, KeyHandler, TextInputHandler,
};
use crate::executor::{Executor, RedrawRequester};
use crate::paint_cache::{TextShapingCache, TextShapingCacheObserver};
use crate::reactive_state::StateRegistry;
use crate::text_system::TextSystem;
use super::window_state::WindowState;
pub(crate) type ErasedViewFactory = Box<dyn FnMut(&AppContext) -> Box<dyn ErasedView>>;
pub(crate) struct PendingWindowCreate {
pub window: Arc<DefaultWindow>,
pub view_factory: ErasedViewFactory,
}
pub struct AppState {
pub windows: RefCell<HashMap<WindowId, WindowState>>,
pub runtime: Arc<slate_reactive::Runtime>,
pub executor: Executor,
pub text_system: Rc<RefCell<Option<TextSystem>>>,
pub text_shaping_cache: Rc<RefCell<TextShapingCache>>,
pub text_shaping_cache_observer: Rc<TextShapingCacheObserver>,
pub(crate) state_registry: RefCell<StateRegistry>,
pub redraw_requesters: Arc<Mutex<Vec<(WindowId, RedrawRequester)>>>,
pub pending_quit: std::cell::Cell<bool>,
pub(crate) platform: RefCell<Option<Rc<DefaultPlatform>>>,
pub(crate) pending_window_creates: RefCell<Vec<PendingWindowCreate>>,
pub(super) on_key_down: RefCell<Vec<KeyHandler>>,
pub(super) on_key_up: RefCell<Vec<KeyHandler>>,
pub(super) on_text_input: RefCell<Vec<TextInputHandler>>,
pub(super) on_ime_preedit: RefCell<Vec<ImePreeditHandler>>,
pub(super) on_ime_commit: RefCell<Vec<ImeCommitHandler>>,
pub(super) on_ime_enabled: RefCell<Vec<ImeLifecycleHandler>>,
pub(super) on_ime_disabled: RefCell<Vec<ImeLifecycleHandler>>,
}
impl Drop for AppState {
fn drop(&mut self) {
log::debug!("AppState dropped — cycle-free shutdown verified");
}
}