/// Getx路由管理
library;

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:loopin/bings/chat_binding.dart';
import 'package:loopin/pages/chat/chat.dart';
import 'package:loopin/pages/chat/chat_group.dart';
import 'package:loopin/pages/chat/chat_no_friend.dart';
import 'package:loopin/pages/chat/notify/interaction.dart';
import 'package:loopin/pages/chat/notify/newFoucs.dart';
import 'package:loopin/pages/chat/notify/noFriend.dart';
import 'package:loopin/pages/chat/notify/orderNotify.dart';
import 'package:loopin/pages/groupChat/groupList.dart';
import 'package:loopin/pages/groupChat/index.dart';
import 'package:loopin/pages/my/all_function.dart';
import 'package:loopin/pages/my/delete.dart';
import 'package:loopin/pages/my/des.dart';
import 'package:loopin/pages/my/fans.dart';
import 'package:loopin/pages/my/flowing.dart';
import 'package:loopin/pages/my/merchant/income.dart';
import 'package:loopin/pages/my/mutual_followers.dart';
import 'package:loopin/pages/my/nick_name.dart';
import 'package:loopin/pages/my/setting.dart';
import 'package:loopin/pages/my/user_info.dart';
import 'package:loopin/pages/my/vloger.dart';
import 'package:loopin/pages/order/my_order.dart';
import 'package:loopin/pages/order/seller_order.dart';
import 'package:loopin/pages/search/index.dart';
import 'package:loopin/pages/search/search_result.dart';
import 'package:loopin/pages/video/commonVideo.dart';
import 'package:loopin/pages/video/report.dart';

import '../layouts/index.dart';
/* 引入路由页面 */
import '../pages/auth/login.dart';
// 商品详细
import '../pages/goods/detail.dart';
import '../pages/order/detail.dart';
import '../pages/order/seller_detail.dart';
// 引入工具类
import '../utils/common.dart';

// 路由地址集合
final Map<String, Widget> routes = {
  '/': const Layout(),
  '/goods': const Goods(),
  // '/chatNoFriend': const ChatNoFriend(),
  // '/chatGroup': const ChatGroup(),
  // '/order': const Order(),
  '/sellerOrder': const SellerOrder(),
  '/sellerOrder/detail': const SellerOrderDetail(),
  '/myOrder': const MyOrder(),
  '/order/detail': const OrderDetail(),
  '/vloger': const Vloger(),
  '/report': const ReportPage(),
  '/videoDetail': const VideoDetailPage(),
  '/search': const SearchPage(),
  '/search-result': const SearchResultPage(),
  //settins
  '/setting': const Setting(),
  '/functions': const AllFunctionsPage(),
  '/merchant/income': const SellerRevenue(),
  '/userInfo': const UserInfo(),
  '/notifications': const Setting(),
  '/privacy': const Setting(),
  '/about': const Setting(),
  '/des': const Des(),
  '/nickName': const NickName(),
  '/delete': const Delete(),

  //通知相关
  '/noFriend': const Nofriend(),
  '/newFocus': const Newfoucs(),
  // '/system': const System(),
  '/interaction': const Interaction(),
  '/order': const OrderNotify(),

  //关系链
  '/fans': const Fans(),
  '/flow': const Flowing(),
  '/eachFlow': const MutualFollowers(),
  //群
  '/group': const StartGroupChatPage(), // 创建群聊
  '/groupList': const Grouplist(), // 已入群列表
};

final List<GetPage> routeList = routes.entries
    .map((e) => GetPage(
          name: e.key, // 路由名称
          page: () => e.value, // 路由页面
          // transition: Transition.rightToLeftWithFade, // 跳转路由动画
          transition: Transition.rightToLeft, // 跳转路由动画
          middlewares: [RouteMiddleware()], // 路由中间件
        ))
    .toList();

final List<GetPage> bingsRoutes = [
  GetPage(
    name: '/chat',
    page: () => const Chat(),
    binding: ChatBinding(),
    transition: Transition.rightToLeft,
    middlewares: [RouteMiddleware()],
  ),
  GetPage(
    name: '/chatNoFriend',
    page: () => const ChatNoFriend(),
    binding: ChatBinding(),
    transition: Transition.rightToLeft,
    middlewares: [RouteMiddleware()],
  ),
  GetPage(
    name: '/chatGroup',
    page: () => const ChatGroup(),
    binding: ChatBinding(),
    transition: Transition.rightToLeft,
    middlewares: [RouteMiddleware()],
  ),
];

final List<GetPage> routePages = [
  GetPage(name: '/login', page: () => const Login()),
  ...routeList,
  ...bingsRoutes,
];

// 路由中间件拦截验证
class RouteMiddleware extends GetMiddleware {
  @override
  RouteSettings? redirect(String? route) {
    return Common.isLogin()
        ? null
        : const RouteSettings(
            name: '/login',
          );
  }
}
