"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.showServicesMenu = showServicesMenu;
exports.showServiceCategory = showServiceCategory;
exports.showServicePackage = showServicePackage;
exports.buildPriceText = buildPriceText;
const grammy_1 = require("grammy");
const ServiceCategory_1 = require("../models/ServiceCategory");
const Service_1 = require("../models/Service");
const mainMenu_1 = require("../menus/mainMenu");
/** Tampilkan menu 3 kategori: Web, APK, Bot */
async function showServicesMenu(ctx) {
    const categories = ServiceCategory_1.ServiceCategoryModel.getAll();
    if (ctx.callbackQuery) {
        try {
            await ctx.deleteMessage();
        }
        catch (_) { }
    }
    await ctx.reply(`🛠 *Layanan JD Technolody*\n\nPilih kategori layanan:`, { parse_mode: "Markdown", reply_markup: (0, mainMenu_1.getServiceCategoriesMenu)(categories) });
}
/** Tampilkan daftar paket dalam satu kategori */
async function showServiceCategory(ctx, categorySlug) {
    const category = ServiceCategory_1.ServiceCategoryModel.getBySlug(categorySlug);
    if (!category)
        return;
    const packages = Service_1.ServiceModel.getByCategory(categorySlug);
    try {
        await ctx.deleteMessage();
    }
    catch (_) { }
    if (packages.length === 0) {
        await ctx.reply(`${category.icon} *${category.name}*\n\nBelum ada paket tersedia.`, {
            parse_mode: "Markdown",
            reply_markup: new grammy_1.InlineKeyboard().text("🔙 Kembali", "services_menu"),
        });
        return;
    }
    await ctx.reply(`${category.icon} *${category.name}*\n\n${category.description}\n\nPilih paket:`, { parse_mode: "Markdown", reply_markup: (0, mainMenu_1.getServicePackagesMenu)(packages, categorySlug) });
}
/** Tampilkan detail satu paket */
async function showServicePackage(ctx, packageId) {
    const pkg = Service_1.ServiceModel.getById(packageId);
    if (!pkg)
        return;
    const category = ServiceCategory_1.ServiceCategoryModel.getBySlug(pkg.category_slug);
    const features = (0, Service_1.parseFeatures)(pkg.features);
    try {
        await ctx.deleteMessage();
    }
    catch (_) { }
    let text = `${pkg.icon} *${pkg.name}*\n\n`;
    text += `${pkg.description}\n\n`;
    text += `💰 *Harga: ${pkg.price}*\n\n`;
    if (features.length > 0) {
        text += `✅ *Yang Anda dapatkan:*\n`;
        text += features.map((f) => `• ${f}`).join("\n");
        text += "\n\n";
    }
    text += `_Harga dapat berubah sesuai kompleksitas. Konsultasi gratis!_`;
    await ctx.reply(text, {
        parse_mode: "Markdown",
        reply_markup: new grammy_1.InlineKeyboard()
            .text("🤖 Konsultasi Sekarang", `consult_cat_${pkg.category_slug}`).row()
            .text("🔙 Paket Lainnya", `svc_back_${pkg.category_slug}`),
    });
}
/** Tampilkan harga ringkas semua kategori untuk menu 💰 Harga */
function buildPriceText() {
    const categories = ServiceCategory_1.ServiceCategoryModel.getAll();
    let text = `💰 *Daftar Harga Layanan JD Technolody*\n\n`;
    for (const cat of categories) {
        const packages = Service_1.ServiceModel.getByCategory(cat.slug);
        if (packages.length === 0)
            continue;
        text += `${cat.icon} *${cat.name}*\n`;
        text += packages.map((p) => `   • ${p.name}: *${p.price}*`).join("\n");
        text += "\n\n";
    }
    text += `_Harga dapat berubah sesuai kompleksitas fitur._`;
    return text;
}
