// src/config/lackSuitMap.ts


import type {Suit} from "../types/tile.ts";

const lackSuitImageModules = import.meta.glob(
    '/src/assets/images/flowerClolor/*.png',
    {
        eager: true,
        import: 'default',
    },
) as Record<string, string>

const SUIT_FILE_MAP: Record<Suit, 'wan' | 'tong' | 'tiao'> = {
    W: 'wan',
    T: 'tong',
    B: 'tiao',
}

function buildLackSuitImageKey(suit: Suit): string {
    const fileName = SUIT_FILE_MAP[suit]
    return `/src/assets/images/flowerClolor/${fileName}.png`
}

/**
 * 根据花色获取缺门图标
 * W -> wan.png
 * T -> tong.png
 * B -> tiao.png
 */
export function getLackSuitImage(suit: Suit): string {
    const key = buildLackSuitImageKey(suit)
    return lackSuitImageModules[key] || ''
}

/**
 * 判断是否为合法缺门花色
 */
export function isValidLackSuit(suit: string): suit is Suit {
    return suit === 'W' || suit === 'T' || suit === 'B'
}