import 'dart:convert' as convert;

import 'package:fluro/fluro.dart';
import 'package:liftmanager/internal/lift/model/lift_item.dart';
import 'package:liftmanager/internal/lift/page/lift_brand_page.dart';
import 'package:liftmanager/internal/lift/page/lift_create_page.dart';
import 'package:liftmanager/internal/lift/page/lift_detail_page.dart';
import 'package:liftmanager/internal/lift/page/lift_list_page.dart';
import 'package:liftmanager/internal/lift/page/lift_map_page.dart';
import 'package:liftmanager/routers/router_init.dart';

class LiftRouter implements IRouterProvider{

  static String liftListPage     = "/lift/list";
  static String liftCreatePage     = "/lift/create";
  static String liftDetailPage     = "/lift/detail";
  static String liftBrandPage     = "/lift/brand";
  static String liftMapPage     = "/lift/map";
  @override
  void initRouter(Router router) {
    router.define(liftListPage, handler: Handler(handlerFunc: (_,params){
      String id = params['id']?.first;
      return LiftListPage(id);
    }));
    router.define(liftDetailPage, handler: Handler(handlerFunc: (_,params){
      String projectId = params['project_id']?.first;
      String id = params['id']?.first;
      return LiftDetailPage(projectId,id);
    }));
    router.define(liftCreatePage, handler: Handler(handlerFunc: (_,params){
      var item = params['item']?.first;
      String id = params['id']?.first;
      if(item == null){
        return LiftCreatePage(id);
      }
      LiftItem model = LiftItem.fromJsonMap(convert.jsonDecode(item));
      return LiftCreatePage(id,item: model,);
    }));
    router.define(liftBrandPage, handler: Handler(handlerFunc: (_,params){
      return LiftBrandPage();
    }));
    router.define(liftMapPage, handler: Handler(handlerFunc: (_,params){
      String type = params["type"].first;
      String coordinate = params["coordinate"].first;
      if(type == "look"){
        return LiftMapPage(type: MapPageType.Look,coordinate: coordinate);
      }
      return LiftMapPage();
    }));
  }
}