import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl/intl.dart' as intl;

import 'app_localizations_en.dart';
import 'app_localizations_zh.dart';

// ignore_for_file: type=lint

/// Callers can lookup localized strings with an instance of AppL10n
/// returned by `AppL10n.of(context)`.
///
/// Applications need to include `AppL10n.delegate()` in their app's
/// `localizationDelegates` list, and the locales they support in the app's
/// `supportedLocales` list. For example:
///
/// ```dart
/// import 'generated/app_localizations.dart';
///
/// return MaterialApp(
///   localizationsDelegates: AppL10n.localizationsDelegates,
///   supportedLocales: AppL10n.supportedLocales,
///   home: MyApplicationHome(),
/// );
/// ```
///
/// ## Update pubspec.yaml
///
/// Please make sure to update your pubspec.yaml to include the following
/// packages:
///
/// ```yaml
/// dependencies:
///   # Internationalization support.
///   flutter_localizations:
///     sdk: flutter
///   intl: any # Use the pinned version from flutter_localizations
///
///   # Rest of dependencies
/// ```
///
/// ## iOS Applications
///
/// iOS applications define key application metadata, including supported
/// locales, in an Info.plist file that is built into the application bundle.
/// To configure the locales supported by your app, you’ll need to edit this
/// file.
///
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
/// Then, in the Project Navigator, open the Info.plist file under the Runner
/// project’s Runner folder.
///
/// Next, select the Information Property List item, select Add Item from the
/// Editor menu, then select Localizations from the pop-up menu.
///
/// Select and expand the newly-created Localizations item then, for each
/// locale your application supports, add a new item and select the locale
/// you wish to add from the pop-up menu in the Value field. This list should
/// be consistent with the languages listed in the AppL10n.supportedLocales
/// property.
abstract class AppL10n {
  AppL10n(String locale)
    : localeName = intl.Intl.canonicalizedLocale(locale.toString());

  final String localeName;

  static AppL10n of(BuildContext context) {
    return Localizations.of<AppL10n>(context, AppL10n)!;
  }

  static const LocalizationsDelegate<AppL10n> delegate = _AppL10nDelegate();

  /// A list of this localizations delegate along with the default localizations
  /// delegates.
  ///
  /// Returns a list of localizations delegates containing this delegate along with
  /// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
  /// and GlobalWidgetsLocalizations.delegate.
  ///
  /// Additional delegates can be added by appending to this list in
  /// MaterialApp. This list does not have to be used at all if a custom list
  /// of delegates is preferred or required.
  static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
      <LocalizationsDelegate<dynamic>>[
        delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ];

  /// A list of this localizations delegate's supported locales.
  static const List<Locale> supportedLocales = <Locale>[
    Locale('en'),
    Locale('zh'),
  ];

  /// No description provided for @appTitle.
  ///
  /// In en, this message translates to:
  /// **'Chanora'**
  String get appTitle;

  /// No description provided for @homeNotProductionReadyBanner.
  ///
  /// In en, this message translates to:
  /// **'Beta build — voice in/out wired; not production ready.'**
  String get homeNotProductionReadyBanner;

  /// No description provided for @fieldServerHost.
  ///
  /// In en, this message translates to:
  /// **'Server address'**
  String get fieldServerHost;

  /// No description provided for @fieldNickname.
  ///
  /// In en, this message translates to:
  /// **'Nickname'**
  String get fieldNickname;

  /// No description provided for @fieldServerPassword.
  ///
  /// In en, this message translates to:
  /// **'Server password'**
  String get fieldServerPassword;

  /// No description provided for @fieldServerPasswordHelp.
  ///
  /// In en, this message translates to:
  /// **'Leave blank if the server does not require one.'**
  String get fieldServerPasswordHelp;

  /// No description provided for @fieldPassword.
  ///
  /// In en, this message translates to:
  /// **'Password'**
  String get fieldPassword;

  /// No description provided for @fieldDisplayName.
  ///
  /// In en, this message translates to:
  /// **'Display name'**
  String get fieldDisplayName;

  /// No description provided for @connectAction.
  ///
  /// In en, this message translates to:
  /// **'Connect'**
  String get connectAction;

  /// No description provided for @disconnectAction.
  ///
  /// In en, this message translates to:
  /// **'Disconnect'**
  String get disconnectAction;

  /// No description provided for @refreshAction.
  ///
  /// In en, this message translates to:
  /// **'Refresh'**
  String get refreshAction;

  /// No description provided for @diagnosticsAction.
  ///
  /// In en, this message translates to:
  /// **'Diagnostics'**
  String get diagnosticsAction;

  /// No description provided for @aboutAction.
  ///
  /// In en, this message translates to:
  /// **'About'**
  String get aboutAction;

  /// No description provided for @aboutVersion.
  ///
  /// In en, this message translates to:
  /// **'Version {version}'**
  String aboutVersion(String version);

  /// No description provided for @aboutNonAffiliation.
  ///
  /// In en, this message translates to:
  /// **'Chanora is independent and is not affiliated with, endorsed by, sponsored by, or officially associated with TeamSpeak.'**
  String get aboutNonAffiliation;

  /// No description provided for @aboutLicenseHeading.
  ///
  /// In en, this message translates to:
  /// **'License'**
  String get aboutLicenseHeading;

  /// No description provided for @aboutLicenseBody.
  ///
  /// In en, this message translates to:
  /// **'Chanora is dual-licensed under the Apache License, Version 2.0 or the MIT License, at your option. The full license texts ship as LICENSE-APACHE and LICENSE-MIT at the repository root.'**
  String get aboutLicenseBody;

  /// No description provided for @aboutThirdPartyHeading.
  ///
  /// In en, this message translates to:
  /// **'Third-party software'**
  String get aboutThirdPartyHeading;

  /// No description provided for @aboutThirdPartyBody.
  ///
  /// In en, this message translates to:
  /// **'Chanora is built on tsclientlib, flutter_rust_bridge, cpal, rusqlite, and the Flutter framework, among others. See the NOTICE file at the repository root for the current attribution list.'**
  String get aboutThirdPartyBody;

  /// No description provided for @copyAction.
  ///
  /// In en, this message translates to:
  /// **'Copy'**
  String get copyAction;

  /// No description provided for @closeAction.
  ///
  /// In en, this message translates to:
  /// **'Close'**
  String get closeAction;

  /// No description provided for @startAudioAction.
  ///
  /// In en, this message translates to:
  /// **'Start audio'**
  String get startAudioAction;

  /// No description provided for @pttHoldToTalk.
  ///
  /// In en, this message translates to:
  /// **'Hold to talk'**
  String get pttHoldToTalk;

  /// No description provided for @pttTransmitting.
  ///
  /// In en, this message translates to:
  /// **'Transmitting…'**
  String get pttTransmitting;

  /// No description provided for @pttHoldToTalkSemanticsHint.
  ///
  /// In en, this message translates to:
  /// **'Press and hold to transmit voice; release to stop.'**
  String get pttHoldToTalkSemanticsHint;

  /// No description provided for @pttCapabilityBadge.
  ///
  /// In en, this message translates to:
  /// **'PTT: {level} ({backend})'**
  String pttCapabilityBadge(String level, String backend);

  /// No description provided for @pttCapabilityBoundKey.
  ///
  /// In en, this message translates to:
  /// **'Key: {key}'**
  String pttCapabilityBoundKey(String key);

  /// No description provided for @pttCapabilityExplainTitle.
  ///
  /// In en, this message translates to:
  /// **'Push-to-Talk capability'**
  String get pttCapabilityExplainTitle;

  /// No description provided for @pttCapabilityExplainFocusedHeading.
  ///
  /// In en, this message translates to:
  /// **'Focused PTT'**
  String get pttCapabilityExplainFocusedHeading;

  /// No description provided for @pttCapabilityExplainFocusedBody.
  ///
  /// In en, this message translates to:
  /// **'Chanora is currently using Focused Push-to-Talk: the binding only fires while the Chanora window is focused. This is the universal fallback used on every platform when a global capture path is not available.'**
  String get pttCapabilityExplainFocusedBody;

  /// No description provided for @pttCapabilityExplainGoGlobalWindows.
  ///
  /// In en, this message translates to:
  /// **'On Windows, Global PTT is engaged automatically once you bind a key. No additional permission is required.'**
  String get pttCapabilityExplainGoGlobalWindows;

  /// No description provided for @pttCapabilityExplainGoGlobalMacos.
  ///
  /// In en, this message translates to:
  /// **'On macOS, Global PTT requires Input Monitoring permission. Open System Settings → Privacy & Security → Input Monitoring, allow Chanora, then re-bind the key.'**
  String get pttCapabilityExplainGoGlobalMacos;

  /// No description provided for @pttCapabilityExplainGoGlobalLinux.
  ///
  /// In en, this message translates to:
  /// **'On Linux, Global PTT requires a GNOME-Wayland desktop with the GlobalShortcuts portal. Re-bind the key and accept the desktop\'s shortcut dialog when it appears.'**
  String get pttCapabilityExplainGoGlobalLinux;

  /// No description provided for @pttCapabilityExplainGoGlobalGeneric.
  ///
  /// In en, this message translates to:
  /// **'Global PTT is not available in this environment. Focused PTT will keep working while the Chanora window has focus.'**
  String get pttCapabilityExplainGoGlobalGeneric;

  /// No description provided for @pttConfigureAction.
  ///
  /// In en, this message translates to:
  /// **'Configure'**
  String get pttConfigureAction;

  /// No description provided for @pttConfigureTitle.
  ///
  /// In en, this message translates to:
  /// **'Configure Push-to-Talk binding'**
  String get pttConfigureTitle;

  /// No description provided for @pttConfigurePrompt.
  ///
  /// In en, this message translates to:
  /// **'Press the key or mouse side button you want to use for Push-to-Talk.'**
  String get pttConfigurePrompt;

  /// No description provided for @pttConfigureWaiting.
  ///
  /// In en, this message translates to:
  /// **'(waiting for input…)'**
  String get pttConfigureWaiting;

  /// No description provided for @pttConfigureCaptured.
  ///
  /// In en, this message translates to:
  /// **'Captured'**
  String get pttConfigureCaptured;

  /// No description provided for @pttConfigurePrivacyNote.
  ///
  /// In en, this message translates to:
  /// **'Chanora never logs the actual key value. Only the input class (keyboard / mouse-side-button) and a platform-neutral label leave this dialog.'**
  String get pttConfigurePrivacyNote;

  /// No description provided for @pttConfigureSaveAction.
  ///
  /// In en, this message translates to:
  /// **'Save'**
  String get pttConfigureSaveAction;

  /// No description provided for @pttConfigurePortalRedirect.
  ///
  /// In en, this message translates to:
  /// **'Your desktop environment will open its own shortcut dialog. Pick the key you want to use for Push-to-Talk.'**
  String get pttConfigurePortalRedirect;

  /// No description provided for @inputMuteAction.
  ///
  /// In en, this message translates to:
  /// **'Mute mic'**
  String get inputMuteAction;

  /// No description provided for @inputUnmuteAction.
  ///
  /// In en, this message translates to:
  /// **'Unmute mic'**
  String get inputUnmuteAction;

  /// No description provided for @outputMuteAction.
  ///
  /// In en, this message translates to:
  /// **'Mute speaker'**
  String get outputMuteAction;

  /// No description provided for @outputUnmuteAction.
  ///
  /// In en, this message translates to:
  /// **'Unmute speaker'**
  String get outputUnmuteAction;

  /// No description provided for @joinChannelAction.
  ///
  /// In en, this message translates to:
  /// **'Join channel'**
  String get joinChannelAction;

  /// No description provided for @channelPasswordTitle.
  ///
  /// In en, this message translates to:
  /// **'Channel password'**
  String get channelPasswordTitle;

  /// No description provided for @bookmarksHeading.
  ///
  /// In en, this message translates to:
  /// **'Bookmarks'**
  String get bookmarksHeading;

  /// No description provided for @bookmarksEmpty.
  ///
  /// In en, this message translates to:
  /// **'No bookmarks yet. Enter a server above and tap \"Save bookmark\".'**
  String get bookmarksEmpty;

  /// No description provided for @bookmarkAddAction.
  ///
  /// In en, this message translates to:
  /// **'Save bookmark'**
  String get bookmarkAddAction;

  /// No description provided for @bookmarkAddTitle.
  ///
  /// In en, this message translates to:
  /// **'Save bookmark'**
  String get bookmarkAddTitle;

  /// No description provided for @bookmarkDeleteAction.
  ///
  /// In en, this message translates to:
  /// **'Delete bookmark'**
  String get bookmarkDeleteAction;

  /// No description provided for @statusIdle.
  ///
  /// In en, this message translates to:
  /// **'Not connected'**
  String get statusIdle;

  /// No description provided for @statusConnecting.
  ///
  /// In en, this message translates to:
  /// **'Connecting…'**
  String get statusConnecting;

  /// No description provided for @statusConnected.
  ///
  /// In en, this message translates to:
  /// **'Connected to {server}'**
  String statusConnected(String server);

  /// No description provided for @statusError.
  ///
  /// In en, this message translates to:
  /// **'Error: {message}'**
  String statusError(String message);

  /// No description provided for @statusReconnecting.
  ///
  /// In en, this message translates to:
  /// **'Reconnecting… attempt {attempt}, in {delay}s'**
  String statusReconnecting(int attempt, int delay);

  /// No description provided for @statusConnectionLost.
  ///
  /// In en, this message translates to:
  /// **'Connection lost: {reason}'**
  String statusConnectionLost(String reason);

  /// No description provided for @audioStatsLine.
  ///
  /// In en, this message translates to:
  /// **'TX {sent} frames • RX {received} frames • PTT {ptt}'**
  String audioStatsLine(int sent, int received, String ptt);

  /// No description provided for @channelsHeading.
  ///
  /// In en, this message translates to:
  /// **'Channels'**
  String get channelsHeading;

  /// No description provided for @clientsHeading.
  ///
  /// In en, this message translates to:
  /// **'Online clients'**
  String get clientsHeading;

  /// No description provided for @countChannelsAndClients.
  ///
  /// In en, this message translates to:
  /// **'{channels} channels • {clients} online'**
  String countChannelsAndClients(int channels, int clients);
}

class _AppL10nDelegate extends LocalizationsDelegate<AppL10n> {
  const _AppL10nDelegate();

  @override
  Future<AppL10n> load(Locale locale) {
    return SynchronousFuture<AppL10n>(lookupAppL10n(locale));
  }

  @override
  bool isSupported(Locale locale) =>
      <String>['en', 'zh'].contains(locale.languageCode);

  @override
  bool shouldReload(_AppL10nDelegate old) => false;
}

AppL10n lookupAppL10n(Locale locale) {
  // Lookup logic when only language code is specified.
  switch (locale.languageCode) {
    case 'en':
      return AppL10nEn();
    case 'zh':
      return AppL10nZh();
  }

  throw FlutterError(
    'AppL10n.delegate failed to load unsupported locale "$locale". This is likely '
    'an issue with the localizations generation tool. Please file an issue '
    'on GitHub with a reproducible sample app and the gen-l10n configuration '
    'that was used.',
  );
}
