import { useEffect, useState, type ImgHTMLAttributes } from 'react' type BrandingSettings = { siteLogo?: string | null siteLogoDark?: string | null siteName?: string | null } const fallbackLogo = '/default-favicon.ico' export const Logo = ({ className = 'w-auto h-5', ...props }: Omit, 'alt' | 'src'>) => { const [branding, setBranding] = useState({}) useEffect(() => { const controller = new AbortController() fetch('/api/site-settings?scope=branding', { credentials: 'same-origin', signal: controller.signal, }) .then((response) => (response.ok ? response.json() : null)) .then((settings: BrandingSettings | null) => { if (settings) setBranding(settings) }) .catch(() => undefined) return () => controller.abort() }, []) const logo = branding.siteLogoDark || branding.siteLogo || fallbackLogo const siteName = branding.siteName?.trim() || 'HiCAD' return ( {siteName} { if (!event.currentTarget.src.endsWith(fallbackLogo)) { event.currentTarget.src = fallbackLogo } }} src={logo} /> ) }