import '../../../../core/i18n/locale_utils.dart';

String buildQrApprovePath(
  String scannedValue, {
  String? localeCode,
  Uri? currentUri,
}) {
  final value = scannedValue.trim();
  final explicitLocale = localeCode?.trim();
  final uri = currentUri ?? Uri.base;
  final resolvedLocale = explicitLocale != null && explicitLocale.isNotEmpty
      ? explicitLocale.toLowerCase().replaceAll('_', '-')
      : normalizeLocaleCode(
          extractLocaleFromPath(uri) ?? resolvePreferredLocaleCode(),
        );
  return '/$resolvedLocale/approve?ref=${Uri.encodeQueryComponent(value)}';
}

String buildQrBackFallbackPath({String? localeCode, Uri? currentUri}) {
  final explicitLocale = localeCode?.trim();
  final uri = currentUri ?? Uri.base;
  final resolvedLocale = explicitLocale != null && explicitLocale.isNotEmpty
      ? explicitLocale.toLowerCase().replaceAll('_', '-')
      : normalizeLocaleCode(
          extractLocaleFromPath(uri) ?? resolvePreferredLocaleCode(),
        );
  return '/$resolvedLocale/dashboard';
}
