const icons = Object.fromEntries(
    Object.entries(
        import.meta.glob<{ default: ImageMetadata }>(`node_modules/@phosphor-icons/core/assets/light/*.svg`, {
            eager: true,
        }),
    ).map(([path, module]) => [path.split('/').pop()!.split('.')[0].replace('-light', ''), module]),
)

type Props = {
    name: string
}

export const PhosphorIcon = ({ name }: Props) => {
    const icon = icons[name]

    if (!icon) {
        throw new Error(`Icon "${name}" not found`)
    }

    return <img class="phosphor-icon" src={icon.default.src} alt={name} />
}
