'use client' import { useEffect, useState } from 'react' import { useTranslations } from 'next-intl' import { Globe, CheckCircle2, AlertTriangle, RefreshCcw, Loader2 } from 'lucide-react' import { Button } from '@/components/ui/button' type Source = 'api' | 'fallback' | 'unavailable' interface Status { year: number source: Source reachable: boolean checkedAt: string } interface Props { year?: number compact?: boolean } export function TaxTableStatus({ year, compact = false }: Props) { const t = useTranslations('salary_tax_tables') const [status, setStatus] = useState(null) const [loading, setLoading] = useState(true) async function check() { setLoading(true) const params = new URLSearchParams() if (year) params.set('year', String(year)) const res = await fetch(`/api/salary/tax-tables/status?${params}`) if (res.ok) { const { data } = await res.json() setStatus(data) } setLoading(false) } useEffect(() => { check() // eslint-disable-next-line react-hooks/exhaustive-deps }, [year]) if (loading && !status) { return (
{t('checking')}
) } if (!status) return null const Icon = status.source === 'api' ? CheckCircle2 : AlertTriangle const iconColor = status.source === 'api' ? 'text-success' : status.source === 'fallback' ? 'text-warning' : 'text-destructive' const label = status.source === 'api' ? t('source_api', { year: status.year }) : status.source === 'fallback' ? t('source_fallback', { year: status.year }) : t('source_unavailable', { year: status.year }) if (compact) { return (

{label}

) } // Flat row presentation (Fönster settings language): muted status line // with a quiet right-aligned recheck, no box. return (
{label}
) }