import 'package:flutter/cupertino.dart';
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/dialog/select_message_reminder_date_dialog.dart';
import '../../../dialog/select_guard_time_dialog.dart';
import '../select_address/common_point_select_address_page.dart';

@injectable
class CommonPointAddController extends BaseController {
  final TextEditingController titleController = TextEditingController();
  final RxBool _isShowDuplicateName = RxBool(true);

  bool get isShowDuplicateName => _isShowDuplicateName.value;

  final RxnString _guardTimePeriod = RxnString();

  String? get guardTimePeriod => _guardTimePeriod.value;

  DateTime? guardStartTime;
  DateTime? guardEndTime;

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

  void onGuardTimePeriodClick() {
    hideKeyboard(Get.context!);
    SelectGuardTimeDialog.show(
        startDate: guardStartTime,
        endDate: guardEndTime,
        sureCallback: (DateTime startDate, DateTime endDate) {
          guardStartTime = startDate;
          guardEndTime = endDate;
          _guardTimePeriod.value =
              '${startDate.hour.toString().padLeft(2, '0')}:${startDate.minute.toString().padLeft(2, '0')}-${endDate.hour.toString().padLeft(2, '0')}:${endDate.minute.toString().padLeft(2, '0')}';
        });
  }

  void onSelectMessageReminderClick() {
    hideKeyboard(Get.context!);
    SelectMessageReminderDateDialog.show();
  }

  void onSelectAddressClick() {
    hideKeyboard(Get.context!);
    CommonPointSelectAddressPage.start();
  }
}
