//write minimal holdem api

class Card {
    constructor(suit, rank) {
        this.suit = suit;
        this.rank = rank;
    }
}

class Deck {
    constructor() {
        this.cards = [];
        const suits = ["♥", "♦", "♣", "♠"];
        const ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"];

        for (const suit of suits) {
            for (const rank of ranks) {
                this.cards.push(new Card(suit, rank));
            }
        }

        this.shuffle();
    }

    shuffle() {
        const { cards } = this;
        let m = cards.length,
            i;

        while (m) {
            m--;
            const i = Math.floor(Math.random() * (m + 1));
            [cards[m], cards[i]] = [cards[i], cards[m]];
        }

        return this;
    }

    draw(num = 1) {
        return this.cards.splice(0, num);
    }
}

function dealCards(deck, numPlayers) {
    const playerHands = Array.from({ length: numPlayers }, () => []);

    for (let i = 0; i < 2; i++) {
        playerHands.forEach((hand) => hand.push(...deck.draw()));
    }

    return playerHands;
}

function dealFlop(deck) {
    deck.draw(); // Burn card
    return deck.draw(3); // Flop
}

function dealTurn(deck) {
    deck.draw(); // Burn card
    return deck.draw(); // Turn
}

function dealRiver(deck) {
    deck.draw(); // Burn card
    return deck.draw(); // River
}

//In Texas Hold'em, players can only change their cards before the pre-flop action by discarding one or both of their hole cards and receiving new ones from the dealer. This option is called "mucking" or "burn and turn," but it's not commonly used in most games.

//During the betting rounds, each player can take one of these actions:

//1. Check: if there was no bet made during that round, the player has the option to check (i.e., take no action, end their turn).

//2. Bet: a player can make a wager on their hand’s strength - this amount is determined by the table limit or agreed-upon amount.

//3. Call: if a bet has already been made during that round, a player can choose to match that bet rather than raise.

//4. Raise: if a bet has already been made during that round, a player can choose to increase the size of the wager with an additional amount equal to or greater than what was originally bet.

//5. Fold: A player may choose to forfeit their hand and leave the game at any time.

//dummy function, add a proper implemented hand evaluation method
function evaluateHand(hand) {
//!!COMPLETE THE FUNC

    return hand;
}

function determineWinners(playerHands, sharedCards) {
//!!COMPLETE THE FUNC
    const playerEvaluations = playerHands.map((hand) => evaluateHand(hand.concat(sharedCards)));

    //Dummy logic, add proper hand comparison logic
    let maxPlayerEval = playerEvaluations[0];
    let winners = [0];

    for (let i = 1; i < playerEvaluations.length; i++) {
        const currentPlayerEval = playerEvaluations[i];
        //Compare currentPlayerEval to maxPlayerEval
        //If currentPlayerEval is better, set maxPlayerEval to currentPlayerEval and reset winners array
        //If currentPlayerEval is equal to maxPlayerEval, add i to winners array
    }

    return winners;
}

var deck1 = new Deck();
var numPlayers = 6;
var playerHands = dealCards(deck1, numPlayers);
console.log(playerHands);
//betting
var flop = dealFlop(deck1);
console.log(flop);
//betting
var turn = dealTurn(deck1);
console.log(turn);
//betting
var river = dealRiver(deck1);
console.log(river);
//betting
var winners = determineWinners(playerHands, flop.concat(turn, river));
console.log(winners);

///!!OUTPUT MISSING LOGIC ONLY