import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:liftmanager/internal/account/account_router.dart';
import 'package:liftmanager/internal/bbs/bbs_router.dart';
import 'package:liftmanager/internal/means/means_router.dart';
import 'package:liftmanager/internal/friends/friends_router.dart';
import 'package:liftmanager/internal/home/home_page.dart';
import 'package:liftmanager/internal/home/webview_page.dart';
import 'package:liftmanager/internal/lift/lift_router.dart';
import 'package:liftmanager/internal/maintenance/maintenance_router.dart';
import 'package:liftmanager/internal/project/project_router.dart';
import 'package:liftmanager/internal/repair/repair_router.dart';
import 'package:liftmanager/internal/yearly/yearly_router.dart';
import 'package:liftmanager/routers/router_init.dart';
import 'package:liftmanager/internal/search/search_router.dart';
import 'package:liftmanager/internal/sign/sign_router.dart';
import 'package:liftmanager/internal/wode/wode_router.dart';
import 'package:liftmanager/internal/team/team_router.dart';
import 'package:liftmanager/internal/message/message_router.dart';
import 'package:liftmanager/internal/news/news_router.dart';
import 'package:liftmanager/internal/hospital/hospital_roter.dart';
import 'package:liftmanager/internal/heavy/heavy_router.dart';

import '404.dart';

class Routers {
  static String home = "/home";
  static String webViewPage = "/webview";

  static List<IRouterProvider> _listRouter = [];

  static void configureRouters(Router router){
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
          debugPrint("未找到目标页");
          return WidgetNotFound();
        });

    router.define(home, handler: Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) => HomePage()));

    router.define(webViewPage, handler: Handler(handlerFunc: (_, params){
      String title = params['title']?.first;
      String url = params['url']?.first;
      return WebViewPage(title: title, url: url);
    }));

    _listRouter.clear();
    /// 各自路由由各自模块管理，统一在此添加初始化
//    _listRouter.add(ShopRouter());
    _listRouter.add(AccountRouter());
    _listRouter.add(ProjectRouter());
    _listRouter.add(WodeRouter());
    _listRouter.add(SearchRouter());
    _listRouter.add(SignRouter());
    _listRouter.add(LiftRouter());
    _listRouter.add(RepairRouter());
    _listRouter.add(YearlyRouter());
    _listRouter.add(MaintenanceRouter());
    _listRouter.add(BbsRouter());
    _listRouter.add(MeansRouter());
    _listRouter.add(FriendsRouter());
    _listRouter.add(TeamRouter());
    _listRouter.add(NewsRouter());
    _listRouter.add(HeavyRouter());
    _listRouter.add(MessageRouter());
    _listRouter.add(HospitalRouter());
//    _listRouter.add(StatisticsRouter());

    /// 初始化路由
    _listRouter.forEach((routerProvider){
      routerProvider.initRouter(router);
    });
  }
}