
import 'package:satu/views/work/views/add_by_barcode/add_by_barcode_view.dart';
import 'package:satu/views/work/views/add_product/add_product_view.dart';
import 'package:satu/views/login/login_view.dart';
import 'package:satu/views/main/main_view.dart';
import 'package:satu/views/settings/printer_bluetooth/PrinterSelect.dart';
import 'package:satu/views/work/views/contragent/select_contragent_view.dart';
import 'package:satu/views/work/views/payment/payment_view.dart';
import 'package:satu/views/work/work_view.dart';

import './route_names.dart';
import 'package:flutter/material.dart';

Route<dynamic> generateRoute(RouteSettings settings) {
  switch (settings.name) {
    case loginViewRoute:
      //LoginModel model = settings.arguments as LoginModel;
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: LoginView(),
      );
    case workViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: WorkView(),
      );
    case mainViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: MainView(),
      );
    case addProductViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: AddProductView(),
      );
    case addByBarcodeViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: AddByBarcodeView(),
      );
    case settingPrinterBluetoothViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        //viewToShow: PrinterSelectView(title: 'Принтер печати чеков',),
      );
    case contragentSelectViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: SelectContragentView(),
      );
    case paymentViewRoute:
      return _getPageRoute(
        routeName: settings.name!,
        viewToShow: PaymentView(),
      );
    // case ImageShowRoute:
    //   ImageShowModel data = settings.arguments as ImageShowModel;
    //   //return SlideRightRoute(widget: ImageShowContainer(data));
    //   return _getPageRoute(
    //     routeName: settings.name,
    //     viewToShow: ImageShowContainer(data),
    //   );
    default:
      return MaterialPageRoute(
          builder: (_) => Scaffold(
                body: Center(
                    child: Text('No route defined for ${settings.name}')),
              ));
  }
}

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

class SlideRightRoute extends PageRouteBuilder {
  final Widget? widget;
  SlideRightRoute({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,
            );
          },
        );
}
