import humanizeDuration from 'humanize-duration';
export const event = 'threadDelete'

export async function callback(client, thread) {
    try {
    const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger
    let auditLog = await getAuditLog(thread.guild, 'THREAD_UPDATE');
    let audit = auditLog.entries.filter(entry => entry.target.id == thread.id).first();
    if (audit.executor.id == client.user.id) return;
    let data = {
        meta: {
            type: 'channelDelete',
            displayName: 'Thread Deleted',
            calculateType: 'channelUpdate',
            color: NucleusColors.red,
            emoji: "CHANNEL.TEXT.DELETE",
            timestamp: new Date().getTime()
        },
        list: {
            id: entry(thread.id, `\`${thread.id}\``),
            name: entry(thread.name, thread.name),
            parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
            category: entry(thread.parent.parent ? thread.parent.parent.name : 'None', thread.parent.parent ? renderChannel(thread.parent.parent) : 'None'),
            autoArchiveDuration: entry(thread.autoArchiveDuration, humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { round: true })),
            membersInThread: entry(thread.memberCount, thread.memberCount),
            deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
            created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)),
            deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
        },
        hidden: {
            guild: thread.guild.id
        }
    }
    log(data, thread.client);
    } catch {}
}
