import { Content } from "../components/Content.tsx";
import { PlayerList } from "../islands/players.tsx";
import { getPlayerData, PlayerData } from "../util/players.ts";

export default async function PlayerManager() {
  // TODO: change these to support instances
  const whitelist = await Promise.all<PlayerData[]>(
    JSON.parse(await Deno.readTextFile("./server/whitelist.json")).map(async (
      p: { name: string },
    ) => await getPlayerData(p.name)),
  );
  const banlist = await Promise.all<PlayerData[]>(
    JSON.parse(await Deno.readTextFile("./server/banned-players.json")).map(
      async (
        p: { name: string; reason: string },
      ) => ({ ...await getPlayerData(p.name), banReason: p.reason }),
    ),
  );
  const oplist = await Promise.all<PlayerData[]>(
    JSON.parse(await Deno.readTextFile("./server/ops.json")).map(async (
      p: { name: string },
    ) => await getPlayerData(p.name)),
  );
  return (
    <div className="container p-8">
      <Content>
        <PlayerList
          whitelist={whitelist}
          banlist={banlist}
          oplist={oplist}
        />
      </Content>
    </div>
  );
}
