import { getCommandMentionByName } from "./../utils/getCommandDataByName.js";
import { LoadingEmbed } from "../utils/defaults.js";
import Discord, {
    ActionRowBuilder,
    ButtonBuilder,
    MessageComponentInteraction,
    Guild,
    CommandInteraction,
    GuildTextBasedChannel,
    Message,
    ButtonStyle,
    ChannelType
} from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js";
import getEmojiByName from "../utils/getEmojiByName.js";
import createPageIndicator from "../utils/createPageIndicator.js";
import { Embed } from "../utils/defaults.js";

export default async (guild: Guild | null, interaction?: CommandInteraction) => {
    let m: Message;
    if (guild) {
        let c: GuildTextBasedChannel | null = guild.publicUpdatesChannel
            ? guild.publicUpdatesChannel
            : guild.systemChannel;
        c = c
            ? c
            : (guild.channels.cache.find(
                  (ch) =>
                      [
                          ChannelType.GuildText,
                          ChannelType.GuildAnnouncement,
                          ChannelType.PublicThread,
                          ChannelType.PrivateThread,
                          ChannelType.AnnouncementThread
                      ].includes(ch.type) &&
                      ch.permissionsFor(guild.roles.everyone).has("SendMessages") &&
                      ch.permissionsFor(guild.members.me!).has("EmbedLinks")
              ) as GuildTextBasedChannel | undefined) ?? null;
        if (interaction) c = interaction.channel as GuildTextBasedChannel;
        if (!c) {
            return;
        }
        if (interaction) {
            m = (await interaction.reply({
                embeds: LoadingEmbed,
                fetchReply: true,
                ephemeral: true
            })) as Message;
        } else {
            m = await c.send({ embeds: LoadingEmbed });
        }
    } else {
        if (interaction) {
            m = (await interaction.reply({
                embeds: LoadingEmbed,
                fetchReply: true,
                ephemeral: true
            })) as Message;
        } else {
            return;
        }
    }
    let page = 0;
    const pages = [
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Welcome to Nucleus")
                    .setDescription(
                        "Thanks for adding Nucleus to your server!\n\n" +
                            "The next few pages will show what features Nucleus has to offer, and how to enable them.\n\n" +
                            "If you need support, have questions or want features, you can let us know in [Clicks](https://discord.gg/bPaNnxe)!"
                    )
                    .setEmoji("NUCLEUS.LOGO")
                    .setStatus("Danger")
            )
            .setTitle("Welcome")
            .setDescription("About Nucleus")
            .setPageId(0),
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Logs")
                    .setDescription(
                        "Nucleus can log server events and keep you informed with what content is being posted to your server.\n" +
                            "We have 2 different types of logs, which each can be configured to send to a channel of your choice:\n" +
                            "**General:** These are events like kicks and channel changes etc.\n" +
                            `> These are standard logs and can be set with ${getCommandMentionByName(
                                "settings/logs/general"
                            )}\n` +
                            "**Warnings:** Warnings like NSFW avatars and spam etc. that may require action by a server staff member.\n" +
                            `> These may require special action by a moderator. You can set the channel with ${getCommandMentionByName(
                                "settings/logs/warnings"
                            )}\n` +
                            "**Attachments:** All images sent in the server - Used to keep a record of deleted images\n" +
                            `> Sent to a separate log channel to avoid spam. This can be set with ${getCommandMentionByName(
                                "settings/logs/attachments"
                            )}\n` +
                            `> ${getEmojiByName(
                                "NUCLEUS.PREMIUM"
                            )} Please note this feature is only available with ${getCommandMentionByName(
                                "nucleus/premium"
                            )}`
                    )
                    .setEmoji("ICONS.LOGGING")
                    .setStatus("Danger")
            )
            .setTitle("Logging")
            .setDescription("Logging, staff warning logs etc.")
            .setPageId(1),
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Moderation")
                    .setDescription(
                        "Nucleus has a number of commands that can be used to moderate your server.\n" +
                            `These commands are all found under ${getCommandMentionByName(
                                "mod"
                            )}, and they include:\n` +
                            `${getEmojiByName("PUNISH.WARN.YELLOW")} ${getCommandMentionByName(
                                "mod/warn"
                            )}: The user is warned (via DM) that they violated server rules. More options given if DMs are disabled.\n` +
                            `${getEmojiByName("PUNISH.CLEARHISTORY")} ${getCommandMentionByName(
                                "mod/purge"
                            )}: Deletes messages in a channel, giving options to only delete messages by a certain user.\n` +
                            `${getEmojiByName("PUNISH.MUTE.YELLOW")} ${getCommandMentionByName(
                                "mod/mute"
                            )}: Stops users sending messages or joining voice chats.\n` +
                            `${getEmojiByName("PUNISH.MUTE.GREEN")} ${getCommandMentionByName(
                                "mod/unmute"
                            )}: Allows user to send messages and join voice chats.\n` +
                            `${getEmojiByName("PUNISH.KICK.RED")} ${getCommandMentionByName(
                                "mod/kick"
                            )}: Removes a member from the server. They will be able to rejoin.\n` +
                            `${getEmojiByName("PUNISH.SOFTBAN")} ${getCommandMentionByName(
                                "mod/softban"
                            )}: Kicks the user, deleting their messages from every channel in a given time frame.\n` +
                            `${getEmojiByName("PUNISH.BAN.RED")} ${getCommandMentionByName(
                                "mod/ban"
                            )}: Removes the user from the server, deleting messages from every channel and stops them from rejoining.\n` +
                            `${getEmojiByName("PUNISH.BAN.GREEN")} ${getCommandMentionByName(
                                "mod/unban"
                            )}: Allows a member to rejoin the server after being banned.`
                    )
                    .setEmoji("PUNISH.BAN.RED")
                    .setStatus("Danger")
            )
            .setTitle("Moderation")
            .setDescription("Basic moderation commands")
            .setPageId(2),
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Verify")
                    .setDescription(
                        "Nucleus has a verification system that allows users to prove they aren't bots.\n" +
                            `This is done by running ${getCommandMentionByName(
                                "verify"
                            )} which sends a message only the user can see, giving them a link to a website to verify.\n` +
                            "After the user complete's the check, they are given a role, which can be set to unlock specific channels.\n" +
                            `You can set the role given with ${getCommandMentionByName("settings/verify")}`
                    )
                    .setEmoji("CONTROL.REDTICK")
                    .setStatus("Danger")
            )
            .setTitle("Verify")
            .setDescription("Captcha verification system")
            .setPageId(3),
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Content Scanning")
                    .setDescription(
                        "Nucleus has a content scanning system that automatically scans links and images sent by users.\n" +
                            "The staff team can be notified when an NSFW image is detected, or malicious links are sent.\n" +
                            `You can check and manage what to moderate in ${getCommandMentionByName(
                                "settings/automod"
                            )}`
                    )
                    .setEmoji("MOD.IMAGES.TOOSMALL")
                    .setStatus("Danger")
            )
            .setTitle("Content Scanning")
            .setDescription("Content (NSFW, malware, scams) scanning")
            .setPageId(4),
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Tickets")
                    .setDescription(
                        "Nucleus has a ticket system which allows users to create tickets and talk to the server staff or support team.\n" +
                            `Tickets can be created by users with ${getCommandMentionByName(
                                "ticket/create"
                            )}, or by clicking a button created by moderators.\n` +
                            `After being created, a new channel or thread is created, and the user and support team are pinged. \n` +
                            `The category or channel to create threads in can be set with ${getCommandMentionByName(
                                "settings/tickets"
                            )}\n` +
                            `When the ticket is resolved, anyone can run ${getCommandMentionByName(
                                "ticket/close"
                            )} (or click the button) to close it.\n` +
                            `Running ${getCommandMentionByName("ticket/close")} again will delete the ticket.`
                    )
                    .setEmoji("GUILD.TICKET.CLOSE")
                    .setStatus("Danger")
            )
            .setTitle("Tickets")
            .setDescription("Ticket system")
            .setPageId(5),
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Tags")
                    .setDescription(
                        "Nucleus allows you to create tags, which allow a message to be sent when a specific tag is typed.\n" +
                            `Tags can be created with ${getCommandMentionByName(
                                "tags/create"
                            )}, and can be edited with ${getCommandMentionByName("tags/edit")}\n` +
                            `Tags can be deleted with ${getCommandMentionByName(
                                "tags/delete"
                            )}, and can be listed with ${getCommandMentionByName("tags/list")}\n` +
                            `To use a tag, you can type ${getCommandMentionByName("tag")}, followed by the tag to send`
                    )
                    .setEmoji("PUNISH.NICKNAME.RED")
                    .setStatus("Danger")
            )
            .setTitle("Tags")
            .setDescription("Tag system")
            .setPageId(6),
        new Embed()
            .setEmbed(
                new EmojiEmbed()
                    .setTitle("Premium")
                    .setDescription(
                        "Nucleus Premium allows you to use extra features in your server, which are useful but not essential.\n" +
                            "**No currently free commands will become premium features.**\n" +
                            "Premium features include creating ticket transcripts and attachment logs.\n\n" +
                            "Premium can be purchased in [our server](https://discord.gg/bPaNnxe) in the subscriptions page" // TODO: add a table graphic
                    )
                    .setEmoji("NUCLEUS.PREMIUM")
                    .setStatus("Danger")
            )
            .setTitle("Premium")
            .setDescription("Premium features")
            .setPageId(7)
    ];

    const publicFilter = async (component: MessageComponentInteraction) => {
        return (component.member as Discord.GuildMember).permissions.has("ManageGuild");
    };

    let selectPaneOpen = false;

    let cancelled = false;
    let timedOut = false;
    while (!cancelled && !timedOut) {
        let selectPane: ActionRowBuilder<Discord.StringSelectMenuBuilder | ButtonBuilder>[] = [];

        if (selectPaneOpen) {
            const options: Discord.StringSelectMenuOptionBuilder[] = [];
            pages.forEach((embed) => {
                options.push(
                    new Discord.StringSelectMenuOptionBuilder()
                        .setLabel(embed.title)
                        .setValue(embed.pageId.toString())
                        .setDescription(embed.description || "")
                );
            });
            selectPane = [
                new ActionRowBuilder<Discord.StringSelectMenuBuilder>().addComponents([
                    new Discord.StringSelectMenuBuilder()
                        .addOptions(options)
                        .setCustomId("page")
                        .setMaxValues(1)
                        .setPlaceholder("Choose a page...")
                ])
            ];
        }
        const components: ActionRowBuilder<ButtonBuilder | Discord.StringSelectMenuBuilder>[] = selectPane.concat([
            new ActionRowBuilder<ButtonBuilder>().addComponents(
                new ButtonBuilder()
                    .setCustomId("left")
                    .setEmoji(getEmojiByName("CONTROL.LEFT", "id"))
                    .setStyle(ButtonStyle.Secondary)
                    .setDisabled(page === 0),
                new ButtonBuilder()
                    .setCustomId("select")
                    .setEmoji(getEmojiByName("CONTROL.MENU", "id"))
                    .setStyle(selectPaneOpen ? ButtonStyle.Primary : ButtonStyle.Secondary)
                    .setDisabled(false),
                new ButtonBuilder()
                    .setCustomId("right")
                    .setEmoji(getEmojiByName("CONTROL.RIGHT", "id"))
                    .setStyle(ButtonStyle.Secondary)
                    .setDisabled(page === pages.length - 1)
            )
        ]);
        if (interaction) {
            const em = new Discord.EmbedBuilder(pages[page]!.embed);
            em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
            await interaction.editReply({
                embeds: [em],
                components: components
            });
        } else {
            const em = new Discord.EmbedBuilder(pages[page]!.embed);
            em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
            (await m.edit({
                embeds: [em],
                components: components
            })) as Message;
        }
        let i;
        try {
            i = await m.awaitMessageComponent({
                filter: interaction
                    ? (i) => {
                          return i.user.id === interaction.user.id && i.channel!.id === interaction.channel!.id;
                      }
                    : publicFilter,
                time: 300000
            });
        } catch (e) {
            timedOut = true;
            continue;
        }
        await i.deferUpdate();
        if (!("customId" in i.component)) {
            continue;
        } else if (i.component.customId === "left") {
            if (page > 0) page--;
            selectPaneOpen = false;
        } else if (i.component.customId === "right") {
            if (page < pages.length - 1) page++;
            selectPaneOpen = false;
        } else if (i.component.customId === "select") {
            selectPaneOpen = !selectPaneOpen;
        } else if (i.isStringSelectMenu() && i.component.customId === "page") {
            page = parseInt(i.values[0]!);
            selectPaneOpen = false;
        } else {
            cancelled = true;
        }
    }
    if (timedOut) {
        if (interaction) {
            const em = new Discord.EmbedBuilder(pages[page]!.embed);
            em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
                text: "Message timed out"
            });
            await interaction.editReply({
                embeds: [em],
                components: []
            });
        } else {
            const em = new Discord.EmbedBuilder(pages[page]!.embed);
            em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page)).setFooter({
                text: "Message timed out"
            });
            await m.edit({
                embeds: [em],
                components: []
            });
        }
    } else {
        if (interaction) {
            const em = new Discord.EmbedBuilder(pages[page]!.embed);
            em.setDescription(em.data.description + "\n\n" + createPageIndicator(pages.length, page));
            em.setFooter({ text: "Message closed" });
            await interaction.editReply({
                embeds: [em],
                components: []
            });
        } else {
            await m.delete();
        }
    }
};
