import { world, Player, system } from '@minecraft/server';
import { Command } from '../../handler';
import { sendPlayerMessage, sendAllMessage, config } from '../../../config';
import { ccLd, deadplayers, getScore, revivelist, rpsLd } from '../../../lifesteal';

new Command({
    name: `leaderboard`,
    // Im gonna make it not ghost only so alive players can see it
    code({ player, args }) {
        type Leaderboard = {
            /**
             * Player name
             */
            player: string;
            /**
             * Score of the player
             */
            score: number;
        };
        let ccLdArray: Leaderboard[] = [];
        let rpsLdArray: Leaderboard[] = [];

        Array.of(ccLd).forEach((key, value) => {
            ccLdArray.push({
                player: `${key}`,
                score: +value
            });
        });
        Array.of(ccLd).forEach((key, value) => {
            rpsLdArray.push({
                player: `${key}`,
                score: +value
            });
        });
        ccLdArray.sort((a, b) => b.score - a.score);
        rpsLdArray.sort((a, b) => b.score - a.score);

        sendPlayerMessage(player, `§eLifesteal Ghost Leaderboard ---

§6§lCookieclicker Clicks ---§r§6
${ccLdArray.map(x => {
            return `${x.player}: ${x.score}`;
        }).join(`\n`)}
§6§lRock Paper Scissors Wins ---§r§6
${rpsLdArray.map(x => {
            return `${x.player}: ${x.score}`;
        }).join(`\n`)}`);
    }
});