use std::sync::Arc;
use teloxide::payloads::SendMessageSetters;
use teloxide::types::{ChatId, InlineKeyboardButton, InlineKeyboardMarkup, ParseMode, ThreadId};
use uuid::Uuid;
use super::TelegramState;
pub(crate) const FOLLOWUP_PREFIX: &str = "followup:";
pub(crate) async fn render_suggestions(
bot: &teloxide::Bot,
state: &Arc<TelegramState>,
session_id: Uuid,
chat_id: ChatId,
thread_id: Option<ThreadId>,
options: Vec<String>,
) {
use teloxide::prelude::Requester;
if options.is_empty() {
return;
}
let rows: Vec<Vec<InlineKeyboardButton>> = options
.iter()
.enumerate()
.map(|(i, opt)| {
let label = if opt.chars().count() > 60 {
let mut s: String = opt.chars().take(57).collect();
s.push_str("...");
s
} else {
opt.clone()
};
vec![InlineKeyboardButton::callback(
label,
format!("{FOLLOWUP_PREFIX}{session_id}:{i}"),
)]
})
.collect();
state.set_pending_followups(session_id, options).await;
let keyboard = InlineKeyboardMarkup::new(rows);
let mut req = bot
.send_message(chat_id, "\u{1f4a1} Suggested next:")
.reply_markup(keyboard);
req = req.parse_mode(ParseMode::Html);
if let Some(tid) = thread_id {
req = req.message_thread_id(tid);
}
if let Err(e) = req.await {
tracing::warn!("Telegram suggest_followups: send failed: {e}");
state.clear_pending_followups(session_id).await;
}
}