import { SlashCommandBuilder, MessageFlags } from "discord.js"
import type { ChatInputCommandInteraction } from "discord.js"
import { useQueue } from "discord-player"
import { generatePlayerEmbed } from "@/utils/player"
import uptime from "@/utils/uptime"
import { t } from "@/utils/i18n"

export const data = new SlashCommandBuilder()
	.setName("panel")
	.setDescription("Generate current playback info")
	.setNameLocalizations({ fr: "panneau" })
	.setDescriptionLocalizations({ fr: "Générer les infos de la lecture en cours" })

export async function execute(interaction: ChatInputCommandInteraction) {
	const queue = useQueue(interaction.guild?.id ?? "")
	if (!queue) return interaction.followUp({ content: t(interaction.locale, "player.no_queue"), flags: MessageFlags.Ephemeral })

	const guild = interaction.guild
	if (!guild) return interaction.reply({ content: t(interaction.locale, "common.private_message_not_available"), flags: MessageFlags.Ephemeral })

	const { embed, components } = generatePlayerEmbed(guild, interaction.locale)
	if (components && embed.data.footer) embed.setFooter({ text: `${t(interaction.locale, "player.uptime")}: ${uptime(guild.client.uptime)} \n ${embed.data.footer.text}` })
	else embed.setFooter({ text: `${t(interaction.locale, "player.uptime")}: ${uptime(guild.client.uptime)}` })

	return interaction.reply({ embeds: [embed] })
}
