import 'dart:convert';

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:sport/bean/achievement_info.dart';
import 'package:sport/pages/my/achievement_detail_page.dart';
import 'package:sport/pages/my/achievement_page.dart';
import 'package:sport/pages/my/feedback_detail_page.dart';
import 'package:sport/pages/my/feedback_page.dart';
import 'package:sport/pages/my/game_list_page.dart';
import 'package:sport/pages/my/level_page.dart';
import 'package:sport/pages/my/score_shop.dart';
import 'package:sport/pages/my/shop_detail.dart';
import 'package:sport/pages/setting/message_setting_page.dart';
import 'package:sport/pages/social/chat_page.dart';
import 'package:sport/pages/social/message_detail_page.dart';
import 'package:sport/pages/social/message_page.dart';
import 'package:sport/pages/social/search_page.dart';

import 'route_handles.dart';

class Routes {
  static String root = "/";
  static String home = "/home";

  // setting
  static String setting = "/setting";
  static String privacypolicy = "/privacypolicy";
  static String serviceagreement = "/serviceagreement";
  static String account = "/account";
  static String userInfo = "/user_info";
  static String deviceInfo = "/device_info";
  static String messageSetting = "/message_setting";

  // social
  static String socialDetail = "/social_detail";
  static String socialPost = "/post";
  static String socialPostDetail = "/post_detail";
  static String socialUserDetail = "/user_detail";
  static String socialSearch = "/social_search";
  static String socialMessage = "/social_message";
  static String socialMessageDetail = "/social_message_detail";
  static String chat = '/chat';

  // home
  static String sportDetail = "/sport_detail";
  static String sportHistory = "/sport_history";
  static String targetModify = "/target_modify";
  static String rankIntroduce = '/rank_introduce';
  // game
  static String gameIndex = "/game";
  static String gameDetails = "/game_details";
  static String rankDetails = "/rank_details";
  static String rankPeopleDetails = "/rank_people_detals";

  // login
  static String login = "/login";
  static String license = "/license";
  static String authCode = "/authCode";
  static String register = "/register";
  static String basicInfo = "/basicInfo";
  static String findPassword = "/findPassword";

  // mine
  static String achievement = "/achievement";
  static String achievementDetail = "/achievement_detail";
  static String level = "/level";
  static String feedback = "/feedback";
  static String feedbackDetail = "/feedback_detail";
  static String gamelistpage = "/gamelistpage";
  static String scoreShopPage = "/scoreShopPage";
  static String shopPageDetail = '/shopPageDetail';

  static void configureRoutes(Router router) {
    router.notFoundHandler = Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      print("ROUTE WAS NOT FOUND !!!");
      return null;
    });
    router.define(root, handler: splashHandler);
    router.define(home, handler: homeHandler);

    // setting
    router.define(setting, handler: settingHandler);
    router.define(privacypolicy, handler: privacypolicyHandler);
    router.define(serviceagreement, handler: serviceagreementHandler);
    router.define(account, handler: accountHandler);
    router.define(messageSetting, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return MessageSettingPage();
    }));
    router.define(userInfo, handler: userInfoHandler);
    router.define(deviceInfo, handler: deviceInfoHandler);

    // social
    router.define(socialDetail, handler: socialDetailHandler);
    router.define(socialPost, handler: socialPostHandler);
    router.define(socialPostDetail, handler: socialPostDetailHandler);
    router.define(socialUserDetail, handler: socialUserDetailHandler);
    router.define(socialSearch, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return SearchPage();
    }));
    router.define(socialMessage, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return MessagePage();
    }));
    router.define(socialMessageDetail, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return MessageDetailPage(params['data'].first);
    }));

    router.define(chat, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return ChatPage(params['user'].first,post: params['post'].first,);
    }));

    // home
    router.define(sportDetail, handler: sportDetailHandler);
    router.define(sportHistory, handler: sportHistoryHandler);
    router.define(targetModify, handler: targetModifyHandler);

    // game
    router.define(gameIndex, handler: gameIndexHandler);
    router.define(gameDetails, handler: gameDetailsHandler);
    router.define(rankDetails, handler: rankDetailHandler);
    router.define(rankPeopleDetails, handler: rankPeopleDetailsHandler);
    router.define(rankIntroduce, handler: rankIntroduceHandler);

    // login
    router.define(login, handler: loginHandler);
    router.define(license, handler: licenseHandler);
    router.define(authCode, handler: authCodeHandler);
    router.define(register, handler: registerHandler);
    router.define(basicInfo, handler: basicHandler);
    router.define(findPassword, handler: findPasswordHandler);

    // mine
    router.define(achievement, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return AchievementPage(AchievementInfoData.fromJson(json.decode(params['data'].first)));
    }));
    router.define(achievementDetail, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return AchievementDetailPage(int.parse(params['id'].first),int.parse(params['userId'].first));
    }));
    router.define(level, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return LevelPage();
    }));
    router.define(feedback, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return FeedbackPage();
    }));
    router.define(feedbackDetail, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return FeedbackDetailPage(params['data'].first);
    }));
    router.define(gamelistpage, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return GameListPage();
    }));
    router.define(scoreShopPage, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return ScoreShopPage();
    }));
    router.define(scoreShopPage, handler: Handler(handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      return ShopDetailPage();
    }));
  }
}
