const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

class MatchCommands {
  constructor(playerService) {
    this.playerService = playerService;
    this.baseUrl = 'https://www.vrbattles.gg';
  }

  async handleViewDetails(interaction, matchId) {
    await interaction.deferReply({ ephemeral: true });
    
    try {
      const row = new ActionRowBuilder()
        .addComponents(
          new ButtonBuilder()
            .setLabel('View on VRBattles')
            .setStyle(ButtonStyle.Link)
            .setURL(`${this.baseUrl}/matches/${matchId}`),
          new ButtonBuilder()
            .setLabel('Join VRBattles Discord')
            .setStyle(ButtonStyle.Link)
            .setURL('https://discord.gg/j3DKVATPGQ')
        );

      const embed = new EmbedBuilder()
        .setColor('#0099ff')
        .setTitle('Match Details')
        .setDescription('Click below to view the match details on VRBattles')
        .addFields(
          {
            name: 'Match ID',
            value: `#${matchId}`,
            inline: true
          }
        )
        .setTimestamp()
        .setFooter({ text: 'VRBattles Match System' });

      await interaction.editReply({
        embeds: [embed],
        components: [row],
        ephemeral: true
      });

    } catch (error) {
      console.error('Error handling view details:', error);
      await interaction.editReply({
        content: 'An error occurred. Please try viewing the match on the website directly.',
        ephemeral: true
      });
    }
  }

  // Keeping this as a placeholder for future implementation
  async handleMatchAccept(interaction, matchId) {
    await interaction.reply({
      content: 'This feature is coming soon. Please view and manage matches on the VRBattles website.',
      ephemeral: true
    });
  }
}

module.exports = MatchCommands;