import Discord, { MessageActionRow, MessageButton } from "discord.js";
import { tickets, toHexArray } from "../../utils/calculate.js";
import client from "../../utils/client.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
import getEmojiByName from "../../utils/getEmojiByName.js";

function capitalize(s: string) {
    s = s.replace(/([A-Z])/g, " $1");
    return s.length < 3 ? s.toUpperCase() : s[0].toUpperCase() + s.slice(1).toLowerCase();
}

export default async function (interaction) {
    const { log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;

    const config = await client.database.guilds.read(interaction.guild.id);
    if (!config.tickets.enabled || !config.tickets.category) {
        return await interaction.reply({embeds: [new EmojiEmbed()
            .setTitle("Tickets are disabled")
            .setDescription("Please enable tickets in the configuration to use this command.")
            .setFooter({text: interaction.member.permissions.has("MANAGE_GUILD") ? "You can enable it by running /settings tickets" : ""})
            .setStatus("Danger")
            .setEmoji("CONTROL.BLOCKCROSS")
        ], ephemeral: true});
    }
    const category = interaction.guild.channels.cache.get(config.tickets.category) as Discord.CategoryChannel;
    let count = 0;
    category.children.forEach(element => {
        if (!(element.type === "GUILD_TEXT")) return;
        if ((element as Discord.TextChannel).topic.includes(`${interaction.member.user.id}`)) {
            if ((element as Discord.TextChannel).topic.endsWith("Active")) {
                count++;
            }
        }
    });
    if (count >= config.tickets.maxTickets) {
        return await interaction.reply({embeds: [new EmojiEmbed()
            .setTitle("Create Ticket")
            .setDescription(`You have reached the maximum amount of tickets (${config.tickets.maxTickets}). Please close one of your active tickets before creating a new one.`)
            .setStatus("Danger")
            .setEmoji("CONTROL.BLOCKCROSS")
        ], ephemeral: true});
    }
    let ticketTypes;
    let custom = false;
    if (config.tickets.customTypes && config.tickets.useCustom) { ticketTypes = config.tickets.customTypes; custom = true; }
    else if (config.tickets.types) ticketTypes = toHexArray(config.tickets.types, tickets);
    else ticketTypes = [];
    let chosenType;
    let splitFormattedTicketTypes = [];
    if (ticketTypes.length > 0) {
        let formattedTicketTypes = [];
        formattedTicketTypes = ticketTypes.map(type => {
            if (custom) {
                return new MessageButton()
                    .setLabel(type)
                    .setStyle("PRIMARY")
                    .setCustomId(type);
            } else {
                return new MessageButton()
                    .setLabel(capitalize(type))
                    .setStyle("PRIMARY")
                    .setCustomId(type)
                    .setEmoji(getEmojiByName(("TICKETS." + type.toString().toUpperCase()), "id"));
            }
        });
        for (let i = 0; i < formattedTicketTypes.length; i += 5) {
            splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 5)));
        }
        const m = await interaction.reply({embeds: [new EmojiEmbed()
            .setTitle("Create Ticket")
            .setDescription("Select a ticket type")
            .setStatus("Success")
            .setEmoji("GUILD.TICKET.OPEN")
        ], ephemeral: true, fetchReply: true, components: splitFormattedTicketTypes});
        let component;
        try {
            component = await m.awaitMessageComponent({time: 300000});
        } catch (e) {
            return;
        }
        chosenType = component.customId;
        splitFormattedTicketTypes = [];
        formattedTicketTypes = [];
        formattedTicketTypes = ticketTypes.map(type => {
            if (custom) {
                return new MessageButton()
                    .setLabel(type)
                    .setStyle(chosenType === type ? "SUCCESS" : "SECONDARY")
                    .setCustomId(type)
                    .setDisabled(true);
            } else {
                return new MessageButton()
                    .setLabel(capitalize(type))
                    .setStyle(chosenType === type ? "SUCCESS" : "SECONDARY")
                    .setCustomId(type)
                    .setEmoji(getEmojiByName(("TICKETS." + type.toString().toUpperCase()), "id"))
                    .setDisabled(true);
            }
        });
        for (let i = 0; i < formattedTicketTypes.length; i += 5) {
            splitFormattedTicketTypes.push(new MessageActionRow().addComponents(formattedTicketTypes.slice(i, i + 5)));
        }
        component.update({embeds: [new EmojiEmbed()
            .setTitle("Create Ticket")
            .setDescription("Select a ticket type")
            .setStatus("Success")
            .setEmoji("GUILD.TICKET.OPEN")
        ], components: splitFormattedTicketTypes});
    } else {
        chosenType = null;
        await interaction.reply({embeds: [new EmojiEmbed()
            .setTitle("Create Ticket")
            .setEmoji("GUILD.TICKET.OPEN")
        ], ephemeral: true, components: splitFormattedTicketTypes});
    }
    const overwrites = [{
        id: interaction.member,
        allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
        type: "member"
    }] as Discord.OverwriteResolvable[];
    overwrites.push({
        id: interaction.guild.roles.everyone,
        deny: ["VIEW_CHANNEL"],
        type: "role"
    });
    if (config.tickets.supportRole !== null) {
        overwrites.push({
            id: interaction.guild.roles.cache.get(config.tickets.supportRole),
            allow: ["VIEW_CHANNEL", "SEND_MESSAGES", "ATTACH_FILES", "ADD_REACTIONS", "READ_MESSAGE_HISTORY"],
            type: "role"
        });
    }

    let c;
    try {
        c = await interaction.guild.channels.create(interaction.member.user.username, {
            type: "GUILD_TEXT",
            topic: `${interaction.member.user.id} Active`,
            parent: config.tickets.category,
            nsfw: false,
            permissionOverwrites: (overwrites as Discord.OverwriteResolvable[]),
            reason: "Creating ticket"
        });
    } catch (e) {
        return await interaction.editReply({embeds: [new EmojiEmbed()
            .setTitle("Create Ticket")
            .setDescription("Failed to create ticket")
            .setStatus("Danger")
            .setEmoji("CONTROL.BLOCKCROSS")
        ]});
    }
    try {
        await c.send(
            {
                content: (`<@${interaction.member.user.id}>` + (config.tickets.supportRole !== null ? ` • <@&${config.tickets.supportRole}>` : "")),
                allowedMentions: {
                    users: [(interaction.member as Discord.GuildMember).id],
                    roles: (config.tickets.supportRole !== null ? [config.tickets.supportRole] : [])
                }
            }
        );
        let content = interaction.options ? interaction.options.getString("message") || "" : "";
        if (content) content = `**Message:**\n> ${content}\n`;
        const emoji = custom ? "" : getEmojiByName("TICKETS." + chosenType.toUpperCase());
        await c.send({ embeds: [new EmojiEmbed()
            .setTitle("New Ticket")
            .setDescription(
                `Ticket created by <@${interaction.member.user.id}>\n` +
                `**Support type:** ${chosenType !== null ? (emoji) + " " + capitalize(chosenType) : "General"}\n` +
                `**Ticket ID:** \`${c.id}\`\n${content}\n` +
                "Type `/ticket close` to close this ticket."
            )
            .setStatus("Success")
            .setEmoji("GUILD.TICKET.OPEN")
        ], components: [new MessageActionRow().addComponents([new MessageButton()
            .setLabel("Close")
            .setStyle("DANGER")
            .setCustomId("closeticket")
            .setEmoji(getEmojiByName("CONTROL.CROSS", "id"))
        ])]});
        const data = {
            meta:{
                type: "ticketCreate",
                displayName: "Ticket Created",
                calculateType: "ticketUpdate",
                color: NucleusColors.green,
                emoji: "GUILD.TICKET.OPEN",
                timestamp: new Date().getTime()
            },
            list: {
                ticketFor: entry(interaction.member.user.id, renderUser(interaction.member.user)),
                created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
                ticketChannel: entry(c.id, renderChannel(c))
            },
            hidden: {
                guild: interaction.guild.id
            }
        };
        log(data);
    } catch (e) { console.log(e);}
    await interaction.editReply({embeds: [new EmojiEmbed()
        .setTitle("Create Ticket")
        .setDescription(`Ticket created. You can view it here: <#${c.id}>`)
        .setStatus("Success")
        .setEmoji("GUILD.TICKET.OPEN")
    ], components: splitFormattedTicketTypes});
}