import {
    ActionRowBuilder,
    AttachmentBuilder,
    ButtonBuilder,
    ButtonInteraction,
    ButtonStyle,
    ChannelType,
    CommandInteraction,
    ComponentType,
    Guild,
    ModalBuilder,
    ModalSubmitInteraction,
    TextInputBuilder,
    TextInputStyle
} from "discord.js";
import type { SlashCommandSubcommandBuilder } from "discord.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import client from "../../utils/client.js";
import config from "../../config/main.js";

const command = (builder: SlashCommandSubcommandBuilder) =>
    builder.setName("stats").setDescription("Gets the bot's stats");

const confirm = async (interaction: CommandInteraction) => {
    const requiredTexts = [
        "just do it",
        "yes, do as i say!",
        "clicksminuteper/nucleus",
        "i've said it once i'll say it again",
        "no, i've changed my mind",
        "this incident will be reported",
        "coded told me to",
        "mini told me to",
        "pinea told me to",
        "what's a java script",
        "it's a feature not a bug",
        "that never happened during testing"
    ];
    const chosen = requiredTexts[Math.floor(Math.random() * (requiredTexts.length - 1))]!;

    const modal = new ModalBuilder()
        .addComponents(
            new ActionRowBuilder<TextInputBuilder>().addComponents(
                new TextInputBuilder()
                    .setStyle(TextInputStyle.Short)
                    .setLabel(`Type "${chosen}" below`)
                    .setCustomId("confirm")
                    .setPlaceholder("Guild ID")
                    .setMinLength(chosen.length)
                    .setMaxLength(chosen.length)
            )
        )
        .setTitle("Admin Panel")
        .setCustomId("adminPanel");
    await interaction.showModal(modal);
    let out: ModalSubmitInteraction;
    try {
        out = await interaction.awaitModalSubmit({
            filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id,
            time: 300000
        });
    } catch {
        return;
    }
    await out.deferUpdate();
    const typed = out.fields.getTextInputValue("confirm");
    return typed.toLowerCase() === chosen.toLowerCase();
};

const callback = async (interaction: CommandInteraction): Promise<void> => {
    const description = `**Servers:** ${client.guilds.cache.size}\n` + `**Ping:** \`${client.ws.ping * 2}ms\``;
    const m = await interaction.reply({
        embeds: [
            new EmojiEmbed()
                .setTitle("Stats")
                .setDescription(description)
                .setStatus("Success")
                .setEmoji("SETTINGS.STATS.GREEN")
        ],
        ephemeral: true,
        fetchReply: true
    });
    if (config.owners.includes(interaction.user.id)) {
        await interaction.editReply({
            embeds: [
                new EmojiEmbed()
                    .setTitle("Admin")
                    .setDescription(description)
                    .setStatus("Success")
                    .setEmoji("SETTINGS.STATS.GREEN")
            ],
            components: [
                new ActionRowBuilder<ButtonBuilder>().addComponents(
                    new ButtonBuilder().setCustomId("admin").setLabel("Admin Panel").setStyle(ButtonStyle.Primary)
                )
            ]
        });

        const modal = new ModalBuilder()
            .addComponents(
                new ActionRowBuilder<TextInputBuilder>().addComponents(
                    new TextInputBuilder()
                        .setStyle(TextInputStyle.Short)
                        .setLabel("Guild ID")
                        .setCustomId("guildID")
                        .setPlaceholder("Guild ID")
                        .setMinLength(16)
                        .setMaxLength(25)
                )
            )
            .setTitle("Admin Panel")
            .setCustomId("adminPanel");
        let i1: ButtonInteraction;
        const channel = await client.channels.fetch(interaction.channelId);
        if (
            !channel ||
            [ChannelType.GuildCategory, ChannelType.GroupDM, ChannelType.GuildStageVoice].includes(channel.type)
        )
            return;
        // console.log(interaction)
        if (!("awaitMessageComponent" in channel)) return;
        let GuildID = interaction.guildId;
        if (!GuildID) {
            try {
                i1 = await channel!.awaitMessageComponent<ComponentType.Button>({
                    filter: (i) => i.customId === "admin" && i.user.id === interaction.user.id && i.message.id === m.id,
                    time: 300000
                });
            } catch (e) {
                console.log(e);
                return;
            }
            await i1.showModal(modal);
            let out: ModalSubmitInteraction;
            try {
                out = await i1.awaitModalSubmit({
                    filter: (i) => i.customId === "adminPanel" && i.user.id === interaction.user.id,
                    time: 300000
                });
            } catch {
                return;
            }
            await out.deferUpdate();
            GuildID = out.fields.getTextInputValue("guildID");
        } else if (!client.guilds.cache.has(GuildID)) {
            await interaction.editReply({
                embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")],
                components: []
            });
        }

        await interaction.editReply({
            embeds: [],
            components: [
                new ActionRowBuilder<ButtonBuilder>().addComponents(
                    new ButtonBuilder().setCustomId("stats").setLabel("Stats").setStyle(ButtonStyle.Primary),
                    new ButtonBuilder().setCustomId("data").setLabel("Guild data").setStyle(ButtonStyle.Secondary),
                    new ButtonBuilder().setCustomId("cache").setLabel("Reset cache").setStyle(ButtonStyle.Success),
                    new ButtonBuilder().setCustomId("leave").setLabel("Leave").setStyle(ButtonStyle.Danger),
                    new ButtonBuilder().setCustomId("purge").setLabel("Delete data").setStyle(ButtonStyle.Danger)
                )
            ]
        });
        let i;
        try {
            i = await m.awaitMessageComponent<ComponentType.Button>({
                filter: (i) => i.user.id === interaction.user.id && i.message.id === m.id,
                time: 300000
            });
        } catch {
            return;
        }
        const guild = (await client.guilds.fetch(GuildID)) as Guild | null;
        if (!guild) {
            await i.deferUpdate();
            await interaction.editReply({
                embeds: [new EmojiEmbed().setTitle("Admin").setDescription("Not in server").setStatus("Danger")],
                components: []
            });
            return;
        }
        if (i.customId === "stats") {
            await i.deferUpdate();
            await interaction.editReply({
                embeds: [
                    new EmojiEmbed()
                        .setTitle("Stats")
                        .setDescription(
                            `**Name:** ${guild.name}\n` +
                                `**ID:** \`${guild.id}\`\n` +
                                `**Owner:** ${client.users.cache.get(guild.ownerId)!.tag}\n` +
                                `**Member Count:** ${guild.memberCount}\n` +
                                `**Created:** <t:${guild.createdTimestamp}:F>\n` +
                                `**Added Nucleus:** <t:${guild.members.me!.joinedTimestamp}:R>\n` +
                                `**Nucleus' Perms:** https://discordapi.com/permissions.html#${guild.members.me!.permissions.valueOf()}\n`
                        )
                        .setStatus("Success")
                        .setEmoji("SETTINGS.STATS.GREEN")
                ]
            });
        } else if (i.customId === "leave") {
            if (!(await confirm(interaction))) {
                await interaction.editReply({
                    embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")],
                    components: []
                });
                return;
            }
            await guild.leave();
            await interaction.editReply({
                embeds: [
                    new EmojiEmbed()
                        .setTitle("Left")
                        .setDescription(`Left ${guild.name}`)
                        .setStatus("Success")
                        .setEmoji("SETTINGS.STATS.GREEN")
                ],
                components: []
            });
        } else if (i.customId === "data") {
            await i.deferUpdate();
            // Get all the data and convert to a string
            const data = await client.database.guilds.read(guild.id);
            const stringified = JSON.stringify(data, null, 2);
            const buffer = Buffer.from(stringified);
            const attachment = new AttachmentBuilder(buffer).setName("data.json");
            await interaction.editReply({
                embeds: [
                    new EmojiEmbed().setTitle("Data").setDescription(`Data for ${guild.name}`).setStatus("Success")
                ],
                components: [],
                files: [attachment]
            });
        } else if (i.customId === "purge") {
            if (!(await confirm(interaction))) {
                await interaction.editReply({
                    embeds: [new EmojiEmbed().setTitle("No changes were made").setStatus("Danger")],
                    components: []
                });
                return;
            }
            await client.database.guilds.delete(GuildID);
            await client.database.history.delete(GuildID);
            await client.database.notes.delete(GuildID);
            await client.database.transcripts.deleteAll(GuildID);
            await interaction.editReply({
                embeds: [
                    new EmojiEmbed()
                        .setTitle("Purge")
                        .setDescription(`Deleted data for ${guild.name}`)
                        .setStatus("Success")
                        .setEmoji("SETTINGS.STATS.GREEN")
                ],
                components: []
            });
        } else if (i.customId === "cache") {
            await i.deferUpdate();
            await client.memory.forceUpdate(guild.id);
            await interaction.editReply({
                embeds: [
                    new EmojiEmbed()
                        .setTitle("Cache")
                        .setDescription(`Reset cache for ${guild.name}`)
                        .setStatus("Success")
                        .setEmoji("SETTINGS.STATS.GREEN")
                ],
                components: []
            });
        }
    }
};

export { command };
export { callback };
