const {
    Markup
} = require('telegraf')
const {
    houses,
    cars,
    phones
} = global.config

module.exports = async (ctx) => {
    let data = ctx.update.callback_query.data;
    let prodArray = []
    let text = `Доступно к покупке:\n`
    switch(data){
        case `shop_house`:
            for (i in houses) {
                prodArray.push({text: i, callback_data: `{"action": "buy", "type": "house", "value": "${i}"}`})
                text += i + `. ${houses[i].name} (₽${houses[i].price})\n`
            }
        break;
        case `shop_phone`:
            for (i in phones) {
                prodArray.push({text: i, callback_data: `{"action": "buy", "type": "phone", "value": "${i}"}`})
                text += i + `. ${phones[i].name} (₽${phones[i].price})\n`
            }
        break;
        case `shop_car`:
            for (i in cars) {
                prodArray.push({text: i, callback_data: `{"action": "buy", "type": "car", "value": "${i}"}`})
                text += i + `. ${cars[i].name} (₽${cars[i].price})\n`
            }
        break;
    }
    prodArray.push({text: `Назад`, callback_data: `shopmenu`})
    let rows = []
    while (prodArray.length > 0) {
        rows.push(prodArray.splice(0, 5)) // разбиваем на подмассивы по 5 кнопок
    }
    return await ctx.editMessageText(text, Markup
        .inlineKeyboard(rows)
        .resize())
}