use crate::tui::app::state::App;
use crate::tui::models::InputMode;
pub(super) fn handle_clipboard_paste(app: &mut App) {
if let Some(text) = crate::tui::clipboard::get_clipboard_text() {
insert_clipboard_text(app, &text);
return;
}
match crate::tui::clipboard::get_clipboard_image() {
Some(image) => {
app.state.pending_images.push(image);
let n = app.state.pending_images.len();
app.state.status = if n == 1 {
"Attached 1 clipboard image. Type a message and press Enter to send.".into()
} else {
format!("Attached {n} clipboard images. Press Enter to send them.")
};
}
None => {
app.state.status = "Clipboard empty — use /image <path> for images".into();
}
}
}
fn insert_clipboard_text(app: &mut App, text: &str) {
let normalized = text.replace("\r\n", "\n").replace('\r', "\n");
app.state.input_mode = if app.state.input.is_empty() && normalized.starts_with('/') {
InputMode::Command
} else if app.state.input.starts_with('/') {
InputMode::Command
} else {
InputMode::Editing
};
app.state.insert_text(&normalized);
let line_count = normalized.lines().count();
app.state.status = if line_count > 1 {
format!("Pasted {line_count} lines from clipboard")
} else {
"Pasted from clipboard".to_string()
};
}