import 'package:flutter/widgets.dart';

import '../models/chat.dart';
import 'app_localizations.dart';

String localizeKnownText(BuildContext context, String text) {
  final l10n = AppLocalizations.of(context);
  switch (text.trim()) {
    case 'Auftragsdetails':
      return l10n.jobDetails;
    case 'Aufgaben eines Auftrags':
      return l10n.jobTasks;
    case 'Unterschrift':
      return l10n.signature;
    case 'Allgemeine Nachrichten':
      return l10n.generalMessages;
    case 'Telefon':
      return l10n.phone;
    case 'Erstellt':
      return l10n.created;
    case 'E-Mail-Adresse':
      return l10n.emailAddress;
    case 'Passwort':
      return l10n.password;
    case 'Anmelden':
      return l10n.login;
    default:
      return text;
  }
}

String localizedStationLabel(
  BuildContext context,
  int number, {
  String? suffix,
}) {
  final base = AppLocalizations.of(context).stationNumber(number);
  final trimmedSuffix = suffix?.trim() ?? '';
  if (trimmedSuffix.isEmpty) {
    return base;
  }
  return '$base: ${localizeKnownText(context, trimmedSuffix)}';
}

String localizedChatTitle(BuildContext context, Chat chat) {
  if (chat.type == ChatType.general) {
    return AppLocalizations.of(context).generalMessages;
  }
  return localizeKnownText(context, chat.title);
}
