import 'package:flutter/material.dart';
import 'package:aman_kassa_flutter/core/models/halyk/close_day_data.dart' as halyk;
import 'package:aman_kassa_flutter/core/models/forte/close_day_data.dart' as forte;
import 'package:aman_kassa_flutter/views/bank_setting/bank_setting_view.dart';
import 'package:aman_kassa_flutter/views/bank_view/bank_view.dart';
import 'package:aman_kassa_flutter/views/check/image_show_container.dart';
import "package:aman_kassa_flutter/views/home/home_view_m.dart";
import 'package:aman_kassa_flutter/views/close_day_view/close_day_show_container.dart';
import 'package:aman_kassa_flutter/views/history/history_view.dart';
import 'package:aman_kassa_flutter/views/info_kkm/info_kkm_view.dart';
import 'package:aman_kassa_flutter/views/payment/payment_view.dart';
import 'package:aman_kassa_flutter/views/payment_nfc/payment_nfc_view.dart';
import 'package:aman_kassa_flutter/views/qr_view/qr_view.dart';
import 'package:aman_kassa_flutter/views/settings/printer/views/PrinterSelect.dart';
import 'package:aman_kassa_flutter/views/settings/settings_view.dart';
import 'package:aman_kassa_flutter/views/settings/printer/views/PrinterEncoding.dart';
import 'package:aman_kassa_flutter/views/settings/printer/views/PrinterPaperSize.dart';
import 'package:aman_kassa_flutter/views/settings/setting_printer_view.dart';
import 'package:aman_kassa_flutter/views/login/login_view.dart';
import '../redux/state/bank_state.dart';
import '../redux/store.dart';
import './route_names.dart';
import 'package:aman_kassa_flutter/views/bank_setting/forte_setting_view.dart';


Route<dynamic> generateRoute(RouteSettings settings) {
  switch (settings.name) {
    case LoginViewRoute:
      LoginModel model = settings.arguments as LoginModel;
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: LoginView(loginModel: model,),
      );
    case HomeViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: HomeView(),
      );
    case PaymentViewRoute:
      PaymentModel model = settings.arguments as PaymentModel;
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: PaymentView(model: model),
      );
    case PaymentNfcViewRoute:
    PaymentModel model = settings.arguments as PaymentModel;
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: PaymentNfcView(model: model),
      );
    case HistoryViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: HistoryView(),
      );
    case InfoKkmViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: InfoKkmView(),
      );
    case SettingsViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: SettingView(),
      );
    case BankViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: BankView(),
      );
    case BankSettingViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: BankSettingView(),
      );
    case ForteSettingViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: ForteSettingView(),
      );
    case QrViewRoute:
      ImageShowModel data = settings.arguments as ImageShowModel;
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: QrView(data),
      );
    case ImageShowRoute:
      ImageShowModel data = settings.arguments as ImageShowModel;
      //return SlideRightRoute(widget: ImageShowContainer(data));
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: ImageShowContainer(data),
      );
    case SettingsPrinterRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: SettingPrinterView(),
      );
    case SettingsPrinterBTRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: PrinterSelectView(),
      );
    case SettingsPrinterEncodingRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: PrinterEncodingView(),
      );
    case SettingsPrinterPaperRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: PrinterPaperView(),
      );
    case CloseDayShowRoute:
      var data = settings.arguments;

      if (data is halyk.CloseDayData) {
        return _getPageRoute(
          routeName: settings.name!,
          viewToShow: CloseDayShowContainer(data),
        );
      } else if (data is forte.CloseDayData) {
        return _getPageRoute(
          routeName: settings.name!,
          viewToShow: CloseDayShowContainer(data),
        );
      } else {
        return _getPageRoute(
          routeName: settings.name!,
          viewToShow: Scaffold(
            appBar: AppBar(
              title: Text('Информация недоступна'),
            ),
            body: Center(
              child: Text('Данные не могут быть отображены. Пожалуйста, попробуйте позже.'),
            ),
          ),
        );
      }

    default:
      return MaterialPageRoute(
          builder: (_) => Scaffold(
                body: Center(
                    child: Text('No route defined for ${settings.name}')),
              ));
  }
}

PageRoute _getPageRoute({required String routeName, required Widget viewToShow}) {
  return MaterialPageRoute(
      settings: RouteSettings(
        name: routeName,
      ),
      builder: (_) => viewToShow);
}

class SlideRightRoute extends PageRouteBuilder {
  final Widget widget;
  SlideRightRoute({required this.widget})
      : super(
          pageBuilder: (BuildContext context, Animation<double> animation,
              Animation<double> secondaryAnimation) {
            return widget;
          },
          transitionsBuilder: (BuildContext context,
              Animation<double> animation,
              Animation<double> secondaryAnimation,
              Widget child) {
            return new SlideTransition(
              position: new Tween<Offset>(
                begin: const Offset(1.0, 0.0),
                end: Offset.zero,
              ).animate(animation),
              child: child,
            );
          },
        );
}
