use std::cell::{Cell, RefCell};
use ratatui::Frame;
use ratatui::widgets::TableState;
use crate::app::AppViewSnapshot;
use crate::ui::{self, RenderCacheStore};
#[derive(Default)]
pub(crate) struct PresentationState {
project_table_state: RefCell<TableState>,
render_cache_store: RenderCacheStore,
rendered_surface: Cell<Option<ui::router::SurfaceKind>>,
session_table_state: RefCell<TableState>,
}
impl PresentationState {
pub(crate) fn terminal_clear_needed(&self, snapshot: &AppViewSnapshot<'_>) -> bool {
let current_surface = ui::router::surface_kind_for_mode(snapshot.mode);
self.rendered_surface
.get()
.is_some_and(|rendered_surface| rendered_surface != current_surface)
}
pub(crate) fn record_rendered_surface(&self, snapshot: &AppViewSnapshot<'_>) {
let rendered_surface = ui::router::surface_kind_for_mode(snapshot.mode);
self.rendered_surface.set(Some(rendered_surface));
}
pub(crate) fn render(&self, snapshot: &AppViewSnapshot<'_>, frame: &mut Frame) {
let mut project_table_state = self.project_table_state.borrow_mut();
let mut session_table_state = self.session_table_state.borrow_mut();
ui::render_app(
snapshot,
frame,
&mut project_table_state,
&self.render_cache_store,
&mut session_table_state,
);
}
pub(crate) fn render_cache_store(&self) -> &RenderCacheStore {
&self.render_cache_store
}
}