const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
    name: 'nowplaying',
    alias: 'np',
    usage: '',
    description: 'Current Radio Station',
    permission: 'none',
    category: 'radio',
    data: new SlashCommandBuilder()
        .setName('nowplaying')
        .setDescription('Current Radio Station'),
    async execute(interaction, client, Discord, command) {
        let message = {};
        const radio = client.radio.get(interaction.guild.id);
        if (!radio) return interaction.reply('There is nothing playing.');
		if(!client.stations) {
			message.errorToGetPlaylist = client.messages.errorToGetPlaylist.replace("%client.config.supportGuild%", client.config.supportGuild);
			return interaction.reply(client.messageEmojis["error"] + message.errorToGetPlaylist);
		}
        const completed = (radio.connection.dispatcher.streamTime.toFixed(0));

        message.nowplayingDescription = client.messages.nowplayingDescription.replace("%radio.station.name%", radio.station.name);
        message.nowplayingDescription = message.nowplayingDescription.replace("%radio.station.owner%", radio.station.owner);
        message.nowplayingDescription = message.nowplayingDescription.replace("%client.funcs.msToTime(completed)%", client.funcs.msToTime(completed));

        const embed = new Discord.MessageEmbed()
            .setTitle(client.messages.nowplayingTitle)
            .setThumbnail("https://cdn.discordapp.com/emojis/" + client.messageEmojis["play"].replace(/[^0-9]+/g, ''))
            .setColor(client.config.embedColor)
            .setDescription(message.nowplayingDescription)
            .setFooter(client.messages.footerText, "https://cdn.discordapp.com/emojis/" + client.messageEmojis["eximiabots"].replace(/[^0-9]+/g, ''));
        return interaction.reply({ embeds: [embed] });
    }
};