import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:injectable/injectable.dart';
import 'package:location/base/base_controller.dart';
import 'package:location/data/bean/common_point_bean.dart';
import 'package:location/handler/error_handler.dart';
import 'package:location/module/commonpoint/add/common_point_add_page.dart';
import 'package:location/module/commonpoint/setting/common_point_setting_page.dart';

import '../../data/repositories/range_point_repository.dart';

@injectable
class CommonPointController extends BaseController {
  final RxList<CommonPointBean> commonPointList = RxList();

  final RangePointRepository rangePointRepository;

  CommonPointController(this.rangePointRepository);

  @override
  void onReady() {
    super.onReady();
    _requestCommonPointList();
  }

  _requestCommonPointList() {
    rangePointRepository.commonPointList().then((response) {
      commonPointList.assignAll(response.list ?? []);
    }).catchError((error) {
      ErrorHandler.toastError(error);
      //增加模拟数据
      commonPointList.assignAll([
        CommonPointBean('家里', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('公司', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('外派公司', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean('约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
        CommonPointBean(
            '约会地点', '广州市海珠区滨江东路江怡路嘉仕花园名仕阁310广州市海珠区滨江东路江怡路嘉仕花园名仕阁310'),
      ]);
    });
  }

  void onBack() {
    Get.back();
  }

  void onSettingClick() {
    CommonPointSettingPage.start();
  }

  void onAddCommonPointClick() {
    CommonPointAddPage.start();
  }
}
