import 'package:fluro/fluro.dart';
import 'package:liftmanager/internal/maintenance/model/maintenance_list_entity.dart';
import 'package:liftmanager/internal/maintenance/page/maintenance_detail_page.dart';
import 'package:liftmanager/internal/maintenance/page/maintenance_evaluate_page.dart';
import 'package:liftmanager/internal/maintenance/page/maintenance_submit_page.dart';
import 'package:liftmanager/internal/maintenance/page/maintenance_list_page.dart';
import 'package:liftmanager/internal/maintenance/page/maintenance_record_info_page.dart';
import 'package:liftmanager/internal/maintenance/page/maintenance_safe_page.dart';
import 'package:liftmanager/internal/maintenance/page/view_image_page.dart';
import 'package:liftmanager/routers/router_init.dart';
import 'dart:convert' as convert;

class MaintenanceRouter implements IRouterProvider{

  static String maintenanceListPage = "/maintenance/list";
  static String maintenanceRecordInfo = "/maintenance/record/info";
  static String maintenanceSign = "/maintenance/sign";
  static String maintenanceSubmit = "/maintenance/submit";
  static String maintenanceDetail = "/maintenance/detail";
  static String maintenanceEvaluate = "/maintenance/evaluate";
  static String viewImage = "/maintenance/viewImage";

  @override
  void initRouter(Router router) {
    router.define(maintenanceListPage, handler: Handler(handlerFunc: (_, params){
      String topInto = params["top_into"]?.first??"0";
      print("topInto:${topInto}");
      return MaintenanceListPage(topInto: topInto=="1"?true:false,);
    }));
    router.define(maintenanceRecordInfo, handler: Handler(handlerFunc: (_, params){
      var item = params['item'].first;
      MaintenanceListItem _model = MaintenanceListItem.fromJsonMap(convert.jsonDecode(item));
      return MaintenanceRecordInfo(_model);
    }));
    router.define(maintenanceSign, handler: Handler(handlerFunc: (_, params){
      var item = params['item'].first;
      MaintenanceListItem _model = MaintenanceListItem.fromJsonMap(convert.jsonDecode(item));
      return MaintenanceSafePage(_model);
    }));
    router.define(maintenanceSubmit, handler: Handler(handlerFunc: (_, params){
      var item = params['item'].first;
      MaintenanceListItem _model = MaintenanceListItem.fromJsonMap(convert.jsonDecode(item));
      return MaintenanceSubmitPage(_model);
    }));
    router.define(maintenanceDetail, handler: Handler(handlerFunc: (_, params){
      var item = params['item'].first;
      MaintenanceListItem _model = MaintenanceListItem.fromJsonMap(convert.jsonDecode(item));
      return MaintenanceDetailPage(_model);
    }));
    router.define(maintenanceEvaluate, handler: Handler(handlerFunc: (_, params){
      var id = params['id'].first;
      var type = params['type'].first;
      var category = params['category'].first;
      return MaintenanceEvaluatePage(id,int.parse(category),type);
    }));
    router.define(viewImage, handler: Handler(handlerFunc: (_, params){
      var img = params['img'].first;
      var edit = params['edit'].first;
      return ViewImagePage(img: img,edit:edit=="1"?true:false);
    }));
  }
}