import React, { useState } from 'react'; import { Globe, HardDrive, Store } from 'lucide-react'; import { usePluginAuthorIdentity } from '../../application/state/usePluginAuthorIdentity'; import { useI18n } from '../../application/i18n/I18nProvider'; import { Badge } from '../ui/badge'; export function PluginAuthorRow({ entry, plugin, sourceId, showSource = false }: { entry?: NetcattyPluginCatalogEntry; plugin?: NetcattyInstalledPlugin; sourceId?: string; showSource?: boolean; }) { const { t } = useI18n(); const { ref, identity } = usePluginAuthorIdentity({ entry, plugin, sourceId }); const [failed, setFailed] = useState(null); const author = identity?.author ?? entry?.author ?? plugin?.manifest?.publisher ?? ''; const imageKey = JSON.stringify([entry?.id, entry?.selectionToken, plugin?.id, plugin?.activeVersion, plugin?.archiveSha256, sourceId, identity?.avatar]); const avatar = identity?.avatar; const showImage = avatar && avatar.length <= 700_000 && /^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(avatar) && failed !== imageKey; const source = plugin?.source; const sourceKey = source?.kind === 'third-party' ? 'thirdparty' : source?.kind === 'official' || source?.kind === 'local' ? source.kind : undefined; const sourceLabel = t(sourceKey ? `settings.plugins.sources.short.${sourceKey}` : 'settings.plugins.landing.sourceUnknown'); const sourceDescription = sourceKey ? [t(`settings.plugins.sources.${sourceKey}`), source?.name, source?.origin].filter(Boolean).join(' ยท ') : sourceLabel; const SourceIcon = source?.kind === 'local' ? HardDrive : source?.kind === 'official' ? Store : Globe; return
{(author || showImage || identity?.officialMaintained === true) && {showImage && setFailed(imageKey)} />} {author && {author}} {identity?.officialMaintained === true && {t('settings.plugins.author.official')}} } {showSource && }
; }