import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:trans_lark/entity/scene_entity.dart';
import 'package:trans_lark/generated/assets.dart';
import 'package:trans_lark/router/router.dart';
import 'package:trans_lark/widget/view_state_widget.dart';

class SceneTypeController extends GetxController {
  var sceneTypeList = <SceneEntity>[].obs;
  var viewState = ViewState.loading.obs;

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

    var data = jsonDecode(await rootBundle.loadString(Assets.jsonTranslationScene));
    if (data != null && data is List) {
      sceneTypeList.value = data.map((e) => SceneEntity.fromMap(e)).toList();
    }
    viewState.value = sceneTypeList.isNotEmpty ? ViewState.normal : ViewState.empty;
  }

  void onTapItem(SceneEntity item) {
    Get.toNamed(GetRouter.sceneList, arguments: item.sceneList);
  }
}
