import 'package:electronic_assistant/base/base_controller.dart';
import 'package:electronic_assistant/data/repositories/talk_repository.dart';
import 'package:electronic_assistant/module/talk/summary/view.dart';
import 'package:electronic_assistant/module/talk/todo/view.dart';
import 'package:electronic_assistant/resource/string.gen.dart';
import 'package:electronic_assistant/router/app_pages.dart';
import 'package:electronic_assistant/utils/toast_util.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

import '../../data/bean/talks.dart';
import 'original/view.dart';

class TalkController extends BaseController {
  final talkBean = TalkBean().obs;

  final analyseStatus = TalkStatus.notAnalysis.obs;

  final isShowElectricLow = false.obs;

  final List<String> tabBeans = [
    StringName.talkTabSummary.tr,
    StringName.talkTabMyTask.tr,
    StringName.talkTabOriginal.tr
  ];

  final pages = [SummaryView(), TodoView(), OriginalView()];

  @override
  void onInit() {
    super.onInit();
    getArguments();
  }

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

  void getArguments() {
    if (Get.arguments is TalkBean) {
      talkBean.value = Get.arguments as TalkBean;
      analyseStatus.value = talkBean.value.status ?? TalkStatus.notAnalysis;
    }
  }

  void checkCanAnalyze() {
    String? id = talkBean.value.id;
    double? duration = talkBean.value.duration;
    if (id == null || duration == null) {
      return;
    }
    talkRepository.checkElectric(duration).then((data) {
      if (data.enough) {
        //提交分析
        _requestAnalyze();
      } else {
        isShowElectricLow.value = true;
      }
    }).catchError((error) {
      ToastUtil.showToast(error);
    });
  }

  void _requestAnalyze() {
    //提交文件
  }

  void goElectricStore() {
    //TODO 跳转至商店页
    Get.toNamed(RoutePath.login);
  }
}
