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: {
            threadId: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);
    } catch {}
}
