import { InlineKeyboard, Keyboard } from "grammy";
import { ServiceCategoryRow } from "../models/ServiceCategory";
import { ServiceRow } from "../models/Service";

// ─── Reply Keyboard (muncul di bawah kolom chat) ─────────────────────────────

export function getMainReplyKeyboard(): Keyboard {
  return new Keyboard()
    .text("ℹ️ Tentang Kami").row()
    .text("🛠 Layanan").text("🗂 Portfolio").row()
    .text("💰 Harga").text("🤖 Konsultasi AI").row()
    .text("👨‍💼 Hubungi Admin").text("📢 Channel").row()
    .resized()
    .persistent();
}

// ─── Inline Keyboards (muncul di dalam pesan) ─────────────────────────────────

export function getPortfolioMenu(): InlineKeyboard {
  return new InlineKeyboard()
    .text("🌐 Website", "portfolio_web_0")
    .text("🤖 Bot Telegram", "portfolio_bot_0").row()
    .text("📱 Mobile App", "portfolio_mobile_0").row()
    .text("🏠 Menu Utama", "main_menu");
}

/** Menu kategori layanan (🌐 Web | 📱 APK | 🤖 Bot) */
export function getServiceCategoriesMenu(categories: ServiceCategoryRow[]): InlineKeyboard {
  const kb = new InlineKeyboard();
  categories.forEach((c, i) => {
    kb.text(`${c.icon} ${c.name}`, `svc_cat_${c.slug}`);
    if (i % 2 === 1) kb.row();
  });
  if (categories.length % 2 === 1) kb.row();
  return kb.text("🏠 Menu Utama", "main_menu");
}

/** Menu paket dalam satu kategori */
export function getServicePackagesMenu(
  packages: ServiceRow[],
  categorySlug: string
): InlineKeyboard {
  const kb = new InlineKeyboard();
  packages.forEach((s, i) => {
    kb.text(`${s.icon} ${s.name}`, `svc_pkg_${s.id}`);
    if (i % 2 === 1) kb.row();
  });
  if (packages.length % 2 === 1) kb.row();
  return kb.text("🔙 Kembali", `svc_back_${categorySlug}`);
}

/** Menu kategori untuk pilih konsultasi */
export function getConsultationCategoryMenu(categories: ServiceCategoryRow[]): InlineKeyboard {
  const kb = new InlineKeyboard();
  categories.forEach((c, i) => {
    kb.text(`${c.icon} ${c.name}`, `consult_cat_${c.slug}`);
    if (i % 2 === 1) kb.row();
  });
  if (categories.length % 2 === 1) kb.row();
  return kb.text("❌ Batal", "cancel_consult");
}

export function getFaqNavKeyboard(page: number, total: number): InlineKeyboard {
  const kb = new InlineKeyboard();
  if (page > 0) kb.text("◀️", `faq_${page - 1}`);
  kb.text(`${page + 1}/${total}`, "noop");
  if (page < total - 1) kb.text("▶️", `faq_${page + 1}`);
  return kb;
}

export function getPortfolioNavKeyboard(
  category: string,
  index: number,
  total: number
): InlineKeyboard {
  const kb = new InlineKeyboard();
  if (index > 0) kb.text("◀️", `portfolio_${category}_${index - 1}`);
  kb.text(`${index + 1}/${total}`, "noop");
  if (index < total - 1) kb.text("▶️", `portfolio_${category}_${index + 1}`);
  kb.row().text("🔙 Kategori Lain", "portfolio_menu");
  return kb;
}

export function getTestimonialNavKeyboard(index: number, total: number): InlineKeyboard {
  const kb = new InlineKeyboard();
  if (index > 0) kb.text("◀️", `testimonial_${index - 1}`);
  kb.text(`${index + 1}/${total}`, "noop");
  if (index < total - 1) kb.text("▶️", `testimonial_${index + 1}`);
  return kb;
}

export function getCancelMenu(): InlineKeyboard {
  return new InlineKeyboard()
    .text("⬅️ Kembali", "back_consult")
    .text("❌ Batal", "cancel_consult");
}
