import 'package:fluro/fluro.dart';
import 'package:liftmanager/internal/repair/model/repair_fault_entity.dart';
import 'package:liftmanager/internal/repair/model/repair_list_entity.dart';
import 'package:liftmanager/internal/repair/page/repair_create_page.dart';
import 'package:liftmanager/internal/repair/page/repair_detail_page.dart';
import 'package:liftmanager/internal/repair/page/repair_evaluate_page.dart';
import 'package:liftmanager/internal/repair/page/repair_fault_page.dart';
import 'package:liftmanager/internal/repair/page/repair_list_page.dart';
import 'package:liftmanager/internal/repair/page/repair_order_page.dart';
import 'package:liftmanager/internal/repair/page/repair_safe_page.dart';
import 'package:liftmanager/internal/repair/page/repair_select_lift_page.dart';
import 'package:liftmanager/internal/repair/page/repair_select_project_page.dart';
import 'package:liftmanager/internal/repair/page/repair_submit_page.dart';
import 'package:liftmanager/internal/repair/page/signature_page.dart';
import 'package:liftmanager/routers/router_init.dart';
import 'dart:convert' as convert;

class RepairRouter implements IRouterProvider{

  static String repairListPage = "/repair/list";
  static String repairDetailPage = "/repair/detail";
  static String repairSafePage = "/repair/safe";
  static String repairSubmitPage = "/repair/submit";
  static String repairOrderPage = "/repair/order";
  static String repairEvaluatePage = "/repair/evaluate";
  static String repairSignaturePage = "/repair/signature";
  static String repairFaultPage = "/repair/fault";
  static String repairCreatePage = "/repair/create";
  static String repairSelectProjectPage = "/repair/select/project";
  static String repairSelectLiftPage = "/repair/select/lift";

  @override
  void initRouter(Router router) {
    router.define(repairListPage, handler: Handler(handlerFunc: (_, params){
      String topInto = params["top_into"]?.first??"0";
      print("topInto:${topInto}");
      return RepairListPage(topInto: topInto=="1"?true:false,);
    }));
    router.define(repairDetailPage, handler: Handler(handlerFunc: (_, params){
      var item = params['item'].first;
      RepairItem _model = RepairItem.fromJsonMap(convert.jsonDecode(item));
      return RepairDetailPage(_model);
    }));
    router.define(repairSafePage, handler: Handler(handlerFunc: (_, params) {
      var item = params['item'].first;
      RepairItem _model = RepairItem.fromJsonMap(convert.jsonDecode(item));
      return RepairSafePage(_model);
    }));
    router.define(repairSubmitPage, handler: Handler(handlerFunc: (_, params) {
      var item = params['item'].first;
      RepairItem _model = RepairItem.fromJsonMap(convert.jsonDecode(item));
      return RepairSubmitPage(_model);
    }));
    router.define(repairOrderPage, handler: Handler(handlerFunc: (_, params) {
      var item = params['item'].first;
      print(item);
      RepairItem _model = RepairItem.fromJsonMap(convert.jsonDecode(item));
      return RepairOrderPage(_model);
    }));
    router.define(repairEvaluatePage, handler: Handler(handlerFunc: (_, params){
//      this.id,{this.isLook=false,this.service=0,this.star=0,this.advice="",this.imgUrl=""
      var id = params["id"].first;
      var islook = params["islook"].first;
      if(islook == "1"){
        var service = params["service"].first;
        var star = params["star"].first;
        var advice = params["advice"].first;
        var imgurl = params["imgurl"].first;
        return RepairEvaluatePage(id,isLook: true,service: service,star: star,advice:advice,imgUrl: imgurl,);
      }
      return RepairEvaluatePage(id,isLook:false);

    }));
    router.define(repairSignaturePage, handler: Handler(handlerFunc: (_, params) => SignaturePage()));
    router.define(repairFaultPage, handler: Handler(handlerFunc: (_, params){
      var title = params["title"].first;
      var item = params['item'].first;
      RepairFaultEntity _model = RepairFaultEntity.fromJsonMap(convert.jsonDecode(item));
      return RepairFaultPage(title,_model);
    }));
    router.define(repairCreatePage, handler: Handler(handlerFunc: (_, params) => RepairCreatePage()));
    router.define(repairSelectProjectPage, handler: Handler(handlerFunc: (_, params) => RepairSelectProjectPage()));
    router.define(repairSelectLiftPage, handler: Handler(handlerFunc: (_, params) => RepairSelectLiftPage(params["id"].first)));

  }
}