// splash 页面
import 'dart:convert';

import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:sport/bean/post.dart';
import 'package:sport/bean/post_user.dart';
import 'package:sport/bean/game.dart';
import 'package:sport/bean/rank_game_info.dart';
import 'package:sport/bean/user.dart';
import 'package:sport/pages/game/game_detail.dart';
import 'package:sport/pages/game/rank_detail.dart';
import 'package:sport/pages/game/rank_introduce.dart';
import 'package:sport/pages/game/rank_people_detail.dart';
import 'package:sport/pages/home/sport_detail_page.dart';
import 'package:sport/pages/home/sport_history_page.dart';
import 'package:sport/pages/home/target_modify_page.dart';
import 'package:sport/pages/home_page.dart';
import 'package:sport/pages/login/auth_code.dart';
import 'package:sport/pages/login/basic.dart';
import 'package:sport/pages/login/find_password.dart';
import 'package:sport/pages/login/index.dart';
import 'package:sport/pages/login/license.dart';
import 'package:sport/pages/login/register.dart';

import 'package:sport/pages/my/device_info_page.dart';
import 'package:sport/pages/my/user_info_page.dart';
import 'package:sport/pages/setting/account_page.dart';
import 'package:sport/pages/setting/message_setting_page.dart';
import 'package:sport/pages/setting/privacypolicy_page.dart';
import 'package:sport/pages/setting/serviceagreement_page.dart';
import 'package:sport/pages/setting/setting_page.dart';
import 'package:sport/pages/social/post_detail_page.dart';
import 'package:sport/pages/social/post_page.dart';
import 'package:sport/pages/social/social_detail_page.dart';
import 'package:sport/pages/social/user_detail_page.dart';
import 'package:sport/pages/splash_page.dart';

import 'package:sport/pages/game/index.dart';
import 'package:sport/bean/forum.dart';
import 'package:sport/services/Converter.dart';

var splashHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return SplashPage();
});
var homeHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return HomePage();
});

// setting
var settingHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return SettingPage();
});
var privacypolicyHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return PrivacypolicyPage();
});
var serviceagreementHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return ServiceagreementPage();
});
var accountHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return AccountPage();
});
var messageSettingHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return MessageSettingPage();
});

var userInfoHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return UserInfoPage();
});
var deviceInfoHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return DeviceInfoPage();
});

// social
var socialDetailHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return SocialDetailPage(Forum.fromJson(json.decode(params['data'].first)), index: Converter.toInt(params['index']?.first??0),);
});
var socialPostHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return PostPage(params['id'].first);
});
var socialPostDetailHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return PostDetailPage(Post.fromJson(json.decode(params['data'].first)),params['comment'].first == "true", null);
});
var socialUserDetailHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return UserDetailPage(PostUser.fromJson(json.decode(params['data'].first)));
});

// home
var sportDetailHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return SportDetailPage();
});
var sportHistoryHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return SportHistoryPage(
      GameInfoData.fromJson(json.decode(params['details'].first)));
});
var targetModifyHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return TargetModifyPage();
});

// game

var gameIndexHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return GamePage();
});

var gameDetailsHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
//      print(params['details'].first);
  return GameDetailsPage(
      GameInfoData.fromJson(json.decode(params['details'].first)));
});

var rankDetailHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return RankDetailPage(params['id'].first, params['type'].first);
});

var rankPeopleDetailsHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return RankPeopleDetailsPage(
      User.fromJson(json.decode(params['details'].first)));
});

var rankIntroduceHandler = new Handler(
  handlerFunc:  (BuildContext context, Map<String, List<Object>> params) {
    return RankIntroduce(RankGameInfoData.fromJson(json.decode(params['data'].first)));
  });

var loginHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
      if(params != null){
        if(params.containsKey("type")){
          return Login(Converter.toInt(params['type'].first));
        }
      }
  return Login(1);
});

var licenseHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return SportLicensePage();
});

var authCodeHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return AuthCodePage(params['phone'].first);
});

var registerHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return RegisterPage();
});

var basicHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return BasicInfoPage(username: params['username'].first);
});
var findPasswordHandler = new Handler(
    handlerFunc: (BuildContext context, Map<String, List<Object>> params) {
  return FindPasswordPage();
});
