import '../models/app_error.dart'; import '../models/update_failure.dart'; import 'app_localizations.dart'; extension AppLocalizationsHelpers on AppLocalizations { String categoryLabel(String category) { return switch (category.trim().toLowerCase()) { 'bier' || 'beer' => categoryBeer, 'wijn' || 'wine' => categoryWine, 'frisdrank' || 'soft drinks' => categorySoftDrinks, 'cocktails' => categoryCocktails, 'snacks' => categorySnacks, 'coffee' || 'koffie' => categoryCoffee, 'thee' || 'tea' => categoryTea, 'other' || 'overig' => categoryOther, _ => category, }; } String errorText(AppError? error) { return switch (error) { null => genericError, AppError.loadBar => couldNotLoadBar, AppError.createTab => couldNotCreateTabMessage, AppError.outOfStock => productOutOfStock, AppError.addProductToTab => couldNotAddProductToTab, AppError.updateQuantity => couldNotUpdateQuantity, AppError.closeTab => couldNotCloseTab, AppError.renameTab => couldNotRenameTab, AppError.deleteTab => couldNotDeleteTab, AppError.loadHistory => couldNotLoadHistory, AppError.loadMoreTabs => couldNotLoadMoreTabs, AppError.loadProducts => couldNotLoadProducts, AppError.addProduct => couldNotAddProduct, AppError.updateProduct => couldNotUpdateProduct, AppError.deleteProduct => couldNotDeleteProduct, AppError.checkPinStatus => couldNotCheckPinStatus, AppError.savePin => couldNotSavePin, AppError.incorrectPin => incorrectPin, AppError.verifyPin => couldNotVerifyPin, AppError.currentPinIncorrect => currentPinIncorrect, AppError.tooManyPinAttempts => tooManyPinAttempts, AppError.loadSettings => couldNotLoadSettings, AppError.saveSettings => couldNotSaveSettings, }; } String updateFailureText(UpdateFailure? failure) { return switch (failure) { UpdateFailure.download => updateDownloadFailed, UpdateFailure.checksum => updateChecksumFailed, UpdateFailure.permission => updatePermissionDenied, UpdateFailure.install => updateInstallFailed, UpdateFailure.alreadyRunning => updateAlreadyInProgress, UpdateFailure.simulated => simulatedDownloadError, UpdateFailure.unknown || null => updateFailed, }; } String devAction(String? message) { if (message == null) return ''; final seeded = RegExp( r'Seeded (?:default products )?\((\d+) total\)', ).firstMatch(message); if (seeded != null) { return devActionSeededProducts(int.parse(seeded.group(1)!)); } final reseeded = RegExp( r'Cleared and reseeded \((\d+) products\)', ).firstMatch(message); if (reseeded != null) { return devActionReseededProducts(int.parse(reseeded.group(1)!)); } final resetStock = RegExp( r'Reset stock for (\d+) products', ).firstMatch(message); if (resetStock != null) { return devActionResetStock(int.parse(resetStock.group(1)!)); } final seededDemo = RegExp( r'Seeded (\d+) demo products', ).firstMatch(message); if (seededDemo != null) { return devActionSeededProducts(int.parse(seededDemo.group(1)!)); } final testTab = RegExp( r'Created test tab with (\d+) items', ).firstMatch(message); if (testTab != null) { return devActionTestTab(int.parse(testTab.group(1)!)); } final testProducts = RegExp( r'Added (\d+) test products', ).firstMatch(message); if (testProducts != null) { return devActionTestProducts(int.parse(testProducts.group(1)!)); } final lowStock = RegExp( r'Simulated low stock for (\d+) products', ).firstMatch(message); if (lowStock != null) { return devActionLowStock(int.parse(lowStock.group(1)!)); } final mockOrders = RegExp( r'Generated (\d+) mock orders across (\d+) customers', ).firstMatch(message); if (mockOrders != null) { return devActionMockOrders( int.parse(mockOrders.group(1)!), int.parse(mockOrders.group(2)!), ); } return switch (message) { 'Cleared all open tabs' => devActionClearedOpenTabs, 'Cleared closed tab history' => devActionClearedHistory, 'Cleared all products' => devActionClearedProducts, 'Product images cleared' => devActionImagesCleared, 'PIN reset (no PIN required)' => devActionResetPin, 'No products to add to test tab' => devActionNoProducts, 'No products available — seed demo data first' => devActionNoProducts, 'Product images reloaded' => devActionImagesReloaded, 'Image cache cleared (no-op in debug mode)' => devActionCacheCleared, _ when message.startsWith('Failed to clear images') => devActionFailedImages, _ => message, }; } }