2026-06-06 21:10:52 +02:00
|
|
|
import { useEntitlements } from '../context/EntitlementsContext'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Zeigt Vereins-Kontingent für ein Feature (M4 UsageBadge).
|
|
|
|
|
* Unbegrenzt (limit null) → nichts rendern.
|
|
|
|
|
*/
|
|
|
|
|
export default function FeatureUsageBadge({ featureId = 'ai_calls', label = 'KI-Kontingent' }) {
|
2026-06-07 07:05:02 +02:00
|
|
|
const { entitlements, loading, error, getFeature } = useEntitlements()
|
2026-06-06 21:10:52 +02:00
|
|
|
const feat = getFeature(featureId)
|
|
|
|
|
|
|
|
|
|
if (loading && !feat) {
|
|
|
|
|
return (
|
|
|
|
|
<span className="feature-usage-badge muted" style={{ fontSize: '0.8rem' }}>
|
|
|
|
|
{label}: …
|
|
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-07 07:05:02 +02:00
|
|
|
if (!feat) {
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<span
|
|
|
|
|
className="feature-usage-badge muted"
|
|
|
|
|
style={{ fontSize: '0.8rem', color: 'var(--text3)' }}
|
|
|
|
|
title={error}
|
|
|
|
|
>
|
|
|
|
|
{label}: —
|
|
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
2026-06-06 21:10:52 +02:00
|
|
|
|
2026-06-07 07:43:35 +02:00
|
|
|
const { used = 0, limit, remaining, allowed, platform_exempt: platformExempt, reason } = feat
|
|
|
|
|
|
|
|
|
|
if (platformExempt || reason === 'platform_exempt' || reason === 'capability_quota_bypass') {
|
|
|
|
|
return (
|
|
|
|
|
<span
|
|
|
|
|
className="feature-usage-badge"
|
|
|
|
|
style={{ fontSize: '0.8rem', color: 'var(--accent-dark)' }}
|
|
|
|
|
title="Plattform-Ausnahme: zählt nicht gegen das Vereins-Kontingent"
|
|
|
|
|
>
|
|
|
|
|
{label}: Plattform (unbegrenzt)
|
|
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-07 07:05:02 +02:00
|
|
|
// limit === 0 (z. B. Free-Plan ai_calls) anzeigen; nur echtes Unbegrenzt (null) ausblenden
|
2026-06-06 21:10:52 +02:00
|
|
|
if (limit == null) return null
|
|
|
|
|
|
|
|
|
|
const tone = !allowed || remaining === 0 ? 'var(--danger)' : 'var(--text2)'
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<span
|
|
|
|
|
className="feature-usage-badge"
|
|
|
|
|
style={{ fontSize: '0.8rem', color: tone }}
|
|
|
|
|
title={
|
|
|
|
|
entitlements?.plan_id
|
|
|
|
|
? `Plan: ${entitlements.plan_id}`
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{label}: {used}/{limit}
|
|
|
|
|
{remaining != null ? ` (${remaining} übrig)` : ''}
|
|
|
|
|
</span>
|
|
|
|
|
)
|
|
|
|
|
}
|