import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

class ChineseCupertinoLocalizations implements CupertinoLocalizations {
  final LocalizationsDelegate<dynamic> materialDelegate = GlobalMaterialLocalizations.delegate;
  final LocalizationsDelegate<dynamic> widgetsDelegate = GlobalWidgetsLocalizations.delegate;
  final Locale local = const Locale('zh');

  MaterialLocalizations ml;

  Future<dynamic> init() async {
    ml = await materialDelegate.load(local);
    print(ml.pasteButtonLabel);
  }

  @override
  String get alertDialogLabel => ml.alertDialogLabel;

  @override
  String get anteMeridiemAbbreviation => ml.anteMeridiemAbbreviation;

  @override
  String get copyButtonLabel => ml.copyButtonLabel;

  @override
  String get cutButtonLabel => ml.cutButtonLabel;

  @override
  DatePickerDateOrder get datePickerDateOrder => DatePickerDateOrder.mdy;

  @override
  DatePickerDateTimeOrder get datePickerDateTimeOrder => DatePickerDateTimeOrder.date_time_dayPeriod;

  @override
  String datePickerDayOfMonth(int dayIndex) {
    return dayIndex.toString() + '日';
  }

  @override
  String datePickerHour(int hour) {
    return hour.toString().padLeft(2, '0');
  }

  @override
  String datePickerHourSemanticsLabel(int hour) {
    return '$hour' '时';
  }

  @override
  String datePickerMediumDate(DateTime date) {
    return ml.formatMediumDate(date);
  }

  @override
  String datePickerMinute(int minute) {
    return minute.toString().padLeft(2, '0');
  }

  @override
  String datePickerMinuteSemanticsLabel(int minute) {
    return '$minute' '分';
  }

  @override
  String datePickerMonth(int monthIndex) {
    return '$monthIndex' '月';
  }

  @override
  String datePickerYear(int yearIndex) {
    return yearIndex.toString() + '年';
  }

  @override
  String get pasteButtonLabel => ml.pasteButtonLabel;

  @override
  String get postMeridiemAbbreviation => ml.postMeridiemAbbreviation;

  @override
  String get selectAllButtonLabel => ml.selectAllButtonLabel;

  @override
  String timerPickerHour(int hour) {
    return hour.toString().padLeft(2, '0');
  }

  @override
  String timerPickerHourLabel(int hour) {
    return '$hour'.toString().padLeft(2, '0') + '时';
  }

  @override
  String timerPickerMinute(int minute) {
    return minute.toString().padLeft(2, '0');
  }

  @override
  String timerPickerMinuteLabel(int minute) {
    return minute.toString().padLeft(2, '0') + '分';
  }

  @override
  String timerPickerSecond(int second) {
    return second.toString().padLeft(2, '0');
  }

  @override
  String timerPickerSecondLabel(int second) {
    return second.toString().padLeft(2, '0') + '秒';
  }

  static const LocalizationsDelegate<CupertinoLocalizations> delegate = _ChineseDelegate();

  static Future<CupertinoLocalizations> load(Locale locale) async {
    final ChineseCupertinoLocalizations localizaltions = ChineseCupertinoLocalizations();
    await localizaltions.init();
    return SynchronousFuture<CupertinoLocalizations>(localizaltions);
  }

  @override
  String get todayLabel => null;
}

class _ChineseDelegate extends LocalizationsDelegate<CupertinoLocalizations> {
  const _ChineseDelegate();

  @override
  bool isSupported(Locale locale) {
    return locale.languageCode == 'zh';
  }

  @override
  Future<CupertinoLocalizations> load(Locale locale) {
    return ChineseCupertinoLocalizations.load(locale);
  }

  @override
  bool shouldReload(LocalizationsDelegate<CupertinoLocalizations> old) {
    return false;
  }
}
