const items = {
    buy: {
      limit: {
        exp: 999,
      },
      potion: {
        money: 1250,
      },
      aqua: {
        money: 500,
      },
      trash: {
        money: 40,
      },
      wood: {
        money: 700,
      },
      rock: {
        money: 850,
      },
      string: {
        money: 400,
      },
      iron: {
        money: 3e3,
      },
      diamond: {
        money: 7500,
      },
      emerald: {
        money: 8500,
      },
      gold: {
        money: 3500,
      },
      coal: {
        money: 1500,
      },
      common: {
        money: 200,
      },
      uncommon: {
        money: 2e3,
      },
      mythic: {
        money: 25e3,
      },
      legendary: {
        money: 75e3,
      },
      foodpet: {
        money: 3500,
      },
      Fox: {
        money: 4e4,
      },
      naga: {
        money: 12e4,
      },
      pet: {
        money: 12e4,
      },
      anggur: {
        money: 2e3,
      },
      apel: {
        money: 2e3,
      },
      batu: {
        money: 2e3,
      },
      berlian: {
        money: 2e3,
      },
      bibitanggur: {
        money: 2e3,
      },
      bibitapel: {
        money: 2e3,
      },
      bibitjeruk: {
        money: 2e3,
      },
      bibitmangga: {
        money: 2e3,
      },
      bibitpisang: {
        money: 2e3,
      },
      botol: {
        money: 2e3,
      },
      centaur: {
        money: 2e3,
      },
      eleksirb: {
        money: 2e3,
      },
      emasbatang: {
        money: 2e3,
      },
      emasbiasa: {
        money: 2e3,
      },
      exp: {
        money: 2e3,
      },
      gardenboc: {
        money: 2e3,
      },
      gardenboxs: {
        money: 2e3,
      },
      griffin: {
        money: 2e3,
      },
      healtmonster: {
        money: 2e3,
      },
      jeruk: {
        money: 2e3,
      },
      kaleng: {
        money: 2e3,
      },
      kardus: {
        money: 2e3,
      },
      kayu: {
        money: 2e3,
      },
      ketake: {
        money: 2e3,
      },
      koinexpg: {
        money: 2e3,
      },
      kucing: {
        money: 2e3,
      },
      kuda: {
        money: 2e3,
      },
      kyubi: {
        money: 2e3,
      },
      makanancentaur: {
        money: 2e3,
      },
      makanangriffin: {
        money: 2e3,
      },
      makanankyubi: {
        money: 2e3,
      },
      makanannaga: {
        money: 2e3,
      },
      makananpet: {
        money: 2e3,
      },
      makananphonix: {
        money: 2e3,
      },
      mangga: {
        money: 2e3,
      },
      pancingan: {
        money: 2e3,
      },
      phonix: {
        money: 2e3,
      },
      pisang: {
        money: 2e3,
      },
      rubah: {
        money: 2e3,
      },
      sampah: {
        money: 2e3,
      },
      serigala: {
        money: 2e3,
      },
      sword: {
        money: 2e3,
      },
      tiketcoin: {
        money: 2e3,
      },
      umpan: {
        money: 2e3,
      },
    },
    sell: {
      limit: {
        exp: 999,
      },
      potion: {
        money: 1250,
      },
      aqua: {
        money: 500,
      },
      trash: {
        money: 40,
      },
      wood: {
        money: 700,
      },
      rock: {
        money: 850,
      },
      string: {
        money: 400,
      },
      iron: {
        money: 3e3,
      },
      diamond: {
        money: 7500,
      },
      emerald: {
        money: 8500,
      },
      gold: {
        money: 3500,
      },
      coal: {
        money: 1500,
      },
      common: {
        money: 200,
      },
      uncommon: {
        money: 2e3,
      },
      mythic: {
        money: 25e3,
      },
      legendary: {
        money: 75e3,
      },
      foodpet: {
        money: 3500,
      },
      Fox: {
        money: 4e4,
      },
      naga: {
        money: 12e4,
      },
      pet: {
        money: 12e4,
      },
      anggur: {
        money: 2e3,
      },
      apel: {
        money: 2e3,
      },
      batu: {
        money: 2e3,
      },
      berlian: {
        money: 2e3,
      },
      bibitanggur: {
        money: 2e3,
      },
      bibitapel: {
        money: 2e3,
      },
      bibitjeruk: {
        money: 2e3,
      },
      bibitmangga: {
        money: 2e3,
      },
      bibitpisang: {
        money: 2e3,
      },
      botol: {
        money: 2e3,
      },
      centaur: {
        money: 2e3,
      },
      eleksirb: {
        money: 2e3,
      },
      emasbatang: {
        money: 2e3,
      },
      emasbiasa: {
        money: 2e3,
      },
      exp: {
        money: 2e3,
      },
      gardenboc: {
        money: 2e3,
      },
      gardenboxs: {
        money: 2e3,
      },
      griffin: {
        money: 2e3,
      },
      healtmonster: {
        money: 2e3,
      },
      jeruk: {
        money: 2e3,
      },
      kaleng: {
        money: 2e3,
      },
      kardus: {
        money: 2e3,
      },
      kayu: {
        money: 2e3,
      },
      ketake: {
        money: 2e3,
      },
      koinexpg: {
        money: 2e3,
      },
      kucing: {
        money: 2e3,
      },
      kuda: {
        money: 2e3,
      },
      kyubi: {
        money: 2e3,
      },
      makanancentaur: {
        money: 2e3,
      },
      makanangriffin: {
        money: 2e3,
      },
      makanankyubi: {
        money: 2e3,
      },
      makanannaga: {
        money: 2e3,
      },
      makananpet: {
        money: 2e3,
      },
      makananphonix: {
        money: 2e3,
      },
      mangga: {
        money: 2e3,
      },
      pancingan: {
        money: 2e3,
      },
      phonix: {
        money: 2e3,
      },
      pisang: {
        money: 2e3,
      },
      rubah: {
        money: 2e3,
      },
      sampah: {
        money: 2e3,
      },
      serigala: {
        money: 2e3,
      },
      sword: {
        money: 2e3,
      },
      tiketcoin: {
        money: 2e3,
      },
      umpan: {
        money: 2e3,
      },
    },
  },
  handler = async (m, { command, usedPrefix, args }) => {
    let imgr = flaaa.getRandom(),
      user = db.data.users[m.sender];
    const listItems = Object.fromEntries(
      Object.entries(items[command.toLowerCase()]).filter(
        ([v]) => v && v in user,
      ),
    );
    let text = "",
      footer = "",
      image = "",
      buttons = "";
    (text =
      "buy" === command.toLowerCase()
        ? `\n*${htki} BUY ${htka}*\n`.trim()
        : `\n*${htki} SELL ${htka}*\n`.trim()),
      (footer =
        "buy" === command.toLowerCase()
          ? `\n💁🏻‍♂ ᴛɪᴩ :\n⮕ ᴛᴏ ʙᴜʏ ɪᴛᴇᴍs:\n${usedPrefix}${command} *[item] [quantity]*\n★ ᴇxᴀᴍᴩʟᴇ:\n${usedPrefix}${command} *potion 10*\n\n–––––––––––––––––––––––––\n🔖 ɪᴛᴇᴍs ʟɪsᴛ :\n${Object.keys(
              listItems,
            )
              .map((v) => {
                let paymentMethod = Object.keys(listItems[v]).find(
                  (v) => v in user,
                );
                return `👉 1 ${rpg.emoticon(v)}${v} ﹫ ${listItems[v][paymentMethod]} ${rpg.emoticon(paymentMethod)}${paymentMethod}`.trim();
              })
              .join("\n")}\n`.trim()
          : `\n💁🏻‍♂ ᴛɪᴩ :\n⮕ ᴛᴏ sᴇʟʟ ɪᴛᴇᴍs:\n${usedPrefix}${command} *[item] [quantity]*\n★ ᴇxᴀᴍᴩʟᴇ:\n${usedPrefix}${command} *potion 10*\n\n–––––––––––––––––––––––––\n🔖 ɪᴛᴇᴍs ʟɪsᴛ :\n${Object.keys(
              listItems,
            )
              .map((v) => {
                let paymentMethod = Object.keys(listItems[v]).find(
                  (v) => v in user,
                );
                return `👉 1 ${rpg.emoticon(v)}${v} ﹫ ${listItems[v][paymentMethod]} ${rpg.emoticon(paymentMethod)}${paymentMethod}`.trim();
              })
              .join("\n")}\n`.trim()),
      (image = "buy" === command.toLowerCase() ? imgr + "buy" : imgr + "sell"),
      (buttons =
        "buy" === command.toLowerCase()
          ? [
              ["ʙᴜʏ ʟɪᴍɪᴛ", `${usedPrefix}buy limit`],
              ["ʙᴜʏ ᴩᴏᴛɪᴏɴ", `${usedPrefix}buy potion`],
            ]
          : [
              ["sᴇʟʟ ᴩᴏᴛɪᴏɴ", `${usedPrefix}sell potion`],
              ["sᴇʟʟ ᴛʀᴀsʜ", `${usedPrefix}sell trash`],
            ]);
    const item = (args[0] || "").toLowerCase(),
      total =
        1 *
        Math.floor(
          isNumber(args[1])
            ? Math.min(Math.max(parseInt(args[1]), 1), Number.MAX_SAFE_INTEGER)
            : 1,
        );
    if (!listItems[item])
      return await conn.sendFile(m.chat, image, "", text + "\n" + footer, m);
    if ("buy" === command.toLowerCase()) {
      let paymentMethod = Object.keys(listItems[item]).find((v) => v in user);
      return user[paymentMethod] < listItems[item][paymentMethod] * total
        ? await conn.sendFile(
            m.chat,
            imgr + "lowcredit",
            "",
            `*–『 INSUFFICIENT CREDIT 』–*\nʏᴏᴜ ɴᴇᴇᴅ ᴇxᴛʀᴀ *${listItems[item][paymentMethod] * total - user[paymentMethod]}* ${rpg.emoticon(paymentMethod)}${paymentMethod} ᴛᴏ ʙᴜʏ *${total}* ${rpg.emoticon(item)}${item}.\nʏᴏᴜ'ᴠᴇ *${user[paymentMethod]}* ${rpg.emoticon(paymentMethod)}${paymentMethod} ɪɴ ʙᴀɢ.\n–––––––––––––––––––––––––\n💁🏻‍♂ ᴛɪᴩ :\nᴏᴩᴇɴ ᴄʀᴀᴛᴇs & ᴄᴏʟʟᴇᴄᴛ ʀᴇᴡᴀʀᴅs.\n⮕ ᴛᴏ ᴏᴩᴇɴ ᴄʀᴀᴛᴇs:\n.open crate\n⮕ ᴛᴏ ᴄᴏʟʟᴇᴄᴛ ʀᴇᴡᴀʀᴅs:\n.adventure | .daily | .monthly\n`.trim(),
            m,
          )
        : ((user[paymentMethod] -= listItems[item][paymentMethod] * total),
          (user[item] += total),
          await conn.sendFile(
            m.chat,
            imgr + "bought",
            "",
            `*${htki} BOUGHT ${htka}*\nʏᴏᴜ *ʙᴏᴜɢʜᴛ ${total} ${rpg.emoticon(item)}${item}*.\n`.trim(),
            m,
          ));
    }
    return user[item] < total
      ? m.reply(
          `You don't have enough *${rpg.emoticon(item)}${item}* to sell, you only have ${user[item]} items`,
        )
      : ((user[item] -= total),
        (user.money += listItems[item].money * total),
        await conn.sendFile(
          m.chat,
          imgr + "sold",
          "",
          `*${htki} SOLD ${htka}*\nʏᴏᴜ *sᴏʟᴅ ${total} ${rpg.emoticon(item)}${item}*.\n`.trim(),
          m,
        ));
  };
(handler.help = ["buy", "sell"].map((v) => v + " [item] [count]")),
  (handler.tags = ["rpg"]),
  (handler.command = /^(buy|sell)$/i),
  (handler.disabled = !1);
export default handler;

function isNumber(number) {
  return number
    ? "number" == typeof (number = parseInt(number)) && !isNaN(number)
    : number;
}
