import type { CommandInteraction } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";
import generateKeyValueList, { toCapitals } from "../../utils/generateKeyValueList.js";
import client from "../../utils/client.js";

const command = (builder: SlashCommandSubcommandBuilder) =>
    builder.setName("about").setDescription("Shows info about the server");

const callback = async (interaction: CommandInteraction): Promise<void> => {
    const guild = interaction.guild!;
    const { renderUser, renderDelta } = client.logger;
    interaction.reply({
        embeds: [
            new EmojiEmbed()
                .setTitle("Server Info")
                .setStatus("Success")
                .setEmoji("GUILD.GREEN")
                .setDescription(
                    generateKeyValueList({
                        name: guild.name,
                        id: `\`${guild.id}\``,
                        owner: `${renderUser((await guild.fetchOwner()).user)}`,
                        created: `${renderDelta(guild.createdTimestamp)}`,
                        emojis:
                            `${guild.emojis.cache.size}` +
                            (guild.emojis.cache.size > 1
                                ? `\n> ${guild.emojis.cache
                                      .first(10)
                                      .map((emoji) => `<${emoji.animated ? "a" : ""}:${emoji.name}:${emoji.id}>`)
                                      .join(" ")}` +
                                  (guild.emojis.cache.size > 10 ? ` and ${guild.emojis.cache.size - 10} more` : "")
                                : ""),
                        icon: `[Discord](${guild.iconURL()})`,
                        "2 factor authentication": `${
                            guild.mfaLevel === "NONE"
                                ? `${getEmojiByName("CONTROL.CROSS")} No`
                                : `${getEmojiByName("CONTROL.TICK")} Yes`
                        }`,
                        "verification level": `${toCapitals(guild.verificationLevel)}`,
                        "explicit content filter": `${toCapitals(
                            guild.explicitContentFilter.toString().replace(/_/, " ")
                        )}`,
                        "nitro boost level": `${guild.premiumTier !== "NONE" ? guild.premiumTier.toString()[-1] : "0"}`,
                        channels: `${guild.channels.cache.size}`,
                        roles: `${guild.roles.cache.size}`,
                        members: `${guild.memberCount}`
                    })
                )
                .setThumbnail(guild.iconURL({ dynamic: true }))
        ],
        ephemeral: true
    });
};

const check = (_interaction: CommandInteraction) => {
    return true;
};

export { command };
export { callback };
export { check };
