module.exports = {
  interaction: {
    name: "anket",
    description: "Embed mesajÄ± iÃ§erisinde bir anket yapar.",
    options: [
      {
        name: "baÅŸlÄ±k",
        description: "Anketin baÅŸlÄ±ÄŸÄ±nÄ± gir.",
        type: 3,
        required: true
      },
      {
        name: "aÃ§Ä±klama",
        description: "Anketin aÃ§Ä±klamasÄ±nÄ± gir.",
        type: 3,
        required: true
      },
      {
        name: "seÃ§enekler",
        description: "SeÃ§enekler arasÄ±na virgÃ¼l ekleyerek seÃ§enekleri belirt.",
        type: 3,
        required: false
      },
      {
        name: "herkesten-bahset",
        description: "@everyone'dan bahsedilsin mi?",
        choices: [
          { name: "Herkesten (@everyone) bahset!", value: "true" },
          { name: "Bahsetme (VarsayÄ±lan)", value: "false" },
        ],
        type: 3,
        required: false
      },
    ]
  },
  interactionOnly: true,
  aliases: ["oylama"],
  category: "Moderation",
  memberPermissions: ["ManageMessages", "MentionEveryone"],
  botPermissions: ["AddReactions", "MentionEveryone"],
  cooldown: 3000,

  async execute(client, interaction, data) {

    const title = interaction.options.getString("baÅŸlÄ±k"),
      description = interaction.options.getString("aÃ§Ä±klama"),
      options = interaction.options.getString("seÃ§enekler"),
      pingEveryone = interaction.options.getString("herkesten-bahset");
    const optionsArray = options?.split(',').filter(v => v);

    if (description.length > 2000)
      return interaction.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.red,
            title: '**Â»** AÃ§Ä±klaman Ã‡ok Uzun!',
            description: `**â€¢** Metnin **2000** karakteri geÃ§memeli.`
          }
        ]
      });

    if (title && title.length > 250)
      return interaction.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.red,
            title: '**Â»** Anket BaÅŸlÄ±ÄŸÄ± Ã‡ok Uzun!',
            description: `**â€¢** BaÅŸlÄ±k **250** karakteri geÃ§memeli.`
          }
        ]
      });

    if (options && options.length > 1000)
      return interaction.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.red,
            title: '**Â»** SeÃ§eneklerin Toplamda 1000 Karakteri GeÃ§memeli!',
            description: `**â€¢** Beni aÅŸÄ±yor, kusuruma bakma canÄ±m.`
          }
        ]
      });

    if (options && optionsArray.length < 2)
      return interaction.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.red,
            title: '**Â»** En Az 2 SeÃ§enek Belirtmelisin!',
            description: `**â€¢** Ya da istersen seÃ§enekleri boÅŸ bÄ±rakabilirsin.`
          }
        ]
      });

    if (options && optionsArray.length > 9)
      return interaction.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.red,
            title: '**Â»** En Fazla 9 SeÃ§enek Belirtebilirsin!',
            description: `**â€¢** Bu yÃ¼kÃ¼ kaldÄ±ramam ben kardeeeÅŸ.`
          }
        ]
      });

    await interaction.reply({
      embeds: [{
        color: client.settings.embedColors.green,
        title: "**Â»** BaÅŸarÄ±lÄ±!",
        description: `**â€¢** Anket mesajÄ± gÃ¶nderiliyor...`
      }],
      ephemeral: true
    });

    const mapping = {
      1: '1ï¸�âƒ£',
      2: '2ï¸�âƒ£',
      3: '3ï¸�âƒ£',
      4: '4ï¸�âƒ£',
      5: '5ï¸�âƒ£',
      6: '6ï¸�âƒ£',
      7: '7ï¸�âƒ£',
      8: '8ï¸�âƒ£',
      9: '9ï¸�âƒ£',
    };

    return await interaction.channel.send({
      content: pingEveryone === "true" ? "@everyone" : null,
      embeds: [
        {
          color: client.settings.embedColors.default,
          author: {
            name: `${interaction.guild.name} â€¢ Anket!`,
            icon_url: interaction.guild.iconURL(),
          },
          title: title || null,
          description: `${description}${options ? `\n\n${optionsArray.map((option, index) => `${mapping[index + 1]} ${option}`).join('\n')}` : ""}`,
          timestamp: new Date().toISOString(),
          footer: {
            text: `${interaction.user.username} tarafÄ±ndan yapÄ±ldÄ±.`,
            icon_url: interaction.user.displayAvatarURL(),
          },
        }
      ]
    }).then(async message => {

      if (!options) {
        await message.react('ðŸ‘�');
        await message.react('ðŸ‘Ž');
      } else {
        for await (let option of optionsArray.map((option, index) => index)) {
          await message.react(mapping[option + 1]);
          await client.wait(500);
        }
      }

    });
  }
};