import { LinkWarningFooter } from './../../utils/defaults.js';
import { ActionRowBuilder, ButtonBuilder, CommandInteraction, GuildMember, ButtonStyle, Message } from "discord.js";
import type { SlashCommandSubcommandBuilder } from "discord.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import keyValueList from "../../utils/generateKeyValueList.js";
import client from "../../utils/client.js";
import { areTicketsEnabled, create } from "../../actions/createModActionTicket.js";


const command = (builder: SlashCommandSubcommandBuilder) => builder
    .setName("nick")
    // .setNameLocalizations({"ru": "name", "zh-CN": "nickname"})
    .setDescription("Changes a users nickname")
    .addUserOption((option) => option.setName("user").setDescription("The user to change").setRequired(true))
    .addStringOption((option) =>
        option.setName("name").setDescription("The name to set | Leave blank to clear").setRequired(false)
    );


const callback = async (interaction: CommandInteraction): Promise<unknown> => {
    const { log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
    // TODO:[Modals] Replace this with a modal
    let notify = true;
    let confirmation;
    let timedOut = false;
    let success = false;
    let createAppealTicket = false;
    let firstRun = true;
    do {
        confirmation = await new confirmationMessage(interaction)
            .setEmoji("PUNISH.NICKNAME.RED")
            .setTitle("Nickname")
            .setDescription(
                keyValueList({
                    user: renderUser(interaction.options.getUser("user")!),
                    "new nickname": `${
                        interaction.options.get("name")?.value as string ? interaction.options.get("name")?.value as string : "*No nickname*"
                    }`
                }) +
                    `Are you sure you want to ${interaction.options.get("name")?.value as string ? "change" : "clear"} <@!${
                        (interaction.options.getMember("user") as GuildMember).id
                    }>'s nickname?`
            )
            .setColor("Danger")
            .addCustomBoolean(
                "appeal",
                "Create appeal ticket",
                !(await areTicketsEnabled(interaction.guild!.id)),
                async () => await create(interaction.guild!, interaction.options.getUser("user")!, interaction.user, "Nickname changed"),
                "An appeal ticket will be created",
                null,
                "CONTROL.TICKET",
                createAppealTicket
            )
            .addCustomBoolean(
                "notify",
                "Notify user",
                false,
                null,
                "The user will be sent a DM",
                null,
                "ICONS.NOTIFY." + (notify ? "ON" : "OFF"),
                notify
            )
            .setFailedMessage("No changes were made", "Success", "PUNISH.NICKNAME.GREEN")
            .send(!firstRun);
        firstRun = false;
        if (confirmation.cancelled) timedOut = true;
        else if (confirmation.success !== undefined) success = true;
        else if (confirmation.components) {
            notify = confirmation.components['notify']!.active;
            createAppealTicket = confirmation.components["appeal"]!.active;
        }
    } while (!timedOut && !success);
    if (timedOut || !success) return;
    let dmSent = false;
    let dmMessage: Message;
    const config = await client.database.guilds.read(interaction.guild!.id);
    try {
        if (notify) {
            const messageData: {
                embeds: EmojiEmbed[];
                components: ActionRowBuilder<ButtonBuilder>[];
            } = {
                embeds: [
                    new EmojiEmbed()
                        .setEmoji("PUNISH.NICKNAME.RED")
                        .setTitle("Nickname changed")
                        .setDescription(
                            `Your nickname was ${interaction.options.get("name")?.value as string ? "changed" : "cleared"} in ${
                                interaction.guild!.name
                            }.` +
                                (interaction.options.get("name")?.value as string
                                    ? ` it is now: ${interaction.options.get("name")?.value as string}`
                                    : "") +
                                "\n\n" +
                                (createAppealTicket
                                    ? `You can appeal this in the ticket created in <#${confirmation.components!["appeal"]!.response}>`
                                    : "")
                        )
                        .setStatus("Danger")
                ], components: []
            };
            if (config.moderation.nick.text && config.moderation.nick.link) {
                messageData.embeds[0]!.setFooter(LinkWarningFooter)
                messageData.components.push(new ActionRowBuilder<ButtonBuilder>()
                        .addComponents(new ButtonBuilder()
                            .setStyle(ButtonStyle.Link)
                            .setLabel(config.moderation.nick.text)
                            .setURL(config.moderation.nick.link.replaceAll("{id}", (interaction.options.getMember("user") as GuildMember).id))
                        )
                )
            }
            dmMessage = await (interaction.options.getMember("user") as GuildMember).send(messageData);
            dmSent = true;
        }
    } catch {
        dmSent = false;
    }
    let member: GuildMember;
    let before: string | null;
    let nickname: string | undefined;
    try {
        member = interaction.options.getMember("user") as GuildMember;
        before = member.nickname;
        nickname = interaction.options.get("name")?.value as string | undefined;
        member.setNickname(nickname ?? null, "Nucleus Nickname command");
        await client.database.history.create(
            "nickname",
            interaction.guild!.id,
            member.user,
            interaction.user,
            null,
            before,
            nickname
        );
    } catch {
        await interaction.editReply({
            embeds: [
                new EmojiEmbed()
                    .setEmoji("PUNISH.NICKNAME.RED")
                    .setTitle("Nickname")
                    .setDescription("Something went wrong and the users nickname could not be changed.")
                    .setStatus("Danger")
            ],
            components: []
        });
        if (dmSent) await dmMessage!.delete();
        return;
    }
    const data = {
        meta: {
            type: "memberUpdate",
            displayName: "Member Updated",
            calculateType: "guildMemberUpdate",
            color: NucleusColors.yellow,
            emoji: "PUNISH.NICKNAME.YELLOW",
            timestamp: new Date().getTime()
        },
        list: {
            memberId: entry(member.id, `\`${member.id}\``),
            before: entry(before, before ?? "*No nickname set*"),
            after: entry(nickname ?? null, nickname ?? "*No nickname set*"),
            updated: entry(new Date().getTime(), renderDelta(new Date().getTime())),
            updatedBy: entry(interaction.user.id, renderUser(interaction.user))
        },
        hidden: {
            guild: interaction.guild!.id
        }
    };
    log(data);
    const failed = !dmSent && notify;
    await interaction.editReply({
        embeds: [
            new EmojiEmbed()
                .setEmoji(`PUNISH.NICKNAME.${failed ? "YELLOW" : "GREEN"}`)
                .setTitle("Nickname")
                .setDescription(
                    "The members nickname was changed" +
                        (failed ? ", but was not notified" : "") +
                        (confirmation.components!["appeal"]!.response !== null
                            ? ` and an appeal ticket was opened in <#${confirmation.components!["appeal"]!.response}>`
                            : "")
                )
                .setStatus(failed ? "Warning" : "Success")
        ],
        components: []
    });
};

const check = async (interaction: CommandInteraction, partial: boolean = false) => {
    const member = interaction.member as GuildMember;
    // Check if the user has manage_nicknames permission
    if (!member.permissions.has("ManageNicknames")) return "You do not have the *Manage Nicknames* permission";
    if (partial) return true;
    const me = interaction.guild!.members.me!;
    const apply = interaction.options.getMember("user") as GuildMember;
    const memberPos = member.roles.cache.size ? member.roles.highest.position : 0;
    const mePos = me.roles.cache.size ? me.roles.highest.position : 0;
    const applyPos = apply.roles.cache.size ? apply.roles.highest.position : 0;
    if (!interaction.guild) return false;
    // Do not allow any changing of the owner
    if (member.id === interaction.guild.ownerId) return "You cannot change the owner's nickname";
    // Check if Nucleus can change the nickname
    if (!(mePos > applyPos)) return "I do not have a role higher than that member";
    // Check if Nucleus has permission to change the nickname
    if (!me.permissions.has("ManageNicknames")) return "I do not have the *Manage Nicknames* permission";
    // Allow the owner to change anyone's nickname
    if (member.id === interaction.guild.ownerId) return true;
    // Allow changing your own nickname
    if (member === apply) return true;
    // Check if the user is below on the role list
    if (!(memberPos > applyPos)) return "You do not have a role higher than that member";
    // Allow change
    return true;
};

export { command, callback, check };
