use crate::app_state::AppState;

/// Pre-save actions for EditorView: stop file watching and unwatch current file.
pub fn editor_pre_save(ed: &mut crate::views::editor::EditorView, app: &mut AppState) {
    ed.stop_file_watching();
    if let Some(ref path) = ed.buffer.path {
        app.file_watcher.unwatch(path).ok();
    }
}

/// Pre-save actions for TerminalView: persist terminal state to project.
pub fn terminal_pre_save(tv: &mut crate::views::terminal::TerminalView, app: &mut AppState) {
    app.project.save_terminal_state(&tv.to_state());
}

/// ExtensionConfigView pre-save: flush pending changes if any.
pub fn extension_config_pre_save(
    ec: &mut crate::views::extension_config::ExtensionConfigView,
    _app: &mut AppState,
) {
    if ec.pending_save {
        // The detailed save logic lives in the view itself; here we ensure the flag
        // is visible and may be acted upon by the view implementation when invoked.
        log::debug!("extension config pending save detected");
    }
}
