import fetch from "node-fetch";
import fs from "fs";
import { pickRandom } from "../../lib/other-function.js";
const handler = async (m, { conn, args, text, usedPrefix, command }) => {
  wm, author, snh, fs.readFileSync("./thumbnail.jpg");
  if (((conn.slots = conn.slots ? conn.slots : {}), m.chat in conn.slots))
    return m.reply(
      "Masih ada Yang Melakukan Slots Disini, Tunggu Sampai selesai!!",
    );
  conn.slots[m.chat] = !0;
  try {
    if (args.length < 1)
      return m.reply(
        `Gunakan format *${usedPrefix}${command} [jumlah]*\ncontoh *${usedPrefix}${command} 10*`,
      );
    let WinOrLose,
      Hadiah,
      count = args[0],
      _spin1 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin2 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin3 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin4 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin5 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin6 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin7 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin8 = pickRandom(["1", "2", "3", "4", "5"]),
      _spin9 = pickRandom(["1", "2", "3", "4", "5"]),
      spin1 = 1 * _spin1,
      spin2 = 1 * _spin2,
      spin3 = 1 * _spin3,
      spin4 = 1 * _spin4,
      spin5 = 1 * _spin5,
      spin6 = 1 * _spin6,
      spin7 = 1 * _spin7,
      spin8 = 1 * _spin8,
      spin9 = 1 * _spin9,
      spins1 =
        1 === spin1
          ? "🍊"
          : 2 === spin1
            ? "🍇"
            : 3 === spin1
              ? "🍉"
              : 4 === spin1
                ? "🍌"
                : 5 === spin1
                  ? "🍍"
                  : "",
      spins2 =
        1 === spin2
          ? "🍊"
          : 2 === spin2
            ? "🍇"
            : 3 === spin2
              ? "🍉"
              : 4 === spin2
                ? "🍌"
                : 5 === spin2
                  ? "🍍"
                  : "",
      spins3 =
        1 === spin3
          ? "🍊"
          : 2 === spin3
            ? "🍇"
            : 3 === spin3
              ? "🍉"
              : 4 === spin3
                ? "🍌"
                : 5 === spin3
                  ? "🍍"
                  : "",
      spins4 =
        1 === spin4
          ? "🍊"
          : 2 === spin4
            ? "🍇"
            : 3 === spin4
              ? "🍉"
              : 4 === spin4
                ? "🍌"
                : 5 === spin4
                  ? "🍍"
                  : "",
      spins5 =
        1 === spin5
          ? "🍊"
          : 2 === spin5
            ? "🍇"
            : 3 === spin5
              ? "🍉"
              : 4 === spin5
                ? "🍌"
                : 5 === spin5
                  ? "🍍"
                  : "",
      spins6 =
        1 === spin6
          ? "🍊"
          : 2 === spin6
            ? "🍇"
            : 3 === spin6
              ? "🍉"
              : 4 === spin6
                ? "🍌"
                : 5 === spin6
                  ? "🍍"
                  : "",
      spins7 =
        1 === spin7
          ? "🍊"
          : 2 === spin7
            ? "🍇"
            : 3 === spin7
              ? "🍉"
              : 4 === spin7
                ? "🍌"
                : 5 === spin7
                  ? "🍍"
                  : "",
      spins8 =
        1 === spin8
          ? "🍊"
          : 2 === spin8
            ? "🍇"
            : 3 === spin8
              ? "🍉"
              : 4 === spin8
                ? "🍌"
                : 5 === spin8
                  ? "🍍"
                  : "",
      spins9 =
        1 === spin9
          ? "🍊"
          : 2 === spin9
            ? "🍇"
            : 3 === spin9
              ? "🍉"
              : 4 === spin9
                ? "🍌"
                : 5 === spin9
                  ? "🍍"
                  : "",
      user = db.data.users[m.sender];
    user.money -= Math.ceil(1 * count);
    for (let i = 0; i < 3; i++)
      m.reply(
        m.chat,
        `\n            *🎰VIRTUAL SLOTS🎰*\n            \n${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}|${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}|${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}\n${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}|${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}|${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])} <<==\n${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}|${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}|${pickRandom(["🍊", "🍇", "🍉", "🍌", "🍍"])}\n            \n            `,
        m,
      );
    spin1 === spin2 &&
    spin2 === spin3 &&
    spin3 === spin4 &&
    spin4 === spin5 &&
    spin5 === spin6 &&
    spin6 === spin7 &&
    spin7 === spin8 &&
    spin8 === spin9
      ? ((WinOrLose = "BIG JACKPOT🥳🥳"),
        (Hadiah = `+${Math.ceil(4 * count)}`),
        (user.money += Math.ceil(4 * count)))
      : spin4 === spin5 && spin5 === spin6
        ? ((WinOrLose = "JACKPOT🥳"),
          (Hadiah = `+${Math.ceil(2 * count)}`),
          (user.money += Math.ceil(2 * count)))
        : (spin1 === spin2 && spin2 === spin3) ||
            (spin7 === spin8 && spin8 === spin9)
          ? ((Hadiah = `-${Math.ceil(1 * count)}`),
            (WinOrLose = "DIKIT LAGI!!"))
          : ((Hadiah = `-${Math.ceil(1 * count)}`), (WinOrLose = "YOU LOSE")),
      await conn.reply(
        m.chat,
        `\n       *🎰VIRTUAL SLOTS🎰*\n\n${spins1}|${spins2}|${spins3}\n${spins4}|${spins5}|${spins6} <<==\n${spins7}|${spins8}|${spins9}\n\n*${WinOrLose}* *${Hadiah}*\n`,
        m,
      );
  } catch (e) {
    console.log(e), await conn.reply(m.chat, "Error", m);
  } finally {
    delete conn.slots[m.chat];
  }
};
(handler.help = ["slot", "jackpot"]),
  (handler.tags = ["rpg", "game"]),
  (handler.command = /^slots?|jac?kpot$/i);
export default handler;
