import { Context } from "grammy";
import { faqData, testimonials } from "../data/faq";
import { getFaqNavKeyboard, getTestimonialNavKeyboard } from "../menus/mainMenu";

export async function showFaq(ctx: Context, page: number) {
  const total = faqData.length;
  const i = Math.max(0, Math.min(page, total - 1));
  const item = faqData[i];

  const text =
    `❓ *FAQ — ${i + 1}/${total}*\n\n` +
    `*${item.question}*\n\n` +
    `${item.answer}`;

  try { await ctx.deleteMessage(); } catch (_) {}
  await ctx.reply(text, {
    parse_mode: "Markdown",
    reply_markup: getFaqNavKeyboard(i, total),
  });
}

export async function showTestimonial(ctx: Context, index: number) {
  const total = testimonials.length;
  const i = Math.max(0, Math.min(index, total - 1));
  const t = testimonials[i];
  const stars = "⭐".repeat(t.rating);

  const text =
    `⭐ *Testimoni Klien — ${i + 1}/${total}*\n\n` +
    `${stars}\n\n` +
    `"${t.text}"\n\n` +
    `— *${t.name}*\n` +
    `🏢 ${t.company}`;

  try { await ctx.deleteMessage(); } catch (_) {}
  await ctx.reply(text, {
    parse_mode: "Markdown",
    reply_markup: getTestimonialNavKeyboard(i, total),
  });
}
