import React from 'react' import { cn } from '@/lib/utils' interface AppIconProps { name: string iconUrl?: string | null className?: string size?: 'sm' | 'md' | 'lg' | 'xl' } export function AppIcon({ name, iconUrl, className, size = 'md' }: AppIconProps) { const sizeClasses = { sm: 'w-7 h-7 text-xs rounded-lg', md: 'w-10 h-10 text-base rounded-xl', lg: 'w-12 h-12 text-lg rounded-2xl', xl: 'w-16 h-16 text-2xl rounded-3xl', }[size] // If iconUrl is an image (starts with http, / or data:image) const isImage = iconUrl && ( iconUrl.startsWith('http://') || iconUrl.startsWith('https://') || iconUrl.startsWith('/') || iconUrl.startsWith('data:image/') ) // Gradient generator from app name const initial = name ? name.charAt(0).toUpperCase() : 'A' const gradients = [ 'from-emerald-500 to-teal-700', 'from-cyan-500 to-blue-700', 'from-indigo-500 to-purple-700', 'from-amber-500 to-orange-700', 'from-rose-500 to-pink-700', 'from-violet-500 to-fuchsia-700', ] const gradientIndex = (name.charCodeAt(0) || 0) % gradients.length const bgGradient = gradients[gradientIndex] if (isImage) { return (
{/* eslint-disable-next-line @next/next/no-img-element */} {name} { // fallback if image fails to load e.currentTarget.style.display = 'none' }} />
) } // If iconUrl is an emoji or custom text if (iconUrl && iconUrl.trim()) { return (
{iconUrl}
) } // Fallback initial with background gradient return (
{initial}
) }