'use client'; import { memo } from 'react'; import { Check } from 'lucide-react'; import { distros, getIconUrl, type DistroId, type AppData } from '@/lib/data'; import { isAurPackage } from '@/lib/aur'; import { AppIcon } from './AppIcon'; const COLOR_MAP: Record = { 'orange': '#f97316', 'blue': '#3b82f6', 'emerald': '#10b981', 'sky': '#0ea5e9', 'yellow': '#eab308', 'slate': '#64748b', 'zinc': '#71717a', 'rose': '#f43f5e', 'purple': '#a855f7', 'red': '#ef4444', 'indigo': '#6366f1', 'cyan': '#06b6d4', 'green': '#22c55e', 'teal': '#14b8a6', 'gray': '#6b7280', 'fuchsia': '#d946ef', }; interface AppItemProps { app: AppData; isSelected: boolean; isAvailable: boolean; isFocused: boolean; selectedDistro: DistroId; onToggle: () => void; onTooltipEnter: (t: string, e: React.MouseEvent) => void; onTooltipLeave: () => void; onFocus?: () => void; color?: string; isVerified?: boolean; verificationSource?: 'flathub' | 'snap' | null; } export const AppItem = memo(function AppItem({ app, isSelected, isAvailable, isFocused, selectedDistro, onToggle, onTooltipEnter, onTooltipLeave, onFocus, color = 'gray', isVerified = false, verificationSource = null, }: AppItemProps) { const getUnavailableText = () => { const distroName = distros.find(d => d.id === selectedDistro)?.name || ''; let msg = ''; if (!isAvailable) { msg = app.unavailableReason || `Not available in ${distroName} repos`; } if (app.note) { msg = msg ? `${msg} — ${app.note}` : app.note; } return msg; }; const isAur = selectedDistro === 'arch' && app.targets?.arch && isAurPackage(app.targets.arch); const universalTarget = !app.targets?.[selectedDistro] ? ( app.targets?.npm ? 'npm' : app.targets?.script ? 'script' : null ) : null; const hexColor = COLOR_MAP[color] || COLOR_MAP['gray']; const checkboxColor = isAur ? '#1793d1' : hexColor; return (
{ e.stopPropagation(); onFocus?.(); if (isAvailable) { onToggle(); } }} >
{isSelected && }
{ e.stopPropagation(); const tooltipText = app.note ? `${app.description} — ${app.note}` : app.description; onTooltipEnter(tooltipText, e); }} onMouseLeave={(e) => { e.stopPropagation(); onTooltipLeave(); }} > {app.name} {isAur && ( This is an AUR package )} {isVerified && verificationSource && ( {verificationSource === 'flathub' ? 'Verified on Flathub' : 'Verified publisher on Snap Store'} )} {universalTarget && ( { e.stopPropagation(); onTooltipEnter(`Installed via ${universalTarget}. Requires correct runtime.`, e); }} onMouseLeave={(e) => { e.stopPropagation(); onTooltipLeave(); }} > {universalTarget} )}
{(!isAvailable || universalTarget) && (
{ e.stopPropagation(); onTooltipEnter(getUnavailableText(), e); }} onMouseLeave={(e) => { e.stopPropagation(); onTooltipLeave(); }} >
)}
); });