import { callback as roleMenu } from "../actions/roleMenu.js";
import verify from "../reflex/verify.js";
import create from "../actions/tickets/create.js";
import close from "../actions/tickets/delete.js";
import createTranscript from "../premium/createTranscript.js";

import type { Interaction } from "discord.js";
import type Discord from "discord.js";
import type { NucleusClient } from "../utils/client.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";

export const event = "interactionCreate";

async function interactionCreate(interaction: Interaction) {
    if (interaction.isButton()) {
        switch (interaction.customId) {
            case "rolemenu": {
                return await roleMenu(interaction);
            }
            case "verifybutton": {
                return await verify(interaction);
            }
            case "createticket": {
                return await create(interaction);
            }
            case "closeticket": {
                return await close(interaction);
            }
            case "createtranscript": {
                return await createTranscript(interaction);
            }
            case "suggestionAccept": {
                return await modifySuggestion(interaction, true);
            }
            case "suggestionDeny": {
                return await modifySuggestion(interaction, false);
            }
        }
    }
}

async function modifySuggestion(interaction: Discord.MessageComponentInteraction, accept: boolean) {
    const message = await interaction.message;
    await message.fetch();
    if (message.embeds.length === 0) return;
    const embed = message.embeds[0];
    const newcolor = accept ? "Success" : "Danger";
    const footer = {
        text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`,
        iconURL: interaction.user.displayAvatarURL()
    };

    const newEmbed = new EmojiEmbed()
        .setTitle(embed!.title!)
        .setDescription(embed!.description!)
        .setFooter(footer)
        .setStatus(newcolor);

    await interaction.update({ embeds: [newEmbed], components: [] });
}

export async function callback(_client: NucleusClient, interaction: Interaction) {
    await interactionCreate(interaction);
}
