import { Events } from "discord.js"
import type { GuildMember } from "discord.js"
import { t, getGuildLocale } from "@/utils/i18n"

export const name = Events.GuildMemberRemove
export function execute(member: GuildMember) {
	if (member.guild.id === "1086577543651524699") {
		// Salon posé tamisé
		const guild = member.guild

		guild.members.fetch().then(async () => {
			let i = 0
			guild.members.cache.forEach(member => { if (!member.user.bot) i++ })

			const channel = guild.channels.cache.get("1091140609139560508")
			if (!channel) return

			const guildLocale = await getGuildLocale(guild.id)
			await channel.setName(t(guildLocale, "salonpostam.update.loading"))
			await channel.setName(t(guildLocale, "salonpostam.update.members_updated", { count: i.toString() }))
		}).catch(console.error)
	}
}
