import { getColor } from "@/data/colors"
import { Player } from "@/lib/schema/player"

type NewPackageRank = Player["player"]["newPackageRank"]
type MonthlyPackageRank = Player["player"]["monthlyPackageRank"]
type RankColor = Player["player"]["monthlyRankColor"]

export default function DisplayName(
    { ign, rank, monthly, rankColor, plusColor, guildTag, tagColor }: {
        ign: string
        rank: NewPackageRank
        monthly: MonthlyPackageRank
        rankColor: RankColor
        plusColor: string | undefined
        guildTag: string | undefined
        tagColor: string | undefined
    }
) {
    return (
        <>
            <PlayerRank rank={rank} monthly={monthly} plusColor={plusColor} rankColor={rankColor} />{" "}
            <PlayerIGN ign={ign} rank={rank} monthly={monthly} rankColor={rankColor} /> <GuildTag tag={guildTag} tagColor={tagColor} />
        </>
    )
}

function PlayerIGN({ ign, rank, monthly, rankColor }: { ign: string, rank: NewPackageRank, monthly: MonthlyPackageRank, rankColor: RankColor }) {
    if (monthly === "SUPERSTAR") {
        if (rankColor === "GOLD") {
            return <span className="text-mc-gold">{ign}</span>
        } else {
            return <span className="text-mc-aqua">{ign}</span>
        }
    }

    switch (rank) {
        case "VIP":
            return <span className="text-mc-green">{ign}</span>
        case "VIP_PLUS":
            return <span className="text-mc-green">{ign}</span>
        case "MVP":
            return <span className="text-mc-aqua">{ign}</span>
        case "MVP_PLUS":
            return <span className="text-mc-aqua">{ign}</span>
        default:
            return <span className="text-mc-gray">{ign}</span>
    }
}

function PlayerRank(
    { rank, monthly, plusColor, rankColor }: { rank: NewPackageRank, monthly: MonthlyPackageRank, plusColor?: string, rankColor: RankColor }
) {
    if (monthly === "SUPERSTAR") {
        if (rankColor === "GOLD") {
            return (
                <>
                    <span className="text-mc-gold">[MVP</span>
                    <span className={getColor(plusColor)}>++</span>
                    <span className="text-mc-gold">]</span>
                </>
            )
        } else {
            return (
                <>
                    <span className="text-mc-aqua">[MVP</span>
                    <span className={getColor(plusColor)}>++</span>
                    <span className="text-mc-aqua">]</span>
                </>
            )
        }
    }

    switch (rank) {
        case "VIP":
            return <span className="text-mc-green">[VIP]</span>
        case "VIP_PLUS":
            return (
                <>
                    <span className="text-mc-green">[VIP</span>
                    <span className="text-mc-gold">+</span>
                    <span className="text-mc-green">]</span>
                </>
            )
        case "MVP":
            return <span className="text-mc-aqua">[MVP]</span>
        case "MVP_PLUS":
            return (
                <>
                    <span className="text-mc-aqua">[MVP</span>
                    <span className={getColor(plusColor)}>+</span>
                    <span className="text-mc-aqua">]</span>
                </>
            )
        default:
            return null
    }
}

function GuildTag({ tag, tagColor }: { tag?: string, tagColor?: string }) {
    if (!tag) return null

    const color = getColor(tagColor, "text", "gray")

    return <span className={color}>[{tag}]</span>
}
