String? normalizedOptionalText(String? value) {
  final normalized = value?.trim();
  if (normalized == null || normalized.isEmpty) return null;
  return normalized;
}

({String label, String tooltip}) categoryChipText({
  required String? categoryPath,
  required String fallbackL1,
}) {
  final path = categoryPath?.trim();
  if (path == null || path.isEmpty) {
    return (label: fallbackL1, tooltip: fallbackL1);
  }

  final parts = path
      .split('>')
      .map((part) => part.trim())
      .where((part) => part.isNotEmpty)
      .toList();

  if (parts.isEmpty) {
    return (label: fallbackL1, tooltip: fallbackL1);
  }

  return (label: parts.last, tooltip: parts.join(' > '));
}

String locationLabel(String prefix, String location) => '$prefix$location';
