const { PermissionsBitField, EmbedBuilder, ActionRowBuilder, ButtonBuilder,ButtonStyle } = require("discord.js");
const kanal = require("../../../../../../Global/Settings/AyarName");
const { DiscordTogether } = require('discord-together');
const client = global.client;
client.discordTogether = new DiscordTogether(client);

module.exports = {
    name: "aktivite",
    description: "Ses kanalÄ±nda oyun oynarsÄ±nÄ±z.",
    category: "USER",
    cooldown: 0,
    command: {
      enabled: true,
      aliases: ["aktivite", "together","etkinlik"],
      usage: ".aktivite", 
    },
  

    onLoad: function (client) { },

    onCommand: async function (client, message, args, ertuembed) {

        if (!message.member.voice.channel) {
            return message.reply({ content: `Herhangi bir ses kanalÄ± baÄŸlÄ± deÄŸilsin, ÃœzgÃ¼nÃ¼m!` }).delete(10);
          }
          
          const row = new ActionRowBuilder().addComponents(
            new StringSelectMenuBuilder()
              .setCustomId("aktivite")
              .setPlaceholder(`Aktiviteler iÃ§in menÃ¼yÃ¼ aÃ§Ä±n!`)
              .addOptions(
                { label: "Youtube", description: "ArkadaÅŸlarÄ±nla birlikte YouTube videolarÄ± izlemek ister misin?", value: "youtube", emoji: { id: "997820361246789713" } },
                { label: "Poker Night", description: "ArkadaÅŸlarÄ±nla Poker Night oynamak ister misin? EÄŸlenceli bir poker deneyimi iÃ§in buradayÄ±z!", value: "poker", emoji: { name: "ğŸƒ�" } },
                { label: "SatranÃ§", description: "ArkadaÅŸlarÄ±nla SatranÃ§ oynamak ister misin? Zeka ve strateji gerektiren bir oyun.", value: "chess", emoji: { name: "â™Ÿï¸�" } },
                { label: "Dama", description: "ArkadaÅŸlarÄ±nla Dama oynamak ister misin? Dama oyununun keyfini Ã§Ä±karÄ±n.", value: "checkers", emoji: { name: "ğŸ¥�" } },
                { label: "Kelime Oyunu", description: "ArkadaÅŸlarÄ±nla Kelime Oyunu oynamak ister misin? Kelime daÄŸarcÄ±ÄŸÄ±nÄ±zÄ± test edin.", value: "wordsnack", emoji: { name: "ğŸ” " } },
                { label: "Heceleme", description: "ArkadaÅŸlarÄ±nla Heceleme oynamak ister misin? Kelimeleri nasÄ±l doÄŸru bir ÅŸekilde heceleyebildiÄŸini gÃ¶ster!", value: "spellcast", emoji: { name: "ğŸ†—" } }                
              ),
          );
          
          const embed = new EmbedBuilder()
            .setAuthor({ name: message.guild.name, iconURL: message.guild.iconURL({ dynamic: true }) })
            .setTimestamp()
            .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL({ dynamic: true }) })
            .setThumbnail(message.guild.iconURL({ dynamic: true }))
            .addFields(
            { name: "AKTÄ°VÄ°TE SEÃ‡Ä°MÄ°", value: `\` â�¯ \` AÅŸaÄŸÄ±da listelenen aktivitelerden birini seÃ§erek arkadaÅŸlarÄ±nla oynayabilir veya aktivite yapabilirsin.`, inline: false },
            );
          
          message.channel.send({ embeds: [embed], components: [row] }).then(msg => {
            var filter = (component) => component.user.id === message.author.id;
            let collector = msg.createMessageComponentCollector({ filter, time: 30000 });
          
            collector.on('collect', async (i) => {
              if (i.customId === "aktivite") {
                const etkinlik = i.values[0];

                function bebegimharbidennekibarsinmanitanasoylebenisalsin(activityType) {
                  client.discordTogether.createTogetherCode(message.member.voice.channel.id, activityType).then(async invite => {
                    embed.setDescription(`${message.member} tarafÄ±ndan ${activityType === 'youtube' ? 'Youtube Together' : activityType} seÃ§ildi!`).setFooter({ text: "Bu davet 10 saniye iÃ§erisinde silinecektir." });
                    msg.edit({ embeds: [embed], components: [] }).then((e) => setTimeout(() => { e.delete(); }, 10000));
                    await i.reply({ content: `Ä°zlemek iÃ§in arkadaÅŸlarÄ±nla bu davet kodunu kullanabilirsin.\n${invite.code}`, ephemeral: true });
                  });
                }
          
                switch (etkinlik) {
                  case "youtube":
                    bebegimharbidennekibarsinmanitanasoylebenisalsin('youtube');
                    break;
                  case "poker":
                    bebegimharbidennekibarsinmanitanasoylebenisalsin('poker');
                    break;
                  case "chess":
                    bebegimharbidennekibarsinmanitanasoylebenisalsin('chess');
                    break;
                  case "checkers":
                    bebegimharbidennekibarsinmanitanasoylebenisalsin('checkers');
                    break;
                  case "wordsnack":
                    bebegimharbidennekibarsinmanitanasoylebenisalsin('wordsnack');
                    break;
                  case "spellcast":
                    bebegimharbidennekibarsinmanitanasoylebenisalsin('spellcast');
                    break;
                  default:
                    i.reply({ content: "GeÃ§ersiz etkinlik seÃ§ildi.", ephemeral: true });
                    break;
                }
              }
            });
          });          

     },
  };