import 'package:application/service/api.dart';
import 'package:application/service/map_watch.dart';
import 'package:application/utils.dart';

import '../../../widget.dart';


enum Flag{
  red, yellow, blue,

  ;

  Color color(){
    return switch(this){
      red=> Colors.red,
      yellow=> Colors.yellow,
      blue=>Colors.blue,
    };
  }
}

class ActiveInfo{
  var id=0;
  var name = '';
  var userList = <UserInfo>[];
}
extension ToActionInfoExt on ToActionInfo{
  ActiveInfo toActiveInfo(){
    return ActiveInfo()
      ..id=actId
      ..userList=userList.map((e) => e.toUserInfo()).toList();
  }
}

class UserInfo{
  var index = 0;
  late String name;
  DateTime? startAt;
  final _isNotShow = false.obs;
  final _flag = Flag.red.obs;
  bool get isNotShow => _isNotShow.value;
  set isNotShow(bool v){
    _isNotShow.value = v;
  }
  Flag get flag => _flag.value;
  set flag(Flag v){
    _flag.value = v;
  }
}
extension ToOrienteerInGameInfoExt on ToOrienteerInGameInfo{
  UserInfo toUserInfo(){
    return UserInfo()
      ..startAt=gameSaveInfo.hasStartAt()? gameSaveInfo.startAt.toDateTime(toLocal: true): null;
  }
}


class UserManageController extends GetxController{
  @override
  void onInit() {
    super.onInit();
    flushData();
  }

  Future<void> flushData()async{
    await tryApi(() async{
      final r = await ApiService.to.stub.toUserDetailQueryV2(ToUserDetailQueryRequestV2()
        ..mapId=MapWatchService.instance?.id.toInt()??0);
      activeList.value = r.list.map((e) => e.toActiveInfo()).toList();
      activeList.value = [
        ActiveInfo()
          ..id=1
          ..name='穿越荒野：勇闯野性之旅'
          ..userList.addAll([
            UserInfo()
              ..index=0
              ..name='123',
            UserInfo()
              ..index=1
              ..name='431'
              ..startAt = DateTime.now(),
          ]),
        ActiveInfo()
          ..id=2
          ..name='极限挑战 战胜重力'
      ];
    });
  }

  final activeList = <ActiveInfo>[].obs;
  final Rx<ActiveInfo?> selectActive = Rx(null);
}