import 'dart:io';

import 'package:get/get.dart';
import 'package:injectable/injectable.dart';
import 'package:location/base/base_controller.dart';
import 'package:location/data/repositories/account_repository.dart';
import 'package:location/handler/event_handler.dart';
import 'package:location/module/browser/browser_view.dart';
import 'package:location/resource/string.gen.dart';
import 'package:location/utils/toast_util.dart';

import '../../data/consts/event_id.dart';
import '../../utils/app_info_util.dart';

@injectable
class FeedBackController extends BaseController {
  final RxString _content = RxString('');

  String get content => _content.value;

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

  set content(String value) {
    _content.value = value;
  }

  void submit() {
    if (content.isEmpty) {
      ToastUtil.show(StringName.feedBackHint);
      return;
    }
    EventHandler.report(EventId.event_8004002,
        params: {EventId.eventFeedbackId: content});
    ToastUtil.show(StringName.feedBackSuccess);
    Get.back();
  }

  void onCustomerServiceClick() {
    String phone = AccountRepository.getInstance().loginPhoneNum.value ?? '';
    String url = "https://qiyu-kefu.atmob.com?"
        "ssid=$phone"
        "&device_id=$phone"
        "&app_platform=${Platform.isAndroid ? 1 : 2}"
        "&app_version=${appInfoUtil.appVersionName}"
        "&package_name=${appInfoUtil.packageName}"
        "&app_name=${Platform.isIOS? StringName.appNameIos : StringName.appName}"
        "&phone=$phone";
    BrowserPage.start(url);
  }
}
