const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require("discord.js"); const { getPokerService } = require("../../utils/crumbPoker"); const { POKER_TABLE_FOOTER_PREFIX, deferPokerReply, editPokerError, getPokerGameIdFromInteraction } = require("../../utils/pokerDiscord"); module.exports = { name: "pokerCancel", async execute(interaction) { await deferPokerReply(interaction); const gameId = getPokerGameIdFromInteraction(interaction); if (!gameId) { return interaction.editReply({ content: "❌ This Poker table is no longer active.", embeds: [], components: [] }); } try { const game = await getPokerService().getTable({ gameId }); if ( String(game.data.ownerId) !== String(interaction.user.id) ) { return interaction.editReply({ content: "❌ Only the table owner can cancel this Poker table.", embeds: [], components: [] }); } return interaction.editReply({ content: "", embeds: [ new EmbedBuilder() .setTitle("🛑 Cancel Poker Table?") .setDescription( [ "All seated players will be safely cashed out.", "", "This cannot be undone." ].join("\n") ) .setFooter({ text: `${POKER_TABLE_FOOTER_PREFIX}:${gameId}` }) ], components: [ new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId("pokerCancelConfirm") .setLabel("Cancel Table") .setEmoji("🛑") .setStyle(ButtonStyle.Danger), new ButtonBuilder() .setCustomId("pokerCancelKeep") .setLabel("Keep Table") .setStyle(ButtonStyle.Secondary) ) ] }); } catch (error) { return editPokerError(interaction, error); } } };