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_sv.dart';

// ignore_for_file: type=lint

/// Callers can lookup localized strings with an instance of AppLocalizations
/// returned by `AppLocalizations.of(context)`.
///
/// Applications need to include `AppLocalizations.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: AppLocalizations.localizationsDelegates,
///   supportedLocales: AppLocalizations.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 AppLocalizations.supportedLocales
/// property.
abstract class AppLocalizations {
  AppLocalizations(String locale)
      : localeName = intl.Intl.canonicalizedLocale(locale.toString());

  final String localeName;

  static AppLocalizations? of(BuildContext context) {
    return Localizations.of<AppLocalizations>(context, AppLocalizations);
  }

  static const LocalizationsDelegate<AppLocalizations> delegate =
      _AppLocalizationsDelegate();

  /// 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('sv')
  ];

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

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

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

  /// No description provided for @mealPlanLoading.
  ///
  /// In en, this message translates to:
  /// **'Loading meal plan...'**
  String get mealPlanLoading;

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

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

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

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

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

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

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

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

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

  /// No description provided for @mealPlanPlannedRecipes.
  ///
  /// In en, this message translates to:
  /// **'{count, plural, one {# recipe planned} other {# recipes planned}}'**
  String mealPlanPlannedRecipes(int count);

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

  /// No description provided for @mealPlanPickRecipeHint.
  ///
  /// In en, this message translates to:
  /// **'Choose recipes above to see the combined ingredient list.'**
  String get mealPlanPickRecipeHint;

  /// No description provided for @mealPlanNoShoppingItems.
  ///
  /// In en, this message translates to:
  /// **'No ingredients to show for this week.'**
  String get mealPlanNoShoppingItems;

  /// No description provided for @mealPlanNoRecipesTitle.
  ///
  /// In en, this message translates to:
  /// **'There are no recipes to plan yet.'**
  String get mealPlanNoRecipesTitle;

  /// No description provided for @mealPlanNoRecipesDescription.
  ///
  /// In en, this message translates to:
  /// **'Create at least one recipe first, then add it to the meal plan.'**
  String get mealPlanNoRecipesDescription;

  /// No description provided for @mealPlanMissingCount.
  ///
  /// In en, this message translates to:
  /// **'{count, plural, one {# missing} other {# missing}}'**
  String mealPlanMissingCount(int count);

  /// No description provided for @mealPlanPartialCount.
  ///
  /// In en, this message translates to:
  /// **'{count, plural, one {# partially at home} other {# partially at home}}'**
  String mealPlanPartialCount(int count);

  /// No description provided for @mealPlanEnoughCount.
  ///
  /// In en, this message translates to:
  /// **'{count, plural, one {# at home} other {# at home}}'**
  String mealPlanEnoughCount(int count);

  /// No description provided for @mealPlanPantryCount.
  ///
  /// In en, this message translates to:
  /// **'{count, plural, one {# pantry staple} other {# pantry staples}}'**
  String mealPlanPantryCount(int count);

  /// No description provided for @mealPlanAllAtHome.
  ///
  /// In en, this message translates to:
  /// **'You already have everything at home.'**
  String get mealPlanAllAtHome;

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

  /// No description provided for @mealPlanStatusPartial.
  ///
  /// In en, this message translates to:
  /// **'Partially at home'**
  String get mealPlanStatusPartial;

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

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

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

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

  /// No description provided for @usernameRequired.
  ///
  /// In en, this message translates to:
  /// **'Enter your username.'**
  String get usernameRequired;

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

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

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

  /// No description provided for @sessionExpiredError.
  ///
  /// In en, this message translates to:
  /// **'Your session has expired. Sign in again.'**
  String get sessionExpiredError;

  /// No description provided for @forbiddenError.
  ///
  /// In en, this message translates to:
  /// **'You do not have permission to use this feature.'**
  String get forbiddenError;

  /// No description provided for @serverError.
  ///
  /// In en, this message translates to:
  /// **'A server error occurred. Try again in a moment.'**
  String get serverError;

  /// No description provided for @networkError.
  ///
  /// In en, this message translates to:
  /// **'Network error. Check your connection and try again.'**
  String get networkError;

  /// No description provided for @unexpectedError.
  ///
  /// In en, this message translates to:
  /// **'An unexpected error occurred.'**
  String get unexpectedError;
}

class _AppLocalizationsDelegate
    extends LocalizationsDelegate<AppLocalizations> {
  const _AppLocalizationsDelegate();

  @override
  Future<AppLocalizations> load(Locale locale) {
    return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
  }

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

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

AppLocalizations lookupAppLocalizations(Locale locale) {
  // Lookup logic when only language code is specified.
  switch (locale.languageCode) {
    case 'en':
      return AppLocalizationsEn();
    case 'sv':
      return AppLocalizationsSv();
  }

  throw FlutterError(
      'AppLocalizations.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.');
}
