import type { WidgetTranslations } from '../i18n';

/**
 * How many try-ons the visitor has left on the demo, worded, or null when a
 * number would be a guess or a distraction.
 *
 * Rewritten rather than ported: the Shopify widget read this from its billing
 * API, which the WooCommerce widget has no equivalent of. Here the number the
 * visitor actually meets is the demo's own allowance, counted in their browser.
 *
 * Null on purpose when the demo never advertised a limit (limit 0) or when the
 * caller passes something nonsensical: silence beats a wrong promise.
 */
export function demoCounterLabel(
	remaining: number,
	limit: number,
	t: WidgetTranslations
): string | null {
	if ( limit <= 0 ) {
		return null;
	}
	if ( ! Number.isFinite( remaining ) || remaining < 0 ) {
		return null;
	}
	return t.counter.remaining( remaining );
}
