import 'package:sharesdk_plugin/sharesdk_interface.dart';
import 'package:sharesdk_plugin/sharesdk_register.dart';
import 'package:zhiying_base_widget/pages/favorite_page/favorite_page.dart';
import 'package:zhiying_base_widget/pages/goods_details_page/goods_details_page.dart';
import 'package:zhiying_base_widget/pages/invited_friends/invited_friends.dart';
import 'package:zhiying_base_widget/pages/launch_page/launch_page.dart';
import 'package:zhiying_base_widget/pages/main_page/main_page.dart';
import 'package:zhiying_base_widget/pages/mine_detail_page/mine_detail_page.dart';
import 'package:zhiying_base_widget/pages/orders_page/orders_page.dart';
import 'package:zhiying_base_widget/pages/search_page/item/search_item_page.dart';
import 'package:zhiying_base_widget/pages/search_result_page/item/search_result_item_page.dart';
import 'package:zhiying_base_widget/pages/search_result_page/search_result_page.dart';
import 'package:zhiying_base_widget/pages/security_page/security_bind_alipay/security_bind_alipay_page.dart';
import 'package:zhiying_base_widget/pages/security_page/security_mobile/security_mobile.dart';
import 'package:zhiying_base_widget/pages/security_page/security_page.dart';
import 'package:zhiying_base_widget/pages/security_page/security_password/security_password.dart';
import 'package:zhiying_base_widget/pages/setting_page/setting_page.dart';
import 'package:zhiying_base_widget/pages/webview/base_webview.dart';
import 'package:zhiying_base_widget/widgets/goods_details/footer/goods_details_footer_widget.dart';
import 'package:zhiying_base_widget/widgets/goods_details/price/goods_details_price_widget.dart';
import 'package:zhiying_base_widget/widgets/goods_details/slide_banner/goods_details_slide_banner_widget.dart';
import 'package:zhiying_base_widget/widgets/goods_details/store/store_widget.dart';
import 'package:zhiying_base_widget/widgets/goods_details/upgrade_tip/upgrade_tip_widget.dart';
import 'package:zhiying_base_widget/widgets/home/home_banner/home_banner_creater.dart';
import 'package:zhiying_base_widget/widgets/home/home_banner/home_banner_widget.dart';
import 'package:zhiying_base_widget/widgets/home/home_goods/home_goods_creater.dart';
import 'package:zhiying_base_widget/widgets/home/home_notice/home_notice_widget.dart';
import 'package:zhiying_base_widget/widgets/home/home_slide_banner/home_slide_banner_creater.dart';
import 'package:zhiying_base_widget/widgets/home/home_sreach/home_sreach_creater.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_data/mine_data.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_header/mine_header.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_nav/mine_nav_bg.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_nav/mine_nav_creater.dart';
import 'package:zhiying_base_widget/widgets/mine/mine_quick_entry/mine_quick_entry.dart';
import 'package:zhiying_base_widget/widgets/others/normal_nav/normal_nav_creater.dart';
import 'package:zhiying_base_widget/widgets/search/tabbar/search_tab_creater.dart';
import 'package:zhiying_base_widget/widgets/search_result/sort/search_result_sort_widget.dart';
import 'package:zhiying_base_widget/widgets/search_result/tarbar/search_result_tab_creater.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_appbar/wallet_appbar.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_bil/wallet_bil.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_data/wallet_data.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_detail/wallet_detail.dart';
import 'package:zhiying_base_widget/widgets/wallet/wallet_income/wallet_income.dart';
import 'package:zhiying_comm/util/defalut_widget_creater.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

import 'pages/search_page/search_page.dart';
import 'pages/wallet_page/wallet_page.dart';
import 'widgets/goods_details/coupon/counpon_widget.dart';
import 'widgets/goods_details/detail_img/goods_details_img.dart';
import 'widgets/goods_details/evaluate/goods_details_evaluate_widget.dart';
import 'widgets/goods_details/recommend/goods_detail_commend_creater.dart';
import 'widgets/goods_details/title/goods_details_title_widget.dart';
import 'widgets/home/home_quick_entry/home_quick_entry.dart';
import 'widgets/home/home_sreach/home_sreach_creater.dart';
import 'widgets/search/history_tag/search_history_tag.dart';
import 'widgets/search/hot_tag/search_hot_tag_widget.dart';
import 'widgets/search/input/search_input_widget.dart';
import 'widgets/search/tabbar/search_tab_creater.dart';
import 'widgets/search_result/goods_list/search_result_goods_list_widget.dart';
import 'widgets/search_result/search_input/search_result_input.dart';

class BaseWidgetRegister {
  /// 初始化方法
  static void init() {
    BaseWidgetRegister.registPage();
    BaseWidgetRegister.registWidgets();
    BaseWidgetRegister.registInit();
  }

  static void registInit() {
    Application.addMethod(() async {
      if (await BaseSettingModel.init() == null) {
        throw Future.error('BaseSettingModel 初始化失败');
      }
    });

    Application.addMethod(() async {
      ShareSDKRegister register = ShareSDKRegister();
      register.setupWechat("wx617c77c82218ea2c",
          "c7253e5289986cf4c4c74d1ccc185fb1", "https://www.sandslee.com/");
      register.setupSinaWeibo("568898243", "38a4f8204cc784f81f9f0daaf31e02e3",
          "http://www.sharesdk.cn");
      register.setupQQ("1111030588", "XoHKlrBybXy7ORBt");
      SharesdkPlugin.regist(register);
    });
  }

  // 注册页面
  static void registPage() {
    PageFactory.regist('homePage', (model) => LaunchPage());
    PageFactory.regist('pub.flutter.index', (model) => MainPage(model));
    PageFactory.regist('pub.flutter.profile', (model) => MainPage(model));
    PageFactory.regist(
        'pub.flutter.my_wallet', (model) => WalletPage(data: model));
    PageFactory.regist('goods_details', (model) => GoodsDetailsPage(model));
    PageFactory.regist('search', (model) => SearchPage(model));
    PageFactory.regist('search_item_page', (model) => SearchItemPage(model));
    PageFactory.regist('search_result', (model) => SearchResultPage(model));
    PageFactory.regist(
        'search_result_item', (model) => SearchResultItemPage(model));
    // PageFactory.regist('search_think_page', (model) => SearchThinkPage(model));
    // PageFactory.regist('login', (model) => LoginPage(model));
    // PageFactory.regist('login_quick', (model) => LoginQuickPage(model));
    // PageFactory.regist('login_account', (model) => LoginAccountPage(model));
    // PageFactory.regist('login_invite', (model) => LoginInvitePage());

    // webview
    PageFactory.regist('pub.flutter.url', (model) => BaseWebview(model));

    PageFactory.regist(
        'pub.flutter.profile_settings', (model) => MineDetailPage());
    PageFactory.regist('pub.flutter.settings', (model) => SettingPage(model));

    PageFactory.regist('pub.flutter.my_order', (model) => OrdersPage(model));
    PageFactory.regist(
        'pub.flutter.account_security', (model) => SecurityPage(model));
    PageFactory.regist('pub.flutter.account_security_alipay',
        (model) => SecurityBindAlipayPage(model));
    // 登录密码
    PageFactory.regist('pub.flutter.account_security_password',
        (model) => SecurityPassword(model));
    // 修改手机号
    PageFactory.regist('pub.flutter.account_security_mobile',
        (model) => SecurityMobile(model));
    // 邀请好友
    PageFactory.regist(
        'pub.flutter.invite_friends', (model) => InvitedFriendsPage(model));
    PageFactory.regist('pub.flutter.fav', (model) => FavoritePage());
  }

  // 注册控件
  static void registWidgets() {
    // ==================== 通用组件
    // 导航栏
    WidgetFactory.regist('normal_nav', NormalNavCreater());

    // ==================== 首页
    // WidgetFactory.regist('index_title', NormalNavCreater());
    /// 首页搜索栏
    WidgetFactory.regist('index_search', HomeSreachCreater());
    // WidgetFactory.regist('index_search',
    //     DefaultWidgetCreater((model) => HomeSreachWidget(model)));

    /// 可滚动banner
    WidgetFactory.regist('index_carousel', HomeSlideBannerCreater());
    WidgetFactory.regist('index_recommend_list', GoodsListCreater());

    /// 首页快速入口
    WidgetFactory.regist(
        'multi_nav', DefaultWidgetCreater((model) => HomeQuickEntry(model)));

    /// 滚动公告
    WidgetFactory.regist('index_placard',
        DefaultWidgetCreater((model) => HomeNoticeWidget(model)));

    /// 不可以滚动banner
    WidgetFactory.regist('index_banner_one', HomeBannerCreater());
    WidgetFactory.regist('index_banner_two', HomeBannerCreater());
    // WidgetFactory.regist('index_taobao_auth_tip', HomeAuthCreater());

    /// ==================== 搜索页面 ==================== ///
    // 搜索标题
    // WidgetFactory.regist('search_index_app_bar', DefaultWidgetCreater((model) => SearchAppbarWidget(model)));
    // 搜索输入框
    WidgetFactory.regist('search_index_input',
        DefaultWidgetCreater((model) => SearchInputWidget(model)));
    // // 搜索tabBar
    WidgetFactory.regist('search_index_icon_list', SearcchTabCreater());
    // WidgetFactory.regist('search_index_icon_list', DefaultWidgetCreater((model) => SearchTabWidget(model)));
    // // 热门搜索标签
    WidgetFactory.regist('search_index_host_keyword',
        DefaultWidgetCreater((model) => SearchHotTagWidget(model)));
    // // 历史搜索标签
    WidgetFactory.regist('search_index_history',
        DefaultWidgetCreater((model) => SearchHistoryTagWidget(model)));

    /// ==================== 搜索结果页面 ==================== ///
    // 输入框
    WidgetFactory.regist('search_result_input',
        DefaultWidgetCreater((model) => SearchResultInputWidget(model)));
    // tabbar
    WidgetFactory.regist('search_result_icon_list', SearchResultTabCreater());

    // 搜索结果页筛选widget 淘宝
    WidgetFactory.regist('search_result_taobao_sort',
        DefaultWidgetCreater((model) => SearchResultSortWidget(model)));
    // 搜索结果的商品列表   淘宝
    WidgetFactory.regist('search_result_taobao_item',
        DefaultWidgetCreater((model) => SearchResultGoodsListWidget(model)));

    // 搜索结果页筛选widget 京东
    WidgetFactory.regist('search_result_jd_sort',
        DefaultWidgetCreater((model) => SearchResultSortWidget(model)));
    // 搜索结果的商品列表  京东
    WidgetFactory.regist('search_result_jd_item',
        DefaultWidgetCreater((model) => SearchResultGoodsListWidget(model)));

    // 搜索结果页筛选widget 苏宁
    WidgetFactory.regist('search_result_suning_sort',
        DefaultWidgetCreater((model) => SearchResultSortWidget(model)));
    // 搜索结果的商品列表  苏宁
    WidgetFactory.regist('search_result_suning_item',
        DefaultWidgetCreater((model) => SearchResultGoodsListWidget(model)));

    // 搜索结果页筛选widget 拼多多
    WidgetFactory.regist('search_result_pdd_sort',
        DefaultWidgetCreater((model) => SearchResultSortWidget(model)));
    // 搜索结果的商品列表  拼多多
    WidgetFactory.regist('search_result_pdd_item',
        DefaultWidgetCreater((model) => SearchResultGoodsListWidget(model)));

    // 搜索结果页筛选widget 唯品会
    WidgetFactory.regist('search_result_vip',
        DefaultWidgetCreater((model) => SearchResultSortWidget(model)));
    // 搜索结果的商品列表  唯品会
    WidgetFactory.regist('search_result_vip_item',
        DefaultWidgetCreater((model) => SearchResultGoodsListWidget(model)));

    // 搜索结果页筛选widget 考拉
    WidgetFactory.regist('search_result_kaola',
        DefaultWidgetCreater((model) => SearchResultSortWidget(model)));
    // 搜索结果的商品列表 考拉
    WidgetFactory.regist('search_result_kaola_item',
        DefaultWidgetCreater((model) => SearchResultGoodsListWidget(model)));

    /// ==================== 商品详情 ==================== ///
    // 商品详情轮播图
    WidgetFactory.regist('product_detail_carousel',
        DefaultWidgetCreater((model) => GoodsDetailsSlideBannerWidget(model)));
    // 商品详情下载APP提示
    WidgetFactory.regist('product_detail_download_tips',
        DefaultWidgetCreater((model) => UpgradeTipWidget(model)));
    // 商品详情价格显示
    WidgetFactory.regist('product_detail_price',
        DefaultWidgetCreater((model) => GoodsDetailsPriceWidget(model)));
    // 商品详情标题
    WidgetFactory.regist('product_detail_title',
        DefaultWidgetCreater((model) => GoodsDetailsTitleWidget(model)));
    // 商品详情优惠劵
    WidgetFactory.regist('product_detail_coupon',
        DefaultWidgetCreater((model) => CounponWidget(model)));
    // 商品详情店铺
    WidgetFactory.regist('product_detail_shop',
        DefaultWidgetCreater((model) => StoreWidget(model)));
    // 商品详情宝贝评价
    WidgetFactory.regist('product_detail_comment',
        DefaultWidgetCreater((model) => GoodsDetailsEvaluateWidget(model)));
    // 商品详情图片
    WidgetFactory.regist('product_detail_img_list',
        DefaultWidgetCreater((model) => GoodsDetailsImgWidget(model)));
    // 商品详情底部推荐列表
    WidgetFactory.regist(
        'product_detail_bottom_rec', GoodsDetailCommendCreater());
    // 商品详情底部
    WidgetFactory.regist('product_detail_bottom',
        DefaultWidgetCreater((model) => GoodsDetailsFooterWidget(model)));

    // ==================== 个人中心
    WidgetFactory.regist('profile_appbar', MineNavCreater());
    WidgetFactory.regist('profile_background',
        DefaultWidgetCreater((model) => MineNavBg(model)));
    WidgetFactory.regist(
        'profile_header', DefaultWidgetCreater((model) => MineHeader(model)));
    WidgetFactory.regist(
        'profile_earning', DefaultWidgetCreater((model) => MineData(model)));
    WidgetFactory.regist('profile_functions',
        DefaultWidgetCreater((model) => MineQuickEntry(model)));
    WidgetFactory.regist('profile_my_functions',
        DefaultWidgetCreater((model) => MineQuickEntry(model)));
    // WidgetFactory.regist('profile_carousel', DefaultWidgetCreater((model) => HomeBannerWidget(model)));
    WidgetFactory.regist('profile_carousel',
        DefaultWidgetCreater((model) => HomeBannerWidget(model)));

    // ==================== 钱包
    WidgetFactory.regist(
        'my_wallet_appbar',
        DefaultWidgetCreater((model) => WalletAppbar(
              data: model,
            )));
    WidgetFactory.regist(
        'my_wallet_header', DefaultWidgetCreater((model) => WalletData(model)));
    WidgetFactory.regist(
        'my_wallet_bil', DefaultWidgetCreater((model) => WalletBil(model)));
//    WidgetFactory.regist(
//        'wallet_detail', DefaultWidgetCreater((model) => WalletDetail()));
//     WidgetFactory.regist('wallet_detail', HomeAuthCreater());
    WidgetFactory.regist('my_wallet_providers',
        DefaultWidgetCreater((model) => WalletDetail(model)));

    WidgetFactory.regist(
        'wallet_income', DefaultWidgetCreater((model) => WalletIncome()));

    //======================= 账单明细
  }
}
