import { CommandInteraction, Guild } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku";
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,
    _defaultCheck: WrappedCheck
) => {
    return true;
};

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